diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-06-03 11:58:21 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-03 11:58:21 +0200 |
| commit | 6d0a9504406524957b351aee748d9f5c8a84c299 (patch) | |
| tree | 1b859015ef5e52b2c7c4e7521f428fb2215df21d /tests/cypress/e2e/pages | |
| parent | a8af53c118478e6ed68975c32cc1202b7c7b798e (diff) | |
| parent | fc7a6e98268d34f313d79c817e38c09ad6cde960 (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/pages')
| -rw-r--r-- | tests/cypress/e2e/pages/blog.cy.ts | 44 | ||||
| -rw-r--r-- | tests/cypress/e2e/pages/contact.cy.ts | 41 | ||||
| -rw-r--r-- | tests/cypress/e2e/pages/cv.cy.ts | 6 | ||||
| -rw-r--r-- | tests/cypress/e2e/pages/homepage.cy.ts | 9 | ||||
| -rw-r--r-- | tests/cypress/e2e/pages/legal-notice.cy.ts | 6 | ||||
| -rw-r--r-- | tests/cypress/e2e/pages/projects.cy.ts | 6 |
6 files changed, 112 insertions, 0 deletions
diff --git a/tests/cypress/e2e/pages/blog.cy.ts b/tests/cypress/e2e/pages/blog.cy.ts new file mode 100644 index 0000000..dedc0e4 --- /dev/null +++ b/tests/cypress/e2e/pages/blog.cy.ts @@ -0,0 +1,44 @@ +import { settings } from '@utils/config'; + +describe('Blog Page', () => { + beforeEach(() => { + cy.visit('/blog'); + }); + + it('loads the correct number of pages', () => { + cy.findByText(/(\d+) articles chargés sur un total de (\d+)/i) + .then(($div) => { + type ArticlesGroup = { + first: string; + total: string; + }; + + const firstLastNumbers = /(?<first>\d+).*[\D](?<total>\d+)/; + const result = $div.text().match(firstLastNumbers); + expect(result).to.not.be.null; + + const { first, total } = result!.groups as ArticlesGroup; + const firstArticles = parseInt(first, 10); + const totalArticles = parseInt(total, 10); + expect(firstArticles).to.be.within(1, settings.postsPerPage); + expect(totalArticles).to.be.at.least(1); + + const totalPages = Math.ceil(totalArticles / settings.postsPerPage); + const remainingPages = totalPages - 1; + return Array.from({ length: remainingPages }, (_, i) => i + 1); + }) + .then((remainingPages) => { + if (remainingPages.length >= 1) { + cy.wrap(remainingPages).each(() => { + cy.findByRole('button', { + name: /Charger plus d’articles/i, + }).click(); + }); + } + + cy.findByRole('button', { name: /Charger plus d’articles/i }).should( + 'not.exist' + ); + }); + }); +}); diff --git a/tests/cypress/e2e/pages/contact.cy.ts b/tests/cypress/e2e/pages/contact.cy.ts new file mode 100644 index 0000000..6e1cdb6 --- /dev/null +++ b/tests/cypress/e2e/pages/contact.cy.ts @@ -0,0 +1,41 @@ +const userName = 'Cypress Test'; +const userEmail = 'cypress@testing.com'; +const object = '[Cypress] quos aperiam culpa'; +const message = + 'Asperiores ea nihil. Nam ipsam est sunt porro. Ratione in facilis cum. Voluptatem pariatur rerum.'; + +describe('Contact Page', () => { + beforeEach(() => { + cy.visit('/contact'); + }); + + it('shows a heading and a contact form', () => { + cy.findByRole('heading', { level: 1 }).contains(/Contact/i); + cy.findByRole('form', { name: /Formulaire de contact/i }); + }); + + it('submits the form', async () => { + cy.findByRole('textbox', { name: /Nom/i }) + .type(userName) + .should('have.value', userName); + cy.findByRole('textbox', { name: /E-mail/i }) + .type(userEmail) + .should('have.value', userEmail); + cy.findByRole('textbox', { name: /Sujet/i }) + .type(object) + .should('have.value', object); + cy.findByRole('textbox', { name: /Message/i }) + .type(message) + .should('have.value', message); + cy.findByRole('button', { name: /Envoyer/i }).click(); + cy.findByText(/E-mail en cours d'envoi/i).should('be.visible'); + }); + + it('prevents the form to submit if some fields are missing', async () => { + cy.findByRole('textbox', { name: /E-mail/i }) + .type(userEmail) + .should('have.value', userEmail); + cy.findByRole('button', { name: /Envoyer/i }).click(); + cy.findByText(/E-mail en cours d'envoi/i).should('not.be.visible'); + }); +}); diff --git a/tests/cypress/e2e/pages/cv.cy.ts b/tests/cypress/e2e/pages/cv.cy.ts new file mode 100644 index 0000000..419a098 --- /dev/null +++ b/tests/cypress/e2e/pages/cv.cy.ts @@ -0,0 +1,6 @@ +describe('CV Page', () => { + it('successfully loads', () => { + cy.visit('/cv'); + cy.findByRole('heading', { level: 1 }).contains('CV'); + }); +}); diff --git a/tests/cypress/e2e/pages/homepage.cy.ts b/tests/cypress/e2e/pages/homepage.cy.ts new file mode 100644 index 0000000..52bfbc7 --- /dev/null +++ b/tests/cypress/e2e/pages/homepage.cy.ts @@ -0,0 +1,9 @@ +import { settings } from '@utils/config'; + +describe('HomePage', () => { + it('successfully loads', () => { + cy.visit('/'); + cy.findByRole('heading', { level: 1 }).contains(settings.name); + cy.findByText(settings.baseline.fr).should('exist'); + }); +}); diff --git a/tests/cypress/e2e/pages/legal-notice.cy.ts b/tests/cypress/e2e/pages/legal-notice.cy.ts new file mode 100644 index 0000000..f338a7a --- /dev/null +++ b/tests/cypress/e2e/pages/legal-notice.cy.ts @@ -0,0 +1,6 @@ +describe('Legal Notice Page', () => { + it('successfully loads', () => { + cy.visit('/mentions-legales'); + cy.findByRole('heading', { level: 1 }).contains('Mentions légales'); + }); +}); diff --git a/tests/cypress/e2e/pages/projects.cy.ts b/tests/cypress/e2e/pages/projects.cy.ts new file mode 100644 index 0000000..b477400 --- /dev/null +++ b/tests/cypress/e2e/pages/projects.cy.ts @@ -0,0 +1,6 @@ +describe('Projects Page', () => { + it('successfully loads', () => { + cy.visit('/projets'); + cy.findByRole('heading', { level: 1 }).contains('Projets'); + }); +}); |
