summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2022-05-30 12:08:46 +0200
committerArmand Philippot <git@armandphilippot.com>2022-06-03 11:54:08 +0200
commitd0027d69a921dc43d66807b1698e6b4848bc9b1d (patch)
treeb91fc48c1a92fc3f5683f7fd69ec2a0174a14c84 /tests
parent7de22756ea4ae6e07a26da8c693fcf5d461b053d (diff)
test(e2e): add loading more button test for blog page
Diffstat (limited to 'tests')
-rw-r--r--tests/cypress/e2e/pages/blog.cy.ts44
1 files changed, 44 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'
+ );
+ });
+ });
+});