core-utils.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. /**
  23. * Get the unified search modal (if open)
  24. */
  25. export function getUnifiedSearchModal() {
  26. return cy.get('#unified-search')
  27. }
  28. /**
  29. * Open the unified search modal
  30. */
  31. export function openUnifiedSearch() {
  32. cy.get('button[aria-label="Unified search"]').click({ force: true })
  33. // wait for it to be open
  34. getUnifiedSearchModal().should('be.visible')
  35. }
  36. /**
  37. * Close the unified search modal
  38. */
  39. export function closeUnifiedSearch() {
  40. getUnifiedSearchModal().find('button[aria-label="Close"]').click({ force: true })
  41. getUnifiedSearchModal().should('not.be.visible')
  42. }
  43. /**
  44. * Get the input field of the unified search
  45. */
  46. export function getUnifiedSearchInput() {
  47. return getUnifiedSearchModal().find('[data-cy-unified-search-input]')
  48. }
  49. export enum UnifiedSearchFilter {
  50. FilterCurrentView = 'current-view',
  51. Places = 'places',
  52. People = 'people',
  53. Date = 'date',
  54. }
  55. /**
  56. * Get a filter action from the unified search
  57. * @param filter The filter to get
  58. */
  59. export function getUnifiedSearchFilter(filter: UnifiedSearchFilter) {
  60. return getUnifiedSearchModal().find(`[data-cy-unified-search-filters] [data-cy-unified-search-filter="${CSS.escape(filter)}"]`)
  61. }