]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix(tests): actions adjust and jest fetch mock
authorJohn Molakvoæ <skjnldsv@protonmail.com>
Wed, 16 Aug 2023 10:30:01 +0000 (12:30 +0200)
committerJohn Molakvoæ <skjnldsv@protonmail.com>
Thu, 17 Aug 2023 16:56:38 +0000 (18:56 +0200)
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
__tests__/jest-setup.ts
apps/files/src/actions/openFolderAction.spec.ts
apps/files/src/actions/sidebarAction.spec.ts
apps/files/src/actions/viewInFolderAction.spec.ts
apps/files_sharing/src/actions/openInFilesAction.spec.ts
apps/files_sharing/src/actions/openInFilesAction.ts
jest.config.ts
package-lock.json
package.json

index 1bcd6bf767dd53518b128f463dc19ee5e26ec577..47df5dabffed259d361837cd98d5f7ab998fd830 100644 (file)
@@ -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'
index 5a0ccc98978cca9c44e79ec4555c2a2d8a58b6ef..49fc9a9a63ac5d9354c92ab70d268940b02b9dc4 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  *
  */
-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 () => {
index 69eabe4be79ef1de13e4017661efb2a0b3564ec9..6b33667d1dd5e3023c0ce19d01674b5438e95e78 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  *
  */
-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 () => {
index 887ed5d47c6843ee85d88b8988b32d9aecedbf6c..7d61fa4298d29a32128fcfc51f2948fce1e15789 100644 (file)
@@ -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 () => {
index 8920204ae3fef8617bad1643ad07beede7eb3bdb..49d4e192d390201896565b035a28405449558bc4 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  *
  */
-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' })
        })
 })
index bd9791e85a56367c787b983939eb10812588cf85..ff7ccde2f36aba155649901cac65aa19741fdc18 100644 (file)
@@ -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
        },
index 0763be026785d7f35bd8bf5c7cc5551aebad6d67..78b5912fee905e6c143cc68a41355630e2b58223 100644 (file)
@@ -29,6 +29,7 @@ const ignorePatterns = [
        '@nextcloud/vue',
        'ansi-regex',
        'char-regex',
+       'hot-patcher',
        'is-svg',
        'splitpanes',
        'string-length',
index d7ac37912977c81d5f44859486ecfb2074e6195f..7e3de43074a4926b8a9bb65575605ea3e8db3057 100644 (file)
@@ -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",
         "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",
         "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",
         "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",
       "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",
index a38948e40afbb9e18df4dee539558098e3f83acd..2efb45bc41978e5825808ef92ed04af8f5674c3f 100644 (file)
     "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",
     "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",