diff --git a/cypress/e2e/requests.cy.js b/cypress/e2e/requests.cy.js index 1e7d730..003ef6a 100644 --- a/cypress/e2e/requests.cy.js +++ b/cypress/e2e/requests.cy.js @@ -2,50 +2,103 @@ describe('Viewing all requests', () => { describe('as a logged out user', () => { it('should show an error message.', () => { // Visit a protected route in order to allow cypress to set the cookie and mock the login - cy.visit("/requests") + cy.visit('/requests') cy.get('div.alert-heading').contains('Unauthorized').then(() => { - cy.log("A logged out user is not able to view requests.") + cy.log('A logged out user is not able to view requests.') }) }) }) describe('as a logged in user', () => { let scientistApiBaseURL = `https://${Cypress.env('NEXT_PUBLIC_PROVIDER_NAME')}.scientist.com/api/v2` + // declare variables that can be used to change how the response is intercepted. let requestList + let loading + let error beforeEach(() => { // Call the custom cypress command to log in cy.login(Cypress.env('TEST_SCIENTIST_USER'), Cypress.env('TEST_SCIENTIST_PW')) - // Intercept the response from the endpoint to view all requests + // TODO(summer-cook): extract out this base url into the config to use as an environment variable. it was not cooperating before cy.intercept('GET', `${scientistApiBaseURL}/quote_groups/mine.json`, (req) => { - if (requestList === true) { - req.reply({fixture: 'all-requests/requests.json'}) - } else { - req.reply({fixture: 'all-requests/no-requests.json'}) + if ((requestList === undefined) && (loading === true)) { + // reply with an empty response: both data and error will be undefined. + req.reply() + } else if ((requestList === undefined) && (loading === false) && (error === true)) { + // error will be defined + req.reply({ statusCode: 500 }) + } else if (requestList === true) { + // reply with a request body- default status code is 200 + req.reply({ fixture: 'all-requests/requests.json' }) + } else if (requestList === false) { + req.reply({ fixture: 'all-requests/no-requests.json' }) } - }).as('useAllRequests') - cy.visit("/requests") + }) + // Intercept the response from the endpoint that gets the default ware ID + cy.intercept('GET', `${scientistApiBaseURL}/wares.json?q=make-a-request`, { fixture: 'all-requests/make-a-request.json' }) + cy.visit('/requests') }) - context('has requests', () => { + + context('request list is loading', () => { before(() => { - requestList = true + loading = true }) - it("shows the user's request list.", () => { - cy.get('article.request-item').should('exist').then(() => { - cy.log('Successfully viewing request list.') + it('should show a loading spinner.', () => { + cy.get("[aria-label='tail-spin-loading']").should('be.visible').then(() => { + cy.log('Loading spinner displays correctly.') }) }) }) - context('has 0 requests', () => { - before(() => { - requestList = false + // TODO: uncomment this and try to make the page it not get an undefined error + // context('error while making a request to the api', () => { + // before(() => { + // requestList = undefined + // loading = false + // error = true + // }) + // it('should show an error message.', () => { + // cy.get("div[role='alert']").should('be.visible').then(() => { + // cy.log('Successfully hits an error.') + // }) + // }) + // }) + + describe('request components are loading successfully, &', () => { + context('the user has requests', () => { + before(() => { + requestList = true + }) + it("should show the user's request list.", () => { + cy.get('article.request-item').should('exist').then(() => { + cy.log('Successfully viewing request list.') + }) + }) + }) + + context('the user has 0 requests', () => { + before(() => { + requestList = [] + }) + it("should show a message notifying the user they don't have any requests.", () => { + cy.get('p.no-requests').contains('You do not have any requests yet.').then(() => { + cy.log('Successfully viewing request page with no requests.') + }) + }) }) - it("shows a message notifying the user they don't have any requests.", () => { - cy.get('p.no-requests').contains('You do not have any requests yet.').then(() => { - cy.log('Successfully viewing request page with no requests.') + + context('the user can see the component', () => { + [true, false].forEach((value) => { + before(() => { + requestList = value + }) + it(`should show a button that links to the initialize request page for the default ware ${value ? 'with a request list' : 'with 0 requests'}.`, () => { + cy.get("a[data-cy='linked-button']").should('have.attr', 'href', `/requests/new/make-a-request?id=123`).then(() => { + cy.log('The component displays correctly') + }) + }) }) }) }) diff --git a/cypress/fixtures/all-requests/make-a-request.json b/cypress/fixtures/all-requests/make-a-request.json new file mode 100644 index 0000000..6c36641 --- /dev/null +++ b/cypress/fixtures/all-requests/make-a-request.json @@ -0,0 +1,7 @@ +{ + "ware_refs": [ + { + "id": 123 + } + ] +} \ No newline at end of file diff --git a/cypress/fixtures/all-requests/requests.json b/cypress/fixtures/all-requests/requests.json index ed9d5b4..af6016c 100644 --- a/cypress/fixtures/all-requests/requests.json +++ b/cypress/fixtures/all-requests/requests.json @@ -30,7 +30,7 @@ "uuid": "596127b7-2356-45aa-aec4-a4f8608ae755", "name": "Example Request 3", "description": "

Here is a 3rd request

", - "status": "Compliance Required", + "status": "SOW Submitted", "billing_same_as_shipping": false, "proposed_deadline": null, "updated_at": "2023-02-23T07:12:44.086Z",