Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .eslintignore

This file was deleted.

13 changes: 0 additions & 13 deletions .eslintrc.json

This file was deleted.

4 changes: 2 additions & 2 deletions __mocks__/@nextcloud/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
* SPDX-FileCopyrightText: 2022-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
export const getCurrentUser = function() {
export function getCurrentUser() {
return {
uid: 'test',
displayName: 'Test',
isAdmin: false,
}
}

export const getRequestToken = function() {
export function getRequestToken() {
return 'some-token-string'
}
45 changes: 16 additions & 29 deletions __tests__/actions/fileAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import type { Folder, Node } from '../../lib/node/index.ts'
import type { FileActionData } from '../../lib/actions/index.ts'
import type { View } from '../../lib/navigation/view.ts'
import type { Folder, Node } from '../../lib/node/index.ts'

import { beforeEach, describe, expect, test, vi } from 'vitest'
import { getFileActions, registerFileAction, FileAction, DefaultType, FileActionData } from '../../lib/actions/index.ts'
import { DefaultType, FileAction, getFileActions, registerFileAction } from '../../lib/actions/index.ts'
import logger from '../../lib/utils/logger.ts'

const folder = {} as Folder
const view = {} as View
describe('FileActions init', () => {

beforeEach(() => {
delete window._nc_fileactions
})
Expand Down Expand Up @@ -101,17 +101,15 @@ describe('Invalid FileAction creation', () => {
displayName: () => 'Test',
iconSvgInline: () => '<svg></svg>',
exec: async () => true,
} as unknown as FileAction),
).toThrowError('Invalid id')
} as unknown as FileAction)).toThrowError('Invalid id')
})
test('Invalid displayName', () => {
expect(() => new FileAction({
id: 'test',
displayName: 'Test',
iconSvgInline: () => '<svg></svg>',
exec: async () => true,
} as unknown as FileAction),
).toThrowError('Invalid displayName function')
} as unknown as FileAction)).toThrowError('Invalid displayName function')
})
test('Invalid title', () => {
expect(() => new FileAction({
Expand All @@ -120,26 +118,23 @@ describe('Invalid FileAction creation', () => {
title: 'Test',
iconSvgInline: () => '<svg></svg>',
exec: async () => true,
} as unknown as FileAction),
).toThrowError('Invalid title function')
} as unknown as FileAction)).toThrowError('Invalid title function')
})
test('Invalid iconSvgInline', () => {
expect(() => new FileAction({
id: 'test',
displayName: () => 'Test',
iconSvgInline: '<svg></svg>',
exec: async () => true,
} as unknown as FileAction),
).toThrowError('Invalid iconSvgInline function')
} as unknown as FileAction)).toThrowError('Invalid iconSvgInline function')
})
test('Invalid exec', () => {
expect(() => new FileAction({
id: 'test',
displayName: () => 'Test',
iconSvgInline: () => '<svg></svg>',
exec: false,
} as unknown as FileAction),
).toThrowError('Invalid exec function')
} as unknown as FileAction)).toThrowError('Invalid exec function')
})
test('Invalid enabled', () => {
expect(() => new FileAction({
Expand All @@ -148,8 +143,7 @@ describe('Invalid FileAction creation', () => {
iconSvgInline: () => '<svg></svg>',
exec: async () => true,
enabled: false,
} as unknown as FileAction),
).toThrowError('Invalid enabled function')
} as unknown as FileAction)).toThrowError('Invalid enabled function')
})
test('Invalid execBatch', () => {
expect(() => new FileAction({
Expand All @@ -158,8 +152,7 @@ describe('Invalid FileAction creation', () => {
iconSvgInline: () => '<svg></svg>',
exec: async () => true,
execBatch: false,
} as unknown as FileAction),
).toThrowError('Invalid execBatch function')
} as unknown as FileAction)).toThrowError('Invalid execBatch function')
})
test('Invalid order', () => {
expect(() => new FileAction({
Expand All @@ -168,8 +161,7 @@ describe('Invalid FileAction creation', () => {
iconSvgInline: () => '<svg></svg>',
exec: async () => true,
order: 'invalid',
} as unknown as FileAction),
).toThrowError('Invalid order')
} as unknown as FileAction)).toThrowError('Invalid order')
})
test('Invalid parent', () => {
expect(() => new FileAction({
Expand All @@ -178,8 +170,7 @@ describe('Invalid FileAction creation', () => {
iconSvgInline: () => '<svg></svg>',
exec: async () => true,
parent: true,
} as unknown as FileAction),
).toThrowError('Invalid parent')
} as unknown as FileAction)).toThrowError('Invalid parent')
})
test('Invalid default', () => {
expect(() => new FileAction({
Expand All @@ -188,8 +179,7 @@ describe('Invalid FileAction creation', () => {
iconSvgInline: () => '<svg></svg>',
exec: async () => true,
default: 'invalid',
} as unknown as FileAction),
).toThrowError('Invalid default')
} as unknown as FileAction)).toThrowError('Invalid default')
})
test('Invalid destructives', () => {
expect(() => new FileAction({
Expand All @@ -198,8 +188,7 @@ describe('Invalid FileAction creation', () => {
iconSvgInline: () => '<svg></svg>',
exec: async () => true,
destructive: 'false',
} as unknown as FileActionData),
).toThrowError('Invalid destructive')
} as unknown as FileActionData)).toThrowError('Invalid destructive')
})
test('Invalid inline', () => {
expect(() => new FileAction({
Expand All @@ -208,8 +197,7 @@ describe('Invalid FileAction creation', () => {
iconSvgInline: () => '<svg></svg>',
exec: async () => true,
inline: true,
} as unknown as FileAction),
).toThrowError('Invalid inline function')
} as unknown as FileAction)).toThrowError('Invalid inline function')

expect(() => new FileAction({
id: 'test',
Expand All @@ -218,8 +206,7 @@ describe('Invalid FileAction creation', () => {
exec: async () => true,
inline: () => true,
renderInline: false,
} as unknown as FileAction),
).toThrowError('Invalid renderInline function')
} as unknown as FileAction)).toThrowError('Invalid renderInline function')
})
})

