Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update unit tests for PSP-7039 #3576

Merged
merged 2 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ describe('TakesDetailView component', () => {
expect(onEdit).toHaveBeenCalled();
});

it('displays the number of takes in other files', () => {
setup({
props: {
loading: false,
takes: [
{ ...getMockApiTakes()[0], takeStatusTypeCode: 'CANCELLED', id: 1 },
{ ...getMockApiTakes()[0], takeStatusTypeCode: 'INPROGRESS' },
],
allTakesCount: 10,
},
});
const takesNotInFile = screen.getByTestId('takes-in-other-files');
expect(takesNotInFile).toHaveTextContent('8');
});

it('displays all non-cancelled takes and then cancelled takes', () => {
setup({
props: {
Expand All @@ -75,7 +90,7 @@ describe('TakesDetailView component', () => {
},
});
const { getByText } = within(screen.getByTestId('take-0'));
expect(getByText('In-progress'));
expect(getByText('In-progress')).toBeVisible();
});

it('does not display an area fields if all is radio buttons are false', () => {
Expand Down Expand Up @@ -116,6 +131,23 @@ describe('TakesDetailView component', () => {
expect(getAllByText('Area:')).toHaveLength(5);
});

it('displays srwEndDt if specified', async () => {
const { findByText } = setup({
props: {
loading: false,
takes: [
{
...getMockApiTakes()[0],
isNewInterestInSrw: true,
srwEndDt: '2020-01-01',
},
],
},
});
const date = await findByText('SRW end date:');
expect(date).toBeVisible();
});

it('displays ltcEndDt if specified', async () => {
const { findByText } = setup({
props: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const TakesDetailView: React.FunctionComponent<ITakesDetailViewProps> = (
labelWidth="8"
label="Takes for this property in other files"
tooltip="The number of takes in completed, In-progress or cancelled state for this property, in files other than this acquisition file. The other files can be found under the Acquisition section of the PIMS Files tab"
valueTestId="takes-in-other-files"
>
{takesNotInFile}
</SectionField>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ exports[`TakesDetailView component renders as expected 1`] = `
</div>
<div
class="c6 text-left col"
data-testid="takes-in-other-files"
>
0
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { forwardRef } from 'react';
import { mockLookups } from '@/mocks/lookups.mock';
import { getMockApiPropertyFiles } from '@/mocks/properties.mock';
import { getMockApiTakes } from '@/mocks/takes.mock';
import { Api_Take } from '@/models/api/Take';
import { lookupCodesSlice } from '@/store/slices/lookupCodes';
import { render, RenderOptions } from '@/utils/test-utils';
import { act, render, RenderOptions, waitForEffects } from '@/utils/test-utils';

import { TakeModel } from './models';
import TakesUpdateContainer, { ITakesDetailContainerProps } from './TakesUpdateContainer';
Expand Down Expand Up @@ -77,8 +78,9 @@ describe('TakesUpdateContainer component', () => {
jest.clearAllMocks();
});

it('renders as expected', () => {
it('renders as expected', async () => {
const { asFragment } = setup({});
await waitForEffects();
expect(asFragment()).toMatchSnapshot();
});

Expand All @@ -87,17 +89,31 @@ describe('TakesUpdateContainer component', () => {
expect(render).toThrow('File property must have id');
});

it('calls onSuccess when onSubmit method is called', () => {
it('calls onSuccess when onSubmit method is called', async () => {
setup({});
const formikHelpers = { setSubmitting: jest.fn() };
viewProps.onSubmit({ takes: [new TakeModel(getMockApiTakes()[0])] }, formikHelpers as any);
await waitForEffects();
await act(() =>
viewProps.onSubmit({ takes: [new TakeModel(getMockApiTakes()[0])] }, formikHelpers as any),
);

expect(mockUpdateApi.execute).toHaveBeenCalled();
expect(onSuccess).toHaveBeenCalled();
});

it('returns an empty takes array if no takes are returned from the api', () => {
it('returns an empty takes array if no takes are returned from the api', async () => {
setup({});
await waitForEffects();

expect(viewProps.takes).toStrictEqual([new TakeModel(emptyTake)]);
});

it('returns converts takes returned from the api into form models', async () => {
const apiTake: Api_Take = { ...getMockApiTakes()[0], propertyAcquisitionFileId: 1 };
mockGetApi.execute.mockResolvedValue([apiTake]);
setup({});
await waitForEffects();

expect(viewProps.takes).toStrictEqual([new TakeModel(apiTake)]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface ITakesUpdateFormProps {
fileProperty: Api_PropertyFile;
takes: TakeModel[];
loading: boolean;
onSubmit: (model: TakesForm, formikHelpers: FormikHelpers<TakesForm>) => void;
onSubmit: (model: TakesForm, formikHelpers: FormikHelpers<TakesForm>) => Promise<void>;
}

export interface TakesForm {
Expand Down
Loading