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

10293 to test: use unique React key in PendingReportList.tsx #5630

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
2 changes: 1 addition & 1 deletion shared/src/business/utilities/formatPendingItem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('formatPendingItem', () => {
];
});

it('should return a list of formatted pending items', () => {
it('should return a list of formatted pending items with correct display properties', () => {
const result = mockPendingItems.map(item =>
formatPendingItem(item, {
applicationContext,
Expand Down
4 changes: 3 additions & 1 deletion shared/src/business/utilities/formatPendingItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ export type PendingItemFormatted = {
shouldIndent: boolean;
isLeadCase: boolean;
docketNumberWithSuffix: string;
receivedAt: string;
};

export const formatPendingItem = (
item: PendingItem,
{ applicationContext }: { applicationContext: IApplicationContext },
{ applicationContext },
): PendingItemFormatted => {
const pendingItemWithConsolidatedFlags = applicationContext
.getUtilities()
Expand Down Expand Up @@ -62,6 +63,7 @@ export const formatPendingItem = (
formattedStatus,
inConsolidatedGroup: pendingItemWithConsolidatedFlags.inConsolidatedGroup,
isLeadCase: pendingItemWithConsolidatedFlags.isLeadCase,
receivedAt: item.receivedAt,
shouldIndent: pendingItemWithConsolidatedFlags.shouldIndent,
};
};
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { advancedDocumentSearchHelper as advancedDocumentSearchComputed } from '../src/presenter/computeds/AdvancedSearch/advancedDocumentSearchHelper';
import { caseDeadlineReportHelper as caseDeadlineReportComputed } from '../src/presenter/computeds/caseDeadlineReportHelper';
import { caseInventoryReportHelper as caseInventoryReportComputed } from '../src/presenter/computeds/caseInventoryReportHelper';
import { formattedPendingItemsHelper as formattedPendingItemsComputed } from '../src/presenter/computeds/formattedPendingItems';
import { loginAs, setupTest } from './helpers';
import { messageModalHelper as messageModalHelperComputed } from '../src/presenter/computeds/messageModalHelper';
import { pendingReportListHelper as pendingReportListComputed } from '../src/presenter/computeds/pendingReportListHelper';
import { runCompute } from '@web-client/presenter/test.cerebral';
import { withAppContextDecorator } from '../src/withAppContext';

Expand Down Expand Up @@ -58,15 +58,15 @@ describe('Petitions clerk verifies offboarded judge journey', () => {
});

it(`petitions clerk verifies judge ${judgeName} does not appear in the pending report judge dropdown`, () => {
const formattedPendingItems = withAppContextDecorator(
formattedPendingItemsComputed,
const pendingReportList = withAppContextDecorator(
pendingReportListComputed,
);

const formattedPendingItemsHelper = runCompute(formattedPendingItems, {
const pendingReportListHelper = runCompute(pendingReportList, {
state: cerebralTest.getState(),
});

expect(formattedPendingItemsHelper.judges).not.toContain(judgeName);
expect(pendingReportListHelper.judges).not.toContain(judgeName);
});

it(`petitions clerk verifies judge ${judgeName} does not appear in the add trial session judge drop down`, async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
import { applicationContextForClient as applicationContext } from '@web-client/test/createClientTestApplicationContext';
import { presenter } from '@web-client/presenter/presenter-mock';
import { runAction } from '@web-client/presenter/test.cerebral';
import { setPendingItemsAction } from './setPendingItemsAction';

describe('setPendingItemsAction', () => {
beforeAll(() => {
presenter.providers.applicationContext = applicationContext;
});

it('sets state.pendingReports.pendingItems to the passed in props.pendingItems', async () => {
applicationContext.getUtilities().formatPendingItem.mockReturnValue({});

const { state } = await runAction(setPendingItemsAction, {
modules: { presenter },
props: {
pendingItems: ['DocketRecord'],
pendingItems: [{}],
},
state: {
pendingReports: {
pendingItems: [],
},
},
});
expect(state.pendingReports.pendingItems).toEqual(['DocketRecord']);

expect(state.pendingReports.pendingItems).toEqual([{}]);
});

it('sets state.pendingReports.hasPendingItemsResults to true when state.pendingReports.pendingItems contains items', async () => {
it('sets state.pendingReports.pendingItems to the passed in props.pendingItems and replaces any items that were previously stored in state.pendingReport.pendingItems', async () => {
applicationContext.getUtilities().formatPendingItem.mockReturnValue({});

const { state } = await runAction(setPendingItemsAction, {
modules: { presenter },
props: {
pendingItems: ['DocketRecord'],
pendingItems: [{}],
},
state: {
pendingReports: {
Expand All @@ -28,13 +41,14 @@ describe('setPendingItemsAction', () => {
},
});

expect(state.pendingReports.hasPendingItemsResults).toBe(true);
expect(state.pendingReports.pendingItems).toEqual([{}]);
});

it('sets state.pendingReports.hasPendingItemsResults to true when props.pendingItems contains items', async () => {
const { state } = await runAction(setPendingItemsAction, {
modules: { presenter },
props: {
pendingItems: ['DocketRecord'],
pendingItems: [{}],
},
state: {
pendingReports: {
Expand All @@ -47,6 +61,7 @@ describe('setPendingItemsAction', () => {

it('sets state.pendingReports.hasPendingItemsResults to false when neither props.pendingItems nor state.pendingReports.pendingItems contain items', async () => {
const { state } = await runAction(setPendingItemsAction, {
modules: { presenter },
props: {
pendingItems: [],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,25 @@ import { PendingItem } from '@web-api/business/useCases/pendingItems/fetchPendin
import { state } from '@web-client/presenter/app.cerebral';

export const setPendingItemsAction = ({
get,
applicationContext,

props,
store,
}: ActionProps<{ pendingItems: PendingItem[]; total: number }>) => {
const pendingItems = [
...get(state.pendingReports.pendingItems),
...props.pendingItems,
];
store.set(state.pendingReports.pendingItems, pendingItems);
store.set(state.pendingReports.hasPendingItemsResults, !!pendingItems.length);
store.set(state.pendingReports.pendingItemsTotal, pendingItems.length);
}: ActionProps<{ pendingItems: PendingItem[] }>) => {
const { pendingItems } = props;
const formattedPendingItems = pendingItems.map(item =>
applicationContext
.getUtilities()
.formatPendingItem(item, { applicationContext }),
);

store.set(state.pendingReports.pendingItems, formattedPendingItems);
store.set(
state.pendingReports.hasPendingItemsResults,
!!formattedPendingItems.length,
);
store.set(
state.pendingReports.pendingItemsTotal,
formattedPendingItems.length,
);
};
99 changes: 0 additions & 99 deletions web-client/src/presenter/computeds/formattedPendingItems.test.ts

This file was deleted.

34 changes: 0 additions & 34 deletions web-client/src/presenter/computeds/formattedPendingItems.ts

This file was deleted.

35 changes: 35 additions & 0 deletions web-client/src/presenter/computeds/pendingReportHelper.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { cloneDeep } from 'lodash';
import { initialPendingReportsState } from '@web-client/presenter/state/pendingReportState';
import { pendingReportHelper as pendingReportComputed } from './pendingReportHelper';
import { runCompute } from '@web-client/presenter/test.cerebral';
import { withAppContextDecorator } from '../../withAppContext';

describe('pendingReportHelper', () => {
const pendingReportHelper = withAppContextDecorator(pendingReportComputed);

const pendingReportsState = cloneDeep(initialPendingReportsState);

it('appends screenMetadata.pendingItemsFilters.judge on the printUrl if one is present', () => {
const result = runCompute(pendingReportHelper, {
state: {
judges: [],
pendingReports: pendingReportsState,
screenMetadata: { pendingItemsFilters: { judge: 'Judge Somebody' } },
},
});

expect(result.printUrl).toContain('Judge%20Somebody');
});

it('returns default printUrl if screenMetadata.pendingItemsFilters.judge is not set', () => {
const result = runCompute(pendingReportHelper, {
state: {
judges: [],
pendingReports: pendingReportsState,
screenMetadata: { pendingItemsFilters: {} },
},
});

expect(result.printUrl).toEqual('/reports/pending-report/printable?');
});
});
16 changes: 16 additions & 0 deletions web-client/src/presenter/computeds/pendingReportHelper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Get } from 'cerebral';
import { state } from '@web-client/presenter/app.cerebral';
import qs from 'qs';

export const pendingReportHelper = (
get: Get,
): {
printUrl: string;
} => {
const judgeFilter = get(state.screenMetadata.pendingItemsFilters.judge);
const queryString = qs.stringify({ judgeFilter });

return {
printUrl: `/reports/pending-report/printable?${queryString}`,
};
};
Loading
Loading