Skip to content

Commit 8f7e479

Browse files
authored
Merge pull request #380 from scientist-softserv/362-requests-specs
362-requests-specs
2 parents 60b689c + a791cb7 commit 8f7e479

File tree

5 files changed

+71
-75
lines changed

5 files changed

+71
-75
lines changed

cypress/e2e/home.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ describe('Navigating to the home page', () => {
6565
})
6666

6767
cy.get('input.search-bar').type(invalidQuery)
68-
cy.get('button.search-button').click()
68+
cy.get('button.search-button').click()
6969
cy.url().should('include', `/browse?q=${invalidQuery}`)
7070
cy.get('input.search-bar').should('have.value', invalidQuery)
7171
cy.get("p[data-cy='no-results']").should('contain', `Your search for ${invalidQuery} returned no results`)

cypress/e2e/request.cy.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,13 @@ describe.skip('Viewing one request', () => {
9797
files = true
9898
})
9999

100-
it("should show the request stats section.", () => {
100+
it('should show the request stats section.', () => {
101101
cy.get('div.request-stats-card').should('exist').then(() => {
102102
cy.log('Request stats section renders successfully.')
103103
})
104104
})
105105

106-
it("should show the status bar.", () => {
106+
it('should show the status bar.', () => {
107107
cy.get("div[data-cy='status-bar']").should('exist').then(() => {
108108
cy.log('Status bar renders successfully.')
109109
})

cypress/e2e/requests.cy.js

Lines changed: 63 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,103 @@
1-
import { scientistApiBaseURL } from '../support/e2e'
2-
31
describe('Viewing all requests', () => {
42
describe('as a logged out user', () => {
5-
it('should show an error message.', () => {
6-
// Visit a protected route in order to allow cypress to set the cookie and mock the login
3+
it('shows an error message.', () => {
74
cy.visit('/requests')
85
cy.get('div.alert-heading').contains('Unauthorized').then(() => {
96
cy.log('A logged out user is not able to view requests.')
107
})
118
})
129
})
13-
10+
1411
describe('as a logged in user', () => {
1512
// declare variables that can be used to change how the response is intercepted.
16-
let requestList
17-
let loading
13+
let data
1814
let error
1915

2016
beforeEach(() => {
21-
// Call the custom cypress command to log in
2217
cy.login(Cypress.env('TEST_SCIENTIST_USER'), Cypress.env('TEST_SCIENTIST_PW'))
23-
// Intercept the response from the endpoint to view all requests
24-
cy.customApiIntercept({
25-
action: 'GET',
26-
alias: 'useAllRequests',
27-
requestURL: `/quote_groups/mine.json`,
28-
data: requestList,
29-
defaultFixture: 'all-requests/requests.json',
30-
emptyFixture: 'all-requests/no-requests.json',
31-
loading,
32-
error
33-
})
34-
// Intercept the response from the endpoint that gets the default ware ID
35-
cy.customApiIntercept({
36-
action: 'GET',
37-
alias: 'useDefaultWare',
38-
requestURL: `/wares.json?q=make-a-request`,
39-
defaultFixture: 'all-requests/make-a-request.json',
40-
error
41-
})
42-
cy.visit('/requests')
4318
})
4419

20+
describe('makes a call to the api', () => {
21+
beforeEach(() => {
22+
cy.customApiIntercept({
23+
alias: 'useAllRequests',
24+
data,
25+
error,
26+
requestURL: `/quote_groups/mine.json`,
27+
})
4528

46-
context('request list is loading', () => {
47-
before(() => {
48-
loading = true
29+
cy.visit('/requests')
4930
})
50-
it('should show a loading spinner.', () => {
51-
cy.get("[aria-label='tail-spin-loading']").should('be.visible').then(() => {
52-
cy.log('Loading spinner displays correctly.')
31+
32+
context('which when given an invalid access token', () => {
33+
before(() => {
34+
error = {
35+
body: {
36+
message: 'No access token provided.',
37+
},
38+
statusCode: 403,
39+
}
5340
})
54-
})
55-
})
5641

57-
context('error while making a request to the api', () => {
58-
before(() => {
59-
requestList = undefined
60-
loading = false
61-
error = true
62-
})
63-
it('should show an error message.', () => {
64-
cy.get("div[role='alert']").should('be.visible').then(() => {
65-
cy.log('Successfully hits an error.')
42+
it('shows an error message.', () => {
43+
cy.get("div[role='alert']").should('be.visible').then(() => {
44+
cy.log('Successfully hits an error.')
45+
})
46+
cy.get("div[role='alert']").contains('No access token provided.')
6647
})
6748
})
68-
})
6949

70-
describe('request components are loading successfully, &', () => {
71-
context('the user has requests', () => {
72-
before(() => {
73-
requestList = true
74-
error = false
75-
})
76-
it("should show the user's request list.", () => {
77-
cy.get('article.request-item').should('exist').then(() => {
78-
cy.log('Successfully viewing request list.')
50+
context('which when returns undefined error and data values', () => {
51+
it('shows a loading spinner.', () => {
52+
cy.get("[aria-label='tail-spin-loading']").should('be.visible').then(() => {
53+
cy.log('Loading spinner displays correctly.')
7954
})
8055
})
8156
})
8257

83-
context('the user has 0 requests', () => {
58+
describe('which when returns a data object', () => {
8459
before(() => {
85-
requestList = false
60+
data = 'all-requests/requests.json'
61+
cy.customApiIntercept({
62+
alias: 'useDefaultWare',
63+
data: 'all-requests/make-a-request.json',
64+
error,
65+
requestURL: '/wares.json',
66+
})
67+
})
68+
69+
it('renders the "New Request" button for the default service', () => {
70+
cy.get("a[data-cy='linked-button']")
71+
.should('have.attr', 'href', `/requests/new/make-a-request?id=123`)
72+
.and('have.text', 'Initiate a New Request')
73+
.then(() => {
74+
cy.log('The <LinkedButton /> component displays correctly')
75+
})
8676
})
87-
it("should show a message notifying the user they don't have any requests.", () => {
88-
cy.get('p.no-requests').contains('You do not have any requests yet.').then(() => {
89-
cy.log('Successfully viewing request page with no requests.')
77+
78+
context('with values', () => {
79+
it("shows the user's request list.", () => {
80+
cy.get('article.request-item')
81+
.should('exist')
82+
.and('have.length', 3)
83+
.then(() => {
84+
cy.log('Successfully viewing request list.')
85+
})
9086
})
9187
})
92-
})
9388

94-
context('the user can see the <LinkedButton /> component', () => {
95-
[true, false].forEach((value) => {
89+
context('with no values', () => {
9690
before(() => {
97-
requestList = value
91+
data = 'all-requests/no-requests.json'
9892
})
99-
it(`should show a button that links to the initialize request page for the default ware ${value ? 'with a request list' : 'with 0 requests'}.`, () => {
100-
cy.get("a[data-cy='linked-button']").should('have.attr', 'href', `/requests/new/make-a-request?id=123`).then(() => {
101-
cy.log('The <LinkedButton /> component displays correctly')
93+
94+
it("shows a message notifying the user they don't have any requests.", () => {
95+
cy.get('p.no-requests').contains('You do not have any requests yet.').then(() => {
96+
cy.log('Successfully viewing request page with no requests.')
10297
})
10398
})
10499
})
105100
})
106101
})
107102
})
108-
})
103+
})
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"ware_refs": [
33
{
4-
"id": 123
4+
"id": 123,
5+
"slug": "make-a-request"
56
}
67
]
7-
}
8+
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"cypress:e2e": "start-server-and-test dev http://localhost:3000 \"cypress open --e2e --browser electron\"",
1111
"cypress:headless:e2e": "start-server-and-test dev http://localhost:3000 \"cypress run --e2e --browser electron\"",
1212
"dev": "next dev",
13-
"lint": "next lint --dir pages --dir utils",
14-
"lint:fix": "next lint --dir pages --dir utils --fix",
13+
"lint": "next lint --dir pages --dir utils --dir cypress/e2e",
14+
"lint:fix": "next lint --dir pages --dir utils --dir cypress/e2e --fix",
1515
"jest": "jest",
1616
"jest-watch": "jest --watch",
1717
"release": "release-it",

0 commit comments

Comments
 (0)