files-selection.cy.ts 2.4 KB

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