Skip to content

Commit

Permalink
Test updates
Browse files Browse the repository at this point in the history
  • Loading branch information
asanchezr committed Dec 24, 2024
1 parent 7f2c985 commit 1bb044e
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import { createMemoryHistory } from 'history';
import { useMap } from 'react-leaflet';

import { useMapStateMachine } from '@/components/common/mapFSM/MapStateMachineContext';
import Claims from '@/constants/claims';
import { mockLookups } from '@/mocks/lookups.mock';
import { mapMachineBaseMock } from '@/mocks/mapFSM.mock';
import { emptyPmbcParcel } from '@/models/layers/parcelMapBC';
import { EmptyPropertyLocation } from '@/models/layers/pimsPropertyLocationView';
import { lookupCodesSlice } from '@/store/slices/lookupCodes';
import { pidParser } from '@/utils/propertyUtils';
import { pidParser, pinParser } from '@/utils/propertyUtils';
import { act, render, RenderOptions, userEvent } from '@/utils/test-utils';

import { ILayerPopupViewProps, LayerPopupView } from './LayerPopupView';
import { emptyPimsBoundaryFeatureCollection } from '@/components/common/mapFSM/models';
import { useKeycloak } from '@react-keycloak/web';

vi.mock('react-leaflet');

Expand Down Expand Up @@ -54,6 +49,7 @@ describe('LayerPopupView component', () => {
});
expect(asFragment()).toMatchSnapshot();
});

describe('fly out behaviour', () => {
it('fly out is hidden by default', async () => {
const { queryByText } = setup({
Expand Down Expand Up @@ -122,7 +118,7 @@ describe('LayerPopupView component', () => {
expect(history.location.pathname).toBe(`/mapview/sidebar/property/${propertyId}`);
});

it('handles view property action for non-inventory properties', async () => {
it('handles view property action for non-inventory properties - with PID', async () => {
const pid = '123456789';
const parsedPid = pidParser(pid);
const { getByTestId, getByText } = setup({
Expand Down Expand Up @@ -162,7 +158,51 @@ describe('LayerPopupView component', () => {
const link = getByText('View Property Info');
await act(async () => userEvent.click(link));
expect(history.location.pathname).toBe(
`/mapview/sidebar/non-inventory-property/${parsedPid}`,
`/mapview/sidebar/non-inventory-property/pid/${parsedPid}`,
);
});

it('handles view property action for non-inventory properties - with PIN', async () => {
const pin = '123456789';
const parsedPin = pinParser(pin);
const { getByTestId, getByText } = setup({
layerPopup: {
layers: [
{
data: { PIN: pin },
title: '',
config: {},
},
],
latlng: undefined,
},
featureDataset: {
parcelFeature: {
type: 'Feature',
properties: { ...emptyPmbcParcel, PIN: parsedPin },
geometry: { type: 'Point', coordinates: [] },
},
location: { lat: 0, lng: 0 },
fileLocation: null,
pimsFeature: null,
regionFeature: null,
districtFeature: null,
municipalityFeature: null,
highwayFeature: null,
selectingComponentId: null,
crownLandLeasesFeature: null,
crownLandLicensesFeature: null,
crownLandTenuresFeature: null,
crownLandInventoryFeature: null,
crownLandInclusionsFeature: null,
},
});
const ellipsis = getByTestId('fly-out-ellipsis');
await act(async () => userEvent.click(ellipsis));
const link = getByText('View Property Info');
await act(async () => userEvent.click(link));
expect(history.location.pathname).toBe(
`/mapview/sidebar/non-inventory-property/pin/${parsedPin}`,
);
});

Expand Down Expand Up @@ -440,5 +480,39 @@ describe('LayerPopupView component', () => {
await act(async () => userEvent.click(link));
expect(history.location.pathname).toBe('/mapview/sidebar/consolidation/new');
});

it('handles create lease and licence file action', async () => {
const { getByTestId, getByText } = setup({
layerPopup: {
latlng: undefined,
layers: [],
},
featureDataset: null,

claims: [Claims.LEASE_ADD],
});
const ellipsis = getByTestId('fly-out-ellipsis');
await act(async () => userEvent.click(ellipsis));
const link = getByText('Lease/Licence File');
await act(async () => userEvent.click(link));
expect(history.location.pathname).toBe('/mapview/sidebar/lease/new');
});

it('handles create disposition file action', async () => {
const { getByTestId, getByText } = setup({
layerPopup: {
latlng: undefined,
layers: [],
},
featureDataset: null,

claims: [Claims.DISPOSITION_ADD],
});
const ellipsis = getByTestId('fly-out-ellipsis');
await act(async () => userEvent.click(ellipsis));
const link = getByText('Disposition File');
await act(async () => userEvent.click(link));
expect(history.location.pathname).toBe('/mapview/sidebar/disposition/new');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const LayerPopupView: React.FC<React.PropsWithChildren<ILayerPopupViewPro
history.push(`/mapview/sidebar/non-inventory-property/pin/${parsedPin}`);
} else {
console.warn('Invalid marker when trying to see property information');
toast.warn('A map parcel must have a PID in order to view detailed information');
toast.warn('A map parcel must have a PID or PIN in order to view detailed information');
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
import { createMemoryHistory } from 'history';

import { IMapStateMachineContext } from '@/components/common/mapFSM/MapStateMachineContext';
import { Claims } from '@/constants/claims';
import { getMockCrownTenuresLayerResponse } from '@/mocks/crownTenuresLayerResponse.mock';
import { mockLookups } from '@/mocks/lookups.mock';
import { getMockLtsaResponse } from '@/mocks/ltsa.mock';
import { mapMachineBaseMock } from '@/mocks/mapFSM.mock';
import { lookupCodesSlice } from '@/store/slices/lookupCodes';
import { act, cleanup, render, RenderOptions, userEvent, waitFor } from '@/utils/test-utils';

import MotiInventoryContainer, { IMotiInventoryContainerProps } from './MotiInventoryContainer';
import { getMockCrownTenuresLayerResponse } from '@/mocks/crownTenuresLayerResponse.mock';
import { IMapStateMachineContext } from '@/components/common/mapFSM/MapStateMachineContext';
import { mapMachineBaseMock } from '@/mocks/mapFSM.mock';

const mockAxios = new MockAdapter(axios);
const history = createMemoryHistory();
Expand Down Expand Up @@ -199,7 +199,7 @@ describe('MotiInventoryContainer component', () => {
});

it('hides the property information tab for non-inventory properties', async () => {
history.push('/mapview/sidebar/non-inventory-property/9212434');
history.push('/mapview/sidebar/non-inventory-property/pid/9212434');
// non-inventory properties will not attempt to contact the backend.
const error = {
isAxiosError: true,
Expand Down

0 comments on commit 1bb044e

Please sign in to comment.