diff options
| author | Armand Philippot <git@armandphilippot.com> | 2023-09-26 15:54:28 +0200 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2023-10-24 12:23:48 +0200 |
| commit | 70efcfeaa0603415dd992cb662d8efb960e6e49a (patch) | |
| tree | 5d37e98fae9aa7e5c3d8ef30a10db9fed9b63e36 /tests/cypress/e2e/pages/blog.cy.ts | |
| parent | 31695306bfed44409f03006ea717fd2cceff8f87 (diff) | |
refactor(routes): replace hardcoded routes with constants
It makes it easier to change a route if needed and it avoid typo
mistakes.
I also refactored a bit the concerned files to be complient with the
new ESlint config. However, I should rewrite the pages to reduce
the number of statements.
Diffstat (limited to 'tests/cypress/e2e/pages/blog.cy.ts')
| -rw-r--r-- | tests/cypress/e2e/pages/blog.cy.ts | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/tests/cypress/e2e/pages/blog.cy.ts b/tests/cypress/e2e/pages/blog.cy.ts index 4327332..2ec14c2 100644 --- a/tests/cypress/e2e/pages/blog.cy.ts +++ b/tests/cypress/e2e/pages/blog.cy.ts @@ -1,30 +1,38 @@ import { settings } from '../../../../src/utils/config'; +import { ROUTES } from '../../../../src/utils/constants'; + +type ArticlesGroup = { + first: string; + total: string; +}; describe('Blog Page', () => { beforeEach(() => { - cy.visit('/blog'); + cy.visit(ROUTES.BLOG); }); it('loads the correct number of pages', () => { - cy.findByText(/(\d+) articles chargés sur un total de (\d+)/i) + cy.findByText( + /(?<first>\d+) articles chargés sur un total de (?<total>\d+)/i + ) .then(($div) => { - type ArticlesGroup = { - first: string; - total: string; - }; - const firstLastNumbers = /(?<first>\d+).*[\D](?<total>\d+)/; - const result = $div.text().match(firstLastNumbers); + const result = RegExp(firstLastNumbers).exec($div.text()); + + // eslint-disable-next-line @typescript-eslint/no-unused-expressions expect(result).to.not.be.null; - const { first, total } = result!.groups as ArticlesGroup; - const firstArticles = parseInt(first, 10); + const { first, total } = result + ? (result.groups as ArticlesGroup) + : { first: '0', total: '0' }; const totalArticles = parseInt(total, 10); - expect(firstArticles).to.be.within(1, settings.postsPerPage); + + expect(parseInt(first, 10)).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) => { |
