From ebb4d4b7d6e62ae31138aed6197fdc74a109a691 Mon Sep 17 00:00:00 2001 From: Nehemiah Abuga Date: Wed, 15 Jan 2025 08:25:12 -0700 Subject: [PATCH 1/4] PXBF-1934-client-router-tests: Add Navigation Tests for Life Events Workflow --- .../cypress/e2e/storybook/client-router.cy.js | 113 ++++++++++++++++++ benefit-finder/cypress/support/commands.js | 14 +-- benefit-finder/cypress/support/pageObjects.js | 4 + .../__snapshots__/index.spec.jsx.snap | 1 + .../src/Routes/VerifySelectionsView/index.jsx | 5 +- 5 files changed, 129 insertions(+), 8 deletions(-) create mode 100644 benefit-finder/cypress/e2e/storybook/client-router.cy.js diff --git a/benefit-finder/cypress/e2e/storybook/client-router.cy.js b/benefit-finder/cypress/e2e/storybook/client-router.cy.js new file mode 100644 index 00000000..1655d14d --- /dev/null +++ b/benefit-finder/cypress/e2e/storybook/client-router.cy.js @@ -0,0 +1,113 @@ +import * as utils from '../../support/utils.js' +import { pageObjects } from '../../support/pageObjects' +import * as EN_LOCALE_DATA from '../../../../benefit-finder/src/shared/locales/en/en.json' +import * as EN_DOLO_MOCK_DATA from '../../../../benefit-finder/src/shared/api/mock-data/current.json' +import * as BENEFITS_ELIGIBILITY_DATA from '../../fixtures/benefits-eligibility.json' + +// 18 years ago minus one day - applicant under 18 years old +// 1 day = 365.2425 (accounts for leap year) +const dateOfBirth = utils.getDateByOffset(-(18 * 365.2425 - 1)) +// Date of death - 30 days ago +const dateOfDeath = utils.getDateByOffset(-30) + +const relationship = + EN_DOLO_MOCK_DATA.data.lifeEventForm.sectionsEligibilityCriteria[0].section + .fieldsets[1].fieldset.inputs[0].inputCriteria.values[1].value +const maritalStatus = + EN_DOLO_MOCK_DATA.data.lifeEventForm.sectionsEligibilityCriteria[0].section + .fieldsets[2].fieldset.inputs[0].inputCriteria.values[1].value +const citizenshipStatusId = + EN_DOLO_MOCK_DATA.data.lifeEventForm.sectionsEligibilityCriteria[0].section + .fieldsets[3].fieldset.inputs[0].inputCriteria.id +const paidIntoSocialSecurityId = + EN_DOLO_MOCK_DATA.data.lifeEventForm.sectionsEligibilityCriteria[1].section + .fieldsets[2].fieldset.inputs[0].inputCriteria.id +const publicSafetyOfficerId = + EN_DOLO_MOCK_DATA.data.lifeEventForm.sectionsEligibilityCriteria[1].section + .fieldsets[3].fieldset.inputs[0].inputCriteria.id +const reviewYourSelections = + EN_LOCALE_DATA.reviewSelectionModal.buttonGroup[0].value + +describe('Client Router Tests', () => { + it("Should render the Intro component at '/death/' life event", () => { + cy.visit(utils.storybookUri) + pageObjects + .button() + .contains(EN_LOCALE_DATA.intro.button) + .should('be.visible') + }) + + it("Should render the LifeEventSection component at '/death/about-you'", () => { + cy.visit(utils.storybookUri) + cy.navigateToAboutTheApplicantPage() + }) + + it("should navigate to 'death/verify-selections' and render VerifySelectionsView", () => { + cy.visit(utils.storybookUri) + cy.navigateToModal({ + dateOfBirth, + relationship, + maritalStatus, + dateOfDeath, + }) + cy.clickButton(reviewYourSelections) + cy.url().should('include', '/verify-selections') + pageObjects.verifySelectionsView().should('exist') + }) + + it("Should navigate to '/death/results' and render ResultsView eligible items", () => { + cy.visit(utils.storybookUri) + cy.navigateToBenefitResultsPage({ + dateOfBirth, + relationship, + maritalStatus, + optionalApplicantFields: { + [citizenshipStatusId]: 0, // Select "Yes" for citizenship + }, + dateOfDeath, + optionalDeceasedFields: { + [paidIntoSocialSecurityId]: 0, // Select "Yes" for "Did deceased ever work and pay U.S. Social Security taxes?" + [publicSafetyOfficerId]: 0, // Select "Yes" for "Was the deceased a public safety officer who died in the line of duty" + }, + }) + cy.url().should('include', '/results') + pageObjects.benefitResultsView().should('be.visible') + pageObjects.accordionHeading().should('have.length.greaterThan', 0) + }) + + it("Should navigate to '/death/results/not-eligible' and render ResultsView not-eligible items", () => { + cy.visit(utils.storybookUri) + cy.navigateToBenefitResultsPage({ + dateOfBirth, + relationship, + maritalStatus, + dateOfDeath, + }) + pageObjects.zeroBenefitsViewHeading().should('be.visible') + }) + + it('Should navigate back to the Intro component using the browser back button', () => { + cy.visit(utils.storybookUri) + cy.navigateToBenefitResultsPage({ + dateOfBirth, + relationship, + maritalStatus, + dateOfDeath, + }) + pageObjects.zeroBenefitsViewHeading().should('be.visible') + cy.go('back') + cy.go('back') + cy.go('back') + pageObjects + .button() + .contains(EN_LOCALE_DATA.intro.button) + .should('be.visible') + }) + + it("Should redirect to '/results' when a valid query parameter is present", () => { + const selectedData = BENEFITS_ELIGIBILITY_DATA.scenario_2_veteran.en.param + const scenario = utils.encodeURIFromObject(selectedData) + cy.visit(`${utils.storybookUri}${scenario}`) + cy.url().should('include', '/results') + }) +}) diff --git a/benefit-finder/cypress/support/commands.js b/benefit-finder/cypress/support/commands.js index e6f77cf0..f831a615 100644 --- a/benefit-finder/cypress/support/commands.js +++ b/benefit-finder/cypress/support/commands.js @@ -149,18 +149,18 @@ Cypress.Commands.add( optionalDeceasedFields = {}, additionalDeceasedFields = {}, }) => { - cy.navigateToAboutTheDeceasedPage({ + // Reuse navigateToModal + cy.navigateToModal({ dateOfBirth, relationship, maritalStatus, - optionalFields: optionalApplicantFields, - }) - cy.fillDetailsAboutTheDeceased({ + optionalApplicantFields, dateOfDeath, - optionalFields: optionalDeceasedFields, - additionalFields: additionalDeceasedFields, + optionalDeceasedFields, + additionalDeceasedFields, }) - cy.clickButton(nextButtonGroup) // Open modal + + // Click the "Get Your Results" button to navigate to the results page cy.clickButton(getYourResultsButton) } ) diff --git a/benefit-finder/cypress/support/pageObjects.js b/benefit-finder/cypress/support/pageObjects.js index 28210b14..eb528a24 100644 --- a/benefit-finder/cypress/support/pageObjects.js +++ b/benefit-finder/cypress/support/pageObjects.js @@ -114,6 +114,10 @@ class PageObjects { return cy.get('[data-testid="zero-benefits-view-cta-button"]') } + verifySelectionsView() { + return cy.get('[data-testid="bf-verify-selections-view"]') + } + zeroBenefitsViewHeading() { return cy.get('[data-testid="zero-benefits-view-heading"]') } diff --git a/benefit-finder/src/Routes/VerifySelectionsView/__tests__/__snapshots__/index.spec.jsx.snap b/benefit-finder/src/Routes/VerifySelectionsView/__tests__/__snapshots__/index.spec.jsx.snap index 41b75086..553fd934 100644 --- a/benefit-finder/src/Routes/VerifySelectionsView/__tests__/__snapshots__/index.spec.jsx.snap +++ b/benefit-finder/src/Routes/VerifySelectionsView/__tests__/__snapshots__/index.spec.jsx.snap @@ -4,6 +4,7 @@ exports[`VerifySelectionsView > renders a match to the previous snapshot 1`] = `
{ }, []) return ( -
+
{verifySelectionsView?.heading} From 16efece2a42c4f863dd5a9e4001daadc6cd1394c Mon Sep 17 00:00:00 2001 From: scottqueen-bixal Date: Fri, 17 Jan 2025 10:41:54 -0500 Subject: [PATCH 2/4] PXBF-2058-firefox-hash-bug-fix: remove hash reset to empty string, causes bug in firefox browser history --- benefit-finder/src/shared/components/Modal/index.jsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/benefit-finder/src/shared/components/Modal/index.jsx b/benefit-finder/src/shared/components/Modal/index.jsx index 3006810d..1a3c463f 100644 --- a/benefit-finder/src/shared/components/Modal/index.jsx +++ b/benefit-finder/src/shared/components/Modal/index.jsx @@ -83,8 +83,6 @@ const Modal = ({ const handleCloseModal = triggerRef => { // focus the trigger if it is still in the DOM triggerRef && triggerRef.current.focus() - // clear the hash - window.location.hash = '' window.scrollTo(0, 0) scrollLock.disableScroll() setModalOpen(false) From 56266c14baabf0f78466150b701fff3e2378fe89 Mon Sep 17 00:00:00 2001 From: Nehemiah Abuga <121119072+nehemiah-abuga@users.noreply.github.com> Date: Wed, 22 Jan 2025 11:12:46 -0700 Subject: [PATCH 3/4] Update benefit-finder/cypress/e2e/storybook/client-router.cy.js Co-authored-by: Scott Queen --- benefit-finder/cypress/e2e/storybook/client-router.cy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benefit-finder/cypress/e2e/storybook/client-router.cy.js b/benefit-finder/cypress/e2e/storybook/client-router.cy.js index 1655d14d..b2a172e2 100644 --- a/benefit-finder/cypress/e2e/storybook/client-router.cy.js +++ b/benefit-finder/cypress/e2e/storybook/client-router.cy.js @@ -29,7 +29,7 @@ const reviewYourSelections = EN_LOCALE_DATA.reviewSelectionModal.buttonGroup[0].value describe('Client Router Tests', () => { - it("Should render the Intro component at '/death/' life event", () => { + it("Should render the Intro component at '/death' life event", () => { cy.visit(utils.storybookUri) pageObjects .button() From b11b6b8b903c4ad0fd5b1a62a681a554f9228630 Mon Sep 17 00:00:00 2001 From: Nehemiah Abuga <121119072+nehemiah-abuga@users.noreply.github.com> Date: Wed, 22 Jan 2025 11:14:40 -0700 Subject: [PATCH 4/4] Update client-router.cy.js --- benefit-finder/cypress/e2e/storybook/client-router.cy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benefit-finder/cypress/e2e/storybook/client-router.cy.js b/benefit-finder/cypress/e2e/storybook/client-router.cy.js index b2a172e2..6414a01f 100644 --- a/benefit-finder/cypress/e2e/storybook/client-router.cy.js +++ b/benefit-finder/cypress/e2e/storybook/client-router.cy.js @@ -42,7 +42,7 @@ describe('Client Router Tests', () => { cy.navigateToAboutTheApplicantPage() }) - it("should navigate to 'death/verify-selections' and render VerifySelectionsView", () => { + it("should navigate to '/death/verify-selections' and render VerifySelectionsView", () => { cy.visit(utils.storybookUri) cy.navigateToModal({ dateOfBirth,