UnifiedSearch.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-License-Identifier: AGPL-3.0-or-later
  4. */
  5. /**
  6. * Page object model for the UnifiedSearch
  7. */
  8. export class UnifiedSearchPage {
  9. toggleButton() {
  10. return cy.findByRole('button', { name: 'Unified search' })
  11. }
  12. globalSearchButton() {
  13. return cy.findByRole('button', { name: 'Search everywhere' })
  14. }
  15. localSearchInput() {
  16. return cy.findByRole('textbox', { name: 'Search in current app' })
  17. }
  18. globalSearchInput() {
  19. return cy.findByRole('textbox', { name: /Search apps, files/ })
  20. }
  21. globalSearchModal() {
  22. // TODO: Broken in library
  23. // return cy.findByRole('dialog', { name: 'Unified search' })
  24. return cy.get('#unified-search')
  25. }
  26. // functions
  27. openLocalSearch() {
  28. this.toggleButton()
  29. .if('visible')
  30. .click()
  31. this.localSearchInput().should('exist').and('not.have.css', 'display', 'none')
  32. }
  33. /**
  34. * Type in the local search (must be open before)
  35. * Helper because the input field is overlayed by the global-search button -> cypress thinks the input is not visible
  36. *
  37. * @param text The text to type
  38. * @param options Options as for `cy.type()`
  39. */
  40. typeLocalSearch(text: string, options?: Partial<Omit<Cypress.TypeOptions, 'force'>>) {
  41. return this.localSearchInput()
  42. .type(text, { ...options, force: true })
  43. }
  44. openGlobalSearch() {
  45. this.toggleButton()
  46. .if('visible').click()
  47. this.globalSearchButton()
  48. .if('visible').click()
  49. }
  50. closeGlobalSearch() {
  51. this.globalSearchModal()
  52. .findByRole('button', { name: 'Close' })
  53. .click()
  54. }
  55. getResults(category: string | RegExp) {
  56. return this.globalSearchModal()
  57. .findByRole('list', { name: category })
  58. .findAllByRole('listitem')
  59. }
  60. }