Skip to content

Commit 2dd1c7e

Browse files
authored
Merge pull request #241 from scientist-softserv/239-requests-page-tests
239 requests page tests
2 parents 9d3b31c + 79f8f0c commit 2dd1c7e

File tree

3 files changed

+81
-21
lines changed

3 files changed

+81
-21
lines changed

cypress/e2e/requests.cy.js

Lines changed: 73 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,103 @@ describe('Viewing all requests', () => {
22
describe('as a logged out user', () => {
33
it('should show an error message.', () => {
44
// Visit a protected route in order to allow cypress to set the cookie and mock the login
5-
cy.visit("/requests")
5+
cy.visit('/requests')
66
cy.get('div.alert-heading').contains('Unauthorized').then(() => {
7-
cy.log("A logged out user is not able to view requests.")
7+
cy.log('A logged out user is not able to view requests.')
88
})
99
})
1010
})
1111

1212
describe('as a logged in user', () => {
1313
let scientistApiBaseURL = `https://${Cypress.env('NEXT_PUBLIC_PROVIDER_NAME')}.scientist.com/api/v2`
14+
// declare variables that can be used to change how the response is intercepted.
1415
let requestList
16+
let loading
17+
let error
1518

1619
beforeEach(() => {
1720
// Call the custom cypress command to log in
1821
cy.login(Cypress.env('TEST_SCIENTIST_USER'), Cypress.env('TEST_SCIENTIST_PW'))
19-
2022
// Intercept the response from the endpoint to view all requests
23+
// TODO(summer-cook): extract out this base url into the config to use as an environment variable. it was not cooperating before
2124
cy.intercept('GET', `${scientistApiBaseURL}/quote_groups/mine.json`, (req) => {
22-
if (requestList === true) {
23-
req.reply({fixture: 'all-requests/requests.json'})
24-
} else {
25-
req.reply({fixture: 'all-requests/no-requests.json'})
25+
if ((requestList === undefined) && (loading === true)) {
26+
// reply with an empty response: both data and error will be undefined.
27+
req.reply()
28+
} else if ((requestList === undefined) && (loading === false) && (error === true)) {
29+
// error will be defined
30+
req.reply({ statusCode: 500 })
31+
} else if (requestList === true) {
32+
// reply with a request body- default status code is 200
33+
req.reply({ fixture: 'all-requests/requests.json' })
34+
} else if (requestList === false) {
35+
req.reply({ fixture: 'all-requests/no-requests.json' })
2636
}
27-
}).as('useAllRequests')
28-
cy.visit("/requests")
37+
})
38+
// Intercept the response from the endpoint that gets the default ware ID
39+
cy.intercept('GET', `${scientistApiBaseURL}/wares.json?q=make-a-request`, { fixture: 'all-requests/make-a-request.json' })
40+
cy.visit('/requests')
2941
})
3042

31-
context('has requests', () => {
43+
44+
context('request list is loading', () => {
3245
before(() => {
33-
requestList = true
46+
loading = true
3447
})
35-
it("shows the user's request list.", () => {
36-
cy.get('article.request-item').should('exist').then(() => {
37-
cy.log('Successfully viewing request list.')
48+
it('should show a loading spinner.', () => {
49+
cy.get("[aria-label='tail-spin-loading']").should('be.visible').then(() => {
50+
cy.log('Loading spinner displays correctly.')
3851
})
3952
})
4053
})
4154

42-
context('has 0 requests', () => {
43-
before(() => {
44-
requestList = false
55+
// TODO: uncomment this and try to make the page it not get an undefined error
56+
// context('error while making a request to the api', () => {
57+
// before(() => {
58+
// requestList = undefined
59+
// loading = false
60+
// error = true
61+
// })
62+
// it('should show an error message.', () => {
63+
// cy.get("div[role='alert']").should('be.visible').then(() => {
64+
// cy.log('Successfully hits an error.')
65+
// })
66+
// })
67+
// })
68+
69+
describe('request components are loading successfully, &', () => {
70+
context('the user has requests', () => {
71+
before(() => {
72+
requestList = true
73+
})
74+
it("should show the user's request list.", () => {
75+
cy.get('article.request-item').should('exist').then(() => {
76+
cy.log('Successfully viewing request list.')
77+
})
78+
})
79+
})
80+
81+
context('the user has 0 requests', () => {
82+
before(() => {
83+
requestList = []
84+
})
85+
it("should show a message notifying the user they don't have any requests.", () => {
86+
cy.get('p.no-requests').contains('You do not have any requests yet.').then(() => {
87+
cy.log('Successfully viewing request page with no requests.')
88+
})
89+
})
4590
})
46-
it("shows a message notifying the user they don't have any requests.", () => {
47-
cy.get('p.no-requests').contains('You do not have any requests yet.').then(() => {
48-
cy.log('Successfully viewing request page with no requests.')
91+
92+
context('the user can see the <LinkedButton /> component', () => {
93+
[true, false].forEach((value) => {
94+
before(() => {
95+
requestList = value
96+
})
97+
it(`should show a button that links to the initialize request page for the default ware ${value ? 'with a request list' : 'with 0 requests'}.`, () => {
98+
cy.get("a[data-cy='linked-button']").should('have.attr', 'href', `/requests/new/make-a-request?id=123`).then(() => {
99+
cy.log('The <LinkedButton /> component displays correctly')
100+
})
101+
})
49102
})
50103
})
51104
})
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"ware_refs": [
3+
{
4+
"id": 123
5+
}
6+
]
7+
}

cypress/fixtures/all-requests/requests.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"uuid": "596127b7-2356-45aa-aec4-a4f8608ae755",
3131
"name": "Example Request 3",
3232
"description": "<p>Here is a 3rd request</p>",
33-
"status": "Compliance Required",
33+
"status": "SOW Submitted",
3434
"billing_same_as_shipping": false,
3535
"proposed_deadline": null,
3636
"updated_at": "2023-02-23T07:12:44.086Z",

0 commit comments

Comments
 (0)