From 92fab47c850d03821c8259e75cec6e777e9ef8d3 Mon Sep 17 00:00:00 2001 From: Summer Cook Date: Fri, 3 Mar 2023 09:35:25 -0500 Subject: [PATCH 1/3] indiv request test draft --- cypress/e2e/request.cy.js | 144 ++++++++++++++++++++ cypress/fixtures/empty.json | 1 + cypress/fixtures/one-request/files.json | 24 ++++ cypress/fixtures/one-request/messages.json | 75 ++++++++++ cypress/fixtures/one-request/proposals.json | 119 ++++++++++++++++ cypress/fixtures/one-request/request.json | 41 ++++++ 6 files changed, 404 insertions(+) create mode 100644 cypress/e2e/request.cy.js create mode 100644 cypress/fixtures/empty.json create mode 100644 cypress/fixtures/one-request/files.json create mode 100644 cypress/fixtures/one-request/messages.json create mode 100644 cypress/fixtures/one-request/proposals.json create mode 100644 cypress/fixtures/one-request/request.json diff --git a/cypress/e2e/request.cy.js b/cypress/e2e/request.cy.js new file mode 100644 index 0000000..17e0a68 --- /dev/null +++ b/cypress/e2e/request.cy.js @@ -0,0 +1,144 @@ +import useOneRequestResponseBody from '../fixtures/one-request/request.json' + +describe('Viewing one request', () => { + // currently this is using a real request ID, since the routes are generated dynamically, so far i haven't found a way to generate a route for a fake request within the test + 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 = false + request = true + proposals = true + messages = true + files = true + }) + it("should show the request stats section.", () => { + console.log({loading, request, proposals, messages, files, error}) + // 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.') + // }) + // }) + }) + + // context('the user has 0 requests', () => { + // before(() => { + // requestList = false + // }) + // 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('the user can see the component', () => { + // [true, false].forEach((value) => { + // before(() => { + // requestList = value + // }) + // 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('renders the request page with the appropriate components', () => { + // let requestPath = useOneRequestResponseBody.request.href.pathname + // //let scientistApiBaseURL = `https://${Cypress.env('NEXT_PUBLIC_PROVIDER_NAME')}.scientist.com/api/${Cypress.env('NEXT_PUBLIC_SCIENTIST_API_VERSION')}` + // cy.intercept('GET', `${scientistApiBaseURL}/quote_groups/*`, { fixture: 'one-request/request.json' }).as('useOneRequest') + // //cy.wait(['@useOneRequest']) + // cy.visit(requestPath) + // cy.get('h1').should('contains.text', useOneRequestResponseBody.request.title) + // }) 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 From 60fe4b61b68cf5ecd383e304bd03429adcc0cdbb Mon Sep 17 00:00:00 2001 From: Summer Cook Date: Tue, 7 Mar 2023 08:14:46 -0500 Subject: [PATCH 2/3] skip test and add comments --- cypress/e2e/request.cy.js | 64 +++++++++++---------------------------- 1 file changed, 17 insertions(+), 47 deletions(-) diff --git a/cypress/e2e/request.cy.js b/cypress/e2e/request.cy.js index 17e0a68..55c57b7 100644 --- a/cypress/e2e/request.cy.js +++ b/cypress/e2e/request.cy.js @@ -1,7 +1,9 @@ import useOneRequestResponseBody from '../fixtures/one-request/request.json' -describe('Viewing one request', () => { - // currently this is using a real request ID, since the routes are generated dynamically, so far i haven't found a way to generate a route for a fake request within the test +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 let uuid = useOneRequestResponseBody.uuid describe('as a logged out user', () => { @@ -87,58 +89,26 @@ describe('Viewing one request', () => { describe('request page components are loading successfully, &', () => { context('the request page', () => { before(() => { - loading = false + loading = request = true proposals = true messages = true files = true }) + it("should show the request stats section.", () => { - console.log({loading, request, proposals, messages, files, error}) - // cy.get('div.request-stats-card').should('exist').then(() => { - // cy.log('Request stats section renders successfully.') - // }) + 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.') - // }) - // }) - }) - // context('the user has 0 requests', () => { - // before(() => { - // requestList = false - // }) - // 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('the user can see the component', () => { - // [true, false].forEach((value) => { - // before(() => { - // requestList = value - // }) - // 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("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. + }) }) }) -}) - - - // it('renders the request page with the appropriate components', () => { - // let requestPath = useOneRequestResponseBody.request.href.pathname - // //let scientistApiBaseURL = `https://${Cypress.env('NEXT_PUBLIC_PROVIDER_NAME')}.scientist.com/api/${Cypress.env('NEXT_PUBLIC_SCIENTIST_API_VERSION')}` - // cy.intercept('GET', `${scientistApiBaseURL}/quote_groups/*`, { fixture: 'one-request/request.json' }).as('useOneRequest') - // //cy.wait(['@useOneRequest']) - // cy.visit(requestPath) - // cy.get('h1').should('contains.text', useOneRequestResponseBody.request.title) - // }) +}) \ No newline at end of file From 49d3c99d52e9bbf1e3276f4d0fe6c0283f0c4d25 Mon Sep 17 00:00:00 2001 From: Summer Cook Date: Tue, 7 Mar 2023 08:20:48 -0500 Subject: [PATCH 3/3] add one more comment --- cypress/e2e/request.cy.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cypress/e2e/request.cy.js b/cypress/e2e/request.cy.js index 55c57b7..aa83b90 100644 --- a/cypress/e2e/request.cy.js +++ b/cypress/e2e/request.cy.js @@ -3,7 +3,8 @@ 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 + // 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', () => {