From 0bfd066d576c074ef6041530bcf62805f8b80588 Mon Sep 17 00:00:00 2001 From: Nicolas Ramz Date: Wed, 15 May 2024 10:50:57 +0200 Subject: [PATCH] Cypress: added missing mocks Also fixed some unit tests that needed to be updated --- .github/workflows/github-actions-tests.yml | 8 ++++- e2e/cypress/mocks/electron.js | 5 +++ jest.config.js | 1 - package-lock.json | 23 ------------ package.json | 1 - setupTests.ts | 18 ++++++++++ .../__tests__/shortcutsDialog.test.tsx | 4 +-- src/services/__tests__/FsSort.test.ts | 36 +++++++------------ .../plugins/__tests__/FsLocal.test.ts | 5 +-- 9 files changed, 45 insertions(+), 56 deletions(-) diff --git a/.github/workflows/github-actions-tests.yml b/.github/workflows/github-actions-tests.yml index bde8e530..8d209dd1 100644 --- a/.github/workflows/github-actions-tests.yml +++ b/.github/workflows/github-actions-tests.yml @@ -5,7 +5,7 @@ jobs: strategy: fail-fast: false matrix: - node-version: [14.x] + node-version: [16.x] os: [ubuntu-latest] experimental: [false] # include: @@ -26,6 +26,12 @@ jobs: with: node-version: ${{ matrix.node-version }} cache: 'npm' + - name: Install + run: | + if [ "$RUNNER_OS" == "Linux" ]; then + sudo apt-get install -y libpango-1.0-0 + fi + shell: bash - name: Install node_modules working-directory: ./ run: npm ci diff --git a/e2e/cypress/mocks/electron.js b/e2e/cypress/mocks/electron.js index c5887c1d..6a1a4318 100644 --- a/e2e/cypress/mocks/electron.js +++ b/e2e/cypress/mocks/electron.js @@ -42,5 +42,10 @@ module.exports = { writeText: function(text) { // } + }, + webFrame: { + setVisualZoomLevelLimits: function (minimumLevel, maximumLevel) { + // + } } }; diff --git a/jest.config.js b/jest.config.js index 904d0727..c29ca0d4 100644 --- a/jest.config.js +++ b/jest.config.js @@ -6,7 +6,6 @@ module.exports = { preset: 'ts-jest', setupFilesAfterEnv: [ "/setupTests.ts", - 'jest-canvas-mock' ], moduleDirectories: [ 'node_modules', diff --git a/package-lock.json b/package-lock.json index 71a4a68c..5fea6d05 100644 --- a/package-lock.json +++ b/package-lock.json @@ -69,7 +69,6 @@ "husky": "^3.0.9", "identity-obj-proxy": "^3.0.0", "jest": "^29.3.1", - "jest-canvas-mock": "^2.4.0", "jest-cli": "^29.3.1", "jest-environment-jsdom": "^29.3.1", "lint-staged": "^10.4.2", @@ -5059,11 +5058,6 @@ "node": ">=4" } }, - "node_modules/cssfontparser": { - "version": "1.2.1", - "dev": true, - "license": "MIT" - }, "node_modules/cssom": { "version": "0.5.0", "dev": true, @@ -8705,15 +8699,6 @@ } } }, - "node_modules/jest-canvas-mock": { - "version": "2.4.0", - "dev": true, - "license": "MIT", - "dependencies": { - "cssfontparser": "^1.2.1", - "moo-color": "^1.0.2" - } - }, "node_modules/jest-changed-files": { "version": "29.2.0", "dev": true, @@ -10803,14 +10788,6 @@ "dev": true, "license": "MIT" }, - "node_modules/moo-color": { - "version": "1.0.3", - "dev": true, - "license": "MIT", - "dependencies": { - "color-name": "^1.1.4" - } - }, "node_modules/ms": { "version": "2.1.2", "devOptional": true, diff --git a/package.json b/package.json index 3f186a77..851d2e20 100644 --- a/package.json +++ b/package.json @@ -97,7 +97,6 @@ "husky": "^3.0.9", "identity-obj-proxy": "^3.0.0", "jest": "^29.3.1", - "jest-canvas-mock": "^2.4.0", "jest-cli": "^29.3.1", "jest-environment-jsdom": "^29.3.1", "lint-staged": "^10.4.2", diff --git a/setupTests.ts b/setupTests.ts index 2e23bd75..262bb2ff 100644 --- a/setupTests.ts +++ b/setupTests.ts @@ -2,3 +2,21 @@ import '@testing-library/jest-dom' import '@testing-library/jest-dom/extend-expect' global.console.error = jest.fn() + +interface KeyboardIterator extends Iterator<[string, string]> { + length: number + [key: number]: [string, string] +} + +interface KeyboardMap { + entries: () => KeyboardIterator +} + +// some tests are not executed with dom so won't have navigator property defined +if (global.navigator) + global.navigator.keyboard = { + getLayoutMap: () => + Promise.resolve(({ + entries: () => [] as unknown as [string, string], + } as unknown as KeyboardMap)), + } diff --git a/src/components/dialogs/__tests__/shortcutsDialog.test.tsx b/src/components/dialogs/__tests__/shortcutsDialog.test.tsx index 9fc6c2dd..372299c6 100644 --- a/src/components/dialogs/__tests__/shortcutsDialog.test.tsx +++ b/src/components/dialogs/__tests__/shortcutsDialog.test.tsx @@ -15,9 +15,9 @@ describe('ShortcutsDialog', () => { beforeEach(() => jest.resetAllMocks()) describe('shortcuts list', () => { - it('should render shortcuts', () => { + it('should render shortcuts', async () => { render() - expect(screen.getByText(exitLabel)).toBeInTheDocument() + expect(await screen.findByText(exitLabel)).toBeInTheDocument() expect(screen.getByText(reloadViewLabel)).toBeInTheDocument() }) diff --git a/src/services/__tests__/FsSort.test.ts b/src/services/__tests__/FsSort.test.ts index 49905b75..e387273a 100644 --- a/src/services/__tests__/FsSort.test.ts +++ b/src/services/__tests__/FsSort.test.ts @@ -17,10 +17,7 @@ const files: Array = [ mode: 16877, isDir: true, readonly: false, - id: { - ino: 0n, - dev: 1n, - }, + id: '0-1', isSym: false, target: '', type: '', @@ -37,10 +34,7 @@ const files: Array = [ mode: 33188, isDir: false, readonly: false, - id: { - ino: 1n, - dev: 1n, - }, + id: '1-1', isSym: false, target: '', type: '', @@ -57,10 +51,7 @@ const files: Array = [ mode: 33188, isDir: false, readonly: false, - id: { - ino: 2n, - dev: 1n, - }, + id: '2-1', isSym: false, target: '', type: '', @@ -77,10 +68,7 @@ const files: Array = [ mode: 33188, isDir: false, readonly: false, - id: { - ino: 3n, - dev: 1n, - }, + id: '3-1', isSym: false, target: '', type: '', @@ -90,25 +78,25 @@ const files: Array = [ describe('sorting methods', () => { it('sort by Name/Asc', () => { const sortMethod = getSortMethod('name', 'asc') - const sorted_ids = files.sort(sortMethod).map((file) => file.id.ino) - expect(sorted_ids).toEqual([2n, 0n, 1n, 3n]) + const sorted_ids = files.sort(sortMethod).map((file) => file.id) + expect(sorted_ids).toEqual(['2-1', '0-1', '1-1', '3-1']) }) it('sort by Name/Desc', () => { const sortMethod = getSortMethod('name', 'desc') - const sorted_ids = files.sort(sortMethod).map((file) => file.id.ino) - expect(sorted_ids).toEqual([3n, 1n, 0n, 2n]) + const sorted_ids = files.sort(sortMethod).map((file) => file.id) + expect(sorted_ids).toEqual(['3-1', '1-1', '0-1', '2-1']) }) it('sort by Size/Asc', () => { const sortMethod = getSortMethod('size', 'asc') - const sorted_ids = files.sort(sortMethod).map((file) => file.id.ino) - expect(sorted_ids).toEqual([1n, 0n, 3n, 2n]) + const sorted_ids = files.sort(sortMethod).map((file) => file.id) + expect(sorted_ids).toEqual(['1-1', '0-1', '3-1', '2-1']) }) it('sort by Size/Asc', () => { const sortMethod = getSortMethod('size', 'desc') - const sorted_ids = files.sort(sortMethod).map((file) => file.id.ino) - expect(sorted_ids).toEqual([2n, 3n, 0n, 1n]) + const sorted_ids = files.sort(sortMethod).map((file) => file.id) + expect(sorted_ids).toEqual(['2-1', '3-1', '0-1', '1-1']) }) }) diff --git a/src/services/plugins/__tests__/FsLocal.test.ts b/src/services/plugins/__tests__/FsLocal.test.ts index c0e0cb14..414dc686 100644 --- a/src/services/plugins/__tests__/FsLocal.test.ts +++ b/src/services/plugins/__tests__/FsLocal.test.ts @@ -409,10 +409,7 @@ describe('FsLocal', () => { length: fsStat.size, isDir: false, isSym: false, - id: { - dev: fsStat.dev, - ino: fsStat.ino, - }, + id: `${fsStat.ino}-${fsStat.dev}`, mode: fsStat.mode, readonly: false, target: null,