1
0

files-searching.cy.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /**
  2. * @copyright Copyright (c) 2024 Ferdinand Thiessen <opensource@fthiessen.de>
  3. *
  4. * @author Ferdinand Thiessen <opensource@fthiessen.de>
  5. *
  6. * @license AGPL-3.0-or-later
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. import type { User } from '@nextcloud/cypress'
  23. import { getRowForFile, navigateToFolder } from './FilesUtils'
  24. import { UnifiedSearchFilter, getUnifiedSearchFilter, getUnifiedSearchInput, getUnifiedSearchModal, openUnifiedSearch } from '../core-utils.ts'
  25. describe('files: Search and filter in files list', { testIsolation: true }, () => {
  26. let user: User
  27. beforeEach(() => cy.createRandomUser().then(($user) => {
  28. user = $user
  29. cy.mkdir(user, '/a folder')
  30. cy.uploadContent(user, new Blob([]), 'text/plain', '/b file')
  31. cy.uploadContent(user, new Blob([]), 'text/plain', '/a folder/c file')
  32. cy.login(user)
  33. cy.visit('/apps/files')
  34. }))
  35. it('filters current view', () => {
  36. // All are visible by default
  37. getRowForFile('a folder').should('be.visible')
  38. getRowForFile('b file').should('be.visible')
  39. // Set up a search query
  40. openUnifiedSearch()
  41. getUnifiedSearchInput().type('a folder')
  42. getUnifiedSearchFilter(UnifiedSearchFilter.FilterCurrentView).click({ force: true })
  43. // Wait for modal to close
  44. getUnifiedSearchModal().should('not.be.visible')
  45. // See that only the folder is visible
  46. getRowForFile('a folder').should('be.visible')
  47. getRowForFile('b file').should('not.exist')
  48. })
  49. it('resets filter when changeing the directory', () => {
  50. // All are visible by default
  51. getRowForFile('a folder').should('be.visible')
  52. getRowForFile('b file').should('be.visible')
  53. // Set up a search query
  54. openUnifiedSearch()
  55. getUnifiedSearchInput().type('a folder')
  56. getUnifiedSearchFilter(UnifiedSearchFilter.FilterCurrentView).click({ force: true })
  57. // Wait for modal to close
  58. getUnifiedSearchModal().should('not.be.visible')
  59. // See that only the folder is visible
  60. getRowForFile('a folder').should('be.visible')
  61. getRowForFile('b file').should('not.exist')
  62. // go to that folder
  63. navigateToFolder('a folder')
  64. // see that the folder is not filtered
  65. getRowForFile('c file').should('be.visible')
  66. })
  67. it('resets filter when changeing the view', () => {
  68. // All are visible by default
  69. getRowForFile('a folder').should('be.visible')
  70. getRowForFile('b file').should('be.visible')
  71. // Set up a search query
  72. openUnifiedSearch()
  73. getUnifiedSearchInput().type('a folder')
  74. getUnifiedSearchFilter(UnifiedSearchFilter.FilterCurrentView).click({ force: true })
  75. // Wait for modal to close
  76. getUnifiedSearchModal().should('not.be.visible')
  77. // See that only the folder is visible
  78. getRowForFile('a folder').should('be.visible')
  79. getRowForFile('b file').should('not.exist')
  80. // go to other view
  81. cy.get('[data-cy-files-navigation-item="personal"] a').click({ force: true })
  82. // wait for view changed
  83. cy.url().should('match', /apps\/files\/personal/)
  84. // see that the folder is not filtered
  85. getRowForFile('a folder').should('be.visible')
  86. getRowForFile('b file').should('be.visible')
  87. })
  88. })