diff --git a/__tests__/mock-window.js b/__tests__/mock-window.js index 47ff5f9058052..0daeea122d770 100644 --- a/__tests__/mock-window.js +++ b/__tests__/mock-window.js @@ -1,3 +1,8 @@ +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + window.OC = { ...window.OC } window.OCA = { ...window.OCA } window.OCP = { ...window.OCP } diff --git a/apps/files/src/actions/deleteAction.spec.ts b/apps/files/src/actions/deleteAction.spec.ts index 0dda5788a85f3..0ed19894c3ff5 100644 --- a/apps/files/src/actions/deleteAction.spec.ts +++ b/apps/files/src/actions/deleteAction.spec.ts @@ -191,6 +191,7 @@ describe('Delete action execute tests', () => { jest.spyOn(eventBus, 'emit') const confirmMock = jest.fn() + // @ts-expect-error We only mock what needed window.OC = { dialogs: { confirmDestructive: confirmMock } } const file1 = new File({ diff --git a/apps/files/src/actions/favoriteAction.spec.ts b/apps/files/src/actions/favoriteAction.spec.ts index e8bb1ce28b5f8..71ca0263d33db 100644 --- a/apps/files/src/actions/favoriteAction.spec.ts +++ b/apps/files/src/actions/favoriteAction.spec.ts @@ -21,6 +21,7 @@ const favoriteView = { } as View global.window.OC = { + // @ts-expect-error This constant is currently missing in @nextcloud/typings TAG_FAVORITE: '_$!!$_', } diff --git a/apps/files/src/actions/openFolderAction.spec.ts b/apps/files/src/actions/openFolderAction.spec.ts index 57827ddc208d8..7ce79e0ad17dd 100644 --- a/apps/files/src/actions/openFolderAction.spec.ts +++ b/apps/files/src/actions/openFolderAction.spec.ts @@ -101,6 +101,7 @@ describe('Open folder action enabled tests', () => { describe('Open folder action execute tests', () => { test('Open folder', async () => { const goToRouteMock = jest.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 } } } const folder = new Folder({ @@ -119,6 +120,7 @@ describe('Open folder action execute tests', () => { test('Open folder fails without node', async () => { const goToRouteMock = jest.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 } } } const exec = await action.exec(null as unknown as Node, view, '/') @@ -128,6 +130,7 @@ describe('Open folder action execute tests', () => { test('Open folder fails without Folder', async () => { const goToRouteMock = jest.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 } } } const file = new File({ diff --git a/apps/files/src/actions/openInFilesAction.spec.ts b/apps/files/src/actions/openInFilesAction.spec.ts index f8745174b96b5..c1a80ad442535 100644 --- a/apps/files/src/actions/openInFilesAction.spec.ts +++ b/apps/files/src/actions/openInFilesAction.spec.ts @@ -43,6 +43,7 @@ describe('Open in files action enabled tests', () => { describe('Open in files action execute tests', () => { test('Open in files', async () => { const goToRouteMock = jest.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 } } } const file = new File({ @@ -64,6 +65,7 @@ describe('Open in files action execute tests', () => { test('Open in files with folder', async () => { const goToRouteMock = jest.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 } } } const file = new Folder({ diff --git a/apps/files/src/actions/sidebarAction.spec.ts b/apps/files/src/actions/sidebarAction.spec.ts index 9e1415b0b2c64..2c23755a84d1e 100644 --- a/apps/files/src/actions/sidebarAction.spec.ts +++ b/apps/files/src/actions/sidebarAction.spec.ts @@ -110,6 +110,7 @@ describe('Open sidebar action exec tests', () => { const openMock = jest.fn() window.OCA = { Files: { Sidebar: { open: openMock } } } const goToRouteMock = jest.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 } } } const file = new File({ diff --git a/apps/files/src/actions/viewInFolderAction.spec.ts b/apps/files/src/actions/viewInFolderAction.spec.ts index cad99d25ab05d..89519f1b64db2 100644 --- a/apps/files/src/actions/viewInFolderAction.spec.ts +++ b/apps/files/src/actions/viewInFolderAction.spec.ts @@ -114,6 +114,7 @@ describe('View in folder action enabled tests', () => { describe('View in folder action execute tests', () => { test('View in folder', async () => { const goToRouteMock = jest.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 } } } const file = new File({ @@ -133,6 +134,7 @@ describe('View in folder action execute tests', () => { test('View in (sub) folder', async () => { const goToRouteMock = jest.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 } } } const file = new File({ @@ -153,6 +155,7 @@ describe('View in folder action execute tests', () => { test('View in folder fails without node', async () => { const goToRouteMock = jest.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 } } } const exec = await action.exec(null as unknown as Node, view, '/') @@ -162,6 +165,7 @@ describe('View in folder action execute tests', () => { test('View in folder fails without File', async () => { const goToRouteMock = jest.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 } } } const folder = new Folder({ diff --git a/apps/files/src/main.ts b/apps/files/src/main.ts index 9b057a5d37870..62c4894d1e4b2 100644 --- a/apps/files/src/main.ts +++ b/apps/files/src/main.ts @@ -19,9 +19,10 @@ __webpack_nonce__ = btoa(getRequestToken()) declare global { interface Window { - OC: Nextcloud.v28.OC; - OCA: Record; - OCP: Nextcloud.v28.OCP; + OC: Nextcloud.v29.OC + OCP: Nextcloud.v29.OCP + // eslint-disable-next-line @typescript-eslint/no-explicit-any + OCA: Record } } diff --git a/apps/files_external/src/actions/openInFilesAction.spec.ts b/apps/files_external/src/actions/openInFilesAction.spec.ts index 7cbf953f9c8d3..83aa38f175318 100644 --- a/apps/files_external/src/actions/openInFilesAction.spec.ts +++ b/apps/files_external/src/actions/openInFilesAction.spec.ts @@ -74,6 +74,7 @@ describe('Open in files action enabled tests', () => { describe('Open in files action execute tests', () => { test('Open in files', async () => { const goToRouteMock = jest.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 } } } const storage = new Folder({ @@ -98,6 +99,7 @@ describe('Open in files action execute tests', () => { test('Open in files broken storage', async () => { const confirmMock = jest.fn() + // @ts-expect-error We only mock what is needed window.OC = { dialogs: { confirm: confirmMock } } const storage = new Folder({ diff --git a/apps/files_sharing/src/actions/acceptShareAction.spec.ts b/apps/files_sharing/src/actions/acceptShareAction.spec.ts index 14ff88fa885a9..848bdc5496b64 100644 --- a/apps/files_sharing/src/actions/acceptShareAction.spec.ts +++ b/apps/files_sharing/src/actions/acceptShareAction.spec.ts @@ -5,6 +5,7 @@ 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 axios from '@nextcloud/axios' import '../main' @@ -103,7 +104,7 @@ describe('Accept share action execute tests', () => { permissions: Permission.READ, attributes: { id: 123, - share_type: window.OC.Share.SHARE_TYPE_USER, + share_type: ShareType.User, }, }) @@ -130,7 +131,7 @@ describe('Accept share action execute tests', () => { attributes: { id: 123, remote: 3, - share_type: window.OC.Share.SHARE_TYPE_USER, + share_type: ShareType.User, }, }) @@ -156,7 +157,7 @@ describe('Accept share action execute tests', () => { permissions: Permission.READ, attributes: { id: 123, - share_type: window.OC.Share.SHARE_TYPE_USER, + share_type: ShareType.User, }, }) @@ -168,7 +169,7 @@ describe('Accept share action execute tests', () => { permissions: Permission.READ, attributes: { id: 456, - share_type: window.OC.Share.SHARE_TYPE_USER, + share_type: ShareType.User, }, }) @@ -195,7 +196,7 @@ describe('Accept share action execute tests', () => { permissions: Permission.READ, attributes: { id: 123, - share_type: window.OC.Share.SHARE_TYPE_USER, + share_type: ShareType.User, }, }) diff --git a/apps/files_sharing/src/actions/openInFilesAction.spec.ts b/apps/files_sharing/src/actions/openInFilesAction.spec.ts index d48e3ac81444c..aa73f020bc070 100644 --- a/apps/files_sharing/src/actions/openInFilesAction.spec.ts +++ b/apps/files_sharing/src/actions/openInFilesAction.spec.ts @@ -57,6 +57,7 @@ describe('Open in files action enabled tests', () => { describe('Open in files action execute tests', () => { test('Open in files', async () => { const goToRouteMock = jest.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 } } } const file = new File({ diff --git a/apps/files_sharing/src/actions/rejectShareAction.spec.ts b/apps/files_sharing/src/actions/rejectShareAction.spec.ts index dc4c9a6960141..e4d37cd952c0e 100644 --- a/apps/files_sharing/src/actions/rejectShareAction.spec.ts +++ b/apps/files_sharing/src/actions/rejectShareAction.spec.ts @@ -5,6 +5,7 @@ import { action } from './rejectShareAction' import { expect } from '@jest/globals' import { File, Folder, Permission, View, FileAction } from '@nextcloud/files' +import { ShareType } from '@nextcloud/sharing' import eventBus from '@nextcloud/event-bus' import axios from '@nextcloud/axios' import '../main' @@ -96,7 +97,7 @@ describe('Reject share action enabled tests', () => { owner: 'admin', permissions: Permission.READ, attributes: { - share_type: window.OC.Share.SHARE_TYPE_USER, + share_type: ShareType.User, }, }) const folder2 = new Folder({ @@ -106,7 +107,7 @@ describe('Reject share action enabled tests', () => { permissions: Permission.READ, attributes: { remote_id: 1, - share_type: window.OC.Share.SHARE_TYPE_REMOTE_GROUP, + share_type: ShareType.RemoteGroup, }, }) @@ -130,7 +131,7 @@ describe('Reject share action execute tests', () => { permissions: Permission.READ, attributes: { id: 123, - share_type: window.OC.Share.SHARE_TYPE_USER, + share_type: ShareType.User, }, }) @@ -157,7 +158,7 @@ describe('Reject share action execute tests', () => { attributes: { id: 123, remote: 3, - share_type: window.OC.Share.SHARE_TYPE_USER, + share_type: ShareType.User, }, }) @@ -183,7 +184,7 @@ describe('Reject share action execute tests', () => { permissions: Permission.READ, attributes: { id: 123, - share_type: window.OC.Share.SHARE_TYPE_USER, + share_type: ShareType.User, }, }) @@ -195,7 +196,7 @@ describe('Reject share action execute tests', () => { permissions: Permission.READ, attributes: { id: 456, - share_type: window.OC.Share.SHARE_TYPE_USER, + share_type: ShareType.User, }, }) @@ -222,7 +223,7 @@ describe('Reject share action execute tests', () => { permissions: Permission.READ, attributes: { id: 123, - share_type: window.OC.Share.SHARE_TYPE_USER, + share_type: ShareType.User, }, }) diff --git a/apps/files_sharing/src/actions/rejectShareAction.ts b/apps/files_sharing/src/actions/rejectShareAction.ts index 5c3dc619f2cbd..ce47e0b5f13ff 100644 --- a/apps/files_sharing/src/actions/rejectShareAction.ts +++ b/apps/files_sharing/src/actions/rejectShareAction.ts @@ -8,6 +8,7 @@ import { emit } from '@nextcloud/event-bus' import { generateOcsUrl } from '@nextcloud/router' import { registerFileAction, FileAction } from '@nextcloud/files' import { translatePlural as n } from '@nextcloud/l10n' +import { ShareType } from '@nextcloud/sharing' import axios from '@nextcloud/axios' import CloseSvg from '@mdi/svg/svg/close.svg?raw' @@ -30,7 +31,7 @@ export const action = new FileAction({ // disable rejecting group shares from the pending list because they anyway // land back into that same list after rejecting them if (nodes.some(node => node.attributes.remote_id - && node.attributes.share_type === window.OC.Share.SHARE_TYPE_REMOTE_GROUP)) { + && node.attributes.share_type === ShareType.RemoteGroup)) { return false } diff --git a/apps/files_sharing/src/actions/restoreShareAction.spec.ts b/apps/files_sharing/src/actions/restoreShareAction.spec.ts index f35d0d0ef181d..8132c76fe2b3a 100644 --- a/apps/files_sharing/src/actions/restoreShareAction.spec.ts +++ b/apps/files_sharing/src/actions/restoreShareAction.spec.ts @@ -5,6 +5,7 @@ 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 axios from '@nextcloud/axios' import '../main' @@ -103,7 +104,7 @@ describe('Restore share action execute tests', () => { permissions: Permission.READ, attributes: { id: 123, - share_type: window.OC.Share.SHARE_TYPE_USER, + share_type: ShareType.User, }, }) @@ -129,7 +130,7 @@ describe('Restore share action execute tests', () => { permissions: Permission.READ, attributes: { id: 123, - share_type: window.OC.Share.SHARE_TYPE_USER, + share_type: ShareType.User, }, }) @@ -141,7 +142,7 @@ describe('Restore share action execute tests', () => { permissions: Permission.READ, attributes: { id: 456, - share_type: window.OC.Share.SHARE_TYPE_USER, + share_type: ShareType.User, }, }) @@ -168,7 +169,7 @@ describe('Restore share action execute tests', () => { permissions: Permission.READ, attributes: { id: 123, - share_type: window.OC.Share.SHARE_TYPE_USER, + share_type: ShareType.User, }, }) diff --git a/apps/files_sharing/src/main.ts b/apps/files_sharing/src/main.ts index aaa07fddc3656..3170fbc2a7bba 100644 --- a/apps/files_sharing/src/main.ts +++ b/apps/files_sharing/src/main.ts @@ -4,10 +4,6 @@ */ // register default shares types -if (!window.OC) { - window.OC = {} -} - Object.assign(window.OC, { Share: { SHARE_TYPE_USER: 0, diff --git a/apps/files_sharing/src/views/shares.ts b/apps/files_sharing/src/views/shares.ts index e43c75b3a5eb3..98b68ee25e298 100644 --- a/apps/files_sharing/src/views/shares.ts +++ b/apps/files_sharing/src/views/shares.ts @@ -4,6 +4,7 @@ */ import { translate as t } from '@nextcloud/l10n' import { View, getNavigation } from '@nextcloud/files' +import { ShareType } from '@nextcloud/sharing' import AccountClockSvg from '@mdi/svg/svg/account-clock.svg?raw' import AccountGroupSvg from '@mdi/svg/svg/account-group.svg?raw' import AccountPlusSvg from '@mdi/svg/svg/account-plus.svg?raw' @@ -86,7 +87,7 @@ export default () => { columns: [], - getContents: () => getContents(false, true, false, false, [window.OC.Share.SHARE_TYPE_LINK]), + getContents: () => getContents(false, true, false, false, [ShareType.Link]), })) Navigation.register(new View({