2023-06-14 04:50:55 -04:00
|
|
|
/**
|
2024-05-28 10:42:42 -04:00
|
|
|
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2023-06-14 04:50:55 -04:00
|
|
|
*/
|
2025-10-01 10:03:40 -04:00
|
|
|
import type { View } from '@nextcloud/files'
|
2024-08-24 10:53:33 -04:00
|
|
|
|
2023-06-14 04:50:55 -04:00
|
|
|
import axios from '@nextcloud/axios'
|
2024-07-26 10:04:07 -04:00
|
|
|
import * as capabilities from '@nextcloud/capabilities'
|
2024-08-24 10:53:33 -04:00
|
|
|
import * as eventBus from '@nextcloud/event-bus'
|
2025-10-01 10:03:40 -04:00
|
|
|
import { File, FileAction, Folder, Permission } from '@nextcloud/files'
|
|
|
|
|
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
|
|
|
|
|
import logger from '../logger.ts'
|
|
|
|
|
import { action } from './deleteAction.ts'
|
|
|
|
|
import { shouldAskForConfirmation } from './deleteUtils.ts'
|
2023-06-14 04:50:55 -04:00
|
|
|
|
2024-08-24 10:53:33 -04:00
|
|
|
vi.mock('@nextcloud/auth')
|
|
|
|
|
vi.mock('@nextcloud/axios')
|
|
|
|
|
vi.mock('@nextcloud/capabilities')
|
|
|
|
|
|
2023-06-14 04:50:55 -04:00
|
|
|
const view = {
|
|
|
|
|
id: 'files',
|
|
|
|
|
name: 'Files',
|
2023-08-18 04:59:14 -04:00
|
|
|
} as View
|
2023-06-14 04:50:55 -04:00
|
|
|
|
|
|
|
|
const trashbinView = {
|
|
|
|
|
id: 'trashbin',
|
|
|
|
|
name: 'Trashbin',
|
2023-08-18 04:59:14 -04:00
|
|
|
} as View
|
2023-06-14 04:50:55 -04:00
|
|
|
|
|
|
|
|
describe('Delete action conditions tests', () => {
|
2024-08-24 10:53:33 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
|
vi.restoreAllMocks()
|
2024-01-09 07:08:08 -05:00
|
|
|
})
|
|
|
|
|
|
2024-01-04 08:47:07 -05:00
|
|
|
const file = new File({
|
|
|
|
|
id: 1,
|
|
|
|
|
source: 'https://cloud.domain.com/remote.php/dav/files/test/foobar.txt',
|
|
|
|
|
owner: 'test',
|
|
|
|
|
mime: 'text/plain',
|
|
|
|
|
permissions: Permission.ALL,
|
|
|
|
|
})
|
|
|
|
|
|
2024-01-30 11:20:03 -05:00
|
|
|
const file2 = new File({
|
|
|
|
|
id: 1,
|
|
|
|
|
source: 'https://cloud.domain.com/remote.php/dav/files/admin/foobar.txt',
|
|
|
|
|
owner: 'admin',
|
|
|
|
|
mime: 'text/plain',
|
|
|
|
|
permissions: Permission.ALL,
|
|
|
|
|
attributes: {
|
|
|
|
|
'is-mount-root': true,
|
|
|
|
|
'mount-type': 'shared',
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const folder = new Folder({
|
|
|
|
|
id: 1,
|
|
|
|
|
source: 'https://cloud.domain.com/remote.php/dav/files/admin/Foo',
|
|
|
|
|
owner: 'admin',
|
|
|
|
|
mime: 'text/plain',
|
|
|
|
|
permissions: Permission.ALL,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const folder2 = new Folder({
|
|
|
|
|
id: 1,
|
|
|
|
|
source: 'https://cloud.domain.com/remote.php/dav/files/admin/Foo',
|
|
|
|
|
owner: 'admin',
|
|
|
|
|
mime: 'text/plain',
|
|
|
|
|
permissions: Permission.ALL,
|
|
|
|
|
attributes: {
|
|
|
|
|
'is-mount-root': true,
|
|
|
|
|
'mount-type': 'shared',
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const folder3 = new Folder({
|
|
|
|
|
id: 1,
|
|
|
|
|
source: 'https://cloud.domain.com/remote.php/dav/files/admin/Foo',
|
|
|
|
|
owner: 'admin',
|
|
|
|
|
mime: 'text/plain',
|
|
|
|
|
permissions: Permission.ALL,
|
|
|
|
|
attributes: {
|
|
|
|
|
'is-mount-root': true,
|
|
|
|
|
'mount-type': 'external',
|
|
|
|
|
},
|
|
|
|
|
})
|
2024-01-04 08:47:07 -05:00
|
|
|
|
2023-06-14 04:50:55 -04:00
|
|
|
test('Default values', () => {
|
|
|
|
|
expect(action).toBeInstanceOf(FileAction)
|
|
|
|
|
expect(action.id).toBe('delete')
|
2024-01-30 11:20:03 -05:00
|
|
|
expect(action.displayName([file], view)).toBe('Delete file')
|
2024-08-24 10:53:33 -04:00
|
|
|
expect(action.iconSvgInline([], view)).toMatch(/<svg.+<\/svg>/)
|
2023-06-22 08:57:25 -04:00
|
|
|
expect(action.default).toBeUndefined()
|
2023-06-14 04:50:55 -04:00
|
|
|
expect(action.order).toBe(100)
|
|
|
|
|
})
|
|
|
|
|
|
2024-01-30 11:20:03 -05:00
|
|
|
test('Default folder displayName', () => {
|
|
|
|
|
expect(action.displayName([folder], view)).toBe('Delete folder')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('Default trashbin view displayName', () => {
|
2024-01-04 08:47:07 -05:00
|
|
|
expect(action.displayName([file], trashbinView)).toBe('Delete permanently')
|
|
|
|
|
})
|
|
|
|
|
|
2024-07-26 10:04:07 -04:00
|
|
|
test('Trashbin disabled displayName', () => {
|
2024-08-24 10:53:33 -04:00
|
|
|
vi.spyOn(capabilities, 'getCapabilities').mockImplementation(() => {
|
2024-07-26 10:04:07 -04:00
|
|
|
return {
|
|
|
|
|
files: {},
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
expect(action.displayName([file], view)).toBe('Delete permanently')
|
|
|
|
|
expect(capabilities.getCapabilities).toBeCalledTimes(1)
|
|
|
|
|
})
|
|
|
|
|
|
2024-01-30 11:20:03 -05:00
|
|
|
test('Shared root node displayName', () => {
|
|
|
|
|
expect(action.displayName([file2], view)).toBe('Leave this share')
|
|
|
|
|
expect(action.displayName([folder2], view)).toBe('Leave this share')
|
|
|
|
|
expect(action.displayName([file2, folder2], view)).toBe('Leave these shares')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('External storage root node displayName', () => {
|
|
|
|
|
expect(action.displayName([folder3], view)).toBe('Disconnect storage')
|
|
|
|
|
expect(action.displayName([folder3, folder3], view)).toBe('Disconnect storages')
|
|
|
|
|
})
|
2024-01-04 08:47:07 -05:00
|
|
|
|
2024-01-30 11:20:03 -05:00
|
|
|
test('Shared and owned nodes displayName', () => {
|
|
|
|
|
expect(action.displayName([file, file2], view)).toBe('Delete and unshare')
|
|
|
|
|
})
|
2023-06-14 04:50:55 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
describe('Delete action enabled tests', () => {
|
2025-01-07 11:02:43 -05:00
|
|
|
let initialState: HTMLInputElement
|
|
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
|
document.body.removeChild(initialState)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
initialState = document.createElement('input')
|
|
|
|
|
initialState.setAttribute('type', 'hidden')
|
|
|
|
|
initialState.setAttribute('id', 'initial-state-files_trashbin-config')
|
|
|
|
|
initialState.setAttribute('value', btoa(JSON.stringify({
|
|
|
|
|
allow_delete: true,
|
|
|
|
|
})))
|
|
|
|
|
document.body.appendChild(initialState)
|
|
|
|
|
})
|
|
|
|
|
|
2023-06-14 04:50:55 -04:00
|
|
|
test('Enabled with DELETE permissions', () => {
|
|
|
|
|
const file = new File({
|
|
|
|
|
id: 1,
|
2024-01-04 08:47:07 -05:00
|
|
|
source: 'https://cloud.domain.com/remote.php/dav/files/test/foobar.txt',
|
|
|
|
|
owner: 'test',
|
2023-06-14 04:50:55 -04:00
|
|
|
mime: 'text/plain',
|
|
|
|
|
permissions: Permission.ALL,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
expect(action.enabled).toBeDefined()
|
|
|
|
|
expect(action.enabled!([file], view)).toBe(true)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('Disabled without DELETE permissions', () => {
|
|
|
|
|
const file = new File({
|
|
|
|
|
id: 1,
|
2024-01-04 08:47:07 -05:00
|
|
|
source: 'https://cloud.domain.com/remote.php/dav/files/test/foobar.txt',
|
|
|
|
|
owner: 'test',
|
2023-06-14 04:50:55 -04:00
|
|
|
mime: 'text/plain',
|
|
|
|
|
permissions: Permission.READ,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
expect(action.enabled).toBeDefined()
|
|
|
|
|
expect(action.enabled!([file], view)).toBe(false)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('Disabled without nodes', () => {
|
|
|
|
|
expect(action.enabled).toBeDefined()
|
|
|
|
|
expect(action.enabled!([], view)).toBe(false)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('Disabled if not all nodes can be deleted', () => {
|
|
|
|
|
const folder1 = new Folder({
|
|
|
|
|
id: 1,
|
2024-01-04 08:47:07 -05:00
|
|
|
source: 'https://cloud.domain.com/remote.php/dav/files/test/Foo/',
|
|
|
|
|
owner: 'test',
|
2023-06-14 04:50:55 -04:00
|
|
|
permissions: Permission.DELETE,
|
|
|
|
|
})
|
|
|
|
|
const folder2 = new Folder({
|
|
|
|
|
id: 2,
|
2024-01-04 08:47:07 -05:00
|
|
|
source: 'https://cloud.domain.com/remote.php/dav/files/test/Bar/',
|
|
|
|
|
owner: 'test',
|
2023-06-14 04:50:55 -04:00
|
|
|
permissions: Permission.READ,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
expect(action.enabled).toBeDefined()
|
|
|
|
|
expect(action.enabled!([folder1], view)).toBe(true)
|
|
|
|
|
expect(action.enabled!([folder2], view)).toBe(false)
|
|
|
|
|
expect(action.enabled!([folder1, folder2], view)).toBe(false)
|
|
|
|
|
})
|
2025-01-07 11:02:43 -05:00
|
|
|
|
|
|
|
|
test('Disabled if not allowed', () => {
|
|
|
|
|
initialState.setAttribute('value', btoa(JSON.stringify({
|
|
|
|
|
allow_delete: false,
|
|
|
|
|
})))
|
|
|
|
|
|
|
|
|
|
expect(action.enabled).toBeDefined()
|
|
|
|
|
expect(action.enabled!([], view)).toBe(false)
|
|
|
|
|
})
|
2023-06-14 04:50:55 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
describe('Delete action execute tests', () => {
|
2024-07-26 10:04:07 -04:00
|
|
|
afterEach(() => {
|
2024-08-24 10:53:33 -04:00
|
|
|
vi.restoreAllMocks()
|
2024-07-26 10:04:07 -04:00
|
|
|
})
|
2023-06-14 04:50:55 -04:00
|
|
|
test('Delete action', async () => {
|
2024-08-24 10:53:33 -04:00
|
|
|
vi.spyOn(axios, 'delete')
|
|
|
|
|
vi.spyOn(eventBus, 'emit')
|
2023-06-14 04:50:55 -04:00
|
|
|
|
|
|
|
|
const file = new File({
|
|
|
|
|
id: 1,
|
2024-01-04 08:47:07 -05:00
|
|
|
source: 'https://cloud.domain.com/remote.php/dav/files/test/foobar.txt',
|
|
|
|
|
owner: 'test',
|
2023-06-14 04:50:55 -04:00
|
|
|
mime: 'text/plain',
|
|
|
|
|
permissions: Permission.READ | Permission.UPDATE | Permission.DELETE,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const exec = await action.exec(file, view, '/')
|
|
|
|
|
|
|
|
|
|
expect(exec).toBe(true)
|
|
|
|
|
expect(axios.delete).toBeCalledTimes(1)
|
2024-01-04 08:47:07 -05:00
|
|
|
expect(axios.delete).toBeCalledWith('https://cloud.domain.com/remote.php/dav/files/test/foobar.txt')
|
2023-06-14 04:50:55 -04:00
|
|
|
|
|
|
|
|
expect(eventBus.emit).toBeCalledTimes(1)
|
|
|
|
|
expect(eventBus.emit).toBeCalledWith('files:node:deleted', file)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('Delete action batch', async () => {
|
2024-08-24 10:53:33 -04:00
|
|
|
vi.spyOn(axios, 'delete')
|
|
|
|
|
vi.spyOn(eventBus, 'emit')
|
2023-06-14 04:50:55 -04:00
|
|
|
|
2024-08-24 10:53:33 -04:00
|
|
|
const confirmMock = vi.fn()
|
2024-01-31 04:09:58 -05:00
|
|
|
window.OC = { dialogs: { confirmDestructive: confirmMock } }
|
|
|
|
|
|
2023-06-14 04:50:55 -04:00
|
|
|
const file1 = new File({
|
|
|
|
|
id: 1,
|
2024-01-04 08:47:07 -05:00
|
|
|
source: 'https://cloud.domain.com/remote.php/dav/files/test/foo.txt',
|
|
|
|
|
owner: 'test',
|
2023-06-14 04:50:55 -04:00
|
|
|
mime: 'text/plain',
|
|
|
|
|
permissions: Permission.READ | Permission.UPDATE | Permission.DELETE,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const file2 = new File({
|
|
|
|
|
id: 2,
|
2024-01-04 08:47:07 -05:00
|
|
|
source: 'https://cloud.domain.com/remote.php/dav/files/test/bar.txt',
|
|
|
|
|
owner: 'test',
|
2023-06-14 04:50:55 -04:00
|
|
|
mime: 'text/plain',
|
|
|
|
|
permissions: Permission.READ | Permission.UPDATE | Permission.DELETE,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const exec = await action.execBatch!([file1, file2], view, '/')
|
|
|
|
|
|
2024-01-31 04:09:58 -05:00
|
|
|
// Not enough nodes to trigger a confirmation dialog
|
|
|
|
|
expect(confirmMock).toBeCalledTimes(0)
|
|
|
|
|
|
2023-06-14 04:50:55 -04:00
|
|
|
expect(exec).toStrictEqual([true, true])
|
|
|
|
|
expect(axios.delete).toBeCalledTimes(2)
|
2024-01-04 08:47:07 -05:00
|
|
|
expect(axios.delete).toHaveBeenNthCalledWith(1, 'https://cloud.domain.com/remote.php/dav/files/test/foo.txt')
|
|
|
|
|
expect(axios.delete).toHaveBeenNthCalledWith(2, 'https://cloud.domain.com/remote.php/dav/files/test/bar.txt')
|
2023-06-14 04:50:55 -04:00
|
|
|
|
|
|
|
|
expect(eventBus.emit).toBeCalledTimes(2)
|
|
|
|
|
expect(eventBus.emit).toHaveBeenNthCalledWith(1, 'files:node:deleted', file1)
|
|
|
|
|
expect(eventBus.emit).toHaveBeenNthCalledWith(2, 'files:node:deleted', file2)
|
|
|
|
|
})
|
|
|
|
|
|
2024-07-26 10:04:07 -04:00
|
|
|
test('Delete action batch large set', async () => {
|
2024-08-24 10:53:33 -04:00
|
|
|
vi.spyOn(axios, 'delete')
|
|
|
|
|
vi.spyOn(eventBus, 'emit')
|
2024-07-26 10:04:07 -04:00
|
|
|
|
|
|
|
|
// Emulate the confirmation dialog to always confirm
|
2024-08-24 10:53:33 -04:00
|
|
|
const confirmMock = vi.fn().mockImplementation((a, b, c, resolve) => resolve(true))
|
2024-07-26 10:04:07 -04:00
|
|
|
window.OC = { dialogs: { confirmDestructive: confirmMock } }
|
|
|
|
|
|
|
|
|
|
const file1 = new File({
|
|
|
|
|
id: 1,
|
|
|
|
|
source: 'https://cloud.domain.com/remote.php/dav/files/test/foo.txt',
|
|
|
|
|
owner: 'test',
|
|
|
|
|
mime: 'text/plain',
|
|
|
|
|
permissions: Permission.READ | Permission.UPDATE | Permission.DELETE,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const file2 = new File({
|
|
|
|
|
id: 2,
|
|
|
|
|
source: 'https://cloud.domain.com/remote.php/dav/files/test/bar.txt',
|
|
|
|
|
owner: 'test',
|
|
|
|
|
mime: 'text/plain',
|
|
|
|
|
permissions: Permission.READ | Permission.UPDATE | Permission.DELETE,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const file3 = new File({
|
|
|
|
|
id: 3,
|
|
|
|
|
source: 'https://cloud.domain.com/remote.php/dav/files/test/baz.txt',
|
|
|
|
|
owner: 'test',
|
|
|
|
|
mime: 'text/plain',
|
|
|
|
|
permissions: Permission.READ | Permission.UPDATE | Permission.DELETE,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const file4 = new File({
|
|
|
|
|
id: 4,
|
|
|
|
|
source: 'https://cloud.domain.com/remote.php/dav/files/test/qux.txt',
|
|
|
|
|
owner: 'test',
|
|
|
|
|
mime: 'text/plain',
|
|
|
|
|
permissions: Permission.READ | Permission.UPDATE | Permission.DELETE,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const file5 = new File({
|
|
|
|
|
id: 5,
|
|
|
|
|
source: 'https://cloud.domain.com/remote.php/dav/files/test/quux.txt',
|
|
|
|
|
owner: 'test',
|
|
|
|
|
mime: 'text/plain',
|
|
|
|
|
permissions: Permission.READ | Permission.UPDATE | Permission.DELETE,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const exec = await action.execBatch!([file1, file2, file3, file4, file5], view, '/')
|
|
|
|
|
|
|
|
|
|
// Enough nodes to trigger a confirmation dialog
|
|
|
|
|
expect(confirmMock).toBeCalledTimes(1)
|
|
|
|
|
|
|
|
|
|
expect(exec).toStrictEqual([true, true, true, true, true])
|
|
|
|
|
expect(axios.delete).toBeCalledTimes(5)
|
|
|
|
|
expect(axios.delete).toHaveBeenNthCalledWith(1, 'https://cloud.domain.com/remote.php/dav/files/test/foo.txt')
|
|
|
|
|
expect(axios.delete).toHaveBeenNthCalledWith(2, 'https://cloud.domain.com/remote.php/dav/files/test/bar.txt')
|
|
|
|
|
expect(axios.delete).toHaveBeenNthCalledWith(3, 'https://cloud.domain.com/remote.php/dav/files/test/baz.txt')
|
|
|
|
|
expect(axios.delete).toHaveBeenNthCalledWith(4, 'https://cloud.domain.com/remote.php/dav/files/test/qux.txt')
|
|
|
|
|
expect(axios.delete).toHaveBeenNthCalledWith(5, 'https://cloud.domain.com/remote.php/dav/files/test/quux.txt')
|
|
|
|
|
|
|
|
|
|
expect(eventBus.emit).toBeCalledTimes(5)
|
|
|
|
|
expect(eventBus.emit).toHaveBeenNthCalledWith(1, 'files:node:deleted', file1)
|
|
|
|
|
expect(eventBus.emit).toHaveBeenNthCalledWith(2, 'files:node:deleted', file2)
|
|
|
|
|
expect(eventBus.emit).toHaveBeenNthCalledWith(3, 'files:node:deleted', file3)
|
|
|
|
|
expect(eventBus.emit).toHaveBeenNthCalledWith(4, 'files:node:deleted', file4)
|
|
|
|
|
expect(eventBus.emit).toHaveBeenNthCalledWith(5, 'files:node:deleted', file5)
|
|
|
|
|
})
|
|
|
|
|
|
2025-07-10 11:37:21 -04:00
|
|
|
test('Delete action batch dialog enabled', async () => {
|
|
|
|
|
// Enable the confirmation dialog
|
|
|
|
|
eventBus.emit('files:config:updated', { key: 'show_dialog_deletion', value: true })
|
|
|
|
|
expect(shouldAskForConfirmation()).toBe(true)
|
|
|
|
|
|
2024-08-24 10:53:33 -04:00
|
|
|
vi.spyOn(axios, 'delete')
|
|
|
|
|
vi.spyOn(eventBus, 'emit')
|
|
|
|
|
vi.spyOn(capabilities, 'getCapabilities').mockImplementation(() => {
|
2024-07-26 10:04:07 -04:00
|
|
|
return {
|
|
|
|
|
files: {},
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Emulate the confirmation dialog to always confirm
|
2024-08-24 10:53:33 -04:00
|
|
|
const confirmMock = vi.fn().mockImplementation((a, b, c, resolve) => resolve(true))
|
2024-07-26 10:04:07 -04:00
|
|
|
window.OC = { dialogs: { confirmDestructive: confirmMock } }
|
|
|
|
|
|
|
|
|
|
const file1 = new File({
|
|
|
|
|
id: 1,
|
|
|
|
|
source: 'https://cloud.domain.com/remote.php/dav/files/test/foo.txt',
|
|
|
|
|
owner: 'test',
|
|
|
|
|
mime: 'text/plain',
|
|
|
|
|
permissions: Permission.READ | Permission.UPDATE | Permission.DELETE,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const file2 = new File({
|
|
|
|
|
id: 2,
|
|
|
|
|
source: 'https://cloud.domain.com/remote.php/dav/files/test/bar.txt',
|
|
|
|
|
owner: 'test',
|
|
|
|
|
mime: 'text/plain',
|
|
|
|
|
permissions: Permission.READ | Permission.UPDATE | Permission.DELETE,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const exec = await action.execBatch!([file1, file2], view, '/')
|
|
|
|
|
|
|
|
|
|
// Will trigger a confirmation dialog because trashbin app is disabled
|
|
|
|
|
expect(confirmMock).toBeCalledTimes(1)
|
|
|
|
|
|
|
|
|
|
expect(exec).toStrictEqual([true, true])
|
|
|
|
|
expect(axios.delete).toBeCalledTimes(2)
|
|
|
|
|
expect(axios.delete).toHaveBeenNthCalledWith(1, 'https://cloud.domain.com/remote.php/dav/files/test/foo.txt')
|
|
|
|
|
expect(axios.delete).toHaveBeenNthCalledWith(2, 'https://cloud.domain.com/remote.php/dav/files/test/bar.txt')
|
|
|
|
|
|
|
|
|
|
expect(eventBus.emit).toBeCalledTimes(2)
|
|
|
|
|
expect(eventBus.emit).toHaveBeenNthCalledWith(1, 'files:node:deleted', file1)
|
|
|
|
|
expect(eventBus.emit).toHaveBeenNthCalledWith(2, 'files:node:deleted', file2)
|
2025-07-10 11:37:21 -04:00
|
|
|
|
|
|
|
|
eventBus.emit('files:config:updated', { key: 'show_dialog_deletion', value: false })
|
2024-07-26 10:04:07 -04:00
|
|
|
})
|
|
|
|
|
|
2023-06-14 04:50:55 -04:00
|
|
|
test('Delete fails', async () => {
|
2025-10-01 10:03:40 -04:00
|
|
|
vi.spyOn(axios, 'delete').mockImplementation(() => {
|
|
|
|
|
throw new Error('Mock error')
|
|
|
|
|
})
|
2024-08-24 10:53:33 -04:00
|
|
|
vi.spyOn(logger, 'error').mockImplementation(() => vi.fn())
|
|
|
|
|
vi.spyOn(eventBus, 'emit')
|
2023-06-14 04:50:55 -04:00
|
|
|
|
|
|
|
|
const file = new File({
|
|
|
|
|
id: 1,
|
2024-01-04 08:47:07 -05:00
|
|
|
source: 'https://cloud.domain.com/remote.php/dav/files/test/foobar.txt',
|
|
|
|
|
owner: 'test',
|
2023-06-14 04:50:55 -04:00
|
|
|
mime: 'text/plain',
|
|
|
|
|
permissions: Permission.READ | Permission.UPDATE | Permission.DELETE,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const exec = await action.exec(file, view, '/')
|
|
|
|
|
|
|
|
|
|
expect(exec).toBe(false)
|
|
|
|
|
expect(axios.delete).toBeCalledTimes(1)
|
2024-01-04 08:47:07 -05:00
|
|
|
expect(axios.delete).toBeCalledWith('https://cloud.domain.com/remote.php/dav/files/test/foobar.txt')
|
2023-06-14 04:50:55 -04:00
|
|
|
|
|
|
|
|
expect(eventBus.emit).toBeCalledTimes(0)
|
|
|
|
|
expect(logger.error).toBeCalledTimes(1)
|
|
|
|
|
})
|
2024-07-26 10:04:07 -04:00
|
|
|
|
2025-07-10 11:37:21 -04:00
|
|
|
test('Delete is cancelled with dialog enabled', async () => {
|
|
|
|
|
// Enable the confirmation dialog
|
|
|
|
|
eventBus.emit('files:config:updated', { key: 'show_dialog_deletion', value: true })
|
|
|
|
|
|
2024-08-24 10:53:33 -04:00
|
|
|
vi.spyOn(axios, 'delete')
|
|
|
|
|
vi.spyOn(eventBus, 'emit')
|
|
|
|
|
vi.spyOn(capabilities, 'getCapabilities').mockImplementation(() => {
|
2024-07-26 10:04:07 -04:00
|
|
|
return {
|
|
|
|
|
files: {},
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Emulate the confirmation dialog to always confirm
|
2024-08-24 10:53:33 -04:00
|
|
|
const confirmMock = vi.fn().mockImplementation((a, b, c, resolve) => resolve(false))
|
2024-07-26 10:04:07 -04:00
|
|
|
window.OC = { dialogs: { confirmDestructive: confirmMock } }
|
|
|
|
|
|
|
|
|
|
const file1 = new File({
|
|
|
|
|
id: 1,
|
|
|
|
|
source: 'https://cloud.domain.com/remote.php/dav/files/test/foo.txt',
|
|
|
|
|
owner: 'test',
|
|
|
|
|
mime: 'text/plain',
|
|
|
|
|
permissions: Permission.READ | Permission.UPDATE | Permission.DELETE,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const exec = await action.execBatch!([file1], view, '/')
|
|
|
|
|
|
|
|
|
|
expect(confirmMock).toBeCalledTimes(1)
|
|
|
|
|
|
|
|
|
|
expect(exec).toStrictEqual([null])
|
|
|
|
|
expect(axios.delete).toBeCalledTimes(0)
|
|
|
|
|
|
|
|
|
|
expect(eventBus.emit).toBeCalledTimes(0)
|
2025-07-10 11:37:21 -04:00
|
|
|
|
|
|
|
|
eventBus.emit('files:config:updated', { key: 'show_dialog_deletion', value: false })
|
2024-07-26 10:04:07 -04:00
|
|
|
})
|
2023-06-14 04:50:55 -04:00
|
|
|
})
|