Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable30] fix(files): multiselect and filters store declaration #49136

Merged
merged 3 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<NcCheckboxRadioSwitch v-else
:aria-label="ariaLabel"
:checked="isSelected"
data-cy-files-list-row-checkbox
@update:checked="onSelectionChange" />
</td>
</template>
Expand Down
2 changes: 1 addition & 1 deletion apps/files/src/components/FilesListTableHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<tr class="files-list__row-head">
<th class="files-list__column files-list__row-checkbox"
@keyup.esc.exact="resetSelection">
<NcCheckboxRadioSwitch v-bind="selectAllBind" @update:checked="onToggleAll" />
<NcCheckboxRadioSwitch v-bind="selectAllBind" data-cy-files-list-selection-checkbox @update:checked="onToggleAll" />
</th>

<!-- Columns display -->
Expand Down
2 changes: 1 addition & 1 deletion apps/files/src/store/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getFileListFilters } from '@nextcloud/files'
import { defineStore } from 'pinia'
import logger from '../logger'

export const useFiltersStore = defineStore('keyboard', {
export const useFiltersStore = defineStore('filters', {
state: () => ({
chips: {} as Record<string, IFileListFilterChip[]>,
filters: [] as IFileListFilter[],
Expand Down
24 changes: 24 additions & 0 deletions cypress/e2e/files/FilesUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,30 @@ export const triggerInlineActionForFile = (filename: string, actionId: string) =
getActionsForFile(filename).get(`button[data-cy-files-list-row-action="${CSS.escape(actionId)}"]`).should('exist').click()
}

export const selectAllFiles = () => {
cy.get('[data-cy-files-list-selection-checkbox]')
.findByRole('checkbox', { checked: false })
.click({ force: true })
}
export const deselectAllFiles = () => {
cy.get('[data-cy-files-list-selection-checkbox]')
.findByRole('checkbox', { checked: true })
.click({ force: true })
}

export const selectRowForFile = (filename: string, options: Partial<Cypress.ClickOptions> = {}) => {
getRowForFile(filename)
.find('[data-cy-files-list-row-checkbox]')
.findByRole('checkbox')
// don't use click to avoid triggering side effects events
.trigger('change', { ...options, force: true })
.should('be.checked')
cy.get('[data-cy-files-list-selection-checkbox]').findByRole('checkbox').should('satisfy', (elements) => {
return elements.length === 1 && (elements[0].checked === true || elements[0].indeterminate === true)
})

}

export const moveFile = (fileName: string, dirPath: string) => {
getRowForFile(fileName).should('be.visible')
triggerActionForFile(fileName, 'move-copy')
Expand Down
77 changes: 77 additions & 0 deletions cypress/e2e/files/files-selection.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import type { User } from '@nextcloud/cypress'
import { deselectAllFiles, selectAllFiles, selectRowForFile } from './FilesUtils'

const files = {
'image.jpg': 'image/jpeg',
'document.pdf': 'application/pdf',
'archive.zip': 'application/zip',
'audio.mp3': 'audio/mpeg',
'video.mp4': 'video/mp4',
'readme.md': 'text/markdown',
'welcome.txt': 'text/plain',
}
const filesCount = Object.keys(files).length

describe('files: Select all files', { testIsolation: true }, () => {
let user: User

before(() => {
cy.createRandomUser().then(($user) => {
user = $user
Object.keys(files).forEach((file) => {
cy.uploadContent(user, new Blob(), files[file], '/' + file)
})
})
})

beforeEach(() => {
cy.login(user)
cy.visit('/apps/files')
})

it('Can select and unselect all files', () => {
cy.get('[data-cy-files-list-row-fileid]').should('have.length', filesCount)
cy.get('[data-cy-files-list-row-checkbox]').should('have.length', filesCount)

selectAllFiles()

cy.get('.files-list__selected').should('have.text', '7 selected')
cy.get('[data-cy-files-list-row-checkbox]').findByRole('checkbox').should('be.checked')

deselectAllFiles()

cy.get('.files-list__selected').should('not.exist')
cy.get('[data-cy-files-list-row-checkbox]').findByRole('checkbox').should('not.be.checked')
})

it('Can select some files randomly', () => {
const randomFiles = Object.keys(files).reduce((acc, file) => {
if (Math.random() > 0.1) {
acc.push(file)
}
return acc
}, [] as string[])

randomFiles.forEach(name => selectRowForFile(name))

cy.get('.files-list__selected').should('have.text', `${randomFiles.length} selected`)
cy.get('[data-cy-files-list-row-checkbox] input[type="checkbox"]:checked').should('have.length', randomFiles.length)
})

it('Can select range of files with shift key', () => {
cy.get('[data-cy-files-list-row-checkbox]').should('have.length', filesCount)
selectRowForFile('audio.mp3')
cy.window().trigger('keydown', { shiftKey: true })
selectRowForFile('readme.md', { shiftKey: true })
cy.window().trigger('keyup', { shiftKey: false })

cy.get('.files-list__selected').should('have.text', '4 selected')
cy.get('[data-cy-files-list-row-checkbox] input[type="checkbox"]:checked').should('have.length', 4)

})
})
4 changes: 2 additions & 2 deletions dist/files-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files-main.js.map

Large diffs are not rendered by default.

Loading