|
| 1 | +/// <reference types="cypress" /> |
| 2 | +const fakeGoogleTagManager = { |
| 3 | + trackingOptIn: () => {}, |
| 4 | + trackingOptOut: () => {} |
| 5 | +} |
| 6 | + |
| 7 | +describe('API reference content', () => { |
| 8 | + const subjects = [ |
| 9 | + '/influxdb/cloud/api/', |
| 10 | + '/influxdb/cloud/api/v1/', |
| 11 | + '/influxdb/cloud/api/v1-compatibility/', |
| 12 | + '/influxdb/cloud/api/v2/', |
| 13 | + |
| 14 | + '/influxdb/v2/api/', |
| 15 | + '/influxdb/v2/api/v1/', |
| 16 | + '/influxdb/v2/api/v1-compatibility/', |
| 17 | + '/influxdb/v2/api/v2/', |
| 18 | + |
| 19 | + '/influxdb3/cloud-dedicated/api/', |
| 20 | + '/influxdb3/cloud-dedicated/api/management/', |
| 21 | + '/influxdb3/cloud-dedicated/api/v1/', |
| 22 | + '/influxdb3/cloud-dedicated/api/v1-compatibility/', |
| 23 | + '/influxdb3/cloud-dedicated/api/v2/', |
| 24 | + |
| 25 | + '/influxdb3/cloud-serverless/api/', |
| 26 | + '/influxdb3/cloud-serverless/api/v1/', |
| 27 | + '/influxdb3/cloud-serverless/api/v1-compatibility/', |
| 28 | + '/influxdb3/cloud-serverless/api/v2/', |
| 29 | + |
| 30 | + '/influxdb3/clustered/api/', |
| 31 | + // TODO '/influxdb3/clustered/api/management/', |
| 32 | + '/influxdb3/clustered/api/v1/', |
| 33 | + '/influxdb3/clustered/api/v1-compatibility/', |
| 34 | + '/influxdb3/clustered/api/v2/', |
| 35 | + '/influxdb3/core/api/', |
| 36 | + |
| 37 | + '/influxdb3/enterprise/api/', |
| 38 | + ]; |
| 39 | + |
| 40 | + subjects.forEach((subject) => { |
| 41 | + describe(subject, () => { |
| 42 | + it(`has API info`, function () { |
| 43 | + cy.visit(subject); |
| 44 | + window.fcdsc = fakeGoogleTagManager; |
| 45 | + cy.stub(window.fcdsc, 'trackingOptIn').as('trackingOptIn'); |
| 46 | + cy.stub(window.fcdsc, 'trackingOptOut').as('trackingOptOut'); |
| 47 | + cy.get('h1').first().should('have.length', 1); |
| 48 | + cy.get('[data-role$=description]').should('have.length', 1); |
| 49 | + }); |
| 50 | + it('links back to the version home page', function () { |
| 51 | + cy.visit(`${subject}`); |
| 52 | + window.fcdsc = fakeGoogleTagManager; |
| 53 | + cy.stub(window.fcdsc, 'trackingOptIn').as('trackingOptIn'); |
| 54 | + cy.stub(window.fcdsc, 'trackingOptOut').as('trackingOptOut'); |
| 55 | + cy.get('a.back').contains('Docs') |
| 56 | + .should('have.length', 1) |
| 57 | + .click(); |
| 58 | + // Path should be the first two segments and trailing slash in $subject |
| 59 | + cy.location('pathname') |
| 60 | + .should('eq', subject.replace(/^(\/[^/]+\/[^/]+\/).*/, '$1')); |
| 61 | + cy.get('h1').should('have.length', 1); |
| 62 | + }); |
| 63 | + it('contains valid internal links', function () { |
| 64 | + cy.visit(subject); |
| 65 | + window.fcdsc = fakeGoogleTagManager; |
| 66 | + cy.stub(window.fcdsc, 'trackingOptIn').as('trackingOptIn'); |
| 67 | + cy.stub(window.fcdsc, 'trackingOptOut').as('trackingOptOut'); |
| 68 | + // The following conditional test isn't the cypress way, but the doc might not have internal links. |
| 69 | + cy.get('body').then(($body) => { |
| 70 | + if ($body.find('p a[href^="/"]').length === 0) { |
| 71 | + cy.log('No internal links found'); |
| 72 | + return; |
| 73 | + } |
| 74 | + cy.get('p a[href^="/"]').as('internal-links'); |
| 75 | + cy.get('@internal-links').each(($a) => { |
| 76 | + cy.log(`** Testing link ${$a.attr('href')} **`); |
| 77 | + // cy.request doesn't show in your browser's Developer Tools |
| 78 | + // because the request comes from Node, not from the browser. |
| 79 | + cy.request($a.attr('href')).its('status').should('eq', 200); |
| 80 | + }); |
| 81 | + |
| 82 | + }); |
| 83 | + }); |
| 84 | + it('contains valid external links', function () { |
| 85 | + cy.visit(subject); |
| 86 | + window.fcdsc = fakeGoogleTagManager; |
| 87 | + cy.stub(window.fcdsc, 'trackingOptIn').as('trackingOptIn'); |
| 88 | + cy.stub(window.fcdsc, 'trackingOptOut').as('trackingOptOut'); |
| 89 | + // The following conditional test isn't the cypress way, but the doc might not have external links. |
| 90 | + cy.get('body').then(($body) => { |
| 91 | + if ($body.find('p a[href^="http"]').length === 0) { |
| 92 | + cy.log('No external links found'); |
| 93 | + return; |
| 94 | + } |
| 95 | + cy.get('p a[href^="http"]').as('external-links'); |
| 96 | + cy.get('@external-links').each(($a) => { |
| 97 | + cy.log(`** Testing link ${$a.attr('href')} **`); |
| 98 | + cy.request($a.attr('href')).its('status').should('eq', 200); |
| 99 | + }); |
| 100 | + }); |
| 101 | + }); |
| 102 | + }); |
| 103 | + }); |
| 104 | +}); |
0 commit comments