-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
22874b1
commit 93697c0
Showing
9 changed files
with
354 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...ontend/src/components/maps/leaflet/Control/AdvancedFilter/FilterContentContainer.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { FormikProps } from 'formik'; | ||
import { createMemoryHistory } from 'history'; | ||
import { forwardRef } from 'react'; | ||
|
||
import { useMapStateMachine } from '@/components/common/mapFSM/MapStateMachineContext'; | ||
import { mockLookups } from '@/mocks/lookups.mock'; | ||
import { mapMachineBaseMock } from '@/mocks/mapFSM.mock'; | ||
import { getMockApiPropertyManagement } from '@/mocks/propertyManagement.mock'; | ||
import { lookupCodesSlice } from '@/store/slices/lookupCodes'; | ||
import { render, RenderOptions, waitFor } from '@/utils/test-utils'; | ||
|
||
import { FilterContentContainer, IFilterContentContainerProps } from './FilterContentContainer'; | ||
import { IFilterContentFormProps } from './FilterContentForm'; | ||
import { PropertyFilterFormModel } from './models'; | ||
|
||
const history = createMemoryHistory(); | ||
const storeState = { | ||
[lookupCodesSlice.name]: { lookupCodes: mockLookups }, | ||
}; | ||
|
||
const mockGetApi = { | ||
error: undefined, | ||
response: [1] as number[] | undefined, | ||
execute: jest.fn().mockResolvedValue([1]), | ||
loading: false, | ||
}; | ||
jest.mock('@/components/common/mapFSM/MapStateMachineContext'); | ||
jest.mock('@/hooks/repositories/usePimsPropertyRepository', () => ({ | ||
usePimsPropertyRepository: () => { | ||
return { | ||
getMatchingProperties: mockGetApi, | ||
}; | ||
}, | ||
})); | ||
|
||
describe('FilterContentContainer component', () => { | ||
let viewProps: IFilterContentFormProps; | ||
|
||
const View = forwardRef<FormikProps<any>, IFilterContentFormProps>((props, ref) => { | ||
viewProps = props; | ||
return <></>; | ||
}); | ||
|
||
const setup = ( | ||
renderOptions?: RenderOptions & { props?: Partial<IFilterContentContainerProps> }, | ||
) => { | ||
renderOptions = renderOptions ?? {}; | ||
const utils = render(<FilterContentContainer {...renderOptions.props} View={View} />, { | ||
...renderOptions, | ||
store: storeState, | ||
history, | ||
}); | ||
|
||
return { | ||
...utils, | ||
}; | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
(useMapStateMachine as jest.Mock).mockImplementation(() => mapMachineBaseMock); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('fetches filter data from the api', async () => { | ||
mockGetApi.execute.mockResolvedValue(getMockApiPropertyManagement(1)); | ||
setup({}); | ||
viewProps.onChange(new PropertyFilterFormModel()); | ||
expect(mockGetApi.execute).toBeCalledWith(new PropertyFilterFormModel().toApi()); | ||
await waitFor(() => | ||
expect(mapMachineBaseMock.setVisiblePimsProperties).toBeCalledWith({ | ||
additionalDetails: 'test', | ||
id: 1, | ||
isLeaseActive: false, | ||
isLeaseExpired: false, | ||
isTaxesPayable: null, | ||
isUtilitiesPayable: null, | ||
leaseExpiryDate: null, | ||
managementPurposes: [], | ||
rowVersion: 1, | ||
}), | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...ce/frontend/src/components/maps/leaflet/Control/AdvancedFilter/FilterContentForm.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { createMemoryHistory } from 'history'; | ||
|
||
import { mockLookups } from '@/mocks/lookups.mock'; | ||
import { getMockApiPropertyManagement } from '@/mocks/propertyManagement.mock'; | ||
import { Api_PropertyManagement } from '@/models/api/Property'; | ||
import { lookupCodesSlice } from '@/store/slices/lookupCodes'; | ||
import { act, render, RenderOptions, userEvent } from '@/utils/test-utils'; | ||
|
||
import { FilterContentForm, IFilterContentFormProps } from './FilterContentForm'; | ||
|
||
const history = createMemoryHistory(); | ||
const storeState = { | ||
[lookupCodesSlice.name]: { lookupCodes: mockLookups }, | ||
}; | ||
|
||
const mockGetApi = { | ||
error: undefined, | ||
response: undefined as Api_PropertyManagement | undefined, | ||
execute: jest.fn(), | ||
loading: false, | ||
}; | ||
|
||
jest.mock('@/hooks/repositories/usePropertyManagementRepository', () => ({ | ||
usePropertyManagementRepository: () => { | ||
return { | ||
getPropertyManagement: mockGetApi, | ||
}; | ||
}, | ||
})); | ||
|
||
describe('FilterContentForm component', () => { | ||
const onChange = jest.fn(); | ||
|
||
const setup = (renderOptions: RenderOptions & { props: IFilterContentFormProps }) => { | ||
renderOptions = renderOptions ?? ({} as any); | ||
const utils = render(<FilterContentForm {...renderOptions.props} />, { | ||
...renderOptions, | ||
store: storeState, | ||
history, | ||
}); | ||
|
||
return { | ||
...utils, | ||
}; | ||
}; | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('shows loading spinner when loading', () => { | ||
mockGetApi.execute.mockResolvedValue(getMockApiPropertyManagement(1)); | ||
const { getByTestId } = setup({ props: { onChange, isLoading: true } }); | ||
expect(getByTestId('filter-backdrop-loading')).toBeVisible(); | ||
}); | ||
|
||
it('displays filters when not loading', async () => { | ||
const apiManagement = getMockApiPropertyManagement(1); | ||
mockGetApi.response = apiManagement; | ||
const { getByDisplayValue } = setup({ props: { onChange, isLoading: false } }); | ||
expect(getByDisplayValue('Select a highway')).toBeVisible(); | ||
expect(getByDisplayValue('Select Lease Transaction')).toBeVisible(); | ||
}); | ||
|
||
it('calls onChange when a filter is changed', async () => { | ||
const apiManagement = getMockApiPropertyManagement(1); | ||
mockGetApi.response = apiManagement; | ||
const { getByTestId } = setup({ props: { onChange, isLoading: false } }); | ||
await act(async () => { | ||
userEvent.selectOptions(getByTestId('leasePayRcvblType'), ['all']); | ||
expect(onChange).toBeCalled(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.