diff options
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) => { |