Expand Down
46 changes: 21 additions & 25 deletions __tests__/actions/fileListAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,25 @@
*/

import type { View } from '../../lib/navigation/view.ts'
import type { Folder } from '../../lib/node/index.ts'

import { beforeEach, describe, expect, test, vi } from 'vitest'
import { getFileListActions, registerFileListAction, FileListAction } from '../../lib/actions/fileListAction.ts'
import { Folder } from '../../lib/node/index.ts'
import { FileListAction, getFileListActions, registerFileListAction } from '../../lib/actions/fileListAction.ts'
import logger from '../../lib/utils/logger.ts'

const folder = {} as Folder
const view = {} as View

const mockAction = (id: string) => new FileListAction({
id,
displayName: () => 'Test',
iconSvgInline: () => '<svg></svg>',
order: 0,
// @ts-expect-error mocking for tests
exec: async () => {},
})
function mockAction(id: string) {
return new FileListAction({
id,
displayName: () => 'Test',
iconSvgInline: () => '<svg></svg>',
order: 0,
// @ts-expect-error mocking for tests
exec: async () => {},
})
}

describe('FileListActions init', () => {
beforeEach(() => {
Expand Down Expand Up @@ -61,9 +63,9 @@ describe('FileListActions init', () => {
registerFileListAction(bazAction)
expect(actions).toHaveLength(3)

expect(actions.find(action => action.id === 'foo')).toStrictEqual(fooAction)
expect(actions.find(action => action.id === 'bar')).toStrictEqual(barAction)
expect(actions.find(action => action.id === 'baz')).toStrictEqual(bazAction)
expect(actions.find((action) => action.id === 'foo')).toStrictEqual(fooAction)
expect(actions.find((action) => action.id === 'bar')).toStrictEqual(barAction)
expect(actions.find((action) => action.id === 'baz')).toStrictEqual(bazAction)
})

test('Register an action with a duplicate id', () => {
Expand Down Expand Up @@ -91,17 +93,15 @@ describe('Invalid FileListAction creation', () => {
iconSvgInline: () => '<svg></svg>',
order: 0,
exec: async () => {},
} as unknown as FileListAction),
).toThrowError('Invalid id')
} as unknown as FileListAction)).toThrowError('Invalid id')
})
test('Invalid displayName', () => {
expect(() => new FileListAction({
id: 'test',
iconSvgInline: () => '<svg></svg>',
order: 0,
exec: async () => {},
} as unknown as FileListAction),
).toThrowError('Invalid displayName function')
} as unknown as FileListAction)).toThrowError('Invalid displayName function')
})
test('Invalid iconSvgInline', () => {
expect(() => new FileListAction({
Expand All @@ -110,8 +110,7 @@ describe('Invalid FileListAction creation', () => {
displayName: () => 'Test',
order: 0,
exec: async () => {},
} as unknown as FileListAction),
).toThrowError('Invalid iconSvgInline function')
} as unknown as FileListAction)).toThrowError('Invalid iconSvgInline function')
})
test('Invalid order', () => {
expect(() => new FileListAction({
Expand All @@ -120,8 +119,7 @@ describe('Invalid FileListAction creation', () => {
iconSvgInline: () => '<svg></svg>',
order: null,
exec: async () => {},
} as unknown as FileListAction),
).toThrowError('Invalid order')
} as unknown as FileListAction)).toThrowError('Invalid order')
})
test('Invalid enabled', () => {
expect(() => new FileListAction({
Expand All @@ -131,17 +129,15 @@ describe('Invalid FileListAction creation', () => {
order: 0,
enabled: null,
exec: async () => {},
} as unknown as FileListAction),
).toThrowError('Invalid enabled function')
} as unknown as FileListAction)).toThrowError('Invalid enabled function')
})
test('Invalid exec', () => {
expect(() => new FileListAction({
id: 'test',
displayName: () => 'Test',
iconSvgInline: () => '<svg></svg>',
exec: null,
} as unknown as FileListAction),
).toThrowError('Invalid exec function')
} as unknown as FileListAction)).toThrowError('Invalid exec function')
})
})

