summaryrefslogtreecommitdiffstats
path: root/tests/cypress/e2e/search.cy.ts
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2022-06-03 11:58:21 +0200
committerGitHub <noreply@github.com>2022-06-03 11:58:21 +0200
commit6d0a9504406524957b351aee748d9f5c8a84c299 (patch)
tree1b859015ef5e52b2c7c4e7521f428fb2215df21d /tests/cypress/e2e/search.cy.ts
parenta8af53c118478e6ed68975c32cc1202b7c7b798e (diff)
parentfc7a6e98268d34f313d79c817e38c09ad6cde960 (diff)
test: add end to end tests (#19)
In addition to Jest tests, I configure Cypress to test some pages and features. I also fix some Jest errors due to images import.
Diffstat (limited to 'tests/cypress/e2e/search.cy.ts')
-rw-r--r--tests/cypress/e2e/search.cy.ts41
1 files changed, 41 insertions, 0 deletions
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');
+ });
+});