Skip to content

Commit

Permalink
test: Adjust Typescript definitions for OCP and OC
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed Jul 2, 2024
1 parent 39a916a commit 91f4df6
Show file tree
Hide file tree
Showing 15 changed files with 40 additions and 23 deletions.
1 change: 1 addition & 0 deletions apps/files/src/actions/deleteAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
1 change: 1 addition & 0 deletions apps/files/src/actions/favoriteAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const favoriteView = {
} as View

global.window.OC = {
// @ts-expect-error This constant is currently missing in @nextcloud/typings
TAG_FAVORITE: '_$!<Favorite>!$_',
}

Expand Down
3 changes: 3 additions & 0 deletions apps/files/src/actions/openFolderAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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, '/')
Expand All @@ -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({
Expand Down
2 changes: 2 additions & 0 deletions apps/files/src/actions/openInFilesAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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({
Expand Down
1 change: 1 addition & 0 deletions apps/files/src/actions/sidebarAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
4 changes: 4 additions & 0 deletions apps/files/src/actions/viewInFolderAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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({
Expand All @@ -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, '/')
Expand All @@ -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({
Expand Down
3 changes: 2 additions & 1 deletion apps/files/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ __webpack_nonce__ = btoa(getRequestToken())
declare global {
interface Window {
OC: Nextcloud.v28.OC;
OCA: Record<string, unknown>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
OCA: Record<string, any>;
OCP: Nextcloud.v28.OCP;
}
}
Expand Down
2 changes: 2 additions & 0 deletions apps/files_external/src/actions/openInFilesAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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({
Expand Down
11 changes: 6 additions & 5 deletions apps/files_sharing/src/actions/acceptShareAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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,
},
})

Expand All @@ -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,
},
})

Expand All @@ -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,
},
})

Expand All @@ -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,
},
})

Expand All @@ -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,
},
})

Expand Down
1 change: 1 addition & 0 deletions apps/files_sharing/src/actions/openInFilesAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
15 changes: 8 additions & 7 deletions apps/files_sharing/src/actions/rejectShareAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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({
Expand All @@ -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,
},
})

Expand All @@ -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,
},
})

Expand All @@ -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,
},
})

Expand All @@ -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,
},
})

Expand All @@ -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,
},
})

Expand All @@ -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,
},
})

Expand Down
3 changes: 2 additions & 1 deletion apps/files_sharing/src/actions/rejectShareAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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
}

Expand Down
9 changes: 5 additions & 4 deletions apps/files_sharing/src/actions/restoreShareAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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,
},
})

Expand All @@ -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,
},
})

Expand All @@ -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,
},
})

Expand All @@ -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,
},
})

Expand Down
4 changes: 0 additions & 4 deletions apps/files_sharing/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
*/

// register default shares types
if (!window.OC) {
window.OC = {}
}

Object.assign(window.OC, {
Share: {
SHARE_TYPE_USER: 0,
Expand Down
3 changes: 2 additions & 1 deletion apps/files_sharing/src/views/shares.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit 91f4df6

Please sign in to comment.