From 99c6c9b4116dd686059a8b82ad5e6113d5f2dc48 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Wed, 8 Mar 2023 19:23:49 +0000 Subject: [PATCH] Tools: Add more eslint/jest rules --- .eslintrc.js | 2 ++ packages/app-desktop/app.reducer.test.ts | 2 +- .../ResizableLayout/utils/movements.test.ts | 6 ++-- .../CodeMirror/markdownCommands.test.ts | 12 -------- .../components/getResponsiveValue.test.ts | 4 +-- packages/lib/models/Note.test.ts | 8 ++--- .../searchengine/SearchFilter.test.ts | 4 +-- packages/pdf-viewer/pdfSource.test.ts | 8 ++--- packages/server/src/models/UserModel.test.ts | 29 ------------------- 9 files changed, 18 insertions(+), 57 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 7f75e0239..3d27a21da 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -92,6 +92,8 @@ module.exports = { // "react-hooks/exhaustive-deps": "warn", 'jest/require-top-level-describe': ['error', { 'maxNumberOfTopLevelDescribes': 1 }], + 'jest/no-identical-title': ['error'], + 'jest/prefer-lowercase-title': ['error', { 'ignoreTopLevelDescribe': true }], 'promise/prefer-await-to-then': 'error', 'no-unneeded-ternary': 'error', diff --git a/packages/app-desktop/app.reducer.test.ts b/packages/app-desktop/app.reducer.test.ts index 69522946f..d24b374a7 100644 --- a/packages/app-desktop/app.reducer.test.ts +++ b/packages/app-desktop/app.reducer.test.ts @@ -3,7 +3,7 @@ import appReducer, { createAppDefaultState } from './app.reducer'; describe('app.reducer', () => { - it('DIALOG_OPEN', async () => { + it('should handle DIALOG_OPEN', async () => { const state: AppState = createAppDefaultState({}, {}); let newState = appReducer(state, { diff --git a/packages/app-desktop/gui/ResizableLayout/utils/movements.test.ts b/packages/app-desktop/gui/ResizableLayout/utils/movements.test.ts index 805464982..ed85ecb54 100644 --- a/packages/app-desktop/gui/ResizableLayout/utils/movements.test.ts +++ b/packages/app-desktop/gui/ResizableLayout/utils/movements.test.ts @@ -147,7 +147,7 @@ describe('movements', () => { expect(canMove(MoveDirection.Right, findItemByKey(layout, 'col2'), findItemByKey(layout, 'root'))).toBe(false); }); - test('Container with only one child should take the width of its parent', () => { + test('container with only one child should take the width of its parent', () => { let layout: LayoutItem = validateLayout({ key: 'root', width: 100, @@ -170,7 +170,7 @@ describe('movements', () => { expect(layout.children[0].children[0].width).toBe(undefined); }); - test('Temp container should take the width of the child it replaces', () => { + test('temp container should take the width of the child it replaces', () => { let layout: LayoutItem = validateLayout({ key: 'root', width: 100, @@ -198,7 +198,7 @@ describe('movements', () => { expect(layout.children[0].children[1].width).toBe(undefined); }); - test('Last child should have flexible width if all siblings have fixed width', () => { + test('last child should have flexible width if all siblings have fixed width', () => { let layout: LayoutItem = validateLayout({ key: 'root', width: 100, diff --git a/packages/app-mobile/components/NoteEditor/CodeMirror/markdownCommands.test.ts b/packages/app-mobile/components/NoteEditor/CodeMirror/markdownCommands.test.ts index 29344fd3a..341ef6c40 100644 --- a/packages/app-mobile/components/NoteEditor/CodeMirror/markdownCommands.test.ts +++ b/packages/app-mobile/components/NoteEditor/CodeMirror/markdownCommands.test.ts @@ -239,17 +239,5 @@ describe('markdownCommands', () => { expect(sel.from).toBe('> Testing...> \n> \n'.length); expect(sel.to).toBe(editor.state.doc.length); }); - - it('toggling inline code should both create and navigate out of an inline code region', async () => { - const initialDocText = 'Testing...\n\n'; - const editor = await createEditor(initialDocText, EditorSelection.cursor(initialDocText.length), []); - - toggleCode(editor); - editor.dispatch(editor.state.replaceSelection('f(x) = ...')); - toggleCode(editor); - - editor.dispatch(editor.state.replaceSelection(' is a function.')); - expect(editor.state.doc.toString()).toBe('Testing...\n\n`f(x) = ...` is a function.'); - }); }); diff --git a/packages/app-mobile/components/getResponsiveValue.test.ts b/packages/app-mobile/components/getResponsiveValue.test.ts index 4cdf9d634..e837ad587 100644 --- a/packages/app-mobile/components/getResponsiveValue.test.ts +++ b/packages/app-mobile/components/getResponsiveValue.test.ts @@ -25,12 +25,12 @@ const testCases: testCase[] = [ describe('getResponsiveValue', () => { - test('Should throw exception if value map is an empty object', () => { + test('should throw exception if value map is an empty object', () => { const input = {}; expect(() => getResponsiveValue(input)).toThrow('valueMap cannot be an empty object!'); }); - test('Should return correct values', () => { + test('should return correct values', () => { const mockReturnValues = [ { width: 400 }, { width: 480 }, diff --git a/packages/lib/models/Note.test.ts b/packages/lib/models/Note.test.ts index 407df9bfc..bc86b9f5f 100644 --- a/packages/lib/models/Note.test.ts +++ b/packages/lib/models/Note.test.ts @@ -413,28 +413,28 @@ describe('models/Note', () => { expect(Note['replaceResourceExternalToInternalLinks_'](pathsToTry, body)).toBe(expected); } - test('Basic replacement', () => { + test('basic replacement', () => { const body = '![image.png](file:///C:Users/Username/resources/849eae4dade045298c107fc706b6d2bc.png?t=1655192326803)'; const pathsToTry = ['file:///C:Users/Username/resources']; const expected = '![image.png](:/849eae4dade045298c107fc706b6d2bc)'; testResourceReplacment(body, pathsToTry, expected); }); - test('Replacement with spaces', () => { + test('replacement with spaces', () => { const body = '![image.png](file:///C:Users/Username%20with%20spaces/resources/849eae4dade045298c107fc706b6d2bc.png?t=1655192326803)'; const pathsToTry = ['file:///C:Users/Username with spaces/resources']; const expected = '![image.png](:/849eae4dade045298c107fc706b6d2bc)'; testResourceReplacment(body, pathsToTry, expected); }); - test('Replacement with Non-ASCII', () => { + test('replacement with Non-ASCII', () => { const body = '![image.png](file:///C:Users/UsernameWith%C3%A9%C3%A0%C3%B6/resources/849eae4dade045298c107fc706b6d2bc.png?t=1655192326803)'; const pathsToTry = ['file:///C:Users/UsernameWithéàö/resources']; const expected = '![image.png](:/849eae4dade045298c107fc706b6d2bc)'; testResourceReplacment(body, pathsToTry, expected); }); - test('Replacement with Non-ASCII and spaces', () => { + test('replacement with Non-ASCII and spaces', () => { const body = '![image.png](file:///C:Users/Username%20With%20%C3%A9%C3%A0%C3%B6/resources/849eae4dade045298c107fc706b6d2bc.png?t=1655192326803)'; const pathsToTry = ['file:///C:Users/Username With éàö/resources']; const expected = '![image.png](:/849eae4dade045298c107fc706b6d2bc)'; diff --git a/packages/lib/services/searchengine/SearchFilter.test.ts b/packages/lib/services/searchengine/SearchFilter.test.ts index 80dad9cf1..58422087d 100644 --- a/packages/lib/services/searchengine/SearchFilter.test.ts +++ b/packages/lib/services/searchengine/SearchFilter.test.ts @@ -66,7 +66,7 @@ describe('services_SearchFilter', () => { for (const searchType of [SearchEngine.SEARCH_TYPE_FTS, SearchEngine.SEARCH_TYPE_NONLATIN_SCRIPT]) { describe(`search type ${searchType}`, () => { - it('Check case insensitivity for filter keywords', (async () => { + it('check case insensitivity for filter keywords', (async () => { let rows; const notebook1 = await Folder.save({ title: 'folderA' }); const notebook2 = await Folder.save({ title: 'folderB' }); @@ -311,7 +311,7 @@ describe('services_SearchFilter', () => { })); - it('should support filtering by tags', (async () => { + it('should support filtering by tags (2)', (async () => { let rows; const n1 = await Note.save({ title: 'peace talks', body: 'battle ground' }); const n2 = await Note.save({ title: 'mouse', body: 'mister' }); diff --git a/packages/pdf-viewer/pdfSource.test.ts b/packages/pdf-viewer/pdfSource.test.ts index 12f14dbc4..12154e267 100644 --- a/packages/pdf-viewer/pdfSource.test.ts +++ b/packages/pdf-viewer/pdfSource.test.ts @@ -22,7 +22,7 @@ function loadFile(filePath: string) { describe('pdfData', () => { - test('Should have correct page count', async () => { + test('should have correct page count', async () => { const file = await loadFile(pdfFilePath1); const pdf = new PdfDocument(document); await pdf.loadDoc(file); @@ -39,7 +39,7 @@ describe('pdfData', () => { // }).rejects.toThrowError(); // }); - test('Should get correct page size', async () => { + test('should get correct page size', async () => { const file = await loadFile(pdfFilePath1); const pdf = new PdfDocument(document); await pdf.loadDoc(file); @@ -48,7 +48,7 @@ describe('pdfData', () => { expect(size.width).toBeCloseTo(594.95996); }); - test('Should calculate scaled size', async () => { + test('should calculate scaled size', async () => { const file = await loadFile(pdfFilePath1); const pdf = new PdfDocument(document); await pdf.loadDoc(file); @@ -56,7 +56,7 @@ describe('pdfData', () => { expect(scaledSize.scale).toBeCloseTo(0.336157); }); - test('Should get correct active page', async () => { + test('should get correct active page', async () => { const file = await loadFile(pdfFilePath1); const pdf = new PdfDocument(document); await pdf.loadDoc(file); diff --git a/packages/server/src/models/UserModel.test.ts b/packages/server/src/models/UserModel.test.ts index f17ef8646..adc3183e6 100644 --- a/packages/server/src/models/UserModel.test.ts +++ b/packages/server/src/models/UserModel.test.ts @@ -237,35 +237,6 @@ describe('UserModel', () => { stripeConfig().enabled = false; }); - test('should disable disable the account and send an email if payment failed for good', async () => { - stripeConfig().enabled = true; - - const { user: user1 } = await models().subscription().saveUserAndSubscription('toto@example.com', 'Toto', AccountType.Basic, 'usr_111', 'sub_111'); - - const sub = await models().subscription().byUserId(user1.id); - - const now = Date.now(); - const paymentFailedTime = now - failedPaymentFinalAccount - 10; - await models().subscription().save({ - id: sub.id, - last_payment_time: now - failedPaymentFinalAccount * 2, - last_payment_failed_time: paymentFailedTime, - }); - - await models().user().handleFailedPaymentSubscriptions(); - - { - const user1 = await models().user().loadByEmail('toto@example.com'); - expect(user1.enabled).toBe(0); - - const email = (await models().email().all()).pop(); - expect(email.key).toBe(`payment_failed_account_disabled_${paymentFailedTime}`); - expect(email.body).toContain(stripePortalUrl()); - } - - stripeConfig().enabled = false; - }); - test('should send emails and flag accounts when it is over the size limit', async () => { const { user: user1 } = await createUserAndSession(1); const { user: user2 } = await createUserAndSession(2);