Skip to content

Commit

Permalink
Desktop: Made the same spellcheck languages more specific in the titl…
Browse files Browse the repository at this point in the history
…e bar

- Fixed the issue laurent22#7834

- added "spellCheckerMenu.test.ts" to test the changes and the expected behavior: all passed!

- added jest.mock in "jest.setup.js" to mock the Menu from @electron/remote.

-  modified "buildScriptIndexes" to ignore ".test.ts" files so it does not include them in index.ts. That caused some issues with duplicate identifiers and more errors.
  • Loading branch information
HahaBill committed Feb 22, 2024
1 parent 4c5e708 commit b07903c
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 4 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@
"eslint-plugin-github": "4.10.1",
"http-server": "14.1.1",
"node-gyp": "9.4.1",
"nodemon": "3.0.3"
"nodemon": "3.0.3",
"sharp": "0.33.2"
},
"packageManager": "yarn@3.6.4",
"resolutions": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { runtime } from './showSpellCheckerMenu';
import { AppState } from '../../../app.reducer';

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-GB, en-US, en-CA, es-ES, es-MX');

});
});
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ 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]);
s.push(language);
});

return s.join(', ');
},
};
Expand Down
12 changes: 12 additions & 0 deletions packages/app-desktop/jest.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ jest.mock('@electron/remote', () => {
};
});

// Mocking bridge().Menu for showSpellCheckerMenu.test.ts
jest.mock('./services/bridge', () => ({
__esModule: true,
default: () => ({
Menu: {
buildFromTemplate: jest.fn().mockReturnValue({
popup: jest.fn(),
}),
},
}),
}));

// Import after mocking problematic libraries
const { afterEachCleanUp, afterAllCleanUp } = require('@joplin/lib/testing/test-utils.js');

Expand Down
2 changes: 1 addition & 1 deletion packages/tools/gulp/tasks/buildScriptIndexes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ 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 && !f.endsWith('.test.ts'));

tsFiles.sort();

Expand Down
3 changes: 2 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37327,6 +37327,7 @@ __metadata:
node-gyp: 9.4.1
nodemon: 3.0.3
npm-package-json-lint: 7.1.0
sharp: ^0.33.2
typescript: 5.2.2
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -38055,7 +38056,7 @@ __metadata:
languageName: node
linkType: hard

"sharp@npm:0.33.2":
"sharp@npm:0.33.2, sharp@npm:^0.33.2":
version: 0.33.2
resolution: "sharp@npm:0.33.2"
dependencies:
Expand Down

0 comments on commit b07903c

Please sign in to comment.