Desktop: Fixes #7834: Merged shorthand variants of spellcheck languages (#9983)

pull/10003/head
Ton Hoang Nguyen (Bill) 2024-02-26 10:27:34 +00:00 committed by GitHub
parent 0b63ba1a28
commit 64684dc896
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 62 additions and 2 deletions

View File

@ -230,6 +230,7 @@ packages/app-desktop/gui/MainScreen/commands/showNoteProperties.js
packages/app-desktop/gui/MainScreen/commands/showPrompt.js
packages/app-desktop/gui/MainScreen/commands/showShareFolderDialog.js
packages/app-desktop/gui/MainScreen/commands/showShareNoteDialog.js
packages/app-desktop/gui/MainScreen/commands/showSpellCheckerMenu.test.js
packages/app-desktop/gui/MainScreen/commands/showSpellCheckerMenu.js
packages/app-desktop/gui/MainScreen/commands/toggleEditors.js
packages/app-desktop/gui/MainScreen/commands/toggleLayoutMoveMode.js

1
.gitignore vendored
View File

@ -210,6 +210,7 @@ packages/app-desktop/gui/MainScreen/commands/showNoteProperties.js
packages/app-desktop/gui/MainScreen/commands/showPrompt.js
packages/app-desktop/gui/MainScreen/commands/showShareFolderDialog.js
packages/app-desktop/gui/MainScreen/commands/showShareNoteDialog.js
packages/app-desktop/gui/MainScreen/commands/showSpellCheckerMenu.test.js
packages/app-desktop/gui/MainScreen/commands/showSpellCheckerMenu.js
packages/app-desktop/gui/MainScreen/commands/toggleEditors.js
packages/app-desktop/gui/MainScreen/commands/toggleLayoutMoveMode.js

View File

@ -0,0 +1,51 @@
import { runtime } from './showSpellCheckerMenu';
import { AppState } from '../../../app.reducer';
jest.mock('../../../services/bridge', () => ({
__esModule: true,
default: () => ({
Menu: {
buildFromTemplate: jest.fn().mockReturnValue({
popup: jest.fn(),
}),
},
}),
}));
describe('mapStateTotitle', () => {
test('should return null if spellchecker.enabled is false', () => {
const mockState: Partial<AppState> = {
settings: {
'spellChecker.enabled': false,
'spellChecker.languages': ['en-GB'],
},
};
const result = runtime().mapStateToTitle(mockState);
expect(result).toBeNull();
});
test('should return null if spellChecker.languages is empty', () => {
const mockState: Partial<AppState> = {
settings: {
'spellChecker.enabled': true,
'spellChecker.languages': [],
},
};
const result = runtime().mapStateToTitle(mockState);
expect(result).toBeNull();
});
test('should return list of countryDisplayName with correct format', () => {
const mockState: Partial<AppState> = {
settings: {
'spellChecker.enabled': true,
'spellChecker.languages': ['en-GB', 'en-US', 'en-CA', 'es-ES', 'es-MX'],
},
};
const result = runtime().mapStateToTitle(mockState);
expect(result).toBe('en, es');
});
});

View File

@ -30,8 +30,10 @@ export const runtime = (): CommandRuntime => {
const s: string[] = [];
// eslint-disable-next-line github/array-foreach -- Old code before rule was applied
languages.forEach((language: string) => {
s.push(language.split('-')[0]);
const onlyLanguage = language.split('-')[0];
if (!s.includes(onlyLanguage)) { s.push(onlyLanguage); }
});
return s.join(', ');
},
};

View File

@ -12,7 +12,12 @@ async function processDirectory(dir, indexFilePath = null, typeScriptType = null
const tsFiles = glob.sync('{**/*.ts,**/*.tsx}', {
cwd: dir,
}).filter(f => `${dir}/${f}` !== indexFilePath);
}).filter(f => `${dir}/${f}` !== indexFilePath)
//
// Exclude Jest test files to
// not include them in index.ts
//
.filter(f => !f.endsWith('.test.ts'));
tsFiles.sort();