Skip to content

Commit 8ec9c8f

Browse files
authored
Merge pull request #49136 from nextcloud/backport/49134/stable30
2 parents c23cdf6 + 87c34e6 commit 8ec9c8f

File tree

9 files changed

+107
-5
lines changed

9 files changed

+107
-5
lines changed

apps/files/src/components/FileEntry/FileEntryCheckbox.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<NcCheckboxRadioSwitch v-else
1010
:aria-label="ariaLabel"
1111
:checked="isSelected"
12+
data-cy-files-list-row-checkbox
1213
@update:checked="onSelectionChange" />
1314
</td>
1415
</template>

apps/files/src/components/FilesListTableHeader.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<tr class="files-list__row-head">
77
<th class="files-list__column files-list__row-checkbox"
88
@keyup.esc.exact="resetSelection">
9-
<NcCheckboxRadioSwitch v-bind="selectAllBind" @update:checked="onToggleAll" />
9+
<NcCheckboxRadioSwitch v-bind="selectAllBind" data-cy-files-list-selection-checkbox @update:checked="onToggleAll" />
1010
</th>
1111

1212
<!-- Columns display -->

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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,30 @@ export const triggerInlineActionForFile = (filename: string, actionId: string) =
2828
getActionsForFile(filename).get(`button[data-cy-files-list-row-action="${CSS.escape(actionId)}"]`).should('exist').click()
2929
}
3030

31+
export const selectAllFiles = () => {
32+
cy.get('[data-cy-files-list-selection-checkbox]')
33+
.findByRole('checkbox', { checked: false })
34+
.click({ force: true })
35+
}
36+
export const deselectAllFiles = () => {
37+
cy.get('[data-cy-files-list-selection-checkbox]')
38+
.findByRole('checkbox', { checked: true })
39+
.click({ force: true })
40+
}
41+
42+
export const selectRowForFile = (filename: string, options: Partial<Cypress.ClickOptions> = {}) => {
43+
getRowForFile(filename)
44+
.find('[data-cy-files-list-row-checkbox]')
45+
.findByRole('checkbox')
46+
// don't use click to avoid triggering side effects events
47+
.trigger('change', { ...options, force: true })
48+
.should('be.checked')
49+
cy.get('[data-cy-files-list-selection-checkbox]').findByRole('checkbox').should('satisfy', (elements) => {
50+
return elements.length === 1 && (elements[0].checked === true || elements[0].indeterminate === true)
51+
})
52+
53+
}
54+
3155
export const moveFile = (fileName: string, dirPath: string) => {
3256
getRowForFile(fileName).should('be.visible')
3357
triggerActionForFile(fileName, 'move-copy')
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)