From d9243363565b953bcdee954fc4fd7f70bc9d6350 Mon Sep 17 00:00:00 2001 From: DaltonMcauliffe Date: Mon, 5 Feb 2024 12:56:55 -0800 Subject: [PATCH 01/26] wip: fix the broken browse test we're importing the waresFixture so that we can, access the new request page as an unauthorized user. - ref: https://github.com/scientist-softserv/webstore/issues/360 Co-authored-by: alisha evans --- cypress/e2e/browse.cy.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cypress/e2e/browse.cy.js b/cypress/e2e/browse.cy.js index dd0e64f0..aee58256 100644 --- a/cypress/e2e/browse.cy.js +++ b/cypress/e2e/browse.cy.js @@ -1,3 +1,5 @@ +import waresFixture from '../fixtures/services/wares.json' + describe('Browsing', () => { let wares let loading @@ -57,6 +59,8 @@ describe('Browsing', () => { context('error while making a request to the api', () => { before(() => { + let ware = waresFixture['ware_refs'][0] + cy.visit(`/requests/new/${ware.slug}?id=${ware.id}`) loading = false error = true }) From 5dceb176b02f6f2790975b63632d674c7564a83e Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Mon, 5 Feb 2024 16:29:56 -0600 Subject: [PATCH 02/26] refactor browse.cy.js update the spec to account for the "new request" flow as an authorized and unauthorized user. left TODO's for dalton, adrian and jean to pick up when they return to this work. --- cypress/e2e/browse.cy.js | 57 ++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/cypress/e2e/browse.cy.js b/cypress/e2e/browse.cy.js index aee58256..7403b0f6 100644 --- a/cypress/e2e/browse.cy.js +++ b/cypress/e2e/browse.cy.js @@ -21,10 +21,10 @@ describe('Browsing', () => { emptyFixture: 'services/no-wares.json', }, ] - + beforeEach(() => { // Intercept the responses from the endpoint to view all requests. - // Even though this is to the same endpoint, the call happens on each page twice, + // Even though this is to the same endpoint, the call happens on each page twice, // once when the page loads with all the wares, and again after any search is performed. // this makes it necessary to create an intercept for each time the call is made. intercepts.forEach((intercept) => { @@ -42,10 +42,6 @@ describe('Browsing', () => { }) describe('from the browse page', () => { - beforeEach(() => { - cy.visit('/browse') - }) - context('browse page is loading', () => { before(() => { loading = true @@ -57,20 +53,6 @@ describe('Browsing', () => { }) }) - context('error while making a request to the api', () => { - before(() => { - let ware = waresFixture['ware_refs'][0] - cy.visit(`/requests/new/${ware.slug}?id=${ware.id}`) - 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.') - }) - }) - }) - // filtering by query is handled in the api and not the webstore // since we are stubbing that response, our tests will not return actual filtered wares based on on test query. // the purpose of these tests is just to show that the correct components appear in the UI in each case. @@ -106,6 +88,37 @@ describe('Browsing', () => { cy.get("p[data-cy='no-results']").should('contain', 'Your search for asdfghjk returned no results') }) }) + + context('while creating a new request', () => { + beforeEach(() => { + const ware = waresFixture['ware_refs'][0] + cy.visit(`/requests/new/${ware.slug}?id=${ware.id}`) + }) + + context('as a logged in user', () => { + before(() => { + // TODO(alishaevn): log in a user + }) + + it('shows a valid request form.', () => { + // TODO(alishaevn): write this spec (no error found) + }) + }) + + context('as a logged out user', () => { + before(() => { + loading = false + error = true + }) + + it.only('shows a disabled request form, with an error message.', () => { + // TODO(alishaevn): why is the page loading instead of rendering? + cy.get("div[role='alert']").should('be.visible').then(() => { + cy.log('Successfully hits an error.') + }) + }) + }) + }) }) describe('from the home page', () => { @@ -132,7 +145,7 @@ describe('Browsing', () => { cy.get('input.search-bar').should('have.value', '') cy.get(".card[data-cy='item-card']").should('be.visible') }) - + it('navigates to "/browse" with a query term', () => { cy.get('input.search-bar').type('test') cy.get('button.search-button').click() @@ -142,4 +155,4 @@ describe('Browsing', () => { }) }) }) -}) \ No newline at end of file +}) From d30991968659cbeb69fd0a24b864dd2cd0c90bdc Mon Sep 17 00:00:00 2001 From: LEARN Academy Date: Tue, 6 Feb 2024 12:59:58 -0800 Subject: [PATCH 03/26] Restored previously working browse specs Co-authored-by: Alisha Evans --- cypress/e2e/browse.cy.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cypress/e2e/browse.cy.js b/cypress/e2e/browse.cy.js index 7403b0f6..b70282fc 100644 --- a/cypress/e2e/browse.cy.js +++ b/cypress/e2e/browse.cy.js @@ -42,6 +42,10 @@ describe('Browsing', () => { }) describe('from the browse page', () => { + beforeEach(() => { + cy.visit('/browse') + }) + context('browse page is loading', () => { before(() => { loading = true @@ -111,7 +115,7 @@ describe('Browsing', () => { error = true }) - it.only('shows a disabled request form, with an error message.', () => { + it('shows a disabled request form, with an error message.', () => { // TODO(alishaevn): why is the page loading instead of rendering? cy.get("div[role='alert']").should('be.visible').then(() => { cy.log('Successfully hits an error.') From 0997e3546a0e71beca646c61b9ecd7f754c6417d Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Wed, 7 Feb 2024 23:26:29 -0600 Subject: [PATCH 04/26] fix the broken browse page specs the intercept command was not ever working. now, we are expecting to use the real api calls instead of mocked ones. this is to ensure that our critical paths of browsing and creating a request are always working, even when the api is updated. I also refactored part of the browse page specs into the home page spec, since that's the flow it was actually testing. also edited the cypress config to make it more dynamic, which will help with this code existing in the various client codebases. --- cypress.config.js | 6 +- cypress/e2e/browse.cy.js | 195 +++++++++++---------------------------- cypress/e2e/home.cy.js | 21 ++++- 3 files changed, 80 insertions(+), 142 deletions(-) diff --git a/cypress.config.js b/cypress.config.js index 529841c3..c46af32d 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -23,8 +23,10 @@ module.exports = defineConfig({ env: { TEST_SCIENTIST_USER: 'test@test.com', TEST_SCIENTIST_PW: '!test1234', - NEXT_PUBLIC_PROVIDER_NAME: 'acme', - NEXT_PUBLIC_PROVIDER_ID: '572' + NEXT_PUBLIC_PROVIDER_NAME: process.env.NEXT_PUBLIC_PROVIDER_NAME, + NEXT_PUBLIC_PROVIDER_ID: process.env.NEXT_PUBLIC_PROVIDER_ID, + NEXT_PUBLIC_TOKEN: process.env.NEXT_PUBLIC_TOKEN, + CYPRESS_SEARCH_QUERY: 'test', }, reporter: 'junit', reporterOptions: { diff --git a/cypress/e2e/browse.cy.js b/cypress/e2e/browse.cy.js index b70282fc..00bd7837 100644 --- a/cypress/e2e/browse.cy.js +++ b/cypress/e2e/browse.cy.js @@ -1,161 +1,78 @@ -import waresFixture from '../fixtures/services/wares.json' - -describe('Browsing', () => { - let wares - let loading - let error - let intercepts = [ - { - alias: 'useFilteredWares', - }, - { - alias: 'useFilteredWares - blank search', - }, - { - alias: 'useFilteredWares - with results', - query: 'test', - }, - { - alias: 'useFilteredWares - no results', - query: 'asdfghjk', - emptyFixture: 'services/no-wares.json', - }, - ] +/** + * In order to ensure that any changes against the API do not negatively + * affect the critical path of browsing all services and creating a request, + * we will not stub the API calls for the browse page. + */ +describe('Navigating to the browse page', () => { beforeEach(() => { - // Intercept the responses from the endpoint to view all requests. - // Even though this is to the same endpoint, the call happens on each page twice, - // once when the page loads with all the wares, and again after any search is performed. - // this makes it necessary to create an intercept for each time the call is made. - intercepts.forEach((intercept) => { - cy.customApiIntercept({ - action: 'GET', - alias: intercept.alias, - requestURL: `/providers/${Cypress.env('NEXT_PUBLIC_PROVIDER_ID')}/wares.json?q=${intercept.query || ''}`, - data: wares, - defaultFixture: 'services/wares.json', - emptyFixture: intercept.emptyFixture || '', - loading, - error - }) - }) + cy.visit('/browse') }) - describe('from the browse page', () => { - beforeEach(() => { - cy.visit('/browse') - }) - - context('browse page is loading', () => { - before(() => { - loading = true - }) - it('should show loading components.', () => { - cy.get(".card-body[data-cy='item-loading']").should('be.visible').then(() => { - cy.log('Loading components display correctly.') - }) + context('while content is loading', () => { + it('should show loading components.', () => { + cy.get(".card-body[data-cy='item-loading']").should('be.visible').then(() => { + cy.log('Loading components display correctly.') }) }) + }) - // filtering by query is handled in the api and not the webstore - // since we are stubbing that response, our tests will not return actual filtered wares based on on test query. - // the purpose of these tests is just to show that the correct components appear in the UI in each case. - context('a search is completed successfully and', () => { - before(() => { - wares = true - error = false - }) - it('has a blank query', () => { - cy.get('button.search-button').click() - cy.url().should('include', '/browse') - cy.url().should('not.include', '?') - cy.get('input.search-bar').should('have.value', '') - cy.get(".card[data-cy='item-card']").should('be.visible') - }) - - it('has a query term', () => { - cy.get('input.search-bar').type('test') - cy.get('button.search-button').click() - cy.url().should('include', '/browse?q=test') - cy.get('input.search-bar').should('have.value', 'test') - cy.get(".card[data-cy='item-card']").should('be.visible') - }) - - before(() => { - wares = false - }) - it('has a query term, but that term has no results', () => { - cy.get('input.search-bar').type('asdfghjk') - cy.get('button.search-button').click() - cy.url().should('include', '/browse?q=asdfghjk') - cy.get('input.search-bar').should('have.value', 'asdfghjk') - cy.get("p[data-cy='no-results']").should('contain', 'Your search for asdfghjk returned no results') - }) + context('and conducting a search', () => { + it('with no query, returns all services', () => { + cy.get('button.search-button').click() + cy.url().should('include', '/browse') + cy.url().should('not.include', '?') + cy.get('input.search-bar').should('have.value', '') + cy.get(".card[data-cy='item-card']").should('be.visible') }) - context('while creating a new request', () => { - beforeEach(() => { - const ware = waresFixture['ware_refs'][0] - cy.visit(`/requests/new/${ware.slug}?id=${ware.id}`) - }) - - context('as a logged in user', () => { - before(() => { - // TODO(alishaevn): log in a user - }) - - it('shows a valid request form.', () => { - // TODO(alishaevn): write this spec (no error found) - }) - }) - - context('as a logged out user', () => { - before(() => { - loading = false - error = true - }) + it('with a valid query, returns matching services', () => { + cy.get('input.search-bar').type(Cypress.env('CYPRESS_SEARCH_QUERY')) + cy.get('button.search-button').click() + cy.url().should('include', `/browse?q=${Cypress.env('CYPRESS_SEARCH_QUERY')}`) + cy.get('input.search-bar').should('have.value', Cypress.env('CYPRESS_SEARCH_QUERY')) + cy.get(".card[data-cy='item-card']").should('be.visible') + }) - it('shows a disabled request form, with an error message.', () => { - // TODO(alishaevn): why is the page loading instead of rendering? - cy.get("div[role='alert']").should('be.visible').then(() => { - cy.log('Successfully hits an error.') - }) - }) - }) + it('with an invalid query, returns no services', () => { + cy.get('input.search-bar').type('asdfghjk') + cy.get('button.search-button').click() + cy.url().should('include', '/browse?q=asdfghjk') + cy.get('input.search-bar').should('have.value', 'asdfghjk') + cy.get("p[data-cy='no-results']").should('contain', 'Your search for asdfghjk returned no results') }) }) - describe('from the home page', () => { + context('and creating a new request', () => { beforeEach(() => { - wares = true - // Intercept the api call being made on the homepage - cy.customApiIntercept({ - action: 'GET', - alias: 'useAllWares', - requestURL: `/providers/${Cypress.env('NEXT_PUBLIC_PROVIDER_ID')}/wares.json`, - data: wares, - defaultFixture: 'services/wares.json', - loading, - error + cy.get('[data-cy="linked-button"]', { timeout: 10000 }).then(($buttons) => { + const count = $buttons.length + const randomIndex = Math.floor(Math.random() * count) + cy.wrap($buttons.eq(randomIndex)).click() }) - cy.visit('/') }) - context('a search is completed successfully and', () => { - it('navigates to "/browse" with a blank query', () => { - cy.get('button.search-button').click() - cy.url().should('include', '/browse') - cy.url().should('not.include', '?') - cy.get('input.search-bar').should('have.value', '') - cy.get(".card[data-cy='item-card']").should('be.visible') + context.skip('as a logged in user', () => { + before(() => { + // TODO(alishaevn): log in a user + }) + + it('shows a valid request form.', () => { + // TODO(alishaevn): write this spec + // - no error found + // submit button isn't disabled }) + }) - it('navigates to "/browse" with a query term', () => { - cy.get('input.search-bar').type('test') - cy.get('button.search-button').click() - cy.url().should('include', '/browse?q=test') - cy.get('input.search-bar').should('have.value', 'test') - cy.get(".card[data-cy='item-card']").should('be.visible') + context('as a logged out user', () => { + it('shows a disabled request form, with an error message.', () => { + cy.get("div[role='alert']").should('be.visible').then(() => { + cy.log('Successfully hits an error.') + }) + cy.get('div.alert-heading').should('have.text', 'Sign in required') + cy.get('form.rjsf').should('be.visible') + cy.scrollTo('bottom') + cy.get('button.btn-primary').should('be.disabled') }) }) }) diff --git a/cypress/e2e/home.cy.js b/cypress/e2e/home.cy.js index cff47a0a..d57857cb 100644 --- a/cypress/e2e/home.cy.js +++ b/cypress/e2e/home.cy.js @@ -64,4 +64,23 @@ describe('Viewing Home page', () => { }) }) }) -}) \ No newline at end of file + + // TODO(alishaevn): check these tests when working on this file + context('a search is completed successfully and', () => { + it('navigates to "/browse" with a blank query', () => { + cy.get('button.search-button').click() + cy.url().should('include', '/browse') + cy.url().should('not.include', '?') + cy.get('input.search-bar').should('have.value', '') + cy.get(".card[data-cy='item-card']").should('be.visible') + }) + + it('navigates to "/browse" with a query term', () => { + cy.get('input.search-bar').type('test') + cy.get('button.search-button').click() + cy.url().should('include', '/browse?q=test') + cy.get('input.search-bar').should('have.value', 'test') + cy.get(".card[data-cy='item-card']").should('be.visible') + }) + }) +}) From 8d41406bb8d3edd1b54e8a0bdae6209b85b9b7fc Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Thu, 8 Feb 2024 11:56:09 -0600 Subject: [PATCH 05/26] update the browse spec to check 10 services there may potentially be hundreds of services on a page. to avoid a timeout, we will only choose from 10 services. this still ensures that a variety of dynamic forms are tested --- cypress/e2e/browse.cy.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cypress/e2e/browse.cy.js b/cypress/e2e/browse.cy.js index 00bd7837..eec89aca 100644 --- a/cypress/e2e/browse.cy.js +++ b/cypress/e2e/browse.cy.js @@ -46,8 +46,10 @@ describe('Navigating to the browse page', () => { context('and creating a new request', () => { beforeEach(() => { cy.get('[data-cy="linked-button"]', { timeout: 10000 }).then(($buttons) => { - const count = $buttons.length - const randomIndex = Math.floor(Math.random() * count) + // there may potentially be hundreds of services on a page. to avoid + // a timeout, we will only choose from 10 services. this still ensures + // that a variety of dynamic forms are tested + const randomIndex = Math.floor(Math.random() * 10) cy.wrap($buttons.eq(randomIndex)).click() }) }) From 573bee61bc952c7db49ffcf2a4220e00c88f542e Mon Sep 17 00:00:00 2001 From: LEARN Academy Date: Thu, 8 Feb 2024 13:38:45 -0800 Subject: [PATCH 06/26] browser spec updated --- cypress/e2e/browse.cy.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cypress/e2e/browse.cy.js b/cypress/e2e/browse.cy.js index eec89aca..72102e07 100644 --- a/cypress/e2e/browse.cy.js +++ b/cypress/e2e/browse.cy.js @@ -54,13 +54,18 @@ describe('Navigating to the browse page', () => { }) }) - context.skip('as a logged in user', () => { + context.only('as a logged in user', () => { before(() => { // TODO(alishaevn): log in a user }) it('shows a valid request form.', () => { // TODO(alishaevn): write this spec + cy.get('form.rjsf').submit() + cy.scrollTo('bottom') + cy.get('button.btn-primary').click().then(() => { + cy.log('Successfully submits form.') + }) // - no error found // submit button isn't disabled }) From 5ed092ad0bd9b3f1fb32803cace073f82db53c25 Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Thu, 8 Feb 2024 16:51:29 -0600 Subject: [PATCH 07/26] able to log in a user on the browse spec Co-authored-by: Dalton Mcauliffe Co-authored-by: Adrian Carranza --- .env.example | 1 + cypress.config.js | 1 + cypress/e2e/browse.cy.js | 4 ++-- cypress/fixtures/session.json | 2 +- cypress/support/commands.js | 12 ++++++------ 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.env.example b/.env.example index 9e0790d8..2a479a01 100644 --- a/.env.example +++ b/.env.example @@ -6,3 +6,4 @@ NEXT_PUBLIC_PROVIDER_ID=0001 NEXT_PUBLIC_PROVIDER_NAME=webstore NEXT_PUBLIC_SCIENTIST_API_VERSION=v2 NEXT_PUBLIC_WEBHOOK_URL=http://ss-mailer/webstore +TEST_SESSION_COOKIE= #ref: https://github.com/scientist-softserv/webstore?tab=readme-ov-file#cypress-env-variables diff --git a/cypress.config.js b/cypress.config.js index c46af32d..b11d4547 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -27,6 +27,7 @@ module.exports = defineConfig({ NEXT_PUBLIC_PROVIDER_ID: process.env.NEXT_PUBLIC_PROVIDER_ID, NEXT_PUBLIC_TOKEN: process.env.NEXT_PUBLIC_TOKEN, CYPRESS_SEARCH_QUERY: 'test', + TEST_SESSION_COOKIE: process.env.TEST_SESSION_COOKIE, }, reporter: 'junit', reporterOptions: { diff --git a/cypress/e2e/browse.cy.js b/cypress/e2e/browse.cy.js index eec89aca..00af8d3b 100644 --- a/cypress/e2e/browse.cy.js +++ b/cypress/e2e/browse.cy.js @@ -54,9 +54,9 @@ describe('Navigating to the browse page', () => { }) }) - context.skip('as a logged in user', () => { + context('as a logged in user', () => { before(() => { - // TODO(alishaevn): log in a user + cy.login(Cypress.env('TEST_SCIENTIST_USER'), Cypress.env('TEST_SCIENTIST_PW')) }) it('shows a valid request form.', () => { diff --git a/cypress/fixtures/session.json b/cypress/fixtures/session.json index 4683ca44..e6f454e9 100644 --- a/cypress/fixtures/session.json +++ b/cypress/fixtures/session.json @@ -6,4 +6,4 @@ }, "expires": "3000-01-01T00:00:00.000Z", "accessToken": "abcdefghijklmnopqrst" -} \ No newline at end of file +} diff --git a/cypress/support/commands.js b/cypress/support/commands.js index dcf2c9a3..c953a598 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -29,12 +29,12 @@ import { scientistApiBaseURL } from './e2e' // source: https://github.com/nextauthjs/next-auth/discussions/2053#discussioncomment-1191016 Cypress.Commands.add('login', (username, password) => { cy.session([username, password], () => { - cy.intercept("/api/auth/session", { fixture: "session.json" }).as("session"); + cy.intercept('/api/auth/session', { fixture: 'session.json' }).as('session') - // Set the cookie for cypress. - // It has to be a valid cookie so next-auth can decrypt it and confirm its validity. - // This cookie also may need to be refreshed intermittently if it expires - cy.setCookie("next-auth.session-token", Cypress.env('TEST_SESSION_COOKIE')); + // Set the cookie for cypress. + // It has to be a valid cookie so next-auth can decrypt it and confirm its validity. + // This cookie also may need to be refreshed intermittently if it expires + cy.setCookie('next-auth.session-token', Cypress.env('TEST_SESSION_COOKIE')) }) }) @@ -66,4 +66,4 @@ Cypress.Commands.add('customApiIntercept', ({ break } }).as(alias || 'customIntercept') -}) \ No newline at end of file +}) From 2e0d5d5ea0ce4e75b36390a03d571000cd9b9432 Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Thu, 8 Feb 2024 17:20:15 -0600 Subject: [PATCH 08/26] correctly testing that reaching a request page as a logged in user works Co-authored-by: DaltonMcauliffe Co-authored-by: Adrian Carranza --- cypress/e2e/browse.cy.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/cypress/e2e/browse.cy.js b/cypress/e2e/browse.cy.js index cd5cc246..2f96ffd2 100644 --- a/cypress/e2e/browse.cy.js +++ b/cypress/e2e/browse.cy.js @@ -59,15 +59,10 @@ describe('Navigating to the browse page', () => { cy.login(Cypress.env('TEST_SCIENTIST_USER'), Cypress.env('TEST_SCIENTIST_PW')) }) - it('shows a valid request form.', () => { - // TODO(alishaevn): write this spec - cy.get('form.rjsf').submit() + it.only('shows a valid request form.', () => { + cy.get("div[role='alert']").should('not.exist') cy.scrollTo('bottom') - cy.get('button.btn-primary').click().then(() => { - cy.log('Successfully submits form.') - }) - // - no error found - // submit button isn't disabled + cy.get('button.btn-primary').should('be.enabled') }) }) From 326b54d06bc7a61ee3cffb63d262ef81361e4d42 Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Thu, 8 Feb 2024 17:22:53 -0600 Subject: [PATCH 09/26] remove the 'only' --- cypress/e2e/browse.cy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cypress/e2e/browse.cy.js b/cypress/e2e/browse.cy.js index 2f96ffd2..43037192 100644 --- a/cypress/e2e/browse.cy.js +++ b/cypress/e2e/browse.cy.js @@ -59,7 +59,7 @@ describe('Navigating to the browse page', () => { cy.login(Cypress.env('TEST_SCIENTIST_USER'), Cypress.env('TEST_SCIENTIST_PW')) }) - it.only('shows a valid request form.', () => { + it('shows a valid request form.', () => { cy.get("div[role='alert']").should('not.exist') cy.scrollTo('bottom') cy.get('button.btn-primary').should('be.enabled') From f222cacaad43d62201efa9ddfe14dbfe3e86c79c Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Thu, 8 Feb 2024 17:31:13 -0600 Subject: [PATCH 10/26] small browse refactor for timeout --- cypress/e2e/browse.cy.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cypress/e2e/browse.cy.js b/cypress/e2e/browse.cy.js index 43037192..9a920787 100644 --- a/cypress/e2e/browse.cy.js +++ b/cypress/e2e/browse.cy.js @@ -45,7 +45,7 @@ describe('Navigating to the browse page', () => { context('and creating a new request', () => { beforeEach(() => { - cy.get('[data-cy="linked-button"]', { timeout: 10000 }).then(($buttons) => { + cy.get('[data-cy="linked-button"]', { timeout: 15000 }).then(($buttons) => { // there may potentially be hundreds of services on a page. to avoid // a timeout, we will only choose from 10 services. this still ensures // that a variety of dynamic forms are tested @@ -61,7 +61,6 @@ describe('Navigating to the browse page', () => { it('shows a valid request form.', () => { cy.get("div[role='alert']").should('not.exist') - cy.scrollTo('bottom') cy.get('button.btn-primary').should('be.enabled') }) }) From abcfa62273307ec54b9f99abefc984ca9beebfaf Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Thu, 8 Feb 2024 17:45:04 -0600 Subject: [PATCH 11/26] update instructions around `TEST_SESSION_COOKIE` --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 20d69257..aed9aa6d 100644 --- a/README.md +++ b/README.md @@ -174,7 +174,7 @@ 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`. - TEST_SESSION_COOKIE= - to get the value for this variable, open your browser to your running app at `localhost:3000`. - inspect the page From 9d1a8ac73140623b8c4bc33862f386bf96333804 Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Fri, 9 Feb 2024 11:33:35 -0600 Subject: [PATCH 12/26] increase the default timeout for browse tests loading a full browse page can take a while. the beachside biotech provider has 585 services and we're loading them all at once. certain services also have more complex dynamic forms, which could mean it takes longer for them to load. increasing the timeout for both operations prevents a failure due to time, opposed to assertion. --- cypress/e2e/browse.cy.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cypress/e2e/browse.cy.js b/cypress/e2e/browse.cy.js index 9a920787..26f713ae 100644 --- a/cypress/e2e/browse.cy.js +++ b/cypress/e2e/browse.cy.js @@ -45,7 +45,7 @@ describe('Navigating to the browse page', () => { context('and creating a new request', () => { beforeEach(() => { - cy.get('[data-cy="linked-button"]', { timeout: 15000 }).then(($buttons) => { + cy.get('[data-cy="linked-button"]', { timeout: 25000 }).then(($buttons) => { // there may potentially be hundreds of services on a page. to avoid // a timeout, we will only choose from 10 services. this still ensures // that a variety of dynamic forms are tested @@ -61,7 +61,9 @@ describe('Navigating to the browse page', () => { it('shows a valid request form.', () => { cy.get("div[role='alert']").should('not.exist') - cy.get('button.btn-primary').should('be.enabled') + cy.get('form.rjsf').should('be.visible') + cy.scrollTo('bottom') + cy.get('button.btn-primary', { timeout: 10000 }).should('be.enabled') }) }) From db10801aff161c8794e4235100fbd3c2427d8aff Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Fri, 9 Feb 2024 15:46:45 -0600 Subject: [PATCH 13/26] cypress env updates alphabetize the env variables add the secrets to the github workflow so they can be picked up by CI --- .github/workflows/build-test-lint.yml | 3 +++ cypress.config.js | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-test-lint.yml b/.github/workflows/build-test-lint.yml index 4ad18a54..db1b8651 100644 --- a/.github/workflows/build-test-lint.yml +++ b/.github/workflows/build-test-lint.yml @@ -32,6 +32,9 @@ jobs: with: start: yarn start wait-on: 'http://localhost:3000' + env: + NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }} + TEST_SESSION_COOKIE: ${{ secrets.TEST_SESSION_COOKIE }} eslint: needs: build uses: scientist-softserv/actions/.github/workflows/lint.yaml@v0.0.13 diff --git a/cypress.config.js b/cypress.config.js index b11d4547..5bdf7588 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -21,12 +21,12 @@ module.exports = defineConfig({ }, }, env: { - TEST_SCIENTIST_USER: 'test@test.com', - 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: 'test@test.com', TEST_SESSION_COOKIE: process.env.TEST_SESSION_COOKIE, }, reporter: 'junit', From b782b26d3bade26b5324bbafb92eceb7498f461e Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Fri, 9 Feb 2024 15:49:02 -0600 Subject: [PATCH 14/26] forgot to add NEXT_PUBLIC_TOKEN to the cypress workflow secrets --- .github/workflows/build-test-lint.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build-test-lint.yml b/.github/workflows/build-test-lint.yml index db1b8651..dac648b9 100644 --- a/.github/workflows/build-test-lint.yml +++ b/.github/workflows/build-test-lint.yml @@ -34,6 +34,7 @@ jobs: wait-on: 'http://localhost:3000' env: NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }} + NEXT_PUBLIC_TOKEN: ${{ secrets.NEXT_PUBLIC_TOKEN }} TEST_SESSION_COOKIE: ${{ secrets.TEST_SESSION_COOKIE }} eslint: needs: build From ae535122be501ad16ce20e76560e6dc41e69f3ff Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Mon, 12 Feb 2024 16:02:46 -0600 Subject: [PATCH 15/26] specify the environment to use for cypress tests currently, all cypress tests are failing in ci through github actions with the error below. ``` Error: [next-auth][error][NO_SECRET] https://next-auth.js.org/errors#no_secret Please define a `secret` in production. MissingSecret [MissingSecretError]: Please define a `secret` in production. ``` the value of `NEXTAUTH_SECRET` has been set in the staging and production github environments however. running the job in debug mode shows that the secret's value is returning as null. ``` ``` this commit is an attempt to get the tests to pass in ci by specifying the environment to use for cypress tests. hopefully it'll pick up the secret. --- .github/workflows/build-test-lint.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build-test-lint.yml b/.github/workflows/build-test-lint.yml index dac648b9..7614e4e7 100644 --- a/.github/workflows/build-test-lint.yml +++ b/.github/workflows/build-test-lint.yml @@ -24,6 +24,8 @@ jobs: webTarget: web cypress: runs-on: ubuntu-22.04 + environment: + name: Production steps: - name: Checkout uses: actions/checkout@v4 From c98802632fc956eebe1e8eed06dcd0a0646fb0cc Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Mon, 12 Feb 2024 16:20:37 -0600 Subject: [PATCH 16/26] add the `NEXTAUTH_URL` to the cypress job attempt to get around new ci error: ``` [next-auth][warn][NEXTAUTH_URL] https://next-auth.js.org/warnings#nextauth_url ``` --- .github/workflows/build-test-lint.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build-test-lint.yml b/.github/workflows/build-test-lint.yml index 7614e4e7..b6e67641 100644 --- a/.github/workflows/build-test-lint.yml +++ b/.github/workflows/build-test-lint.yml @@ -36,6 +36,7 @@ jobs: wait-on: 'http://localhost:3000' env: NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }} + NEXTAUTH_URL: ${{ secrets.NEXTAUTH_URL }} NEXT_PUBLIC_TOKEN: ${{ secrets.NEXT_PUBLIC_TOKEN }} TEST_SESSION_COOKIE: ${{ secrets.TEST_SESSION_COOKIE }} eslint: From 511f7d9003c0c6e7c958d9b11b2dc91ae4b82f94 Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Mon, 12 Feb 2024 18:02:01 -0600 Subject: [PATCH 17/26] only request 10 services in the browse specs intercepting the `useFilteredWares` hook to only request 10 services. we're still hitting the actual api, but hopefully this will speed things up, while still providing dynamic form variety. --- cypress.config.js | 1 + cypress/e2e/browse.cy.js | 8 +++----- cypress/support/commands.js | 7 +++++++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/cypress.config.js b/cypress.config.js index 5bdf7588..41b7ba17 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -21,6 +21,7 @@ module.exports = defineConfig({ }, }, env: { + API_PER_PAGE: 10, CYPRESS_SEARCH_QUERY: 'test', NEXT_PUBLIC_PROVIDER_ID: process.env.NEXT_PUBLIC_PROVIDER_ID, NEXT_PUBLIC_PROVIDER_NAME: process.env.NEXT_PUBLIC_PROVIDER_NAME, diff --git a/cypress/e2e/browse.cy.js b/cypress/e2e/browse.cy.js index 26f713ae..0666be86 100644 --- a/cypress/e2e/browse.cy.js +++ b/cypress/e2e/browse.cy.js @@ -6,6 +6,7 @@ describe('Navigating to the browse page', () => { beforeEach(() => { + cy.useFilteredWares() cy.visit('/browse') }) @@ -45,11 +46,8 @@ describe('Navigating to the browse page', () => { context('and creating a new request', () => { beforeEach(() => { - cy.get('[data-cy="linked-button"]', { timeout: 25000 }).then(($buttons) => { - // there may potentially be hundreds of services on a page. to avoid - // a timeout, we will only choose from 10 services. this still ensures - // that a variety of dynamic forms are tested - const randomIndex = Math.floor(Math.random() * 10) + cy.get('[data-cy="linked-button"]', { timeout: 15000 }).then(($buttons) => { + const randomIndex = Math.floor(Math.random() * Cypress.env('API_PER_PAGE')) cy.wrap($buttons.eq(randomIndex)).click() }) }) diff --git a/cypress/support/commands.js b/cypress/support/commands.js index c953a598..66a64ca2 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -67,3 +67,10 @@ Cypress.Commands.add('customApiIntercept', ({ } }).as(alias || 'customIntercept') }) + +Cypress.Commands.add('useFilteredWares', () => { + cy.intercept(/\/wares\.json\?per_page=2000&q.*/, (req) => { + req.url = req.url.replace(/per_page=\d+/, `per_page=${Cypress.env('API_PER_PAGE')}`) + req.continue() + }) +}) From 49989cb0e26bd83e81e0d2e629ad634af36dc241 Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Mon, 12 Feb 2024 18:22:12 -0600 Subject: [PATCH 18/26] create the waitForElement command attempt to get around long timeouts by waiting for an expected element to be on the page before continuing --- cypress/e2e/browse.cy.js | 3 ++- cypress/support/commands.js | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cypress/e2e/browse.cy.js b/cypress/e2e/browse.cy.js index 0666be86..036be0da 100644 --- a/cypress/e2e/browse.cy.js +++ b/cypress/e2e/browse.cy.js @@ -46,7 +46,8 @@ describe('Navigating to the browse page', () => { context('and creating a new request', () => { beforeEach(() => { - cy.get('[data-cy="linked-button"]', { timeout: 15000 }).then(($buttons) => { + cy.waitForElement('[data-cy="linked-button"]') + cy.get('[data-cy="linked-button"]').then(($buttons) => { const randomIndex = Math.floor(Math.random() * Cypress.env('API_PER_PAGE')) cy.wrap($buttons.eq(randomIndex)).click() }) diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 66a64ca2..d6c77f51 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -74,3 +74,7 @@ Cypress.Commands.add('useFilteredWares', () => { req.continue() }) }) + +Cypress.Commands.add('waitForElement', (selector) => { + cy.get(selector).should('exist') +}) From d566d87ad0e4336a8c3aacbf7b0424133517c8d8 Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Mon, 12 Feb 2024 18:24:11 -0600 Subject: [PATCH 19/26] formatting --- cypress/support/commands.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cypress/support/commands.js b/cypress/support/commands.js index d6c77f51..9b27a096 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -29,12 +29,12 @@ import { scientistApiBaseURL } from './e2e' // source: https://github.com/nextauthjs/next-auth/discussions/2053#discussioncomment-1191016 Cypress.Commands.add('login', (username, password) => { cy.session([username, password], () => { - cy.intercept('/api/auth/session', { fixture: 'session.json' }).as('session') + cy.intercept('/api/auth/session', { fixture: 'session.json' }).as('session') - // Set the cookie for cypress. - // It has to be a valid cookie so next-auth can decrypt it and confirm its validity. - // This cookie also may need to be refreshed intermittently if it expires - cy.setCookie('next-auth.session-token', Cypress.env('TEST_SESSION_COOKIE')) + // Set the cookie for cypress. + // It has to be a valid cookie so next-auth can decrypt it and confirm its validity. + // This cookie also may need to be refreshed intermittently if it expires + cy.setCookie('next-auth.session-token', Cypress.env('TEST_SESSION_COOKIE')) }) }) From 3479ce075109880916f80d1df60cf615d9e8eb21 Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Mon, 12 Feb 2024 18:24:20 -0600 Subject: [PATCH 20/26] run cypress specs headed in ci when running specs locally with "cypress open" (headed), they pass. they fail locally when running "cypress run"(headless) for timeout issues. ci also runs headless, and gets timeout issues. I'm updating the config to run headed in ci in an attempt to get them to pass. ref: https://github.com/cypress-io/github-action/issues/403#issuecomment-1631059947 --- .github/workflows/build-test-lint.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build-test-lint.yml b/.github/workflows/build-test-lint.yml index b6e67641..4ae2beac 100644 --- a/.github/workflows/build-test-lint.yml +++ b/.github/workflows/build-test-lint.yml @@ -34,6 +34,7 @@ jobs: with: start: yarn start wait-on: 'http://localhost:3000' + headed: true env: NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }} NEXTAUTH_URL: ${{ secrets.NEXTAUTH_URL }} From d09233ea63d3aeccc4ac7c9634491e4c8c1cdce4 Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Mon, 12 Feb 2024 18:31:49 -0600 Subject: [PATCH 21/26] pass cypress workflow specific command the change in https://github.com/scientist-softserv/webstore/pull/371/commits/3479ce075109880916f80d1df60cf615d9e8eb21 still erred. I created a new script for the cypress workflow to call specifically. ref: https://github.com/cypress-io/github-action/issues/403#issuecomment-982668400 --- .github/workflows/build-test-lint.yml | 2 +- package.json | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-test-lint.yml b/.github/workflows/build-test-lint.yml index 4ae2beac..a9fffd6b 100644 --- a/.github/workflows/build-test-lint.yml +++ b/.github/workflows/build-test-lint.yml @@ -34,7 +34,7 @@ jobs: with: start: yarn start wait-on: 'http://localhost:3000' - headed: true + command: yarn cypress:e2e:ci env: NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }} NEXTAUTH_URL: ${{ secrets.NEXTAUTH_URL }} diff --git a/package.json b/package.json index c56ec419..93d2c1dc 100644 --- a/package.json +++ b/package.json @@ -2,12 +2,14 @@ "name": "webstore", "version": "0.1.8", "private": true, + "homepage": "https://github.com/scientist-softserv/webstore#readme", "engines": { "node": "^18.13.0" }, "scripts": { "build": "next build", "cypress:e2e": "start-server-and-test dev http://localhost:3000 \"cypress open --e2e --browser electron\"", + "cypress:e2e:ci": "start-server-and-test dev http://localhost:3000 \"cypress run --headed --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", From bd00f6c57d05d188bd398dedc1b0e04a694d1247 Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Mon, 12 Feb 2024 18:42:45 -0600 Subject: [PATCH 22/26] use port 3001 in ci --- .github/workflows/build-test-lint.yml | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-test-lint.yml b/.github/workflows/build-test-lint.yml index a9fffd6b..d4f62465 100644 --- a/.github/workflows/build-test-lint.yml +++ b/.github/workflows/build-test-lint.yml @@ -33,7 +33,7 @@ jobs: uses: cypress-io/github-action@v6 with: start: yarn start - wait-on: 'http://localhost:3000' + wait-on: 'http://localhost:3001' command: yarn cypress:e2e:ci env: NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }} diff --git a/package.json b/package.json index 93d2c1dc..8ac8649a 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "scripts": { "build": "next build", "cypress:e2e": "start-server-and-test dev http://localhost:3000 \"cypress open --e2e --browser electron\"", - "cypress:e2e:ci": "start-server-and-test dev http://localhost:3000 \"cypress run --headed --e2e --browser electron\"", + "cypress:e2e:ci": "start-server-and-test dev http://localhost:3001 \"cypress run --headed --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", From f5a064d3cba4fd1b3a857f6002374cc079108544 Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Tue, 13 Feb 2024 10:06:17 -0600 Subject: [PATCH 23/26] remove ci related code in favor of #378 --- .github/workflows/build-test-lint.yml | 5 +---- package.json | 1 - 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/build-test-lint.yml b/.github/workflows/build-test-lint.yml index d4f62465..75cb0f90 100644 --- a/.github/workflows/build-test-lint.yml +++ b/.github/workflows/build-test-lint.yml @@ -24,8 +24,6 @@ jobs: webTarget: web cypress: runs-on: ubuntu-22.04 - environment: - name: Production steps: - name: Checkout uses: actions/checkout@v4 @@ -33,8 +31,7 @@ jobs: uses: cypress-io/github-action@v6 with: start: yarn start - wait-on: 'http://localhost:3001' - command: yarn cypress:e2e:ci + wait-on: 'http://localhost:3000' env: NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }} NEXTAUTH_URL: ${{ secrets.NEXTAUTH_URL }} diff --git a/package.json b/package.json index 8ac8649a..54bd8ed4 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,6 @@ "scripts": { "build": "next build", "cypress:e2e": "start-server-and-test dev http://localhost:3000 \"cypress open --e2e --browser electron\"", - "cypress:e2e:ci": "start-server-and-test dev http://localhost:3001 \"cypress run --headed --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", From 064dfa39b505cca424f007bc1ed78154ce239604 Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Tue, 13 Feb 2024 10:11:12 -0600 Subject: [PATCH 24/26] add descriptions for newly added cypress commands --- cypress/support/commands.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 9b27a096..da7f3df8 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -68,6 +68,11 @@ Cypress.Commands.add('customApiIntercept', ({ }).as(alias || 'customIntercept') }) +/** + * Intercept the useFilteredWares API call to modify the per_page query + * parameter. We're lowering it in an attempt to speed up the test. Then, + * we continue to hit the server with the modified request. + */ Cypress.Commands.add('useFilteredWares', () => { cy.intercept(/\/wares\.json\?per_page=2000&q.*/, (req) => { req.url = req.url.replace(/per_page=\d+/, `per_page=${Cypress.env('API_PER_PAGE')}`) @@ -75,6 +80,9 @@ Cypress.Commands.add('useFilteredWares', () => { }) }) +/** + * To avoid the flakiness of the test, we wait for the element to exist + */ Cypress.Commands.add('waitForElement', (selector) => { cy.get(selector).should('exist') }) From 7bdd43955ed362809b9872c7bc0cc9dce08aa94e Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Tue, 13 Feb 2024 10:23:26 -0600 Subject: [PATCH 25/26] rearrange order of browse tests in an attempt to reduce flakiness --- cypress/e2e/browse.cy.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/cypress/e2e/browse.cy.js b/cypress/e2e/browse.cy.js index 036be0da..a92625a2 100644 --- a/cypress/e2e/browse.cy.js +++ b/cypress/e2e/browse.cy.js @@ -53,6 +53,18 @@ describe('Navigating to the browse page', () => { }) }) + context('as a logged out user', () => { + it('shows a disabled request form, with an error message.', () => { + cy.get("div[role='alert']").should('be.visible').then(() => { + cy.log('Successfully hits an error.') + }) + cy.get('div.alert-heading').should('have.text', 'Sign in required') + cy.get('form.rjsf').should('be.visible') + cy.scrollTo('bottom') + cy.get('button.btn-primary').should('be.disabled') + }) + }) + context('as a logged in user', () => { before(() => { cy.login(Cypress.env('TEST_SCIENTIST_USER'), Cypress.env('TEST_SCIENTIST_PW')) @@ -65,17 +77,5 @@ describe('Navigating to the browse page', () => { cy.get('button.btn-primary', { timeout: 10000 }).should('be.enabled') }) }) - - context('as a logged out user', () => { - it('shows a disabled request form, with an error message.', () => { - cy.get("div[role='alert']").should('be.visible').then(() => { - cy.log('Successfully hits an error.') - }) - cy.get('div.alert-heading').should('have.text', 'Sign in required') - cy.get('form.rjsf').should('be.visible') - cy.scrollTo('bottom') - cy.get('button.btn-primary').should('be.disabled') - }) - }) }) }) From a6de9cdc93a32ac87e0800489273794d829c656d Mon Sep 17 00:00:00 2001 From: Alisha Evans Date: Wed, 14 Feb 2024 12:16:14 -0600 Subject: [PATCH 26/26] increase the defaultCommandTimeout also wait for more elements to appear on the page before running assertions --- cypress.config.js | 1 + cypress/e2e/browse.cy.js | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/cypress.config.js b/cypress.config.js index 41b7ba17..8e5e7957 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -11,6 +11,7 @@ module.exports = defineConfig({ e2e: { baseUrl: 'http://localhost:3000', chromeWebSecurity: false, + defaultCommandTimeout: 10000, setupNodeEvents(on, config) { config = dotenvFlowPlugin(config) config.env = { diff --git a/cypress/e2e/browse.cy.js b/cypress/e2e/browse.cy.js index a92625a2..4aea0f04 100644 --- a/cypress/e2e/browse.cy.js +++ b/cypress/e2e/browse.cy.js @@ -71,10 +71,11 @@ describe('Navigating to the browse page', () => { }) it('shows a valid request form.', () => { + cy.waitForElement('form.rjsf') cy.get("div[role='alert']").should('not.exist') cy.get('form.rjsf').should('be.visible') cy.scrollTo('bottom') - cy.get('button.btn-primary', { timeout: 10000 }).should('be.enabled') + cy.get('button.btn-primary').should('be.enabled') }) }) })