diff options
author | Ferdinand Thiessen <opensource@fthiessen.de> | 2024-06-27 00:00:53 +0200 |
---|---|---|
committer | Ferdinand Thiessen <opensource@fthiessen.de> | 2024-06-27 12:13:14 +0200 |
commit | 362c6238fcadb74c54c2a8c7b2c12c5a1011c0b5 (patch) | |
tree | 788796ae091291c2753905616f6a6db3aaa02464 /cypress | |
parent | dd3dcf37039ed969b1a2f6b89941a65ccf73b696 (diff) | |
download | nextcloud-server-362c6238fcadb74c54c2a8c7b2c12c5a1011c0b5.tar.gz nextcloud-server-362c6238fcadb74c54c2a8c7b2c12c5a1011c0b5.zip |
fix: Allow to reset unified search using the `nextcloud:unified-search:reset` event
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Diffstat (limited to 'cypress')
-rw-r--r-- | cypress/e2e/files/files-searching.cy.ts | 34 | ||||
-rw-r--r-- | cypress/pages/UnifiedSearch.ts | 75 | ||||
-rw-r--r-- | cypress/support/commands.ts | 1 | ||||
-rw-r--r-- | cypress/tsconfig.json | 8 |
4 files changed, 101 insertions, 17 deletions
diff --git a/cypress/e2e/files/files-searching.cy.ts b/cypress/e2e/files/files-searching.cy.ts index 5f81057000d..10ca1b44e2f 100644 --- a/cypress/e2e/files/files-searching.cy.ts +++ b/cypress/e2e/files/files-searching.cy.ts @@ -5,9 +5,10 @@ import type { User } from '@nextcloud/cypress' import { getRowForFile, navigateToFolder } from './FilesUtils' -import { UnifiedSearchFilter, getUnifiedSearchFilter, getUnifiedSearchInput, getUnifiedSearchModal, openUnifiedSearch } from '../core-utils.ts' +import { UnifiedSearchPage } from '../../pages/UnifiedSearch.ts' describe('files: Search and filter in files list', { testIsolation: true }, () => { + const unifiedSearch = new UnifiedSearchPage() let user: User beforeEach(() => cy.createRandomUser().then(($user) => { @@ -20,17 +21,21 @@ describe('files: Search and filter in files list', { testIsolation: true }, () = cy.visit('/apps/files') })) + it('files app supports local search', () => { + unifiedSearch.openLocalSearch() + unifiedSearch.localSearchInput() + .should('not.have.css', 'display', 'none') + .and('not.be.disabled') + }) + it('filters current view', () => { // All are visible by default getRowForFile('a folder').should('be.visible') getRowForFile('b file').should('be.visible') // Set up a search query - openUnifiedSearch() - getUnifiedSearchInput().type('a folder') - getUnifiedSearchFilter(UnifiedSearchFilter.FilterCurrentView).click({ force: true }) - // Wait for modal to close - getUnifiedSearchModal().should('not.be.visible') + unifiedSearch.openLocalSearch() + unifiedSearch.typeLocalSearch('a folder') // See that only the folder is visible getRowForFile('a folder').should('be.visible') @@ -43,11 +48,8 @@ describe('files: Search and filter in files list', { testIsolation: true }, () = getRowForFile('b file').should('be.visible') // Set up a search query - openUnifiedSearch() - getUnifiedSearchInput().type('a folder') - getUnifiedSearchFilter(UnifiedSearchFilter.FilterCurrentView).click({ force: true }) - // Wait for modal to close - getUnifiedSearchModal().should('not.be.visible') + unifiedSearch.openLocalSearch() + unifiedSearch.typeLocalSearch('a folder') // See that only the folder is visible getRowForFile('a folder').should('be.visible') @@ -66,11 +68,8 @@ describe('files: Search and filter in files list', { testIsolation: true }, () = getRowForFile('b file').should('be.visible') // Set up a search query - openUnifiedSearch() - getUnifiedSearchInput().type('a folder') - getUnifiedSearchFilter(UnifiedSearchFilter.FilterCurrentView).click({ force: true }) - // Wait for modal to close - getUnifiedSearchModal().should('not.be.visible') + unifiedSearch.openLocalSearch() + unifiedSearch.typeLocalSearch('a folder') // See that only the folder is visible getRowForFile('a folder').should('be.visible') @@ -84,5 +83,8 @@ describe('files: Search and filter in files list', { testIsolation: true }, () = // see that the folder is not filtered getRowForFile('a folder').should('be.visible') getRowForFile('b file').should('be.visible') + + // see the filter bar is gone + unifiedSearch.localSearchInput().should('not.exist') }) }) diff --git a/cypress/pages/UnifiedSearch.ts b/cypress/pages/UnifiedSearch.ts new file mode 100644 index 00000000000..f6e0dd2e7a7 --- /dev/null +++ b/cypress/pages/UnifiedSearch.ts @@ -0,0 +1,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') + } + +} diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index cbc18ec24dc..5a465d0e4f6 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -10,6 +10,7 @@ import { addCommands, User } from '@nextcloud/cypress' import { basename } from 'path' // Add custom commands +import '@testing-library/cypress/add-commands' import 'cypress-if' import 'cypress-wait-until' addCommands() diff --git a/cypress/tsconfig.json b/cypress/tsconfig.json index c5dcff95d70..002fdb4f63e 100644 --- a/cypress/tsconfig.json +++ b/cypress/tsconfig.json @@ -2,6 +2,12 @@ "extends": "../tsconfig.json", "include": ["./**/*.ts"], "compilerOptions": { - "types": ["cypress", "cypress-axe", "cypress-wait-until", "dockerode"], + "types": [ + "@testing-library/cypress", + "cypress", + "cypress-axe", + "cypress-wait-until", + "dockerode" + ], } } |