diff options
author | Ferdinand Thiessen <opensource@fthiessen.de> | 2024-08-24 16:53:33 +0200 |
---|---|---|
committer | Ferdinand Thiessen <opensource@fthiessen.de> | 2024-08-26 17:27:22 +0200 |
commit | a5e58dc45e2078fa6e2330e78d17a73f92168974 (patch) | |
tree | 508f45285616e97677b5493f10a4e0513d478924 /apps/files_sharing/src | |
parent | c0b39bb9095b9e0421314c99d3ff0e149a21c435 (diff) | |
download | nextcloud-server-a5e58dc45e2078fa6e2330e78d17a73f92168974.tar.gz nextcloud-server-a5e58dc45e2078fa6e2330e78d17a73f92168974.zip |
test: Migrated all Jest tests to vitest
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Diffstat (limited to 'apps/files_sharing/src')
7 files changed, 115 insertions, 102 deletions
diff --git a/apps/files_sharing/src/actions/acceptShareAction.spec.ts b/apps/files_sharing/src/actions/acceptShareAction.spec.ts index 848bdc5496b..04199f998d0 100644 --- a/apps/files_sharing/src/actions/acceptShareAction.spec.ts +++ b/apps/files_sharing/src/actions/acceptShareAction.spec.ts @@ -2,14 +2,17 @@ * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later */ +import { beforeAll, beforeEach, describe, expect, test, vi } from 'vitest' + import { action } from './acceptShareAction' -import { expect } from '@jest/globals' import { File, Permission, View, FileAction } from '@nextcloud/files' import { ShareType } from '@nextcloud/sharing' -import eventBus from '@nextcloud/event-bus' +import * as eventBus from '@nextcloud/event-bus' import axios from '@nextcloud/axios' import '../main' +vi.mock('@nextcloud/axios') + const view = { id: 'files', name: 'Files', @@ -39,7 +42,7 @@ describe('Accept share action conditions tests', () => { expect(action).toBeInstanceOf(FileAction) expect(action.id).toBe('accept-share') expect(action.displayName([file], pendingShareView)).toBe('Accept share') - expect(action.iconSvgInline([file], pendingShareView)).toBe('<svg>SvgMock</svg>') + expect(action.iconSvgInline([file], pendingShareView)).toMatch(/<svg.+<\/svg>/) expect(action.default).toBeUndefined() expect(action.order).toBe(1) expect(action.inline).toBeDefined() @@ -92,9 +95,11 @@ describe('Accept share action enabled tests', () => { }) describe('Accept share action execute tests', () => { + beforeEach(() => { vi.resetAllMocks() }) + test('Accept share action', async () => { - jest.spyOn(axios, 'post') - jest.spyOn(eventBus, 'emit') + vi.spyOn(axios, 'post') + vi.spyOn(eventBus, 'emit') const file = new File({ id: 1, @@ -112,15 +117,15 @@ describe('Accept share action execute tests', () => { expect(exec).toBe(true) expect(axios.post).toBeCalledTimes(1) - expect(axios.post).toBeCalledWith('http://localhost/ocs/v2.php/apps/files_sharing/api/v1/shares/pending/123') + expect(axios.post).toBeCalledWith('http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/shares/pending/123') expect(eventBus.emit).toBeCalledTimes(1) expect(eventBus.emit).toBeCalledWith('files:node:deleted', file) }) test('Accept remote share action', async () => { - jest.spyOn(axios, 'post') - jest.spyOn(eventBus, 'emit') + vi.spyOn(axios, 'post') + vi.spyOn(eventBus, 'emit') const file = new File({ id: 1, @@ -139,15 +144,15 @@ describe('Accept share action execute tests', () => { expect(exec).toBe(true) expect(axios.post).toBeCalledTimes(1) - expect(axios.post).toBeCalledWith('http://localhost/ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/123') + expect(axios.post).toBeCalledWith('http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/123') expect(eventBus.emit).toBeCalledTimes(1) expect(eventBus.emit).toBeCalledWith('files:node:deleted', file) }) test('Accept share action batch', async () => { - jest.spyOn(axios, 'post') - jest.spyOn(eventBus, 'emit') + vi.spyOn(axios, 'post') + vi.spyOn(eventBus, 'emit') const file1 = new File({ id: 1, @@ -177,8 +182,8 @@ describe('Accept share action execute tests', () => { expect(exec).toStrictEqual([true, true]) expect(axios.post).toBeCalledTimes(2) - expect(axios.post).toHaveBeenNthCalledWith(1, 'http://localhost/ocs/v2.php/apps/files_sharing/api/v1/shares/pending/123') - expect(axios.post).toHaveBeenNthCalledWith(2, 'http://localhost/ocs/v2.php/apps/files_sharing/api/v1/shares/pending/456') + expect(axios.post).toHaveBeenNthCalledWith(1, 'http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/shares/pending/123') + expect(axios.post).toHaveBeenNthCalledWith(2, 'http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/shares/pending/456') expect(eventBus.emit).toBeCalledTimes(2) expect(eventBus.emit).toHaveBeenNthCalledWith(1, 'files:node:deleted', file1) @@ -186,7 +191,7 @@ describe('Accept share action execute tests', () => { }) test('Accept fails', async () => { - jest.spyOn(axios, 'post').mockImplementation(() => { throw new Error('Mock error') }) + vi.spyOn(axios, 'post').mockImplementation(() => { throw new Error('Mock error') }) const file = new File({ id: 1, @@ -204,7 +209,7 @@ describe('Accept share action execute tests', () => { expect(exec).toBe(false) expect(axios.post).toBeCalledTimes(1) - expect(axios.post).toBeCalledWith('http://localhost/ocs/v2.php/apps/files_sharing/api/v1/shares/pending/123') + expect(axios.post).toBeCalledWith('http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/shares/pending/123') expect(eventBus.emit).toBeCalledTimes(0) }) diff --git a/apps/files_sharing/src/actions/openInFilesAction.spec.ts b/apps/files_sharing/src/actions/openInFilesAction.spec.ts index e7e447ad218..36e4b7ae3c9 100644 --- a/apps/files_sharing/src/actions/openInFilesAction.spec.ts +++ b/apps/files_sharing/src/actions/openInFilesAction.spec.ts @@ -2,8 +2,8 @@ * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later */ -import { expect } from '@jest/globals' import { File, Permission, View, DefaultType, FileAction } from '@nextcloud/files' +import { describe, expect, test, vi } from 'vitest' import '../main' import { action } from './openInFilesAction' @@ -56,7 +56,7 @@ describe('Open in files action enabled tests', () => { describe('Open in files action execute tests', () => { test('Open in files', async () => { - const goToRouteMock = jest.fn() + const goToRouteMock = vi.fn() // @ts-expect-error We only mock what needed, we do not need Files.Router.goTo or Files.Navigation window.OCP = { Files: { Router: { goToRoute: goToRouteMock } } } diff --git a/apps/files_sharing/src/actions/rejectShareAction.spec.ts b/apps/files_sharing/src/actions/rejectShareAction.spec.ts index e4d37cd952c..51ded69d1c5 100644 --- a/apps/files_sharing/src/actions/rejectShareAction.spec.ts +++ b/apps/files_sharing/src/actions/rejectShareAction.spec.ts @@ -2,14 +2,17 @@ * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later */ -import { action } from './rejectShareAction' -import { expect } from '@jest/globals' import { File, Folder, Permission, View, FileAction } from '@nextcloud/files' +import { beforeAll, beforeEach, describe, expect, test, vi } from 'vitest' import { ShareType } from '@nextcloud/sharing' -import eventBus from '@nextcloud/event-bus' +import * as eventBus from '@nextcloud/event-bus' import axios from '@nextcloud/axios' + +import { action } from './rejectShareAction' import '../main' +vi.mock('@nextcloud/axios') + const view = { id: 'files', name: 'Files', @@ -39,7 +42,7 @@ describe('Reject share action conditions tests', () => { expect(action).toBeInstanceOf(FileAction) expect(action.id).toBe('reject-share') expect(action.displayName([file], pendingShareView)).toBe('Reject share') - expect(action.iconSvgInline([file], pendingShareView)).toBe('<svg>SvgMock</svg>') + expect(action.iconSvgInline([file], pendingShareView)).toMatch(/<svg.+<\/svg>/) expect(action.default).toBeUndefined() expect(action.order).toBe(2) expect(action.inline).toBeDefined() @@ -119,9 +122,11 @@ describe('Reject share action enabled tests', () => { }) describe('Reject share action execute tests', () => { + beforeEach(() => { vi.resetAllMocks() }) + test('Reject share action', async () => { - jest.spyOn(axios, 'delete') - jest.spyOn(eventBus, 'emit') + vi.spyOn(axios, 'delete') + vi.spyOn(eventBus, 'emit') const file = new File({ id: 1, @@ -139,15 +144,15 @@ describe('Reject share action execute tests', () => { expect(exec).toBe(true) expect(axios.delete).toBeCalledTimes(1) - expect(axios.delete).toBeCalledWith('http://localhost/ocs/v2.php/apps/files_sharing/api/v1/shares/123') + expect(axios.delete).toBeCalledWith('http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/shares/123') expect(eventBus.emit).toBeCalledTimes(1) expect(eventBus.emit).toBeCalledWith('files:node:deleted', file) }) test('Reject remote share action', async () => { - jest.spyOn(axios, 'delete') - jest.spyOn(eventBus, 'emit') + vi.spyOn(axios, 'delete') + vi.spyOn(eventBus, 'emit') const file = new File({ id: 1, @@ -166,15 +171,15 @@ describe('Reject share action execute tests', () => { expect(exec).toBe(true) expect(axios.delete).toBeCalledTimes(1) - expect(axios.delete).toBeCalledWith('http://localhost/ocs/v2.php/apps/files_sharing/api/v1/remote_shares/123') + expect(axios.delete).toBeCalledWith('http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/remote_shares/123') expect(eventBus.emit).toBeCalledTimes(1) expect(eventBus.emit).toBeCalledWith('files:node:deleted', file) }) test('Reject share action batch', async () => { - jest.spyOn(axios, 'delete') - jest.spyOn(eventBus, 'emit') + vi.spyOn(axios, 'delete') + vi.spyOn(eventBus, 'emit') const file1 = new File({ id: 1, @@ -204,8 +209,8 @@ describe('Reject share action execute tests', () => { expect(exec).toStrictEqual([true, true]) expect(axios.delete).toBeCalledTimes(2) - expect(axios.delete).toHaveBeenNthCalledWith(1, 'http://localhost/ocs/v2.php/apps/files_sharing/api/v1/shares/123') - expect(axios.delete).toHaveBeenNthCalledWith(2, 'http://localhost/ocs/v2.php/apps/files_sharing/api/v1/shares/456') + expect(axios.delete).toHaveBeenNthCalledWith(1, 'http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/shares/123') + expect(axios.delete).toHaveBeenNthCalledWith(2, 'http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/shares/456') expect(eventBus.emit).toBeCalledTimes(2) expect(eventBus.emit).toHaveBeenNthCalledWith(1, 'files:node:deleted', file1) @@ -213,7 +218,7 @@ describe('Reject share action execute tests', () => { }) test('Reject fails', async () => { - jest.spyOn(axios, 'delete').mockImplementation(() => { throw new Error('Mock error') }) + vi.spyOn(axios, 'delete').mockImplementation(() => { throw new Error('Mock error') }) const file = new File({ id: 1, @@ -231,7 +236,7 @@ describe('Reject share action execute tests', () => { expect(exec).toBe(false) expect(axios.delete).toBeCalledTimes(1) - expect(axios.delete).toBeCalledWith('http://localhost/ocs/v2.php/apps/files_sharing/api/v1/shares/123') + expect(axios.delete).toBeCalledWith('http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/shares/123') expect(eventBus.emit).toBeCalledTimes(0) }) diff --git a/apps/files_sharing/src/actions/restoreShareAction.spec.ts b/apps/files_sharing/src/actions/restoreShareAction.spec.ts index 8132c76fe2b..d6628810064 100644 --- a/apps/files_sharing/src/actions/restoreShareAction.spec.ts +++ b/apps/files_sharing/src/actions/restoreShareAction.spec.ts @@ -2,14 +2,18 @@ * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later */ -import { action } from './restoreShareAction' -import { expect } from '@jest/globals' import { File, Permission, View, FileAction } from '@nextcloud/files' import { ShareType } from '@nextcloud/sharing' -import eventBus from '@nextcloud/event-bus' +import { beforeAll, beforeEach, describe, expect, test, vi } from 'vitest' + import axios from '@nextcloud/axios' +import * as eventBus from '@nextcloud/event-bus' +import { action } from './restoreShareAction' import '../main' +vi.mock('@nextcloud/auth') +vi.mock('@nextcloud/axios') + const view = { id: 'files', name: 'Files', @@ -39,7 +43,7 @@ describe('Restore share action conditions tests', () => { expect(action).toBeInstanceOf(FileAction) expect(action.id).toBe('restore-share') expect(action.displayName([file], deletedShareView)).toBe('Restore share') - expect(action.iconSvgInline([file], deletedShareView)).toBe('<svg>SvgMock</svg>') + expect(action.iconSvgInline([file], deletedShareView)).toMatch(/<svg.+<\/svg>/) expect(action.default).toBeUndefined() expect(action.order).toBe(1) expect(action.inline).toBeDefined() @@ -92,9 +96,11 @@ describe('Restore share action enabled tests', () => { }) describe('Restore share action execute tests', () => { + beforeEach(() => { vi.resetAllMocks() }) + test('Restore share action', async () => { - jest.spyOn(axios, 'post') - jest.spyOn(eventBus, 'emit') + vi.spyOn(axios, 'post') + vi.spyOn(eventBus, 'emit') const file = new File({ id: 1, @@ -112,15 +118,15 @@ describe('Restore share action execute tests', () => { expect(exec).toBe(true) expect(axios.post).toBeCalledTimes(1) - expect(axios.post).toBeCalledWith('http://localhost/ocs/v2.php/apps/files_sharing/api/v1/deletedshares/123') + expect(axios.post).toBeCalledWith('http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/deletedshares/123') expect(eventBus.emit).toBeCalledTimes(1) expect(eventBus.emit).toBeCalledWith('files:node:deleted', file) }) test('Restore share action batch', async () => { - jest.spyOn(axios, 'post') - jest.spyOn(eventBus, 'emit') + vi.spyOn(axios, 'post') + vi.spyOn(eventBus, 'emit') const file1 = new File({ id: 1, @@ -150,8 +156,8 @@ describe('Restore share action execute tests', () => { expect(exec).toStrictEqual([true, true]) expect(axios.post).toBeCalledTimes(2) - expect(axios.post).toHaveBeenNthCalledWith(1, 'http://localhost/ocs/v2.php/apps/files_sharing/api/v1/deletedshares/123') - expect(axios.post).toHaveBeenNthCalledWith(2, 'http://localhost/ocs/v2.php/apps/files_sharing/api/v1/deletedshares/456') + expect(axios.post).toHaveBeenNthCalledWith(1, 'http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/deletedshares/123') + expect(axios.post).toHaveBeenNthCalledWith(2, 'http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/deletedshares/456') expect(eventBus.emit).toBeCalledTimes(2) expect(eventBus.emit).toHaveBeenNthCalledWith(1, 'files:node:deleted', file1) @@ -159,7 +165,8 @@ describe('Restore share action execute tests', () => { }) test('Restore fails', async () => { - jest.spyOn(axios, 'post').mockImplementation(() => { throw new Error('Mock error') }) + vi.spyOn(axios, 'post') + .mockImplementation(() => { throw new Error('Mock error') }) const file = new File({ id: 1, @@ -177,7 +184,7 @@ describe('Restore share action execute tests', () => { expect(exec).toBe(false) expect(axios.post).toBeCalledTimes(1) - expect(axios.post).toBeCalledWith('http://localhost/ocs/v2.php/apps/files_sharing/api/v1/deletedshares/123') + expect(axios.post).toBeCalledWith('http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/deletedshares/123') expect(eventBus.emit).toBeCalledTimes(0) }) diff --git a/apps/files_sharing/src/lib/SharePermissionsToolBox.spec.js b/apps/files_sharing/src/lib/SharePermissionsToolBox.spec.js index 9ca770a0ac5..a58552063d8 100644 --- a/apps/files_sharing/src/lib/SharePermissionsToolBox.spec.js +++ b/apps/files_sharing/src/lib/SharePermissionsToolBox.spec.js @@ -2,6 +2,7 @@ * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later */ +import { describe, expect, test } from 'vitest' import { ATOMIC_PERMISSIONS, diff --git a/apps/files_sharing/src/services/SharingService.spec.ts b/apps/files_sharing/src/services/SharingService.spec.ts index ba0591a765a..bd0e018db7a 100644 --- a/apps/files_sharing/src/services/SharingService.spec.ts +++ b/apps/files_sharing/src/services/SharingService.spec.ts @@ -3,29 +3,35 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ import type { OCSResponse } from '@nextcloud/typings/ocs' -import { expect } from '@jest/globals' -import { Type } from '@nextcloud/sharing' -import * as auth from '@nextcloud/auth' -import axios from '@nextcloud/axios' -import { getContents } from './SharingService' import { File, Folder } from '@nextcloud/files' +import { ShareType } from '@nextcloud/sharing' +import { beforeAll, beforeEach, describe, expect, test, vi } from 'vitest' + +import { getContents } from './SharingService' +import * as auth from '@nextcloud/auth' import logger from './logger' -window.OC = { - ...window.OC, - TAG_FAVORITE: '_$!<Favorite>!$_', -} +const TAG_FAVORITE = '_$!<Favorite>!$_' + +const axios = vi.hoisted(() => ({ get: vi.fn() })) +vi.mock('@nextcloud/auth') +vi.mock('@nextcloud/axios', () => ({ default: axios })) -// Mock webroot variable +// Mock web root variable beforeAll(() => { + window.OC = { + ...window.OC, + TAG_FAVORITE, + } // eslint-disable-next-line @typescript-eslint/no-explicit-any - (window as any)._oc_webroot = '' + ;(window as any)._oc_webroot = '' }) describe('SharingService methods definitions', () => { - beforeAll(() => { - jest.spyOn(axios, 'get').mockImplementation(async (): Promise<any> => { + beforeEach(() => { + vi.resetAllMocks() + axios.get.mockImplementation(async (): Promise<unknown> => { return { data: { ocs: { @@ -36,20 +42,16 @@ describe('SharingService methods definitions', () => { }, data: [], }, - } as OCSResponse<any>, + } as OCSResponse, } }) }) - afterAll(() => { - jest.restoreAllMocks() - }) - test('Shared with you', async () => { await getContents(true, false, false, false, []) expect(axios.get).toHaveBeenCalledTimes(2) - expect(axios.get).toHaveBeenNthCalledWith(1, 'http://localhost/ocs/v2.php/apps/files_sharing/api/v1/shares', { + expect(axios.get).toHaveBeenNthCalledWith(1, 'http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/shares', { headers: { 'Content-Type': 'application/json', }, @@ -58,7 +60,7 @@ describe('SharingService methods definitions', () => { include_tags: true, }, }) - expect(axios.get).toHaveBeenNthCalledWith(2, 'http://localhost/ocs/v2.php/apps/files_sharing/api/v1/remote_shares', { + expect(axios.get).toHaveBeenNthCalledWith(2, 'http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/remote_shares', { headers: { 'Content-Type': 'application/json', }, @@ -72,7 +74,7 @@ describe('SharingService methods definitions', () => { await getContents(false, true, false, false, []) expect(axios.get).toHaveBeenCalledTimes(1) - expect(axios.get).toHaveBeenCalledWith('http://localhost/ocs/v2.php/apps/files_sharing/api/v1/shares', { + expect(axios.get).toHaveBeenCalledWith('http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/shares', { headers: { 'Content-Type': 'application/json', }, @@ -87,7 +89,7 @@ describe('SharingService methods definitions', () => { await getContents(false, false, true, false, []) expect(axios.get).toHaveBeenCalledTimes(2) - expect(axios.get).toHaveBeenNthCalledWith(1, 'http://localhost/ocs/v2.php/apps/files_sharing/api/v1/shares/pending', { + expect(axios.get).toHaveBeenNthCalledWith(1, 'http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/shares/pending', { headers: { 'Content-Type': 'application/json', }, @@ -95,7 +97,7 @@ describe('SharingService methods definitions', () => { include_tags: true, }, }) - expect(axios.get).toHaveBeenNthCalledWith(2, 'http://localhost/ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending', { + expect(axios.get).toHaveBeenNthCalledWith(2, 'http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending', { headers: { 'Content-Type': 'application/json', }, @@ -109,7 +111,7 @@ describe('SharingService methods definitions', () => { await getContents(false, true, false, false, []) expect(axios.get).toHaveBeenCalledTimes(1) - expect(axios.get).toHaveBeenCalledWith('http://localhost/ocs/v2.php/apps/files_sharing/api/v1/shares', { + expect(axios.get).toHaveBeenCalledWith('http://nextcloud.local/ocs/v2.php/apps/files_sharing/api/v1/shares', { headers: { 'Content-Type': 'application/json', }, @@ -121,7 +123,7 @@ describe('SharingService methods definitions', () => { }) test('Unknown owner', async () => { - jest.spyOn(auth, 'getCurrentUser').mockReturnValue(null) + vi.spyOn(auth, 'getCurrentUser').mockReturnValue(null) const results = await getContents(false, true, false, false, []) expect(results.folder.owner).toEqual(null) @@ -129,8 +131,9 @@ describe('SharingService methods definitions', () => { }) describe('SharingService filtering', () => { - beforeAll(() => { - jest.spyOn(axios, 'get').mockImplementation(async (): Promise<any> => { + beforeEach(() => { + vi.resetAllMocks() + axios.get.mockImplementation(async (): Promise<unknown> => { return { data: { ocs: { @@ -142,7 +145,7 @@ describe('SharingService filtering', () => { data: [ { id: '62', - share_type: Type.SHARE_TYPE_USER, + share_type: ShareType.User, uid_owner: 'test', displayname_owner: 'test', permissions: 31, @@ -168,12 +171,8 @@ describe('SharingService filtering', () => { }) }) - afterAll(() => { - jest.restoreAllMocks() - }) - test('Shared with others filtering', async () => { - const shares = await getContents(false, true, false, false, [Type.SHARE_TYPE_USER]) + const shares = await getContents(false, true, false, false, [ShareType.User]) expect(axios.get).toHaveBeenCalledTimes(1) expect(shares.contents).toHaveLength(1) @@ -182,7 +181,7 @@ describe('SharingService filtering', () => { }) test('Shared with others filtering empty', async () => { - const shares = await getContents(false, true, false, false, [Type.SHARE_TYPE_LINK]) + const shares = await getContents(false, true, false, false, [ShareType.Link]) expect(axios.get).toHaveBeenCalledTimes(1) expect(shares.contents).toHaveLength(0) @@ -275,11 +274,13 @@ describe('SharingService share to Node mapping', () => { mail_send: 0, hide_download: 0, attributes: null, - tags: [window.OC.TAG_FAVORITE], + tags: [TAG_FAVORITE], } + beforeEach(() => { vi.resetAllMocks() }) + test('File', async () => { - jest.spyOn(axios, 'get').mockReturnValueOnce(Promise.resolve({ + axios.get.mockReturnValueOnce(Promise.resolve({ data: { ocs: { data: [shareFile], @@ -295,7 +296,7 @@ describe('SharingService share to Node mapping', () => { const file = shares.contents[0] as File expect(file).toBeInstanceOf(File) expect(file.fileid).toBe(530936) - expect(file.source).toBe('http://localhost/remote.php/dav/files/test/document.md') + expect(file.source).toBe('http://nextcloud.local/remote.php/dav/files/test/document.md') expect(file.owner).toBe('test') expect(file.mime).toBe('text/markdown') expect(file.mtime).toBeInstanceOf(Date) @@ -308,7 +309,7 @@ describe('SharingService share to Node mapping', () => { }) test('Folder', async () => { - jest.spyOn(axios, 'get').mockReturnValueOnce(Promise.resolve({ + axios.get.mockReturnValueOnce(Promise.resolve({ data: { ocs: { data: [shareFolder], @@ -324,7 +325,7 @@ describe('SharingService share to Node mapping', () => { const folder = shares.contents[0] as Folder expect(folder).toBeInstanceOf(Folder) expect(folder.fileid).toBe(531080) - expect(folder.source).toBe('http://localhost/remote.php/dav/files/test/Folder') + expect(folder.source).toBe('http://nextcloud.local/remote.php/dav/files/test/Folder') expect(folder.owner).toBe('test') expect(folder.mime).toBe('httpd/unix-directory') expect(folder.mtime).toBeInstanceOf(Date) @@ -338,8 +339,8 @@ describe('SharingService share to Node mapping', () => { }) test('Empty', async () => { - jest.spyOn(logger, 'error').mockImplementationOnce(() => {}) - jest.spyOn(axios, 'get').mockReturnValueOnce(Promise.resolve({ + vi.spyOn(logger, 'error').mockImplementationOnce(() => {}) + axios.get.mockReturnValueOnce(Promise.resolve({ data: { ocs: { data: [], @@ -353,8 +354,8 @@ describe('SharingService share to Node mapping', () => { }) test('Error', async () => { - jest.spyOn(logger, 'error').mockImplementationOnce(() => {}) - jest.spyOn(axios, 'get').mockReturnValueOnce(Promise.resolve({ + vi.spyOn(logger, 'error').mockImplementationOnce(() => {}) + axios.get.mockReturnValueOnce(Promise.resolve({ data: { ocs: { data: [null], diff --git a/apps/files_sharing/src/views/shares.spec.ts b/apps/files_sharing/src/views/shares.spec.ts index 13e1f1f97e5..153057bc0ad 100644 --- a/apps/files_sharing/src/views/shares.spec.ts +++ b/apps/files_sharing/src/views/shares.spec.ts @@ -4,8 +4,8 @@ */ /* eslint-disable n/no-extraneous-import */ import type { OCSResponse } from '@nextcloud/typings/ocs' -import { expect } from '@jest/globals' import { Folder, Navigation, View, getNavigation } from '@nextcloud/files' +import { beforeEach, describe, expect, test, vi } from 'vitest' import axios from '@nextcloud/axios' import '../main' @@ -20,16 +20,13 @@ declare global { describe('Sharing views definition', () => { let Navigation beforeEach(() => { + delete window._nc_navigation Navigation = getNavigation() expect(window._nc_navigation).toBeDefined() }) - afterAll(() => { - delete window._nc_navigation - }) - test('Default values', () => { - jest.spyOn(Navigation, 'register') + vi.spyOn(Navigation, 'register') expect(Navigation.views.length).toBe(0) @@ -47,7 +44,7 @@ describe('Sharing views definition', () => { expect(shareOverviewView?.id).toBe('shareoverview') expect(shareOverviewView?.name).toBe('Shares') expect(shareOverviewView?.caption).toBe('Overview of shared files.') - expect(shareOverviewView?.icon).toBe('<svg>SvgMock</svg>') + expect(shareOverviewView?.icon).toMatch(/<svg.+<\/svg>/i) expect(shareOverviewView?.order).toBe(20) expect(shareOverviewView?.columns).toStrictEqual([]) expect(shareOverviewView?.getContents).toBeDefined() @@ -68,7 +65,7 @@ describe('Sharing views definition', () => { expect(view?.caption).toBeDefined() expect(view?.emptyTitle).toBeDefined() expect(view?.emptyCaption).toBeDefined() - expect(view?.icon).toBe('<svg>SvgMock</svg>') + expect(view?.icon).match(/<svg.+<\/svg>/) expect(view?.order).toBe(index + 1) expect(view?.columns).toStrictEqual([]) expect(view?.getContents).toBeDefined() @@ -79,16 +76,13 @@ describe('Sharing views definition', () => { describe('Sharing views contents', () => { let Navigation beforeEach(() => { + delete window._nc_navigation Navigation = getNavigation() expect(window._nc_navigation).toBeDefined() }) - afterAll(() => { - delete window._nc_navigation - }) - test('Sharing overview get contents', async () => { - jest.spyOn(axios, 'get').mockImplementation(async (): Promise<any> => { + vi.spyOn(axios, 'get').mockImplementation(async (): Promise<any> => { return { data: { ocs: { |