Skip to content

Commit

Permalink
test updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
devinleighsmith committed Mar 22, 2024
1 parent 5f62080 commit f18a247
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 9 deletions.
9 changes: 8 additions & 1 deletion source/frontend/src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ export const Table = <T extends IIdentifiedObject, TFilter extends object = obje
open?: boolean,
className?: string,
onClick?: (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => void,
id?: string | number,
) => {
const detailsClosedIcon =
props.detailsPanel && props.detailsPanel.icons?.closed ? (
Expand All @@ -576,7 +577,11 @@ export const Table = <T extends IIdentifiedObject, TFilter extends object = obje
tooltipId="expand-all-rows"
tooltip={open ? 'Collapse Row' : 'Expand Row'}
>
<div className={className + ' svg-btn'} onClick={onClick}>
<div
className={className + ' svg-btn'}
data-testid={`table-row-expander-${id}`}
onClick={onClick}
>
{open ? detailsOpenedIcon : detailsClosedIcon}
</div>
</TooltipWrapper>
Expand Down Expand Up @@ -660,6 +665,7 @@ export const Table = <T extends IIdentifiedObject, TFilter extends object = obje
props.detailsPanel && props.detailsPanel.checkExpanded(row.original, expandedRows),
'td expander',
e => handleExpandClick(e, row.original),
row.original.id ?? '',
)}
{props.canRowExpand && !props.canRowExpand(row) ? (
<div className="td">
Expand All @@ -677,6 +683,7 @@ export const Table = <T extends IIdentifiedObject, TFilter extends object = obje
props.detailsPanel && props.detailsPanel.checkExpanded(row.original, expandedRows),
'td expander',
e => handleExpandClick(e, row.original),
row.original.id ?? '',
)}
{row.cells.map((cell: CellWithProps<T>) => {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
waitFor,
prettyDOM,
waitForElementToBeRemoved,
getByTestId,
} from '@/utils/test-utils';

import { defaultFormLeaseTerm, FormLeaseTerm } from './models';
Expand Down Expand Up @@ -293,13 +294,15 @@ describe('TermsPaymentsContainer component', () => {
)),
);
const {
component: { findByText, getByText },
component: { findByText, getByText, findByTestId },
} = await setup({
claims: [Claims.LEASE_EDIT, Claims.LEASE_ADD],
initialValues: defaultLeaseWithTermsPayments,
});
mockAxios.onPost().reply(200, { id: 1 });

const expander = await findByTestId('table-row-expander-');
await act(async () => userEvent.click(expander));
const addButton = await findByText('Record a Payment');
await act(async () => {
userEvent.click(addButton);
Expand All @@ -318,13 +321,15 @@ describe('TermsPaymentsContainer component', () => {
)),
);
const {
component: { findAllByTitle, getByText, findByText },
component: { findAllByTitle, findByTestId, getByText, findByText },
} = await setup({
initialValues: defaultLeaseWithTermsPayments,
claims: [Claims.LEASE_EDIT, Claims.LEASE_ADD],
});
mockAxios.onPut().reply(200, { id: 1 });

const expander = await findByTestId('table-row-expander-');
await act(async () => userEvent.click(expander));
const editButton = await findAllByTitle('edit actual');
await act(async () => {
userEvent.click(editButton[0]);
Expand All @@ -342,13 +347,15 @@ describe('TermsPaymentsContainer component', () => {
)),
);
const {
component: { findAllByTitle, getByText, findByText },
component: { findAllByTitle, getByText, findByText, getByTestId },
} = await setup({
initialValues: defaultLeaseWithTermsPayments,
claims: [Claims.LEASE_EDIT],
});

await findByText('Jan 1, 2020');
await findByText('- Jan 1, 2020', { exact: false });
const expander = getByTestId('table-row-expander-');
await act(async () => userEvent.click(expander));

const deleteButton = (await findAllByTitle('delete actual'))[0];
await act(async () => userEvent.click(deleteButton));
Expand All @@ -363,13 +370,15 @@ describe('TermsPaymentsContainer component', () => {
)),
);
const {
component: { findAllByTitle, getByText, findByText },
component: { findAllByTitle, getByText, findByText, getByTestId },
} = await setup({
initialValues: defaultLeaseWithTermsPayments,
claims: [Claims.LEASE_EDIT],
});
mockAxios.onDelete().reply(200, { id: 1 });
await findByText('Jan 1, 2020');
await findByText('- Jan 1, 2020', { exact: false });
const expander = getByTestId('table-row-expander-');
await act(async () => userEvent.click(expander));

const deleteButton = (await findAllByTitle('delete actual'))[0];
await act(async () => userEvent.click(deleteButton));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,7 @@ exports[`TermsPaymentsContainer component renders as expected 1`] = `
>
<div
class="td expander svg-btn"
data-testid="table-row-expander-"
>
<svg
fill="currentColor"
Expand Down Expand Up @@ -1306,6 +1307,7 @@ exports[`TermsPaymentsContainer component renders with data as expected 1`] = `
>
<div
class="td expander svg-btn"
data-testid="table-row-expander-"
>
<svg
fill="currentColor"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,7 @@ exports[`TermsForm component renders with data as expected 1`] = `
>
<div
class="td expander svg-btn"
data-testid="table-row-expander-"
>
<svg
fill="currentColor"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export const OperationContainer: React.FunctionComponent<IOperationContainerProp
<View
subdivisionOperations={subdivisionOperations}
consolidationOperations={consolidationOperations}
loading={!propertyId || getPropertyOperations.loading}
loading={!exists(propertyId) || getPropertyOperations.loading}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const OperationFileAssociationsContainer: React.FunctionComponent<
data={typedOperationAssociations}
name="PropertyOperationAssociations"
loading={loading}
noRowsMessage="There are no files associated to the property."
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import { createMemoryHistory } from 'history';
import { Claims } from '@/constants/index';
import { render, RenderOptions } from '@/utils/test-utils';
import { usePropertyOperationRepository } from '@/hooks/repositories/usePropertyOperationRepository';
import { getEmptyPropertyOperation } from '@/mocks/propertyOperation.mock';
import { ApiGen_Concepts_PropertyOperation } from '@/models/api/generated/ApiGen_Concepts_PropertyOperation';
import { lookupCodesSlice } from '@/store/slices/lookupCodes';
import { mockLookups } from '@/mocks/lookups.mock';
import { usePimsPropertyRepository } from '@/hooks/repositories/usePimsPropertyRepository';
import { ApiGen_Concepts_Property } from '@/models/api/generated/ApiGen_Concepts_Property';
import { getEmptyProperty } from '@/models/defaultInitializers';
import { IOperationSectionViewProps } from './OperationSectionView';
import { IOperationContainerProps, OperationContainer } from './OperationContainer';
import { toTypeCode } from '@/utils/formUtils';
import { ApiGen_CodeTypes_PropertyOperationTypes } from '@/models/api/generated/ApiGen_CodeTypes_PropertyOperationTypes';
import OperationFileAssociationsContainer, {
IOperationFileAssociationsContainerProps,
} from './OperationFileAssocationsContainer';
import { PropertyOperationResult } from './OperationView';
import { usePropertyAssociations } from '@/hooks/repositories/usePropertyAssociations';
import { ApiGen_Concepts_Association } from '@/models/api/generated/ApiGen_Concepts_Association';
import { ApiGen_Concepts_PropertyAssociations } from '@/models/api/generated/ApiGen_Concepts_PropertyAssociations';
import { LeaseAndLicenses } from '@/components/layout';

const history = createMemoryHistory();
const storeState = {
[lookupCodesSlice.name]: { lookupCodes: mockLookups },
};

const mockGetPropertyAssociations = jest.fn<
Promise<ApiGen_Concepts_PropertyAssociations | undefined>,
any[]
>();
jest.mock('@/hooks/repositories/usePropertyAssociations');
(usePropertyAssociations as jest.Mock).mockReturnValue({
execute: mockGetPropertyAssociations,
response: {},
});

describe('OperationContainer component', () => {
const setup = (
renderOptions: RenderOptions & Partial<IOperationFileAssociationsContainerProps> = {
operation: { id: 1 } as unknown as PropertyOperationResult,
},
) => {
const component = render(
<OperationFileAssociationsContainer operation={renderOptions.operation} />,
{
...renderOptions,
store: storeState,
claims: [Claims.PROPERTY_VIEW],
history,
},
);

return { ...component };
};
beforeEach(() => {
mockGetPropertyAssociations.mockResolvedValue(undefined);
});

it('displays without error when no associations present', async () => {
mockGetPropertyAssociations.mockResolvedValue({
id: 1,
pid: '',
acquisitionAssociations: [],
researchAssociations: [],
dispositionAssociations: [],
leaseAssociations: [],
});
const { findByText } = setup();
await findByText('There are no files associated to the property.');
});

it('displays without error when all associations present', async () => {
(usePropertyAssociations as jest.Mock).mockReturnValue({
execute: mockGetPropertyAssociations,
response: {
id: 1,
pid: '',
acquisitionAssociations: [
{
...getEmptyAssociation(),
fileNumber: 'A-1',
},
],
researchAssociations: [
{
...getEmptyAssociation(),
fileNumber: 'R-1',
},
],
dispositionAssociations: [
{
...getEmptyAssociation(),
fileNumber: 'D-1',
},
],
leaseAssociations: [
{
...getEmptyAssociation(),
fileNumber: 'L-1',
},
],
},
});
const { findByText } = setup();
await findByText('A-1');
await findByText('R-1');
await findByText('D-1');
await findByText('L-1');
});
});

const getEmptyAssociation = () => ({
id: 1,
fileNumber: '1',
fileName: 'acq file',
createdBy: '',
createdByGuid: '',
createdDateTime: '',
status: 'Active',
});
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const OperationView: React.FunctionComponent<IOperationViewProps> = ({
}),
);

/** This is the payments subtable displayed for each term row. */
/** This is the operation association subtable displayed for each term row. */
const renderOperationAssociations = useDeepCompareMemo(
() => (row: PropertyOperationResult) => {
const matchingOperation = operationData.find(t => t.id === row.id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ exports[`Subdivision detail view matches snapshot 1`] = `
>
<div
class="td expander svg-btn"
data-testid="table-row-expander-2"
>
<svg
fill="currentColor"
Expand Down Expand Up @@ -302,6 +303,7 @@ exports[`Subdivision detail view matches snapshot 1`] = `
>
<div
class="td expander svg-btn"
data-testid="table-row-expander-1"
>
<svg
fill="currentColor"
Expand Down

0 comments on commit f18a247

Please sign in to comment.