Skip to content

Commit

Permalink
Merge pull request #380 from scientist-softserv/362-requests-specs
Browse files Browse the repository at this point in the history
362-requests-specs
  • Loading branch information
alishaevn authored Feb 15, 2024
2 parents 60b689c + a791cb7 commit 8f7e479
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 75 deletions.
2 changes: 1 addition & 1 deletion cypress/e2e/home.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/request.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
})
Expand Down
131 changes: 63 additions & 68 deletions cypress/e2e/requests.cy.js
Original file line number Diff line number Diff line change
@@ -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 <LinkedButton /> 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 <LinkedButton /> 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 <LinkedButton /> 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.')
})
})
})
})
})
})
})
})
5 changes: 3 additions & 2 deletions cypress/fixtures/all-requests/make-a-request.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"ware_refs": [
{
"id": 123
"id": 123,
"slug": "make-a-request"
}
]
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 8f7e479

Please sign in to comment.