aboutsummaryrefslogtreecommitdiffstats
path: root/cypress/e2e/files/files-delete.cy.ts
blob: edb88519c599b1f58eaf38b2ca3e7eceffb48d14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*!
 * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

import type { User } from '@nextcloud/cypress'
import { getRowForFile, navigateToFolder, selectAllFiles, triggerActionForFile } from './FilesUtils.ts'

describe('files: Delete files using file actions', { testIsolation: true }, () => {
	let user: User

	beforeEach(() => {
		cy.createRandomUser().then(($user) => {
			user = $user
		})
	})

	it('can delete file', () => {
		cy.uploadContent(user, new Blob([]), 'text/plain', '/file.txt')
		cy.login(user)
		cy.visit('/apps/files')

		// The file must exist and the preview loaded as it locks the file
		getRowForFile('file.txt')
			.should('be.visible')
			.find('.files-list__row-icon-preview--loaded')
			.should('exist')

		cy.intercept('DELETE', '**/remote.php/dav/files/**').as('deleteFile')

		triggerActionForFile('file.txt', 'delete')
		cy.wait('@deleteFile').its('response.statusCode').should('eq', 204)
	})

	it('can delete multiple files', () => {
		cy.mkdir(user, '/root')
		for (let i = 0; i < 5; i++) {
			cy.uploadContent(user, new Blob([]), 'text/plain', `/root/file${i}.txt`)
		}
		cy.login(user)
		cy.visit('/apps/files')
		navigateToFolder('/root')

		// The file must exist and the preview loaded as it locks the file
		cy.get('.files-list__row-icon-preview--loaded')
			.should('have.length', 5)

		cy.intercept('DELETE', '**/remote.php/dav/files/**').as('deleteFile')

		// select all
		selectAllFiles()
		cy.get('[data-cy-files-list-selection-actions]')
			.findByRole('button', { name: 'Actions' })
			.click()
		cy.get('[data-cy-files-list-selection-action="delete"]')
			.findByRole('menuitem', { name: /^Delete files/ })
			.click()

		// see dialog for confirmation
		cy.findByRole('dialog', { name: 'Confirm deletion' })
			.findByRole('button', { name: 'Delete files' })
			.click()

		cy.wait('@deleteFile')
		cy.get('@deleteFile.all')
			.should('have.length', 5)
			// eslint-disable-next-line @typescript-eslint/no-explicit-any
			.should((all: any) => {
				for (const call of all) {
					expect(call.response.statusCode).to.equal(204)
				}
			})
	})
})