new-menu.cy.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /**
  2. * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-License-Identifier: AGPL-3.0-or-later
  4. */
  5. import { createFolder, getRowForFile, haveValidity, navigateToFolder } from './FilesUtils'
  6. describe('"New"-menu', { testIsolation: true }, () => {
  7. beforeEach(() => {
  8. cy.createRandomUser().then(($user) => {
  9. cy.login($user)
  10. cy.visit('/apps/files')
  11. })
  12. })
  13. it('Create new folder', () => {
  14. // Click the "new" button
  15. cy.get('[data-cy-upload-picker]')
  16. .findByRole('button', { name: 'New' })
  17. .should('be.visible')
  18. .click()
  19. // Click the "new folder" menu entry
  20. cy.findByRole('menuitem', { name: 'New folder' })
  21. .should('be.visible')
  22. .click()
  23. // Create a folder
  24. cy.intercept('MKCOL', '**/remote.php/dav/files/**').as('mkdir')
  25. cy.findByRole('dialog', { name: /create new folder/i })
  26. .findByRole('textbox', { name: 'Folder name' })
  27. .type('A new folder{enter}')
  28. cy.wait('@mkdir')
  29. // See the folder is visible
  30. getRowForFile('A new folder')
  31. .should('be.visible')
  32. })
  33. it('Does not allow creating forbidden folder names', () => {
  34. // Click the "new" button
  35. cy.get('[data-cy-upload-picker]')
  36. .findByRole('button', { name: 'New' })
  37. .should('be.visible')
  38. .click()
  39. // Click the "new folder" menu entry
  40. cy.findByRole('menuitem', { name: 'New folder' })
  41. .should('be.visible')
  42. .click()
  43. // enter folder name
  44. cy.findByRole('dialog', { name: /create new folder/i })
  45. .findByRole('textbox', { name: 'Folder name' })
  46. .type('.htaccess')
  47. // See that input has invalid state set
  48. cy.findByRole('dialog', { name: /create new folder/i })
  49. .findByRole('textbox', { name: 'Folder name' })
  50. .should(haveValidity(/reserved name/i))
  51. // See that it can not create
  52. cy.findByRole('dialog', { name: /create new folder/i })
  53. .findByRole('button', { name: 'Create' })
  54. .should('be.disabled')
  55. })
  56. it('Does not allow creating folders with already existing names', () => {
  57. createFolder('already exists')
  58. // Click the "new" button
  59. cy.get('[data-cy-upload-picker]')
  60. .findByRole('button', { name: 'New' })
  61. .should('be.visible')
  62. .click()
  63. // Click the "new folder" menu entry
  64. cy.findByRole('menuitem', { name: 'New folder' })
  65. .should('be.visible')
  66. .click()
  67. // enter folder name
  68. cy.findByRole('dialog', { name: /create new folder/i })
  69. .findByRole('textbox', { name: 'Folder name' })
  70. .type('already exists')
  71. // See that input has invalid state set
  72. cy.findByRole('dialog', { name: /create new folder/i })
  73. .findByRole('textbox', { name: 'Folder name' })
  74. .should(haveValidity(/already in use/i))
  75. // See that it can not create
  76. cy.findByRole('dialog', { name: /create new folder/i })
  77. .findByRole('button', { name: 'Create' })
  78. .should('be.disabled')
  79. })
  80. /**
  81. * Regression test of https://github.com/nextcloud/server/issues/47530
  82. */
  83. it('Create same folder in child folder', () => {
  84. // setup other folders
  85. createFolder('folder')
  86. createFolder('other folder')
  87. navigateToFolder('folder')
  88. // Click the "new" button
  89. cy.get('[data-cy-upload-picker]')
  90. .findByRole('button', { name: 'New' })
  91. .should('be.visible')
  92. .click()
  93. // Click the "new folder" menu entry
  94. cy.findByRole('menuitem', { name: 'New folder' })
  95. .should('be.visible')
  96. .click()
  97. // enter folder name
  98. cy.findByRole('dialog', { name: /create new folder/i })
  99. .findByRole('textbox', { name: 'Folder name' })
  100. .type('other folder')
  101. // See that creating is allowed
  102. cy.findByRole('dialog', { name: /create new folder/i })
  103. .findByRole('textbox', { name: 'Folder name' })
  104. .should(haveValidity(''))
  105. // can create
  106. cy.intercept('MKCOL', '**/remote.php/dav/files/**').as('mkdir')
  107. cy.findByRole('dialog', { name: /create new folder/i })
  108. .findByRole('button', { name: 'Create' })
  109. .click()
  110. cy.wait('@mkdir')
  111. // see it is created
  112. getRowForFile('other folder')
  113. .should('be.visible')
  114. })
  115. })