From d95088a70a7170c2cc0db9d4c93699f3c3a018e5 Mon Sep 17 00:00:00 2001 From: Luna McNulty Date: Tue, 2 Apr 2024 16:53:50 -0400 Subject: [PATCH] Test that buttons appear only when applicable --- .../cypress/e2e/integration/cite.cy.js | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/site/gatsby-site/cypress/e2e/integration/cite.cy.js b/site/gatsby-site/cypress/e2e/integration/cite.cy.js index 78b9951d45..1905409f15 100644 --- a/site/gatsby-site/cypress/e2e/integration/cite.cy.js +++ b/site/gatsby-site/cypress/e2e/integration/cite.cy.js @@ -20,6 +20,8 @@ describe('Cite pages', () => { let user; + let lastIncidentId; + before('before', function () { // Skip all tests if the environment is empty since /cite/{incident_id} is not available Cypress.env('isEmptyEnvironment') && this.skip(); @@ -32,13 +34,35 @@ describe('Cite pages', () => { first_name last_name } + incidents(limit: 1, sortBy: INCIDENT_ID_DESC) { + incident_id + } } `, - }).then(({ data: { user: userData } }) => { + }).then(({ data: { user: userData, incidents: incidentsData } }) => { user = userData; + lastIncidentId = incidentsData[0].incident_id; }); }); + it('Should disable Previous and Next incident buttons in header on first and last incidents', () => { + cy.visit('/cite/1'); + + cy.get(`[data-cy="header-previous-incident-link"]`).should('not.exist'); + + cy.get(`[data-cy="header-next-incident-link"]`) + .should('be.visible') + .should('have.attr', 'href', '/cite/2'); + + cy.visit(`/cite/${lastIncidentId}`); + + cy.get(`[data-cy="header-next-incident-link"]`).should('not.exist'); + + cy.get(`[data-cy="header-previous-incident-link"]`) + .should('be.visible') + .should('have.attr', 'href', `/cite/${lastIncidentId - 1}`); + }); + maybeIt('Should show an edit link to users with the appropriate role', {}, () => { cy.login(Cypress.env('e2eUsername'), Cypress.env('e2ePassword'));