Changeset View
Changeset View
Standalone View
Standalone View
cypress/integration/layout.spec.js
Show First 20 Lines • Show All 161 Lines • ▼ Show 20 Lines | const statusTestData = [ | ||||
} | } | ||||
]; | ]; | ||||
const responses = []; | const responses = []; | ||||
for (const std of statusTestData) { | for (const std of statusTestData) { | ||||
responses.push(genStatusResponse(std.status, std.statusCode)); | responses.push(genStatusResponse(std.status, std.statusCode)); | ||||
} | } | ||||
let i = 0; | const checkStatusDisplay = (i) => { | ||||
for (const std of statusTestData) { | |||||
cy.visit(url); | cy.visit(url); | ||||
// trick to override the response of an intercepted request | // trick to override the response of an intercepted request | ||||
// https://github.com/cypress-io/cypress/issues/9302 | // https://github.com/cypress-io/cypress/issues/9302 | ||||
cy.intercept(`${statusUrl}/**`, req => req.reply(responses.shift())) | cy.intercept(`${statusUrl}/**`, req => req.reply(responses.shift())) | ||||
.as(`getSwhStatusData${i}`); | .as(`getSwhStatusData${i}`); | ||||
cy.wait(`@getSwhStatusData${i}`); | cy.wait(`@getSwhStatusData${i}`); | ||||
cy.get('.swh-current-status-indicator').should('have.class', std.color); | cy.get('.swh-current-status-indicator').should('have.class', statusTestData[i].color); | ||||
cy.get('#swh-current-status-description').should('have.text', std.status); | cy.get('#swh-current-status-description').should('have.text', statusTestData[i].status); | ||||
++i; | }; | ||||
} | |||||
checkStatusDisplay(0); // Operationnal | |||||
checkStatusDisplay(1); // Scheduled Maintenance | |||||
checkStatusDisplay(2); // Degraded Performance | |||||
checkStatusDisplay(3); // Partial Service Disruption | |||||
checkStatusDisplay(4); // Service Disruption | |||||
ardumont: I guess those calls could have been made in a loop though, right?
(just asking out of… | |||||
Done Inline ActionsThe thing is that we can't use for loops with cypress because of its async nature. anlambert: The thing is that we can't use for loops with cypress because of its async nature.
Cypress… | |||||
Not Done Inline Actionsah yes, thx! ardumont: ah yes, thx! | |||||
checkStatusDisplay(5); // Security Event | |||||
}); | }); | ||||
it('should not display swh status widget when data are not available', function() { | it('should not display swh status widget when data are not available', function() { | ||||
cy.intercept(`${statusUrl}/**`, { | cy.intercept(`${statusUrl}/**`, { | ||||
body: {} | body: {} | ||||
}).as('getSwhStatusData'); | }).as('getSwhStatusData'); | ||||
cy.visit(url); | cy.visit(url); | ||||
cy.wait('@getSwhStatusData'); | cy.wait('@getSwhStatusData'); | ||||
▲ Show 20 Lines • Show All 42 Lines • Show Last 20 Lines |
I guess those calls could have been made in a loop though, right?
(just asking out of curiosity, not asking you to change anything ;)