From efb03c205a0d4448f4625381676606a8853ce1e6 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Fri, 27 May 2022 18:11:48 +0200 Subject: test(e2e): add search feature test --- tests/cypress/e2e/search.cy.ts | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 tests/cypress/e2e/search.cy.ts (limited to 'tests/cypress/e2e/search.cy.ts') diff --git a/tests/cypress/e2e/search.cy.ts b/tests/cypress/e2e/search.cy.ts new file mode 100644 index 0000000..f105a5c --- /dev/null +++ b/tests/cypress/e2e/search.cy.ts @@ -0,0 +1,41 @@ +const queryWithArticles = 'Coldark'; +const queryWithoutArticles = 'etEtRerum'; + +describe('Search', () => { + it('should open and close search form by clicking on search button', () => { + cy.visit('/'); + cy.findByLabelText(/Fermer la recherche/i).should('not.exist'); + cy.findByRole('searchbox', { name: /Rechercher/i }).should('not.exist'); + cy.findByLabelText(/Ouvrir la recherche/i).click(); + cy.findByLabelText(/Ouvrir la recherche/i).should('not.exist'); + cy.findByLabelText(/Fermer la recherche/i).should('exist'); + cy.findByRole('searchbox', { name: /Rechercher/i }).should('exist'); + cy.findByLabelText(/Fermer la recherche/i).click(); + cy.findByLabelText(/Fermer la recherche/i).should('not.exist'); + cy.findByRole('searchbox', { name: /Rechercher/i }).should('not.exist'); + cy.findByLabelText(/Ouvrir la recherche/i).should('exist'); + }); + + it('should navigate the search page', async () => { + cy.visit('/'); + cy.findByLabelText(/Ouvrir la recherche/i).click(); + cy.findByRole('searchbox', { name: /Rechercher/i }).type( + `${queryWithArticles}{enter}` + ); + cy.url().should('include', '/blog'); + cy.findByRole('heading', { level: 1 }).contains( + /Résultats de la recherche pour/i + ); + }); + + it('should display the total of articles if successful', async () => { + cy.visit(`/recherche?s=${encodeURIComponent(queryWithArticles)}`); + const dtSiblings = cy.findByRole('term', { name: /Total/i }).siblings(); + dtSiblings.findByRole('definition').contains(/article/i); + }); + + it('should display a search form if unsuccessful', () => { + cy.visit(`/recherche?s=${encodeURIComponent(queryWithoutArticles)}`); + cy.findByRole('searchbox', { name: /Rechercher/i }).should('exist'); + }); +}); -- cgit v1.2.3