Skip to content

Commit d12029a

Browse files
authored
Merge pull request #381 from scientist-softserv/363-request-specs
363 request specs
2 parents 8f7e479 + b5ffbc2 commit d12029a

File tree

17 files changed

+456
-152
lines changed

17 files changed

+456
-152
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,16 @@ There are 2 types of Cypress tests, e2e & component.
174174
If you are creating an e2e test, it will live in the `cypress/e2e` directory. Component tests will need to be created in a directory called `cypress/component `
175175

176176
#### Cypress ENV Variables
177-
- the Cypress suite requires an environment variable that should be stored in your `.env.development` and not committed to git.
177+
- the Cypress suite requires an environment variable that should be stored in your `.env` and not committed to git.
178178
- TEST_SESSION_COOKIE=
179-
- to get the value for this variable, open your browser to your running app at `localhost:3000`.
179+
- to get the value for this variable, open your browser to your running app at `localhost:3000`
180+
- sign in
180181
- inspect the page
181-
- click the "Application" tab
182+
- Chrome: click the "Application" tab
183+
- Firefox: click the "Storage" tab
182184
- click "Cookies"
183185
- find the value for `next-auth.session-token`
184-
- copy that value and paste it in the `TEST_SESSION_COOKIE` variable in your .env.development
186+
- copy that value and paste it in the `TEST_SESSION_COOKIE` variable in your `.env`
185187
- do not ever commit this value
186188
- this value will need to be updated whenever the cookie expires, approximately once per month
187189

