Skip to content

Commit

Permalink
Test updates
Browse files Browse the repository at this point in the history
  • Loading branch information
asanchezr committed Dec 11, 2024
1 parent bef1790 commit a97b743
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -156,7 +156,7 @@ describe('LeaseDetailView component', () => {
claims: [],
});

expect(screen.queryByText(buttonTitle)).toBeNull();
expect(screen.queryByText(buttonText)).toBeNull();
},
);

Expand All @@ -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: {
Expand All @@ -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) => {
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -43,6 +45,7 @@ describe('AgreementView component', () => {

beforeEach(() => {
mockViewProps.agreements = mockAgreementsResponse();
mockViewProps.statusUpdateSolver = new AcquisitionFileStatusUpdateSolver();
});

afterEach(() => {
Expand All @@ -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();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 () => {
Expand All @@ -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);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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}
/>,
Expand All @@ -50,6 +51,8 @@ describe('Compensation Detail View Component', () => {
},
);

await waitForEffects();

return {
...component,
};
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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();
});
});

0 comments on commit a97b743

Please sign in to comment.