|
| 1 | +/* |
| 2 | + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors |
| 3 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | + */ |
| 5 | + |
| 6 | +import { expect, test } from '../../support/fixtures/files-page.ts' |
| 7 | +import { uploadContent } from '../../support/utils/dav.ts' |
| 8 | + |
| 9 | +// Names sort ascending, so the on-screen order is: |
| 10 | +// archive.zip, audio.mp3, document.pdf, image.jpg, readme.md, video.mp4, welcome.txt |
| 11 | +const files: Record<string, string> = { |
| 12 | + 'image.jpg': 'image/jpeg', |
| 13 | + 'document.pdf': 'application/pdf', |
| 14 | + 'archive.zip': 'application/zip', |
| 15 | + 'audio.mp3': 'audio/mpeg', |
| 16 | + 'video.mp4': 'video/mp4', |
| 17 | + 'readme.md': 'text/markdown', |
| 18 | + 'welcome.txt': 'text/plain', |
| 19 | +} |
| 20 | +const filesCount = Object.keys(files).length |
| 21 | + |
| 22 | +test.describe('Files: Select files', () => { |
| 23 | + test.beforeEach(async ({ page, user, filesListPage }) => { |
| 24 | + // Uploading welcome.txt overwrites the auto-created one, so the list holds exactly these files |
| 25 | + for (const [name, mime] of Object.entries(files)) { |
| 26 | + await uploadContent(page.request, user, Buffer.alloc(0), mime, `/${name}`) |
| 27 | + } |
| 28 | + await filesListPage.open() |
| 29 | + }) |
| 30 | + |
| 31 | + test('selects and deselects all files', async ({ page, filesListPage }) => { |
| 32 | + await expect(filesListPage.getRows()).toHaveCount(filesCount) |
| 33 | + await expect(filesListPage.getRowCheckboxes()).toHaveCount(filesCount) |
| 34 | + |
| 35 | + await filesListPage.selectAll() |
| 36 | + await expect(page.getByText(`${filesCount} selected`)).toBeVisible() |
| 37 | + await expect(filesListPage.getSelectedRowCheckboxes()).toHaveCount(filesCount) |
| 38 | + |
| 39 | + await filesListPage.deselectAll() |
| 40 | + await expect(page.getByText(/\d+ selected/)).toHaveCount(0) |
| 41 | + await expect(filesListPage.getSelectedRowCheckboxes()).toHaveCount(0) |
| 42 | + }) |
| 43 | + |
| 44 | + test('selects an arbitrary subset of files', async ({ page, filesListPage }) => { |
| 45 | + const subset = ['image.jpg', 'document.pdf', 'audio.mp3', 'readme.md'] |
| 46 | + |
| 47 | + for (const name of subset) { |
| 48 | + await filesListPage.selectRowForFile(name) |
| 49 | + } |
| 50 | + |
| 51 | + await expect(page.getByText(`${subset.length} selected`)).toBeVisible() |
| 52 | + await expect(filesListPage.getSelectedRowCheckboxes()).toHaveCount(subset.length) |
| 53 | + }) |
| 54 | + |
| 55 | + test('selects a range of files with the shift key', async ({ page, filesListPage }) => { |
| 56 | + // audio.mp3 -> readme.md spans audio.mp3, document.pdf, image.jpg, readme.md |
| 57 | + await filesListPage.selectRowForFile('audio.mp3') |
| 58 | + await filesListPage.selectRowForFile('readme.md', { shift: true }) |
| 59 | + |
| 60 | + await expect(page.getByText('4 selected')).toBeVisible() |
| 61 | + await expect(filesListPage.getSelectedRowCheckboxes()).toHaveCount(4) |
| 62 | + }) |
| 63 | +}) |
0 commit comments