|
| 1 | +/*! |
| 2 | + * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors |
| 3 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | + */ |
| 5 | + |
| 6 | +import type { User } from '@nextcloud/cypress' |
| 7 | + |
| 8 | +// @ts-expect-error package has wrong typings |
| 9 | +import { deleteDownloadsFolderBeforeEach } from 'cypress-delete-downloads-folder' |
| 10 | +import { deleteFileWithRequest, getRowForFileId, selectAllFiles, triggerActionForFileId } from '../files/FilesUtils.ts' |
| 11 | + |
| 12 | +describe('files_trashbin: download files', { testIsolation: true }, () => { |
| 13 | + let user: User |
| 14 | + const fileids: number[] = [] |
| 15 | + |
| 16 | + deleteDownloadsFolderBeforeEach() |
| 17 | + |
| 18 | + before(() => { |
| 19 | + cy.createRandomUser().then(($user) => { |
| 20 | + user = $user |
| 21 | + |
| 22 | + cy.uploadContent(user, new Blob(['<content>']), 'text/plain', '/file.txt') |
| 23 | + .then(({ headers }) => fileids.push(Number.parseInt(headers['oc-fileid']))) |
| 24 | + .then(() => deleteFileWithRequest(user, '/file.txt')) |
| 25 | + cy.uploadContent(user, new Blob(['<content>']), 'text/plain', '/other-file.txt') |
| 26 | + .then(({ headers }) => fileids.push(Number.parseInt(headers['oc-fileid']))) |
| 27 | + .then(() => deleteFileWithRequest(user, '/other-file.txt')) |
| 28 | + }) |
| 29 | + }) |
| 30 | + |
| 31 | + beforeEach(() => { |
| 32 | + cy.login(user) |
| 33 | + cy.visit('/apps/files/trashbin') |
| 34 | + }) |
| 35 | + |
| 36 | + it('can download file', () => { |
| 37 | + getRowForFileId(fileids[0]).should('be.visible') |
| 38 | + getRowForFileId(fileids[1]).should('be.visible') |
| 39 | + |
| 40 | + triggerActionForFileId(fileids[0], 'download') |
| 41 | + |
| 42 | + const downloadsFolder = Cypress.config('downloadsFolder') |
| 43 | + cy.readFile(`${downloadsFolder}/file.txt`, { timeout: 15000 }) |
| 44 | + .should('exist') |
| 45 | + .and('have.length.gt', 8) |
| 46 | + .and('equal', '<content>') |
| 47 | + }) |
| 48 | + |
| 49 | + it('can download a file using default action', () => { |
| 50 | + getRowForFileId(fileids[0]) |
| 51 | + .should('be.visible') |
| 52 | + .findByRole('button', { name: 'Download' }) |
| 53 | + .click({ force: true }) |
| 54 | + |
| 55 | + const downloadsFolder = Cypress.config('downloadsFolder') |
| 56 | + cy.readFile(`${downloadsFolder}/file.txt`, { timeout: 15000 }) |
| 57 | + .should('exist') |
| 58 | + .and('have.length.gt', 8) |
| 59 | + .and('equal', '<content>') |
| 60 | + }) |
| 61 | + |
| 62 | + // TODO: Fix this as this dependens on the webdav zip folder plugin not working for trashbin (and never worked with old NC legacy download ajax as well) |
| 63 | + it('does not offer bulk download', () => { |
| 64 | + cy.get('[data-cy-files-list-row-checkbox]').should('have.length', 2) |
| 65 | + selectAllFiles() |
| 66 | + cy.get('.files-list__selected').should('have.text', '2 selected') |
| 67 | + cy.get('[data-cy-files-list-selection-action="restore"]').should('be.visible') |
| 68 | + cy.get('[data-cy-files-list-selection-action="download"]').should('not.exist') |
| 69 | + }) |
| 70 | +}) |
0 commit comments