1
0

files-sidebar.cy.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 { getRowForFile, navigateToFolder, triggerActionForFile } from './FilesUtils'
  7. import { assertNotExistOrNotVisible } from '../settings/usersUtils'
  8. describe('Files: Sidebar', { testIsolation: true }, () => {
  9. let user: User
  10. let fileId: number = 0
  11. beforeEach(() => cy.createRandomUser().then(($user) => {
  12. user = $user
  13. cy.mkdir(user, '/folder')
  14. cy.uploadContent(user, new Blob([]), 'text/plain', '/file').then((response) => {
  15. fileId = Number.parseInt(response.headers['oc-fileid'] ?? '0')
  16. })
  17. cy.login(user)
  18. }))
  19. it('opens the sidebar', () => {
  20. cy.visit('/apps/files')
  21. getRowForFile('file').should('be.visible')
  22. triggerActionForFile('file', 'details')
  23. cy.get('[data-cy-sidebar]')
  24. .should('be.visible')
  25. .findByRole('heading', { name: 'file' })
  26. .should('be.visible')
  27. })
  28. it('changes the current fileid', () => {
  29. cy.visit('/apps/files')
  30. getRowForFile('file').should('be.visible')
  31. triggerActionForFile('file', 'details')
  32. cy.get('[data-cy-sidebar]').should('be.visible')
  33. cy.url().should('contain', `apps/files/files/${fileId}`)
  34. })
  35. it('changes the sidebar content on other file', () => {
  36. cy.visit('/apps/files')
  37. getRowForFile('file').should('be.visible')
  38. triggerActionForFile('file', 'details')
  39. cy.get('[data-cy-sidebar]')
  40. .should('be.visible')
  41. .findByRole('heading', { name: 'file' })
  42. .should('be.visible')
  43. triggerActionForFile('folder', 'details')
  44. cy.get('[data-cy-sidebar]')
  45. .should('be.visible')
  46. .findByRole('heading', { name: 'folder' })
  47. .should('be.visible')
  48. })
  49. it('closes the sidebar on navigation', () => {
  50. cy.visit('/apps/files')
  51. getRowForFile('file').should('be.visible')
  52. getRowForFile('folder').should('be.visible')
  53. // open the sidebar
  54. triggerActionForFile('file', 'details')
  55. // validate it is open
  56. cy.get('[data-cy-sidebar]')
  57. .should('be.visible')
  58. // if we navigate to the folder
  59. navigateToFolder('folder')
  60. // the sidebar should not be visible anymore
  61. cy.get('[data-cy-sidebar]')
  62. .should(assertNotExistOrNotVisible)
  63. })
  64. it('closes the sidebar on delete', () => {
  65. cy.intercept('DELETE', `**/remote.php/dav/files/${user.userId}/file`).as('deleteFile')
  66. // visit the files app
  67. cy.visit('/apps/files')
  68. getRowForFile('file').should('be.visible')
  69. // open the sidebar
  70. triggerActionForFile('file', 'details')
  71. // validate it is open
  72. cy.get('[data-cy-sidebar]').should('be.visible')
  73. // delete the file
  74. triggerActionForFile('file', 'delete')
  75. cy.wait('@deleteFile', { timeout: 10000 })
  76. // see the sidebar is closed
  77. cy.get('[data-cy-sidebar]')
  78. .should(assertNotExistOrNotVisible)
  79. })
  80. it('changes the fileid on delete', () => {
  81. cy.intercept('DELETE', `**/remote.php/dav/files/${user.userId}/folder/other`).as('deleteFile')
  82. cy.uploadContent(user, new Blob([]), 'text/plain', '/folder/other').then((response) => {
  83. const otherFileId = Number.parseInt(response.headers['oc-fileid'] ?? '0')
  84. cy.login(user)
  85. cy.visit('/apps/files')
  86. getRowForFile('folder').should('be.visible')
  87. navigateToFolder('folder')
  88. getRowForFile('other').should('be.visible')
  89. // open the sidebar
  90. triggerActionForFile('other', 'details')
  91. // validate it is open
  92. cy.get('[data-cy-sidebar]').should('be.visible')
  93. cy.url().should('contain', `apps/files/files/${otherFileId}`)
  94. triggerActionForFile('other', 'delete')
  95. cy.wait('@deleteFile')
  96. cy.get('[data-cy-sidebar]').should('not.exist')
  97. // Ensure the URL is changed
  98. cy.url().should('not.contain', `apps/files/files/${otherFileId}`)
  99. })
  100. })
  101. })