cypress.config.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module.exports = defineConfig({
1111
e2e: {
1212
baseUrl: 'http://localhost:3000',
1313
chromeWebSecurity: false,
14+
defaultCommandTimeout: 10000,
1415
setupNodeEvents(on, config) {
1516
config = dotenvFlowPlugin(config)
1617
config.env = {
@@ -21,12 +22,13 @@ module.exports = defineConfig({
2122
},
2223
},
2324
env: {
24-
TEST_SCIENTIST_USER: '[email protected]',
25-
TEST_SCIENTIST_PW: '!test1234',
26-
NEXT_PUBLIC_PROVIDER_NAME: process.env.NEXT_PUBLIC_PROVIDER_NAME,
25+
CYPRESS_SEARCH_QUERY: 'test',
2726
NEXT_PUBLIC_PROVIDER_ID: process.env.NEXT_PUBLIC_PROVIDER_ID,
27+
NEXT_PUBLIC_PROVIDER_NAME: process.env.NEXT_PUBLIC_PROVIDER_NAME,
2828
NEXT_PUBLIC_TOKEN: process.env.NEXT_PUBLIC_TOKEN,
29-
CYPRESS_SEARCH_QUERY: 'test',
29+
TEST_SCIENTIST_PW: '!test1234',
30+
TEST_SCIENTIST_USER: '[email protected]',
31+
TEST_SESSION_COOKIE: process.env.TEST_SESSION_COOKIE,
3032
},
3133
reporter: 'junit',
3234
reporterOptions: {

cypress/e2e/request.cy.js

Lines changed: 105 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
import useOneRequestResponseBody from '../fixtures/one-request/request.json'
2-
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
7-
// Existing ticket to complete this test: https://github.com/scientist-softserv/webstore/issues/218
8-
let uuid = useOneRequestResponseBody.uuid
1+
import {
2+
requestUuid as uuid,
3+
requestPageApiCalls,
4+
} from '../support/e2e'
95

6+
describe('Viewing one request', () => {
107
describe('as a logged out user', () => {
118
it('should show an error message.', () => {
129
cy.visit(`/requests/${uuid}`)
@@ -17,99 +14,128 @@ describe.skip('Viewing one request', () => {
1714
})
1815

1916
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
17+
let apiCalls = Object.assign({}, requestPageApiCalls)
2718

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
42-
})
4321

44-
cy.customApiIntercept({
45-
action: 'GET',
46-
alias: 'useAllSOWs',
47-
requestURL: `/quote_groups/${uuid}/proposals.json`,
48-
data: proposals,
49-
dataFixture: 'one-request/proposals.json',
50-
emptyDataFixture: 'empty.json',
51-
loading,
52-
error
53-
})
54-
55-
cy.customApiIntercept({
56-
action: 'GET',
57-
alias: 'useAllMessages',
58-
requestURL: `/quote_groups/${uuid}/messages.json`,
59-
data: messages,
60-
dataFixture: 'one-request/messages.json',
61-
emptyDataFixture: 'empty.json',
62-
loading,
63-
error
64-
})
65-
66-
cy.customApiIntercept({
67-
action: 'GET',
68-
alias: 'useAllFiles',
69-
requestURL: `/quote_groups/${uuid}/notes.json`,
70-
data: files,
71-
dataFixture: 'one-request/notes.json',
72-
emptyDataFixture: 'empty.json',
73-
loading,
74-
error
22+
Object.entries(apiCalls).forEach((item) => {
23+
cy.customApiIntercept(item[1])
7524
})
7625
cy.visit(`/requests/${uuid}`)
7726
})
7827

79-
context('request is loading', () => {
80-
before(() => {
81-
loading = true
82-
})
83-
it('should show a loading spinner.', () => {
84-
cy.get("[aria-label='tail-spin-loading']").should('be.visible').then(() => {
85-
cy.log('Loading spinner displays correctly.')
28+
afterEach(() => {
29+
// in order for the tests to not be order dependent, we need to reset the apiCalls object to the original state
30+
apiCalls = Object.assign({}, requestPageApiCalls)
31+
})
32+
33+
describe('makes a call to the api', () => {
34+
context('which when given an invalid uuid', () => {
35+
before(() => {
36+
apiCalls['useOneRequest'] = {
37+
...apiCalls['useOneRequest'],
38+
data: undefined,
39+
error: {
40+
body: {
41+
message: 'Quote Group Not Found',
42+
},
43+
statusCode: 404,
44+
},
45+
}
46+
})
47+
48+
it('returns an error message', () => {
49+
cy.get("div[role='alert']").should('be.visible').then(() => {
50+
cy.log('Successfully hits an error.')
51+
})
52+
cy.get("div[role='alert']").contains('Quote Group Not Found')
8653
})
8754
})
88-
})
8955

90-
describe('request page components are loading successfully, &', () => {
91-
context('the request page', () => {
56+
context('which when returns undefined error and data values', () => {
9257
before(() => {
93-
loading =
94-
request = true
95-
proposals = true
96-
messages = true
97-
files = true
58+
Object.entries(apiCalls).forEach(([key, value]) => {
59+
apiCalls[key] = {
60+
...value,
61+
data: undefined,
62+
error: undefined,
63+
}
64+
})
65+
})
66+
67+
it('shows a loading spinner.', () => {
68+
cy.get("[aria-label='tail-spin-loading']").should('be.visible').then(() => {
69+
cy.log('Loading spinner displays correctly.')
70+
})
9871
})
72+
})
9973

100-
it('should show the request stats section.', () => {
101-
cy.get('div.request-stats-card').should('exist').then(() => {
74+
describe('which when returns request data', () => {
75+
it('shows the request stats section', () => {
76+
cy.get('div.request-stats.card').should('exist').then(() => {
10277
cy.log('Request stats section renders successfully.')
10378
})
10479
})
10580

106-
it('should show the status bar.', () => {
81+
it('shows the status bar', () => {
10782
cy.get("div[data-cy='status-bar']").should('exist').then(() => {
10883
cy.log('Status bar renders successfully.')
10984
})
11085
})
111-
// TODO: add tests to confirm that messages, files, additional info, document sections all show correctly.
86+
87+
context('with messages', () => {
88+
before(() => {
89+
apiCalls['useMessages'] = {
90+
...apiCalls['useMessages'],
91+
data: 'one-request/messages/index.json',
92+
}
93+
})
94+
95+
it('displays the messages', () => {
96+
cy.get('div.card-body p.card-text')
97+
.contains('this is a message from the customer')
98+
.should('be.visible')
99+
})
100+
})
101+
102+
context('with documents', () => {
103+
before(() => {
104+
apiCalls['useAllSOWs'] = {
105+
...apiCalls['useAllSOWs'],
106+
data: 'one-request/sows/index.json',
107+
}
108+
apiCalls['getAllPOs'] = {
109+
...apiCalls['getAllPOs'],
110+
data: 'one-request/pos/index.json',
111+
}
112+
})
113+
114+
it('displays the documents', () => {
115+
cy.get('div.document').should('have.length', 2)
116+
cy.get('div.badge').contains('SOW').should('be.visible')
117+
cy.get('div.badge').contains('PO').should('be.visible')
118+
})
119+
})
120+
121+
context('with files', () => {
122+
before(() => {
123+
apiCalls['useFiles'] = {
124+
...apiCalls['useFiles'],
125+
data: 'one-request/files/index.json',
126+
}
127+
})
128+
129+
it('displays the files', () => {
130+
cy.get('div.actions-group')
131+
.contains('View Files')
132+
.click()
133+
cy.get('div#document-tabs-tabpane-files')
134+
.contains('downtown.jpg')
135+
.should('be.visible')
136+
})
137+
})
112138
})
113139
})
114140
})
115-
})
141+
})

cypress/fixtures/one-request/files.json

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"notes": []
3+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"notes": [
3+
{
4+
"id": 5019371,
5+
"title": "New Attachment",
6+
"status": "Other File",
7+
"body": null,
8+
"created_by": "Alisha Evans",
9+
"created_at": "2024-02-14T19:40:47.759Z",
10+
"updated_at": "2024-02-14T19:40:47.759Z",
11+
"attachments": [
12+
{
13+
"uuid": "fa70a15b-3230-41d5-9913-93ee0bcf2e3e",
14+
"filename": "downtown.jpg",
15+
"content_type": "image/jpeg",
16+
"content_length": 326048,
17+
"created_at": "2024-02-14T19:40:47.769Z",
18+
"download": "/quote_groups/596127b7-2356-45aa-aec4-a4f8608ae755/attachments/downtown.jpg"
19+
}
20+
],
21+
"user_ref": {
22+
"first_name": "Alisha",
23+
"last_name": "Evans",
24+
"organization_name": "Acme",
25+
"email": "[email protected]",
26+
"title": "software engineer",
27+
"company": "Triage Pharmaceuticals [DEMO], Scientist.com",
28+
"image": "https://avatars.scientist.com/avatars/alpha/user/xs?time=1707939658"
29+
}
30+
}
31+
]
32+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"messages": []
3+
}

cypress/fixtures/one-request/messages.json renamed to cypress/fixtures/one-request/messages/index.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"id": 674804,
5555
"title": null,
5656
"status": null,
57-
"body": "hi",
57+
"body": "this is a message from the customer",
5858
"created_by": "Summer Cook",
5959
"created_at": "2023-03-01T22:16:46.167Z",
6060
"updated_at": "2023-03-01T22:16:46.167Z",
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"total": 0,
3+
"purchase_orders": []
4+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"total": 1,
3+
"purchase_orders": [
4+
{
5+
"id": 168795,
6+
"po_number": "PO595363",
7+
"retail_total_price": "1625.0",
8+
"retail_subtotal_price": "1425.0",
9+
"wholesale_total_price": "1553.75",
10+
"wholesale_subtotal_price": "1353.75",
11+
"tax_cost": "0.0",
12+
"shipping_cost": "200.0",
13+
"retail_total_price_currency": "$1,625.00",
14+
"retail_subtotal_price_currency": "$1,425.00",
15+
"wholesale_total_price_currency": "$1,553.75",
16+
"wholesale_subtotal_price_currency": "$1,353.75",
17+
"tax_cost_currency": "$0.00",
18+
"shipping_cost_currency": "$200.00",
19+
"currency": "USD",
20+
"currency_unit": "$",
21+
"provider_name": "Beachside Biotechnology Services [Demo]",
22+
"status": "Work in Progress",
23+
"status_description": "(SOW 595363)",
24+
"created_at": "2023-12-15T19:45:33.745Z",
25+
"updated_at": "2023-12-15T19:45:35.408Z",
26+
"type": "PO",
27+
"identifier": null,
28+
"turn_around_time": {
29+
"id": 890642,
30+
"min": 604800,
31+
"max": 1814400,
32+
"display_units": "weeks",
33+
"human": "1 - 3 weeks"
34+
}
35+
}
36+
]
37+
}

0 commit comments

Comments
 (0)