Skip to content

Commit a34f4fb

Browse files
authored
Merge pull request #49134 from nextcloud/fix/multi-select
2 parents 232eb9c + 63ca2ce commit a34f4fb

File tree

7 files changed

+93
-7
lines changed

7 files changed

+93
-7
lines changed

apps/files/src/store/filters.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { getFileListFilters } from '@nextcloud/files'
88
import { defineStore } from 'pinia'
99
import logger from '../logger'
1010

11-
export const useFiltersStore = defineStore('keyboard', {
11+
export const useFiltersStore = defineStore('filters', {
1212
state: () => ({
1313
chips: {} as Record<string, IFileListFilterChip[]>,
1414
filters: [] as IFileListFilter[],

cypress/e2e/files/FilesUtils.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,22 @@ export const triggerInlineActionForFile = (filename: string, actionId: string) =
3333
}
3434

3535
export const selectAllFiles = () => {
36-
cy.get('[data-cy-files-list-selection-checkbox]').findByRole('checkbox').click({ force: true })
36+
cy.get('[data-cy-files-list-selection-checkbox]')
37+
.findByRole('checkbox', { checked: false })
38+
.click({ force: true })
39+
}
40+
export const deselectAllFiles = () => {
41+
cy.get('[data-cy-files-list-selection-checkbox]')
42+
.findByRole('checkbox', { checked: true })
43+
.click({ force: true })
3744
}
38-
export const selectRowForFile = (filename: string) => {
45+
46+
export const selectRowForFile = (filename: string, options: Partial<Cypress.ClickOptions> = {}) => {
3947
getRowForFile(filename)
4048
.find('[data-cy-files-list-row-checkbox]')
4149
.findByRole('checkbox')
42-
.click({ force: true })
50+
// don't use click to avoid triggering side effects events
51+
.trigger('change', { ...options, force: true })
4352
.should('be.checked')
4453
cy.get('[data-cy-files-list-selection-checkbox]').findByRole('checkbox').should('satisfy', (elements) => {
4554
return elements.length === 1 && (elements[0].checked === true || elements[0].indeterminate === true)
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
})

dist/files-main.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files-main.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)