|
| 1 | +/** |
| 2 | + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors |
| 3 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | + */ |
| 5 | + |
| 6 | +import type { User } from '@nextcloud/cypress' |
| 7 | +import { deselectAllFiles, selectAllFiles, selectRowForFile } from './FilesUtils' |
| 8 | + |
| 9 | +const files = { |
| 10 | + 'image.jpg': 'image/jpeg', |
| 11 | + 'document.pdf': 'application/pdf', |
| 12 | + 'archive.zip': 'application/zip', |
| 13 | + 'audio.mp3': 'audio/mpeg', |
| 14 | + 'video.mp4': 'video/mp4', |
| 15 | + 'readme.md': 'text/markdown', |
| 16 | + 'welcome.txt': 'text/plain', |
| 17 | +} |
| 18 | +const filesCount = Object.keys(files).length |
| 19 | + |
| 20 | +describe('files: Select all files', { testIsolation: true }, () => { |
| 21 | + let user: User |
| 22 | + |
| 23 | + before(() => { |
| 24 | + cy.createRandomUser().then(($user) => { |
| 25 | + user = $user |
| 26 | + Object.keys(files).forEach((file) => { |
| 27 | + cy.uploadContent(user, new Blob(), files[file], '/' + file) |
| 28 | + }) |
| 29 | + }) |
| 30 | + }) |
| 31 | + |
| 32 | + beforeEach(() => { |
| 33 | + cy.login(user) |
| 34 | + cy.visit('/apps/files') |
| 35 | + }) |
| 36 | + |
| 37 | + it('Can select and unselect all files', () => { |
| 38 | + cy.get('[data-cy-files-list-row-fileid]').should('have.length', filesCount) |
| 39 | + cy.get('[data-cy-files-list-row-checkbox]').should('have.length', filesCount) |
| 40 | + |
| 41 | + selectAllFiles() |
| 42 | + |
| 43 | + cy.get('.files-list__selected').should('have.text', '7 selected') |
| 44 | + cy.get('[data-cy-files-list-row-checkbox]').findByRole('checkbox').should('be.checked') |
| 45 | + |
| 46 | + deselectAllFiles() |
| 47 | + |
| 48 | + cy.get('.files-list__selected').should('not.exist') |
| 49 | + cy.get('[data-cy-files-list-row-checkbox]').findByRole('checkbox').should('not.be.checked') |
| 50 | + }) |
| 51 | + |
| 52 | + it('Can select some files randomly', () => { |
| 53 | + const randomFiles = Object.keys(files).reduce((acc, file) => { |
| 54 | + if (Math.random() > 0.1) { |
| 55 | + acc.push(file) |
| 56 | + } |
| 57 | + return acc |
| 58 | + }, [] as string[]) |
| 59 | + |
| 60 | + randomFiles.forEach(name => selectRowForFile(name)) |
| 61 | + |
| 62 | + cy.get('.files-list__selected').should('have.text', `${randomFiles.length} selected`) |
| 63 | + cy.get('[data-cy-files-list-row-checkbox] input[type="checkbox"]:checked').should('have.length', randomFiles.length) |
| 64 | + }) |
| 65 | + |
| 66 | + it('Can select range of files with shift key', () => { |
| 67 | + cy.get('[data-cy-files-list-row-checkbox]').should('have.length', filesCount) |
| 68 | + selectRowForFile('audio.mp3') |
| 69 | + cy.window().trigger('keydown', { shiftKey: true }) |
| 70 | + selectRowForFile('readme.md', { shiftKey: true }) |
| 71 | + cy.window().trigger('keyup', { shiftKey: false }) |
| 72 | + |
| 73 | + cy.get('.files-list__selected').should('have.text', '4 selected') |
| 74 | + cy.get('[data-cy-files-list-row-checkbox] input[type="checkbox"]:checked').should('have.length', 4) |
| 75 | + |
| 76 | + }) |
| 77 | +}) |
0 commit comments