diff --git a/cypress/e2e/request.cy.js b/cypress/e2e/request.cy.js new file mode 100644 index 0000000..aa83b90 --- /dev/null +++ b/cypress/e2e/request.cy.js @@ -0,0 +1,115 @@ +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 + + describe('as a logged out user', () => { + it('should show an error message.', () => { + cy.visit(`/requests/${uuid}`) + cy.get('div.alert-heading').contains('Unauthorized').then(() => { + cy.log('A logged out user is not able to view a single 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 + + 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 + }) + 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.') + }) + }) + }) + + describe('request page components are loading successfully, &', () => { + context('the request page', () => { + before(() => { + loading = + request = true + proposals = true + messages = true + files = true + }) + + 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.", () => { + 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. + }) + }) + }) +}) \ No newline at end of file diff --git a/cypress/fixtures/empty.json b/cypress/fixtures/empty.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/cypress/fixtures/empty.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/cypress/fixtures/one-request/files.json b/cypress/fixtures/one-request/files.json new file mode 100644 index 0000000..e21dbf1 --- /dev/null +++ b/cypress/fixtures/one-request/files.json @@ -0,0 +1,24 @@ +{ + "notes": [ + { + "id": 674804, + "title": null, + "status": null, + "body": "hi", + "created_by": "Summer Cook", + "created_at": "2023-03-01T22:16:46.167Z", + "updated_at": "2023-03-01T22:16:46.167Z", + "attachments": [], + "user_ref": { + "first_name": "Summer", + "last_name": "Cook", + "organization_name": "Acme", + "email": "summer@scientist.com", + "title": "Frontend Dev", + "company": "", + "site": "{\"name\"=>\"Cell Based Assays\", \"billing_same_as_shipping\"=>true}", + "image": "https://avatars.scientist.com/avatars/0d93b3808f701fc3dbde5002a80c2475/S C/xs?time=1677774999" + } + } + ] +} \ No newline at end of file diff --git a/cypress/fixtures/one-request/messages.json b/cypress/fixtures/one-request/messages.json new file mode 100644 index 0000000..a348136 --- /dev/null +++ b/cypress/fixtures/one-request/messages.json @@ -0,0 +1,75 @@ +{ + "messages": [ + { + "id": 674334, + "title": "SOW Submitted to Customer", + "status": "SOW Submitted", + "body": null, + "created_by": "Sherman Tang", + "created_at": "2023-02-23T07:16:25.153Z", + "updated_at": "2023-02-23T07:16:25.153Z", + "attachments": [], + "user_ref": { + "first_name": "Sherman", + "last_name": "Tang", + "organization_name": "Biogen", + "email": "sherman@scientist.com", + "title": "Master tester", + "company": "", + "site": "Asia", + "image": "https://avatars.scientist.com/avatars/20c7e703deca8fcabb2df42096142740/S T/xs?time=1677774999" + }, + "proposal_ref": { + "id": 4594, + "type": "SOW", + "identifier": "092985", + "retail_total_price": "6.0", + "retail_subtotal_price": "3.0", + "wholesale_total_price": "5.7", + "wholesale_subtotal_price": "2.7", + "tax_cost": "0.0", + "shipping_cost": "3.0", + "retail_total_price_currency": "$6.00", + "retail_subtotal_price_currency": "$3.00", + "wholesale_total_price_currency": "$5.70", + "wholesale_subtotal_price_currency": "$2.70", + "tax_cost_currency": "$0.00", + "shipping_cost_currency": "$3.00", + "currency": "USD", + "currency_unit": "$", + "provider_name": "Dragon Pharmacology", + "status": "Approval Required", + "status_description": "You must submit this SOW for internal approval before proceeding", + "created_at": "2023-02-23T07:15:57.950Z", + "updated_at": "2023-02-23T07:16:25.081Z", + "turn_around_time": { + "id": 908312, + "min": 3024000, + "max": 3628800, + "display_units": "weeks", + "human": "5 - 6 weeks" + } + } + }, + { + "id": 674804, + "title": null, + "status": null, + "body": "hi", + "created_by": "Summer Cook", + "created_at": "2023-03-01T22:16:46.167Z", + "updated_at": "2023-03-01T22:16:46.167Z", + "attachments": [], + "user_ref": { + "first_name": "Summer", + "last_name": "Cook", + "organization_name": "Acme", + "email": "summer@scientist.com", + "title": "Frontend Dev", + "company": "", + "site": "{\"name\"=>\"Cell Based Assays\", \"billing_same_as_shipping\"=>true}", + "image": "https://avatars.scientist.com/avatars/0d93b3808f701fc3dbde5002a80c2475/S C/xs?time=1677774999" + } + } + ] +} \ No newline at end of file diff --git a/cypress/fixtures/one-request/proposals.json b/cypress/fixtures/one-request/proposals.json new file mode 100644 index 0000000..41a1cff --- /dev/null +++ b/cypress/fixtures/one-request/proposals.json @@ -0,0 +1,119 @@ +[ + { + "id": 4594, + "type": "SOW", + "identifier": "092985", + "retail_total_price": "6.0", + "retail_subtotal_price": "3.0", + "wholesale_total_price": "5.7", + "wholesale_subtotal_price": "2.7", + "tax_cost": "0.0", + "shipping_cost": "3.0", + "retail_total_price_currency": "$6.00", + "retail_subtotal_price_currency": "$3.00", + "wholesale_total_price_currency": "$5.70", + "wholesale_subtotal_price_currency": "$2.70", + "tax_cost_currency": "$0.00", + "shipping_cost_currency": "$3.00", + "currency": "USD", + "currency_unit": "$", + "provider_name": "Dragon Pharmacology", + "status": "Approval Required", + "status_description": "You must submit this SOW for internal approval before proceeding", + "created_at": "2023-02-22T23:15:57.950-08:00", + "updated_at": "2023-02-22T23:16:25.081-08:00", + "uuid": "1327b754-b750-4ab6-b9f6-5f11d942412c", + "compliance_status": { + "status": "Approval Required", + "description": "You must submit this SOW for internal approval before proceeding" + }, + "line_items": [ + { + "id": 21189, + "retail_unit_price_currency": "$1.00", + "retail_unit_price": "1.0", + "retail_subtotal_price_currency": "$1.00", + "retail_subtotal_price": "1.0", + "quantity": "1.0", + "currency": "USD", + "currency_unit": "$", + "name": "Test Item A - Study Design", + "subtotal": "$1.00", + "unit_price": "$1.00" + }, + { + "id": 21190, + "retail_unit_price_currency": "$2.00", + "retail_unit_price": "2.0", + "retail_subtotal_price_currency": "$2.00", + "retail_subtotal_price": "2.0", + "quantity": "1.0", + "currency": "USD", + "currency_unit": "$", + "name": "Test Item B - Analysis", + "subtotal": "$2.00", + "unit_price": "$2.00" + } + ], + "payment_terms": "NET 60", + "ship_to": { + "id": 454297, + "organization_name": "acme-staging", + "street": "9833 45th Avenue SW", + "street2": "", + "city": "Seattle", + "state": "WA", + "zipcode": "98136", + "country": "Mexico", + "latitude": null, + "longitude": null, + "name": null, + "attention": "", + "person_name": "Summer Cook", + "care_of": null, + "text": "9833 45th Avenue SW\nSeattle, WA, 98136" + }, + "ship_from": { + "id": 454299, + "organization_name": "San Diego Beach Warehouse", + "street": "404 San Diego Lane", + "street2": "", + "city": "San Diego", + "state": "california", + "zipcode": "92075", + "country": "US", + "latitude": null, + "longitude": null, + "name": null, + "attention": null, + "person_name": null, + "care_of": null, + "text": "404 San Diego Lane\nSan Diego, california, 92075\nUnited States" + }, + "quote_group_name": "Cell Based Assays", + "quote_group_identifier": "8AE755", + "download_pdf": "/quote_groups/596127b7-2356-45aa-aec4-a4f8608ae755/proposals/1327b754-b750-4ab6-b9f6-5f11d942412c.pdf", + "organization_provider_ref": { + "id": 1065239, + "uuid": "5599e8b0-0192-4473-a25d-3c23536b1ec4", + "provider_id": 609, + "slug": "dragon-pharmacology", + "name": "Dragon Pharmacology", + "website": "http://www.dragonpharmacology.com", + "snippet_plain": "Dragon Pharmacology provides research models for various diseases. Dragon Pharmacology is a trusted TEST vendor for pharmacological animal models.", + "snippet": "Dragon Pharmacology provides research models for various diseases. Dragon Pharmacology is a trusted *TEST* vendor for pharmacological animal models.", + "html_snippet": "

Dragon Pharmacology provides research models for various diseases. Dragon Pharmacology is a trusted TEST vendor for pharmacological animal models.

", + "description": "Dragon Pharmacology provides research models for various diseases. Dragon Pharmacology is a trusted TEST vendor for pharmacological animal models.", + "html_description": "

Dragon Pharmacology provides research models for various diseases. Dragon Pharmacology is a trusted TEST vendor for pharmacological animal models.

", + "created_at": "2011-07-11T15:43:27.000-07:00", + "updated_at": "2022-08-15T22:37:49.568-07:00", + "urls": { + "storefront": "https://acme-staging.scientist.com/wares/make-a-request/quote_groups/new?provider=Dragon+Pharmacology&name=Dragon+Pharmacology", + "backoffice": "https://backoffice-staging.scientist.com/providers/dragon-pharmacology/edit", + "provider_rfis": "https://acme-staging.scientist.com/providers/5599e8b0-0192-4473-a25d-3c23536b1ec4#rfis609" + } + }, + "assigned_legal_document_pdf": "/quote_groups/596127b7-2356-45aa-aec4-a4f8608ae755/quoted_wares/bec88afc-8e3f-4ae5-80d1-6a7f0761f199/legal_documents/13.pdf", + "attachments": [] + } +] \ No newline at end of file diff --git a/cypress/fixtures/one-request/request.json b/cypress/fixtures/one-request/request.json new file mode 100644 index 0000000..a9b05c0 --- /dev/null +++ b/cypress/fixtures/one-request/request.json @@ -0,0 +1,41 @@ +{ + "id": 80688, + "identifier": "8AE755", + "uuid": "596127b7-2356-45aa-aec4-a4f8608ae755", + "name": "Example Request", + "description": "

this is an example request

", + "status": "Compliance Required", + "billing_same_as_shipping": false, + "proposed_deadline": null, + "updated_at": "2023-02-23T07:12:44.086Z", + "created_at": "2023-02-16T21:51:59.343Z", + "shipping_address": { + "id": 453994, + "organization_name": "acme-staging", + "street": "123 Pineapple Way", + "street2": "", + "city": "Bikini Bottom", + "state": "CA", + "zipcode": "92107", + "country": "Mexico", + "person_name": "Summer Cook", + "text": "123 Pineapple Way\nBikini Bottom, CA, 92107" + }, + "billing_address": { + "id": 453995, + "organization_name": "acme-staging", + "street": "123 Pineapple Way", + "street2": "", + "city": "Bikini Bottom", + "state": "CA", + "zipcode": "92107", + "country": "Mexico", + "name": null, + "text": "123 Pineapple Way\nBikini Bottom, CA, 92107" + }, + "quoted_ware_refs": [ + { + "id": 728152 + } + ] +} \ No newline at end of file