diff --git a/source/frontend/src/features/mapSideBar/property/tabs/takes/detail/TakesDetailView.test.tsx b/source/frontend/src/features/mapSideBar/property/tabs/takes/detail/TakesDetailView.test.tsx index 559127e58c..b5508d8bfc 100644 --- a/source/frontend/src/features/mapSideBar/property/tabs/takes/detail/TakesDetailView.test.tsx +++ b/source/frontend/src/features/mapSideBar/property/tabs/takes/detail/TakesDetailView.test.tsx @@ -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: { @@ -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', () => { @@ -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: { diff --git a/source/frontend/src/features/mapSideBar/property/tabs/takes/detail/TakesDetailView.tsx b/source/frontend/src/features/mapSideBar/property/tabs/takes/detail/TakesDetailView.tsx index b579636016..0fcee7da31 100644 --- a/source/frontend/src/features/mapSideBar/property/tabs/takes/detail/TakesDetailView.tsx +++ b/source/frontend/src/features/mapSideBar/property/tabs/takes/detail/TakesDetailView.tsx @@ -69,6 +69,7 @@ export const TakesDetailView: React.FunctionComponent = ( 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} diff --git a/source/frontend/src/features/mapSideBar/property/tabs/takes/detail/__snapshots__/TakesDetailView.test.tsx.snap b/source/frontend/src/features/mapSideBar/property/tabs/takes/detail/__snapshots__/TakesDetailView.test.tsx.snap index 118f57f2dc..214de8ea42 100644 --- a/source/frontend/src/features/mapSideBar/property/tabs/takes/detail/__snapshots__/TakesDetailView.test.tsx.snap +++ b/source/frontend/src/features/mapSideBar/property/tabs/takes/detail/__snapshots__/TakesDetailView.test.tsx.snap @@ -147,6 +147,7 @@ exports[`TakesDetailView component renders as expected 1`] = `
0
diff --git a/source/frontend/src/features/mapSideBar/property/tabs/takes/update/TakesUpdateContainer.test.tsx b/source/frontend/src/features/mapSideBar/property/tabs/takes/update/TakesUpdateContainer.test.tsx index 2f4bc865c0..8fec3001b3 100644 --- a/source/frontend/src/features/mapSideBar/property/tabs/takes/update/TakesUpdateContainer.test.tsx +++ b/source/frontend/src/features/mapSideBar/property/tabs/takes/update/TakesUpdateContainer.test.tsx @@ -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'; @@ -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(); }); @@ -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)]); + }); }); diff --git a/source/frontend/src/features/mapSideBar/property/tabs/takes/update/TakesUpdateForm.tsx b/source/frontend/src/features/mapSideBar/property/tabs/takes/update/TakesUpdateForm.tsx index 20d7cade2d..8a94693304 100644 --- a/source/frontend/src/features/mapSideBar/property/tabs/takes/update/TakesUpdateForm.tsx +++ b/source/frontend/src/features/mapSideBar/property/tabs/takes/update/TakesUpdateForm.tsx @@ -18,7 +18,7 @@ export interface ITakesUpdateFormProps { fileProperty: Api_PropertyFile; takes: TakeModel[]; loading: boolean; - onSubmit: (model: TakesForm, formikHelpers: FormikHelpers) => void; + onSubmit: (model: TakesForm, formikHelpers: FormikHelpers) => Promise; } export interface TakesForm {