aboutsummaryrefslogtreecommitdiffstats
path: root/cypress/pages/UnifiedSearch.ts
blob: f6e0dd2e7a79214ed81dedff853e814f42ffeb96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
 * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

/**
 * Page object model for the UnifiedSearch
 */
export class UnifiedSearchPage {

	toggleButton() {
		return cy.findByRole('button', { name: 'Unified search' })
	}

	globalSearchButton() {
		return cy.findByRole('button', { name: 'Search everywhere' })
	}

	localSearchInput() {
		return cy.findByRole('textbox', { name: 'Search in current app' })
	}

	globalSearchInput() {
		return cy.findByRole('textbox', { name: /Search apps, files/ })
	}

	globalSearchModal() {
		// TODO: Broken in library
		// return cy.findByRole('dialog', { name: 'Unified search' })
		return cy.get('#unified-search')
	}

	// functions

	openLocalSearch() {
		this.toggleButton()
			.if('visible')
			.click()

		this.localSearchInput().should('exist').and('not.have.css', 'display', 'none')
	}

	/**
	 * Type in the local search (must be open before)
	 * Helper because the input field is overlayed by the global-search button -> cypress thinks the input is not visible
	 *
	 * @param text The text to type
	 * @param options Options as for `cy.type()`
	 */
	typeLocalSearch(text: string, options?: Partial<Omit<Cypress.TypeOptions, 'force'>>) {
		return this.localSearchInput()
			.type(text, { ...options, force: true })
	}

	openGlobalSearch() {
		this.toggleButton()
			.if('visible').click()

		this.globalSearchButton()
			.if('visible').click()
	}

	closeGlobalSearch() {
		this.globalSearchModal()
			.findByRole('button', { name: 'Close' })
			.click()
	}

	getResults(category: string | RegExp) {
		return this.globalSearchModal()
			.findByRole('list', { name: category })
			.findAllByRole('listitem')
	}

}