diff --git a/cypress/e2e/home.cy.js b/cypress/e2e/home.cy.js
index 5bc8e0f9..1d967bfe 100644
--- a/cypress/e2e/home.cy.js
+++ b/cypress/e2e/home.cy.js
@@ -65,7 +65,7 @@ describe('Navigating to the home page', () => {
})
cy.get('input.search-bar').type(invalidQuery)
- cy.get('button.search-button').click()
+ cy.get('button.search-button').click()
cy.url().should('include', `/browse?q=${invalidQuery}`)
cy.get('input.search-bar').should('have.value', invalidQuery)
cy.get("p[data-cy='no-results']").should('contain', `Your search for ${invalidQuery} returned no results`)
diff --git a/cypress/e2e/request.cy.js b/cypress/e2e/request.cy.js
index aa83b904..703fce47 100644
--- a/cypress/e2e/request.cy.js
+++ b/cypress/e2e/request.cy.js
@@ -97,13 +97,13 @@ describe.skip('Viewing one request', () => {
files = true
})
- it("should show the request stats section.", () => {
+ it('should show the request stats section.', () => {
cy.get('div.request-stats-card').should('exist').then(() => {
cy.log('Request stats section renders successfully.')
})
})
- it("should show the status bar.", () => {
+ it('should show the status bar.', () => {
cy.get("div[data-cy='status-bar']").should('exist').then(() => {
cy.log('Status bar renders successfully.')
})
diff --git a/cypress/e2e/requests.cy.js b/cypress/e2e/requests.cy.js
index 9217f4d4..4b325573 100644
--- a/cypress/e2e/requests.cy.js
+++ b/cypress/e2e/requests.cy.js
@@ -1,108 +1,103 @@
-import { scientistApiBaseURL } from '../support/e2e'
-
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
+ it('shows an error message.', () => {
cy.visit('/requests')
cy.get('div.alert-heading').contains('Unauthorized').then(() => {
cy.log('A logged out user is not able to view requests.')
})
})
})
-
+
describe('as a logged in user', () => {
// declare variables that can be used to change how the response is intercepted.
- let requestList
- let loading
+ let data
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
- cy.customApiIntercept({
- action: 'GET',
- alias: 'useAllRequests',
- requestURL: `/quote_groups/mine.json`,
- data: requestList,
- defaultFixture: 'all-requests/requests.json',
- emptyFixture: 'all-requests/no-requests.json',
- loading,
- error
- })
- // Intercept the response from the endpoint that gets the default ware ID
- cy.customApiIntercept({
- action: 'GET',
- alias: 'useDefaultWare',
- requestURL: `/wares.json?q=make-a-request`,
- defaultFixture: 'all-requests/make-a-request.json',
- error
- })
- cy.visit('/requests')
})
+ describe('makes a call to the api', () => {
+ beforeEach(() => {
+ cy.customApiIntercept({
+ alias: 'useAllRequests',
+ data,
+ error,
+ requestURL: `/quote_groups/mine.json`,
+ })
- context('request list is loading', () => {
- before(() => {
- loading = true
+ cy.visit('/requests')
})
- it('should show a loading spinner.', () => {
- cy.get("[aria-label='tail-spin-loading']").should('be.visible').then(() => {
- cy.log('Loading spinner displays correctly.')
+
+ context('which when given an invalid access token', () => {
+ before(() => {
+ error = {
+ body: {
+ message: 'No access token provided.',
+ },
+ statusCode: 403,
+ }
})
- })
- })
- 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.')
+ it('shows an error message.', () => {
+ cy.get("div[role='alert']").should('be.visible').then(() => {
+ cy.log('Successfully hits an error.')
+ })
+ cy.get("div[role='alert']").contains('No access token provided.')
})
})
- })
- describe('request components are loading successfully, &', () => {
- context('the user has requests', () => {
- before(() => {
- requestList = true
- error = false
- })
- it("should show the user's request list.", () => {
- cy.get('article.request-item').should('exist').then(() => {
- cy.log('Successfully viewing request list.')
+ context('which when returns undefined error and data values', () => {
+ it('shows a loading spinner.', () => {
+ cy.get("[aria-label='tail-spin-loading']").should('be.visible').then(() => {
+ cy.log('Loading spinner displays correctly.')
})
})
})
- context('the user has 0 requests', () => {
+ describe('which when returns a data object', () => {
before(() => {
- requestList = false
+ data = 'all-requests/requests.json'
+ cy.customApiIntercept({
+ alias: 'useDefaultWare',
+ data: 'all-requests/make-a-request.json',
+ error,
+ requestURL: '/wares.json',
+ })
+ })
+
+ it('renders the "New Request" button for the default service', () => {
+ cy.get("a[data-cy='linked-button']")
+ .should('have.attr', 'href', `/requests/new/make-a-request?id=123`)
+ .and('have.text', 'Initiate a New Request')
+ .then(() => {
+ cy.log('The component displays correctly')
+ })
})
- 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.')
+
+ context('with values', () => {
+ it("shows the user's request list.", () => {
+ cy.get('article.request-item')
+ .should('exist')
+ .and('have.length', 3)
+ .then(() => {
+ cy.log('Successfully viewing request list.')
+ })
})
})
- })
- context('the user can see the component', () => {
- [true, false].forEach((value) => {
+ context('with no values', () => {
before(() => {
- requestList = value
+ data = 'all-requests/no-requests.json'
})
- 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')
+
+ 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.')
})
})
})
})
})
})
-})
\ No newline at end of file
+})
diff --git a/cypress/fixtures/all-requests/make-a-request.json b/cypress/fixtures/all-requests/make-a-request.json
index 6c366411..3a3c38e0 100644
--- a/cypress/fixtures/all-requests/make-a-request.json
+++ b/cypress/fixtures/all-requests/make-a-request.json
@@ -1,7 +1,8 @@
{
"ware_refs": [
{
- "id": 123
+ "id": 123,
+ "slug": "make-a-request"
}
]
-}
\ No newline at end of file
+}
diff --git a/package.json b/package.json
index c56ec419..3b790408 100644
--- a/package.json
+++ b/package.json
@@ -10,8 +10,8 @@
"cypress:e2e": "start-server-and-test dev http://localhost:3000 \"cypress open --e2e --browser electron\"",
"cypress:headless:e2e": "start-server-and-test dev http://localhost:3000 \"cypress run --e2e --browser electron\"",
"dev": "next dev",
- "lint": "next lint --dir pages --dir utils",
- "lint:fix": "next lint --dir pages --dir utils --fix",
+ "lint": "next lint --dir pages --dir utils --dir cypress/e2e",
+ "lint:fix": "next lint --dir pages --dir utils --dir cypress/e2e --fix",
"jest": "jest",
"jest-watch": "jest --watch",
"release": "release-it",