Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

363 request specs #381

Merged
merged 11 commits into from
Feb 15, 2024
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,16 @@ There are 2 types of Cypress tests, e2e & component.
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 `

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

Expand Down
10 changes: 6 additions & 4 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = defineConfig({
e2e: {
baseUrl: 'http://localhost:3000',
chromeWebSecurity: false,
defaultCommandTimeout: 10000,
setupNodeEvents(on, config) {
config = dotenvFlowPlugin(config)
config.env = {
Expand All @@ -21,12 +22,13 @@ module.exports = defineConfig({
},
},
env: {
TEST_SCIENTIST_USER: '[email protected]',
TEST_SCIENTIST_PW: '!test1234',
NEXT_PUBLIC_PROVIDER_NAME: process.env.NEXT_PUBLIC_PROVIDER_NAME,
CYPRESS_SEARCH_QUERY: 'test',
NEXT_PUBLIC_PROVIDER_ID: process.env.NEXT_PUBLIC_PROVIDER_ID,
NEXT_PUBLIC_PROVIDER_NAME: process.env.NEXT_PUBLIC_PROVIDER_NAME,
NEXT_PUBLIC_TOKEN: process.env.NEXT_PUBLIC_TOKEN,
CYPRESS_SEARCH_QUERY: 'test',
TEST_SCIENTIST_PW: '!test1234',
TEST_SCIENTIST_USER: '[email protected]',
TEST_SESSION_COOKIE: process.env.TEST_SESSION_COOKIE,
},
reporter: 'junit',
reporterOptions: {
Expand Down
184 changes: 105 additions & 79 deletions cypress/e2e/request.cy.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import useOneRequestResponseBody from '../fixtures/one-request/request.json'

describe.skip('Viewing one request', () => {
// TODO: currently this uses a real request uuid, which would allow it to visit a route that actually existed.
// 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
// this test should remain skipped until the above is done since it runs as a regular e2e vs e2e with mocked data
// Existing ticket to complete this test: https://github.com/scientist-softserv/webstore/issues/218
let uuid = useOneRequestResponseBody.uuid
import {
requestUuid as uuid,
requestPageApiCalls,
} from '../support/e2e'

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

describe('as a logged in user', () => {
// declare variables that can be used to change how the response is intercepted.
let request
let proposals
let messages
let files
let loading
let error
let apiCalls = Object.assign({}, requestPageApiCalls)

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 one request
cy.customApiIntercept({
action: 'GET',
alias: 'useOneRequest',
requestURL: `/quote_groups/${uuid}.json`,
data: request,
dataFixture: 'one-request/request.json',
emptyDataFixture: 'empty.json',
loading,
error
})

cy.customApiIntercept({
action: 'GET',
alias: 'useAllSOWs',
requestURL: `/quote_groups/${uuid}/proposals.json`,
data: proposals,
dataFixture: 'one-request/proposals.json',
emptyDataFixture: 'empty.json',
loading,
error
})

cy.customApiIntercept({
action: 'GET',
alias: 'useAllMessages',
requestURL: `/quote_groups/${uuid}/messages.json`,
data: messages,
dataFixture: 'one-request/messages.json',
emptyDataFixture: 'empty.json',
loading,
error
})

cy.customApiIntercept({
action: 'GET',
alias: 'useAllFiles',
requestURL: `/quote_groups/${uuid}/notes.json`,
data: files,
dataFixture: 'one-request/notes.json',
emptyDataFixture: 'empty.json',
loading,
error
Object.entries(apiCalls).forEach((item) => {
cy.customApiIntercept(item[1])
})
cy.visit(`/requests/${uuid}`)
})

context('request is loading', () => {
before(() => {
loading = true
})
it('should show a loading spinner.', () => {
cy.get("[aria-label='tail-spin-loading']").should('be.visible').then(() => {
cy.log('Loading spinner displays correctly.')
afterEach(() => {
// in order for the tests to not be order dependent, we need to reset the apiCalls object to the original state
apiCalls = Object.assign({}, requestPageApiCalls)
})

describe('makes a call to the api', () => {
context('which when given an invalid uuid', () => {
before(() => {
apiCalls['useOneRequest'] = {
...apiCalls['useOneRequest'],
data: undefined,
error: {
body: {
message: 'Quote Group Not Found',
},
statusCode: 404,
},
}
})

it('returns an error message', () => {
cy.get("div[role='alert']").should('be.visible').then(() => {
cy.log('Successfully hits an error.')
})
cy.get("div[role='alert']").contains('Quote Group Not Found')
})
})
})

describe('request page components are loading successfully, &', () => {
context('the request page', () => {
context('which when returns undefined error and data values', () => {
before(() => {
loading =
request = true
proposals = true
messages = true
files = true
Object.entries(apiCalls).forEach(([key, value]) => {
apiCalls[key] = {
...value,
data: undefined,
error: undefined,
}
})
})

it('shows a loading spinner.', () => {
cy.get("[aria-label='tail-spin-loading']").should('be.visible').then(() => {
cy.log('Loading spinner displays correctly.')
})
})
})

it('should show the request stats section.', () => {
cy.get('div.request-stats-card').should('exist').then(() => {
describe('which when returns request data', () => {
it('shows 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('shows the status bar', () => {
cy.get("div[data-cy='status-bar']").should('exist').then(() => {
cy.log('Status bar renders successfully.')
})
})
// TODO: add tests to confirm that messages, files, additional info, document sections all show correctly.

context('with messages', () => {
before(() => {
apiCalls['useMessages'] = {
...apiCalls['useMessages'],
data: 'one-request/messages/index.json',
}
})

it('displays the messages', () => {
cy.get('div.card-body p.card-text')
.contains('this is a message from the customer')
.should('be.visible')
})
})

context('with documents', () => {
before(() => {
apiCalls['useAllSOWs'] = {
...apiCalls['useAllSOWs'],
data: 'one-request/sows/index.json',
}
apiCalls['getAllPOs'] = {
...apiCalls['getAllPOs'],
data: 'one-request/pos/index.json',
}
})

it('displays the documents', () => {
cy.get('div.document').should('have.length', 2)
cy.get('div.badge').contains('SOW').should('be.visible')
cy.get('div.badge').contains('PO').should('be.visible')
})
})

context('with files', () => {
before(() => {
apiCalls['useFiles'] = {
...apiCalls['useFiles'],
data: 'one-request/files/index.json',
}
})

it('displays the files', () => {
cy.get('div.actions-group')
.contains('View Files')
.click()
cy.get('div#document-tabs-tabpane-files')
.contains('downtown.jpg')
.should('be.visible')
})
})
})
})
})
})
})
23 changes: 0 additions & 23 deletions cypress/fixtures/one-request/files.json

This file was deleted.

3 changes: 3 additions & 0 deletions cypress/fixtures/one-request/files/default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"notes": []
}
32 changes: 32 additions & 0 deletions cypress/fixtures/one-request/files/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"notes": [
{
"id": 5019371,
"title": "New Attachment",
"status": "Other File",
"body": null,
"created_by": "Alisha Evans",
"created_at": "2024-02-14T19:40:47.759Z",
"updated_at": "2024-02-14T19:40:47.759Z",
"attachments": [
{
"uuid": "fa70a15b-3230-41d5-9913-93ee0bcf2e3e",
"filename": "downtown.jpg",
"content_type": "image/jpeg",
"content_length": 326048,
"created_at": "2024-02-14T19:40:47.769Z",
"download": "/quote_groups/596127b7-2356-45aa-aec4-a4f8608ae755/attachments/downtown.jpg"
}
],
"user_ref": {
"first_name": "Alisha",
"last_name": "Evans",
"organization_name": "Acme",
"email": "[email protected]",
"title": "software engineer",
"company": "Triage Pharmaceuticals [DEMO], Scientist.com",
"image": "https://avatars.scientist.com/avatars/alpha/user/xs?time=1707939658"
}
}
]
}
3 changes: 3 additions & 0 deletions cypress/fixtures/one-request/messages/default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"messages": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"id": 674804,
"title": null,
"status": null,
"body": "hi",
"body": "this is a message from the customer",
"created_by": "Summer Cook",
"created_at": "2023-03-01T22:16:46.167Z",
"updated_at": "2023-03-01T22:16:46.167Z",
Expand Down
4 changes: 4 additions & 0 deletions cypress/fixtures/one-request/pos/default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"total": 0,
"purchase_orders": []
}
37 changes: 37 additions & 0 deletions cypress/fixtures/one-request/pos/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"total": 1,
"purchase_orders": [
{
"id": 168795,
"po_number": "PO595363",
"retail_total_price": "1625.0",
"retail_subtotal_price": "1425.0",
"wholesale_total_price": "1553.75",
"wholesale_subtotal_price": "1353.75",
"tax_cost": "0.0",
"shipping_cost": "200.0",
"retail_total_price_currency": "$1,625.00",
"retail_subtotal_price_currency": "$1,425.00",
"wholesale_total_price_currency": "$1,553.75",
"wholesale_subtotal_price_currency": "$1,353.75",
"tax_cost_currency": "$0.00",
"shipping_cost_currency": "$200.00",
"currency": "USD",
"currency_unit": "$",
"provider_name": "Beachside Biotechnology Services [Demo]",
"status": "Work in Progress",
"status_description": "(SOW 595363)",
"created_at": "2023-12-15T19:45:33.745Z",
"updated_at": "2023-12-15T19:45:35.408Z",
"type": "PO",
"identifier": null,
"turn_around_time": {
"id": 890642,
"min": 604800,
"max": 1814400,
"display_units": "weeks",
"human": "1 - 3 weeks"
}
}
]
}
Loading
Loading