Skip to content

Commit 0d99f45

Browse files
committed
logged out views for request spec work
1 parent e56fad6 commit 0d99f45

File tree

2 files changed

+99
-27
lines changed

2 files changed

+99
-27
lines changed

cypress/e2e/request.cy.js

Lines changed: 53 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import useOneRequestResponseBody from '../fixtures/one-request/request.json'
1+
import {
2+
requestUuid as uuid,
3+
requestPageApiCalls as apiCalls,
4+
} from '../support/e2e'
25

3-
describe.skip('Viewing one request', () => {
4-
// TODO: currently this uses a real request uuid, which would allow it to visit a route that actually existed.
5-
// since the routes are generated dynamically, we will need to mock the next router in order to generate a route for a fake request w/ mock uuid within the test
6-
// this test should remain skipped until the above is done since it runs as a regular e2e vs e2e with mocked data
6+
describe('Viewing one request', () => {
77
// Existing ticket to complete this test: https://github.com/scientist-softserv/webstore/issues/218
8-
let uuid = useOneRequestResponseBody.uuid
98

109
describe('as a logged out user', () => {
1110
it('should show an error message.', () => {
@@ -17,30 +16,58 @@ describe.skip('Viewing one request', () => {
1716
})
1817

1918
describe('as a logged in user', () => {
20-
// declare variables that can be used to change how the response is intercepted.
21-
let request
22-
let proposals
23-
let messages
24-
let files
25-
let loading
26-
let error
27-
2819
beforeEach(() => {
29-
// Call the custom cypress command to log in
3020
cy.login(Cypress.env('TEST_SCIENTIST_USER'), Cypress.env('TEST_SCIENTIST_PW'))
31-
32-
// Intercept the response from the endpoint to view one request
33-
cy.customApiIntercept({
34-
action: 'GET',
35-
alias: 'useOneRequest',
36-
requestURL: `/quote_groups/${uuid}.json`,
37-
data: request,
38-
dataFixture: 'one-request/request.json',
39-
emptyDataFixture: 'empty.json',
40-
loading,
41-
error
21+
22+
apiCalls.forEach((item) => {
23+
const key = Object.keys(item)[0]
24+
cy.customApiIntercept(item[key])
4225
})
4326

27+
cy.visit(`/requests/${uuid}`)
28+
})
29+
30+
describe('makes a call to the api', () => {
31+
context('which when given an invalid uuid', () => {
32+
before(() => {
33+
apiCalls['useOneRequest'] = {
34+
...apiCalls['useOneRequest'],
35+
error: {
36+
body: {
37+
message: 'Quote Group Not Found',
38+
},
39+
statusCode: 404,
40+
},
41+
requestURL: '/quote_groups/fake-uuid.json'
42+
}
43+
})
44+
45+
it('returns an error message', () => {
46+
cy.get("div[role='alert']").should('be.visible').then(() => {
47+
cy.log('Successfully hits an error.')
48+
})
49+
cy.get("div[role='alert']").contains('Quote Group Not Found')
50+
})
51+
})
52+
53+
context('which when returns undefined error and data values', () => {
54+
before(() => {
55+
apiCalls.forEach((item) => {
56+
const key = Object.keys(item)[0]
57+
58+
item[key].data = undefined
59+
item[key].error = undefined
60+
})
61+
})
62+
63+
it('shows a loading spinner.', () => {
64+
cy.get("[aria-label='tail-spin-loading']").should('be.visible').then(() => {
65+
cy.log('Loading spinner displays correctly.')
66+
})
67+
})
68+
})
69+
70+
4471
cy.customApiIntercept({
4572
action: 'GET',
4673
alias: 'useAllSOWs',

cypress/support/e2e.js

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,49 @@
1616
// Import commands.js using ES2015 syntax:
1717
import './commands'
1818

19-
export const scientistApiBaseURL = `https://${Cypress.env('NEXT_PUBLIC_PROVIDER_NAME')}.scientist.com/api/v2`
19+
export const scientistApiBaseURL = `https://${Cypress.env('NEXT_PUBLIC_PROVIDER_NAME')}.scientist.com/api/v2`
20+
21+
let error
22+
export const requestUuid = '596127b7-2356-45aa-aec4-a4f8608ae755'
23+
export const requestPageApiCalls = [
24+
{
25+
'useOneRequest': {
26+
alias: 'useOneRequest',
27+
data: 'one-request/request.json',
28+
error,
29+
requestURL: `/quote_groups/${requestUuid}.json`,
30+
}
31+
},
32+
{
33+
'useAllMessages': {
34+
alias: 'useAllMessages',
35+
data: { messages: [] },
36+
error,
37+
requestURL: `/quote_groups/${requestUuid}/messages.json`
38+
},
39+
},
40+
{
41+
'useAllSOWs': {
42+
alias: 'useAllSOWs',
43+
data: [],
44+
error,
45+
requestURL: `/quote_groups/${requestUuid}/proposals.json`
46+
}
47+
},
48+
{
49+
'useAllFiles': {
50+
alias: 'useAllFiles',
51+
data: { notes: [] },
52+
error,
53+
requestURL: `/quote_groups/${requestUuid}/notes.json}`,
54+
}
55+
},
56+
{
57+
'getAllPOs': {
58+
alias: 'getAllPOs',
59+
data: [],
60+
error,
61+
requestURL: `/quote_groups/${requestUuid}/quoted_wares/8AE755/purchase_orders.json}`,
62+
}
63+
}
64+
]

0 commit comments

Comments
 (0)