Expand Down
24 changes: 12 additions & 12 deletions __tests__/dav/dav.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
* SPDX-FileCopyrightText: 2023-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
import { readFile } from 'node:fs/promises'

import type { FileStat, WebDAVClient } from 'webdav'

import * as auth from '@nextcloud/auth'
import { readFile } from 'node:fs/promises'
// required as default URL will be the DOM URL class which will use the window.location
import { URL as FileURL } from 'node:url'
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
import {
defaultRemoteURL,
defaultRootPath,
getFavoritesReport,
getFavoriteNodes,
getFavoritesReport,
resultToNode,
} from '../../lib/dav/index'
import { File, Folder, NodeStatus } from '../../lib'
import { FileStat, WebDAVClient } from 'webdav'
import * as auth from '@nextcloud/auth'

// required as default URL will be the DOM URL class which will use the window.location
import { URL as FileURL } from 'node:url'
} from '../../lib/dav/index.ts'
import { File, Folder, NodeStatus } from '../../lib/index.ts'

vi.mock('@nextcloud/auth')
vi.mock('@nextcloud/router')
Expand Down Expand Up @@ -185,7 +185,7 @@ describe('DAV requests', () => {

// Mock the WebDAV client
const client = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any

getDirectoryContents: vi.fn((path: string, options: any) => {
if (options?.details) {
return {
Expand Down Expand Up @@ -218,7 +218,7 @@ describe('DAV requests', () => {

// Mock the WebDAV client
const client = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any

getDirectoryContents: vi.fn((path: string, options: any) => {
if (options?.details) {
return {
Expand Down
8 changes: 3 additions & 5 deletions __tests__/dav/davPermissions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { describe, it, expect } from 'vitest'

import { parsePermissions } from '../../lib/dav/davPermissions'
import { Permission } from '../../lib/permissions'
import { describe, expect, it } from 'vitest'
import { parsePermissions } from '../../lib/dav/davPermissions.ts'
import { Permission } from '../../lib/permissions.ts'

const dataSet = [
{ input: undefined, permissions: Permission.NONE },
Expand All @@ -29,7 +28,6 @@ const dataSet = [
describe('davParsePermissions', () => {
dataSet.forEach(({ input, permissions }) => {
it(`expect ${input} to be ${permissions}`, () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect(parsePermissions(input as any as string)).toBe(permissions)
})
})
Expand Down
Loading