From a97b7436a51d11f6ca4cae367862cd59a5cf5665 Mon Sep 17 00:00:00 2001 From: Alejandro Sanchez Date: Tue, 10 Dec 2024 16:52:00 -0800 Subject: [PATCH] Test updates --- .../details/LeaseDetailsView.test.tsx | 24 +++++------ .../agreement/detail/AgreementView.test.tsx | 40 +++++++++++++++++-- .../form1/ExpropriationForm1.test.tsx | 16 ++++---- .../form5/ExpropriationForm5.test.tsx | 16 ++++---- .../form9/ExpropriationForm9.test.tsx | 16 ++++---- ...CompensationRequisitionDetailView.test.tsx | 25 ++++++++---- 6 files changed, 91 insertions(+), 46 deletions(-) diff --git a/source/frontend/src/features/leases/detail/LeasePages/details/LeaseDetailsView.test.tsx b/source/frontend/src/features/leases/detail/LeasePages/details/LeaseDetailsView.test.tsx index 8e8478a3e0..fea5179f9f 100644 --- a/source/frontend/src/features/leases/detail/LeasePages/details/LeaseDetailsView.test.tsx +++ b/source/frontend/src/features/leases/detail/LeasePages/details/LeaseDetailsView.test.tsx @@ -133,11 +133,11 @@ describe('LeaseDetailView component', () => { }); it.each([ - [ApiGen_CodeTypes_LeaseLicenceTypes.LOOBCTFA, 'Generate H1005(a)'], - [ApiGen_CodeTypes_LeaseLicenceTypes.LIPPUBHWY, 'Generate H1005'], + [ApiGen_CodeTypes_LeaseLicenceTypes.LOOBCTFA, 'Generate H-1005(a)'], + [ApiGen_CodeTypes_LeaseLicenceTypes.LIPPUBHWY, 'Generate H-1005'], ])( 'does not render generation button if missing permissions - %s', - async (leaseTypeCode: string, buttonTitle: string) => { + async (leaseTypeCode: string, buttonText: string) => { setup({ props: { lease: { @@ -156,7 +156,7 @@ describe('LeaseDetailView component', () => { claims: [], }); - expect(screen.queryByText(buttonTitle)).toBeNull(); + expect(screen.queryByText(buttonText)).toBeNull(); }, ); @@ -178,15 +178,15 @@ describe('LeaseDetailView component', () => { }, }); - expect(screen.queryByText(/Generate H1005/i)).toBeNull(); + expect(screen.queryByText(/Generate H-1005/i)).toBeNull(); }); it.each([ - [ApiGen_CodeTypes_LeaseLicenceTypes.LOOBCTFA, 'Generate H1005(a)'], - [ApiGen_CodeTypes_LeaseLicenceTypes.LIPPUBHWY, 'Generate H1005'], + [ApiGen_CodeTypes_LeaseLicenceTypes.LOOBCTFA, 'Generate H-1005(a)'], + [ApiGen_CodeTypes_LeaseLicenceTypes.LIPPUBHWY, 'Generate H-1005'], ])( 'only renders generation button for specific lease types - %s', - async (leaseTypeCode: string, buttonTitle: string) => { + async (leaseTypeCode: string, buttonText: string) => { setup({ props: { lease: { @@ -204,13 +204,13 @@ describe('LeaseDetailView component', () => { }, }); - expect(await screen.findByTitle(buttonTitle)).toBeInTheDocument(); + expect(await screen.findByText(buttonText)).toBeInTheDocument(); }, ); it.each([ - [ApiGen_CodeTypes_LeaseLicenceTypes.LOOBCTFA, 'Generate H1005(a)'], - [ApiGen_CodeTypes_LeaseLicenceTypes.LIPPUBHWY, 'Generate H1005'], + [ApiGen_CodeTypes_LeaseLicenceTypes.LOOBCTFA, 'Generate H-1005(a)'], + [ApiGen_CodeTypes_LeaseLicenceTypes.LIPPUBHWY, 'Generate H-1005'], ])( 'calls onGenerate when generation button is clicked - %s', async (leaseTypeCode: string, buttonTitle: string) => { @@ -231,7 +231,7 @@ describe('LeaseDetailView component', () => { }, }); - const generateButton = await screen.findByTitle(buttonTitle); + const generateButton = await screen.findByText(buttonTitle); expect(generateButton).toBeInTheDocument(); await act(async () => userEvent.click(generateButton)); diff --git a/source/frontend/src/features/mapSideBar/acquisition/tabs/agreement/detail/AgreementView.test.tsx b/source/frontend/src/features/mapSideBar/acquisition/tabs/agreement/detail/AgreementView.test.tsx index 23af780d01..e409d92f71 100644 --- a/source/frontend/src/features/mapSideBar/acquisition/tabs/agreement/detail/AgreementView.test.tsx +++ b/source/frontend/src/features/mapSideBar/acquisition/tabs/agreement/detail/AgreementView.test.tsx @@ -1,10 +1,12 @@ +import { Claims } from '@/constants'; import { mockAgreementsResponse } from '@/mocks/agreements.mock'; import { mockLookups } from '@/mocks/index.mock'; import { lookupCodesSlice } from '@/store/slices/lookupCodes'; -import { render, RenderOptions } from '@/utils/test-utils'; +import { act, render, RenderOptions, screen, userEvent } from '@/utils/test-utils'; -import AgreementView, { IAgreementViewProps } from './AgreementView'; import AcquisitionFileStatusUpdateSolver from '../../fileDetails/detail/AcquisitionFileStatusUpdateSolver'; +import AgreementView, { IAgreementViewProps } from './AgreementView'; +import { ApiGen_CodeTypes_AcquisitionStatusTypes } from '@/models/api/generated/ApiGen_CodeTypes_AcquisitionStatusTypes'; // mock auth library @@ -43,6 +45,7 @@ describe('AgreementView component', () => { beforeEach(() => { mockViewProps.agreements = mockAgreementsResponse(); + mockViewProps.statusUpdateSolver = new AcquisitionFileStatusUpdateSolver(); }); afterEach(() => { @@ -54,8 +57,39 @@ describe('AgreementView component', () => { expect(asFragment()).toMatchSnapshot(); }); - it('renders the agreement type ', () => { + it('renders the agreement type', () => { const { getByText } = setup(); expect(getByText(/License Of Occupation/i)).toBeVisible(); }); + + it('calls onGenerate when generation button is clicked', async () => { + const { getAllByTitle } = setup(); + + const generateButtons = getAllByTitle(/Download File/i); + expect(generateButtons).toHaveLength(2); + await act(async () => userEvent.click(generateButtons[0])); + + expect(mockViewProps.onGenerate).toHaveBeenCalled(); + }); + + it('displays confirmation modal when Delete Agreement button is clicked', async () => { + mockViewProps.statusUpdateSolver = new AcquisitionFileStatusUpdateSolver({ + id: ApiGen_CodeTypes_AcquisitionStatusTypes.ACTIVE, + description: '', + displayOrder: 1, + isDisabled: false, + }); + + const { getAllByTitle } = setup({ + claims: [Claims.ACQUISITION_EDIT], + }); + + const removeButtons = getAllByTitle(/Delete Agreement/i); + expect(removeButtons).toHaveLength(2); + await act(async () => userEvent.click(removeButtons[0])); + + expect( + screen.getByText(/You have selected to delete this Agreement/i, { exact: false }), + ).toBeVisible(); + }); }); diff --git a/source/frontend/src/features/mapSideBar/acquisition/tabs/expropriation/form1/ExpropriationForm1.test.tsx b/source/frontend/src/features/mapSideBar/acquisition/tabs/expropriation/form1/ExpropriationForm1.test.tsx index 273933cc3e..bd10421661 100644 --- a/source/frontend/src/features/mapSideBar/acquisition/tabs/expropriation/form1/ExpropriationForm1.test.tsx +++ b/source/frontend/src/features/mapSideBar/acquisition/tabs/expropriation/form1/ExpropriationForm1.test.tsx @@ -63,8 +63,8 @@ describe('Expropriation Form 1', () => { }); it('validates form values before generating', async () => { - const { getByText } = await setup(); - await act(async () => userEvent.click(getByText('Generate'))); + const { getByText, getByTitle } = await setup(); + await act(async () => userEvent.click(getByTitle(/Download File/i))); expect(getByText('Expropriation authority is required')).toBeInTheDocument(); expect(getByText('At lease one impacted property is required')).toBeInTheDocument(); @@ -83,10 +83,10 @@ describe('Expropriation Form 1', () => { await act(async () => userEvent.paste(getNatureOfInterest(), 'foo')); await act(async () => userEvent.paste(getPurpose(), 'bar')); - await act(async () => userEvent.click(getByText('Generate'))); + await act(async () => userEvent.click(getByTitle(/Download File/i))); - expect(onGenerate).toBeCalled(); - expect(onError).not.toBeCalled(); + expect(onGenerate).toHaveBeenCalled(); + expect(onError).not.toHaveBeenCalled(); }); it(`clears the form when Cancel button is clicked`, async () => { @@ -122,9 +122,9 @@ describe('Expropriation Form 1', () => { await act(async () => userEvent.paste(getNatureOfInterest(), 'foo')); await act(async () => userEvent.paste(getPurpose(), 'bar')); - await act(async () => userEvent.click(getByText('Generate'))); + await act(async () => userEvent.click(getByTitle(/Download File/i))); - expect(onGenerate).toBeCalled(); - expect(onError).toBeCalledWith(error); + expect(onGenerate).toHaveBeenCalled(); + expect(onError).toHaveBeenCalledWith(error); }); }); diff --git a/source/frontend/src/features/mapSideBar/acquisition/tabs/expropriation/form5/ExpropriationForm5.test.tsx b/source/frontend/src/features/mapSideBar/acquisition/tabs/expropriation/form5/ExpropriationForm5.test.tsx index 8a45adffb0..b8acb8b15c 100644 --- a/source/frontend/src/features/mapSideBar/acquisition/tabs/expropriation/form5/ExpropriationForm5.test.tsx +++ b/source/frontend/src/features/mapSideBar/acquisition/tabs/expropriation/form5/ExpropriationForm5.test.tsx @@ -60,8 +60,8 @@ describe('Expropriation Form 1', () => { }); it('validates form values before generating', async () => { - const { getByText } = await setup(); - await act(async () => userEvent.click(getByText('Generate'))); + const { getByText, getByTitle } = await setup(); + await act(async () => userEvent.click(getByTitle(/Download File/i))); expect(getByText('Expropriation authority is required')).toBeInTheDocument(); expect(getByText('At lease one impacted property is required')).toBeInTheDocument(); @@ -77,10 +77,10 @@ describe('Expropriation Form 1', () => { // fill other form fields await act(async () => userEvent.click(getByTestId('selectrow-1'))); - await act(async () => userEvent.click(getByText('Generate'))); + await act(async () => userEvent.click(getByTitle(/Download File/i))); - expect(onGenerate).toBeCalled(); - expect(onError).not.toBeCalled(); + expect(onGenerate).toHaveBeenCalled(); + expect(onError).not.toHaveBeenCalled(); }); it(`clears the form when Cancel button is clicked`, async () => { @@ -105,9 +105,9 @@ describe('Expropriation Form 1', () => { // fill other form fields await act(async () => userEvent.click(getByTestId('selectrow-1'))); - await act(async () => userEvent.click(getByText('Generate'))); + await act(async () => userEvent.click(getByTitle(/Download File/i))); - expect(onGenerate).toBeCalled(); - expect(onError).toBeCalledWith(error); + expect(onGenerate).toHaveBeenCalled(); + expect(onError).toHaveBeenCalledWith(error); }); }); diff --git a/source/frontend/src/features/mapSideBar/acquisition/tabs/expropriation/form9/ExpropriationForm9.test.tsx b/source/frontend/src/features/mapSideBar/acquisition/tabs/expropriation/form9/ExpropriationForm9.test.tsx index e73016a842..4a7ff6aa1c 100644 --- a/source/frontend/src/features/mapSideBar/acquisition/tabs/expropriation/form9/ExpropriationForm9.test.tsx +++ b/source/frontend/src/features/mapSideBar/acquisition/tabs/expropriation/form9/ExpropriationForm9.test.tsx @@ -62,8 +62,8 @@ describe('Expropriation Form 1', () => { }); it('validates form values before generating', async () => { - const { getByText } = await setup(); - await act(async () => userEvent.click(getByText('Generate'))); + const { getByText, getByTitle } = await setup(); + await act(async () => userEvent.click(getByTitle(/Download File/i))); expect(getByText('Expropriation authority is required')).toBeInTheDocument(); expect(getByText('At lease one impacted property is required')).toBeInTheDocument(); @@ -81,10 +81,10 @@ describe('Expropriation Form 1', () => { await act(async () => userEvent.click(getByTestId('selectrow-1'))); await act(async () => userEvent.paste(getRegisteredPlanNumbers(), 'testing')); - await act(async () => userEvent.click(getByText('Generate'))); + await act(async () => userEvent.click(getByTitle(/Download File/i))); - expect(onGenerate).toBeCalled(); - expect(onError).not.toBeCalled(); + expect(onGenerate).toHaveBeenCalled(); + expect(onError).not.toHaveBeenCalled(); }); it(`clears the form when Cancel button is clicked`, async () => { @@ -116,9 +116,9 @@ describe('Expropriation Form 1', () => { await act(async () => userEvent.click(getByTestId('selectrow-1'))); await act(async () => userEvent.paste(getRegisteredPlanNumbers(), 'testing')); - await act(async () => userEvent.click(getByText('Generate'))); + await act(async () => userEvent.click(getByTitle(/Download File/i))); - expect(onGenerate).toBeCalled(); - expect(onError).toBeCalledWith(error); + expect(onGenerate).toHaveBeenCalled(); + expect(onError).toHaveBeenCalledWith(error); }); }); diff --git a/source/frontend/src/features/mapSideBar/compensation/detail/CompensationRequisitionDetailView.test.tsx b/source/frontend/src/features/mapSideBar/compensation/detail/CompensationRequisitionDetailView.test.tsx index 22665b9b56..8a754a40d6 100644 --- a/source/frontend/src/features/mapSideBar/compensation/detail/CompensationRequisitionDetailView.test.tsx +++ b/source/frontend/src/features/mapSideBar/compensation/detail/CompensationRequisitionDetailView.test.tsx @@ -9,17 +9,18 @@ import { getMockApiDefaultCompensation, getMockCompensationPropertiesReq, } from '@/mocks/compensations.mock'; +import { ApiGen_CodeTypes_AcquisitionStatusTypes } from '@/models/api/generated/ApiGen_CodeTypes_AcquisitionStatusTypes'; +import { ApiGen_CodeTypes_FileTypes } from '@/models/api/generated/ApiGen_CodeTypes_FileTypes'; import { ApiGen_Concepts_CompensationRequisition } from '@/models/api/generated/ApiGen_Concepts_CompensationRequisition'; import { toTypeCodeNullable } from '@/utils/formUtils'; -import { act, render, RenderOptions, userEvent, waitFor } from '@/utils/test-utils'; +import { act, render, RenderOptions, userEvent, waitForEffects } from '@/utils/test-utils'; import CompensationRequisitionDetailView, { CompensationRequisitionDetailViewProps, } from './CompensationRequisitionDetailView'; -import { ApiGen_CodeTypes_AcquisitionStatusTypes } from '@/models/api/generated/ApiGen_CodeTypes_AcquisitionStatusTypes'; -import { ApiGen_CodeTypes_FileTypes } from '@/models/api/generated/ApiGen_CodeTypes_FileTypes'; const setEditMode = vi.fn(); +const onGenerate = vi.fn(); const history = createMemoryHistory(); @@ -39,7 +40,7 @@ describe('Compensation Detail View Component', () => { loading={renderOptions.props?.loading ?? false} setEditMode={setEditMode} clientConstant={renderOptions.props?.clientConstant ?? '034'} - onGenerate={vi.fn()} + onGenerate={onGenerate} compensationContactPerson={undefined} compensationContactOrganization={undefined} />, @@ -50,6 +51,8 @@ describe('Compensation Detail View Component', () => { }, ); + await waitForEffects(); + return { ...component, }; @@ -61,8 +64,7 @@ describe('Compensation Detail View Component', () => { it('renders as expected', async () => { const { asFragment } = await setup({}); - const fragment = await waitFor(() => asFragment()); - expect(fragment).toMatchSnapshot(); + expect(asFragment()).toMatchSnapshot(); }); it('Displays the Compensation Requisition Header Information with Draft Status', async () => { @@ -194,7 +196,7 @@ describe('Compensation Detail View Component', () => { }); it('displays the acquisition files properties selected', async () => { - const { findByText, findByTestId } = await setup({ + const { findByText } = await setup({ claims: [Claims.COMPENSATION_REQUISITION_EDIT], props: { compensation: getMockApiCompensationWithProperty(), @@ -250,4 +252,13 @@ describe('Compensation Detail View Component', () => { expect(queryByTestId('file-product')).toHaveTextContent('00048'); }); + + it('calls onGenerate when generation button is clicked', async () => { + const { getByTitle } = await setup({}); + + const generateButton = getByTitle(/Download File/i); + await act(async () => userEvent.click(generateButton)); + + expect(onGenerate).toHaveBeenCalled(); + }); });