aboutsummaryrefslogtreecommitdiffstats
path: root/tests/cypress/e2e/pages/blog.cy.ts
blob: a83caa0c9c7664cadad4fe74b943a4059585c5f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { CONFIG } from '../../../../src/utils/config';
import { ROUTES } from '../../../../src/utils/constants';
import { wpPostsFixture } from '../../../fixtures';

describe('Blog Page', () => {
  beforeEach(() => {
    cy.visit(ROUTES.BLOG);
  });

  it('successfully loads', () => {
    cy.findByRole('heading', { level: 1 }).should('exist');
  });

  it('contains a breadcrumbs', () => {
    cy.findByRole('navigation', { name: 'Fil d’Ariane' }).should('exist');
  });

  it('loads the correct number of posts', () => {
    cy.findByText(
      /(?<first>\d+) articles chargés sur un total de (?<total>\d+)/i
    ).should('exist');
    cy.findAllByRole('link', { name: /En lire plus/ }).should(
      'have.length.at.most',
      CONFIG.postsPerPage
    );

    const loadMorePosts = () => {
      cy.findByRole('button', { name: /Charger plus/ })
        .should((_) => {
          /* do nothing */
        })
        .then(($loadMoreBtn) => {
          if (!$loadMoreBtn.length) {
            cy.log('No more posts');
            return;
          }

          cy.log('Loading more posts');
          // eslint-disable-next-line @typescript-eslint/no-magic-numbers
          cy.wrap($loadMoreBtn).click().wait(500);
          loadMorePosts();
        });
    };

    loadMorePosts();

    cy.findAllByRole('link', { name: /En lire plus/ }).should(
      'have.length',
      wpPostsFixture.length
    );
  });

  it('contains a thematics list widget and a topics list widget', () => {
    cy.findByRole('heading', { level: 2, name: 'Thématiques' }).should('exist');
    cy.findByRole('heading', { level: 2, name: 'Sujets' }).should('exist');
  });
});