aboutsummaryrefslogtreecommitdiff
path: root/cypress/e2e/api.cy.ts
blob: e87ea856f50400baadf80bb0946d4feced996c03 (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
58
59
describe('API Test', () => {
  it('navigates to the api index search', () => {
    // given
    cy.visit('/');

    // when
    cy.get('a').contains('API').click();

    // then
    cy.url().should('include', '/api/');
    cy.contains('API Reference');
  });

  describe('API Reference', () => {
    beforeEach(() => {
      // given
      cy.visit('/api/');
    });

    it('should at least list more than 7 modules', () => {
      cy.get('.api-group').should('have.length.above', 7);
    });

    it('should include at least 1 element in each module', () => {
      cy.get('.api-group').each(($el) => {
        cy.wrap($el).within(() => {
          cy.get('li a[href]').should('have.length.above', 0);
        });
      });
    });

    it('should not have dead links', () => {
      const checked = new Set<string>();
      cy.get('.api-group li').each(($el) => {
        const anchor = $el.find('a');
        const text = anchor.text();
        const link = anchor.attr('href')?.split('#')[0] ?? 'MISSING';
        if (checked.has(link)) {
          return;
        }

        checked.add(link);

        cy.request({
          method: 'HEAD',
          url: link,
          failOnStatusCode: false,
        })
          .should(({ status }) => {
            expect(
              status,
              `${text} to have a working link: /api/${link}`
            ).to.eq(200);
          })
          .end();
      });
    });
  });
});