From: John Molakvoæ Date: Wed, 16 Aug 2023 10:30:01 +0000 (+0200) Subject: fix(tests): actions adjust and jest fetch mock X-Git-Tag: v28.0.0beta1~522^2~7 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5098a2d7db2fb1ee0352fb214330e45455153ac4;p=nextcloud-server.git fix(tests): actions adjust and jest fetch mock Signed-off-by: John Molakvoæ --- diff --git a/__tests__/jest-setup.ts b/__tests__/jest-setup.ts index 1bcd6bf767d..47df5dabffe 100644 --- a/__tests__/jest-setup.ts +++ b/__tests__/jest-setup.ts @@ -24,3 +24,6 @@ import '@testing-library/jest-dom' // Mock `window.location` with Jest spies and extend expect import 'jest-location-mock' + +// Mock `window.fetch` with Jest +import 'jest-fetch-mock' diff --git a/apps/files/src/actions/openFolderAction.spec.ts b/apps/files/src/actions/openFolderAction.spec.ts index 5a0ccc98978..49fc9a9a63a 100644 --- a/apps/files/src/actions/openFolderAction.spec.ts +++ b/apps/files/src/actions/openFolderAction.spec.ts @@ -19,11 +19,13 @@ * along with this program. If not, see . * */ -import { action } from './openFolderAction' +import type { Navigation } from '../services/Navigation' + import { expect } from '@jest/globals' import { File, Folder, Node, Permission } from '@nextcloud/files' + +import { action } from './openFolderAction' import { DefaultType, FileAction } from '../services/FileAction' -import type { Navigation } from '../services/Navigation' const view = { id: 'files', @@ -132,7 +134,7 @@ describe('Open folder action execute tests', () => { // Silent action expect(exec).toBe(null) expect(goToRouteMock).toBeCalledTimes(1) - expect(goToRouteMock).toBeCalledWith(null, null, { dir: '/FooBar' }) + expect(goToRouteMock).toBeCalledWith(null, { fileid: undefined, view: 'files' }, { dir: '/FooBar' }) }) test('Open folder fails without node', async () => { diff --git a/apps/files/src/actions/sidebarAction.spec.ts b/apps/files/src/actions/sidebarAction.spec.ts index 69eabe4be79..6b33667d1dd 100644 --- a/apps/files/src/actions/sidebarAction.spec.ts +++ b/apps/files/src/actions/sidebarAction.spec.ts @@ -19,11 +19,13 @@ * along with this program. If not, see . * */ -import { action } from './sidebarAction' +import type { Navigation } from '../services/Navigation' + import { expect } from '@jest/globals' import { File, Permission } from '@nextcloud/files' + +import { action } from './sidebarAction' import { FileAction } from '../services/FileAction' -import type { Navigation } from '../services/Navigation' import logger from '../logger' const view = { @@ -127,6 +129,8 @@ describe('Open sidebar action exec tests', () => { test('Open sidebar', async () => { const openMock = jest.fn() window.OCA = { Files: { Sidebar: { open: openMock } } } + const goToRouteMock = jest.fn() + window.OCP = { Files: { Router: { goToRoute: goToRouteMock } } } const file = new File({ id: 1, @@ -139,6 +143,12 @@ describe('Open sidebar action exec tests', () => { // Silent action expect(exec).toBe(null) expect(openMock).toBeCalledWith('/foobar.txt') + expect(goToRouteMock).toBeCalledWith( + null, + { view: view.id, fileid: 1 }, + { dir: '/' }, + true, + ) }) test('Open sidebar fails', async () => { diff --git a/apps/files/src/actions/viewInFolderAction.spec.ts b/apps/files/src/actions/viewInFolderAction.spec.ts index 887ed5d47c6..7d61fa4298d 100644 --- a/apps/files/src/actions/viewInFolderAction.spec.ts +++ b/apps/files/src/actions/viewInFolderAction.spec.ts @@ -128,7 +128,7 @@ describe('View in folder action execute tests', () => { // Silent action expect(exec).toBe(null) expect(goToRouteMock).toBeCalledTimes(1) - expect(goToRouteMock).toBeCalledWith(null, { fileid: 1, view: 'files' }, { fileid: 1, dir: '/' }) + expect(goToRouteMock).toBeCalledWith(null, { fileid: 1, view: 'files' }, { dir: '/' }) }) test('View in (sub) folder', async () => { @@ -148,7 +148,7 @@ describe('View in folder action execute tests', () => { // Silent action expect(exec).toBe(null) expect(goToRouteMock).toBeCalledTimes(1) - expect(goToRouteMock).toBeCalledWith(null, { fileid: 1, view: 'files' }, { fileid: 1, dir: '/Foo/Bar' }) + expect(goToRouteMock).toBeCalledWith(null, { fileid: 1, view: 'files' }, { dir: '/Foo/Bar' }) }) test('View in folder fails without node', async () => { diff --git a/apps/files_sharing/src/actions/openInFilesAction.spec.ts b/apps/files_sharing/src/actions/openInFilesAction.spec.ts index 8920204ae3f..49d4e192d39 100644 --- a/apps/files_sharing/src/actions/openInFilesAction.spec.ts +++ b/apps/files_sharing/src/actions/openInFilesAction.spec.ts @@ -19,14 +19,14 @@ * along with this program. If not, see . * */ -import { action } from './openInFilesAction' +import type { Navigation } from '../../../files/src/services/Navigation' + import { expect } from '@jest/globals' import { File, Permission } from '@nextcloud/files' -import { DefaultType, FileAction } from '../../../files/src/services/FileAction' -import * as eventBus from '@nextcloud/event-bus' -import axios from '@nextcloud/axios' -import type { Navigation } from '../../../files/src/services/Navigation' + import '../main' +import { action } from './openInFilesAction' +import { DefaultType, FileAction } from '../../../files/src/services/FileAction' import { deletedSharesViewId, pendingSharesViewId, sharedWithOthersViewId, sharedWithYouViewId, sharesViewId, sharingByLinksViewId } from '../views/shares' const view = { @@ -92,6 +92,6 @@ describe('Open in files action execute tests', () => { // Silent action expect(exec).toBe(null) expect(goToRouteMock).toBeCalledTimes(1) - expect(goToRouteMock).toBeCalledWith(null, { fileid: 1, view: 'files' }, { fileid: 1, dir: '/Foo' }) + expect(goToRouteMock).toBeCalledWith(null, { fileid: 1, view: 'files' }, { dir: '/Foo' }) }) }) diff --git a/apps/files_sharing/src/actions/openInFilesAction.ts b/apps/files_sharing/src/actions/openInFilesAction.ts index bd9791e85a5..ff7ccde2f36 100644 --- a/apps/files_sharing/src/actions/openInFilesAction.ts +++ b/apps/files_sharing/src/actions/openInFilesAction.ts @@ -43,7 +43,7 @@ export const action = new FileAction({ window.OCP.Files.Router.goToRoute( null, // use default route { view: 'files', fileid: node.fileid }, - { dir: node.dirname, fileid: node.fileid }, + { dir: node.dirname }, ) return null }, diff --git a/jest.config.ts b/jest.config.ts index 0763be02678..78b5912fee9 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -29,6 +29,7 @@ const ignorePatterns = [ '@nextcloud/vue', 'ansi-regex', 'char-regex', + 'hot-patcher', 'is-svg', 'splitpanes', 'string-length', diff --git a/package-lock.json b/package-lock.json index d7ac3791297..7e3de43074a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -85,7 +85,6 @@ "vue-multiselect": "^2.1.6", "vue-observe-visibility": "^1.0.0", "vue-router": "^3.6.5", - "vue-virtual-scroll-list": "github:skjnldsv/vue-virtual-scroll-list#master", "vue-virtual-scroller": "^1.1.2", "vuedraggable": "^2.24.3", "vuex": "^3.6.2", @@ -129,6 +128,7 @@ "jasmine-sinon": "^0.4.0", "jest": "^29.0.3", "jest-environment-jsdom": "^29.5.0", + "jest-fetch-mock": "^3.0.3", "jest-location-mock": "^1.0.9", "jsdoc": "^4.0.2", "karma": "^6.4.2", @@ -15343,6 +15343,25 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/jest-fetch-mock": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/jest-fetch-mock/-/jest-fetch-mock-3.0.3.tgz", + "integrity": "sha512-Ux1nWprtLrdrH4XwE7O7InRY6psIi3GOsqNESJgMJ+M5cv4A8Lh7SN9d2V2kKRZ8ebAfcd1LNyZguAOb6JiDqw==", + "dev": true, + "dependencies": { + "cross-fetch": "^3.0.4", + "promise-polyfill": "^8.1.3" + } + }, + "node_modules/jest-fetch-mock/node_modules/cross-fetch": { + "version": "3.1.8", + "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.8.tgz", + "integrity": "sha512-cvA+JwZoU0Xq+h6WkMvAUqPEYy92Obet6UdKLfW60qn99ftItKjB5T+BkyWOFWe2pUyfQ+IJHmpOTznqk1M6Kg==", + "dev": true, + "dependencies": { + "node-fetch": "^2.6.12" + } + }, "node_modules/jest-get-type": { "version": "29.4.3", "resolved": "https://registry.npmjs.org/jest-get-type/-/jest-get-type-29.4.3.tgz", @@ -20427,6 +20446,12 @@ "node": ">=0.4.0" } }, + "node_modules/promise-polyfill": { + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/promise-polyfill/-/promise-polyfill-8.3.0.tgz", + "integrity": "sha512-H5oELycFml5yto/atYqmjyigJoAo3+OXwolYiH7OfQuYlAqhxNvTfiNMbV9hsC6Yp83yE5r2KTVmtrG6R9i6Pg==", + "dev": true + }, "node_modules/prompts": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/prompts/-/prompts-2.4.2.tgz", @@ -25335,11 +25360,6 @@ "integrity": "sha512-4gDntzrifFnCEvyoO8PqyJDmguXgVPxKiIxrBKjIowvL9l+N66196+72XVYR8BBf1Uv1Fgt3bGevJ+sEmxfZzw==", "dev": true }, - "node_modules/vue-virtual-scroll-list": { - "version": "2.3.5", - "resolved": "git+ssh://git@github.com/skjnldsv/vue-virtual-scroll-list.git#0f81a0090c3d5f934a7e44c1a90ab8bf36757ea1", - "license": "MIT" - }, "node_modules/vue-virtual-scroller": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vue-virtual-scroller/-/vue-virtual-scroller-1.1.2.tgz", diff --git a/package.json b/package.json index a38948e40af..2efb45bc419 100644 --- a/package.json +++ b/package.json @@ -111,7 +111,6 @@ "vue-multiselect": "^2.1.6", "vue-observe-visibility": "^1.0.0", "vue-router": "^3.6.5", - "vue-virtual-scroll-list": "github:skjnldsv/vue-virtual-scroll-list#master", "vue-virtual-scroller": "^1.1.2", "vuedraggable": "^2.24.3", "vuex": "^3.6.2", @@ -155,6 +154,7 @@ "jasmine-sinon": "^0.4.0", "jest": "^29.0.3", "jest-environment-jsdom": "^29.5.0", + "jest-fetch-mock": "^3.0.3", "jest-location-mock": "^1.0.9", "jsdoc": "^4.0.2", "karma": "^6.4.2",