Skip to content

Commit

Permalink
10293: modify naming and organization of pending report-related compu…
Browse files Browse the repository at this point in the history
…teds
  • Loading branch information
akuny committed Dec 10, 2024
1 parent dd63874 commit 2e96cf5
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 60 deletions.
16 changes: 0 additions & 16 deletions shared/src/business/utilities/formatPendingItem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,6 @@ describe('formatPendingItem', () => {
]);
});

it('should return a list of formatted pending items with unique renderKey properties for each item', () => {
const result = mockPendingItems.map(item =>
formatPendingItem(item, {
applicationContext,
}),
);

const allPendingItemFormattedObjectsHaveRenderKey = result.every(
obj => typeof obj.renderKey === 'string',
);
const uniqueRenderKeys = new Set(result.map(obj => obj.renderKey));

expect(allPendingItemFormattedObjectsHaveRenderKey).toBe(true);
expect(uniqueRenderKeys.size).toBe(result.length);
});

it('should add consolidated properties to a pending item in a consolidated group', () => {
pendingItem.leadDocketNumber = '100-19';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,16 @@
import { applicationContextForClient as applicationContext } from '@web-client/test/createClientTestApplicationContext';
import { cloneDeep } from 'lodash';
import { formattedPendingItemsHelper as formattedPendingItemsComputed } from './formattedPendingItems';
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('formattedPendingItems', () => {
const { CHIEF_JUDGE } = applicationContext.getConstants();

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

const pendingReportsState = cloneDeep(initialPendingReportsState);

it('should return formatted and sorted list of judges', () => {
const result = runCompute(formattedPendingItems, {
state: {
judges: [{ name: 'Judge A' }, { name: 'Judge B' }],
pendingReports: pendingReportsState,
},
});

expect(result.judges).toEqual(['A', 'B', CHIEF_JUDGE]);
});

it('appends screenMetadata.pendingItemsFilters.judge on the printUrl if one is present', () => {
const result = runCompute(formattedPendingItems, {
const result = runCompute(pendingReportHelper, {
state: {
judges: [],
pendingReports: pendingReportsState,
Expand All @@ -38,7 +22,7 @@ describe('formattedPendingItems', () => {
});

it('returns default printUrl if screenMetadata.pendingItemsFilters.judge is not set', () => {
const result = runCompute(formattedPendingItems, {
const result = runCompute(pendingReportHelper, {
state: {
judges: [],
pendingReports: pendingReportsState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,15 @@ import { Get } from 'cerebral';
import { state } from '@web-client/presenter/app.cerebral';
import qs from 'qs';

export const formattedPendingItemsHelper = (
export const pendingReportHelper = (
get: Get,
applicationContext: IApplicationContext,
): {
printUrl: string;
judges: string[];
} => {
const { CHIEF_JUDGE } = applicationContext.getConstants();

const judgeFilter = get(state.screenMetadata.pendingItemsFilters.judge);
const judges = get(state.judges)
.map(i => applicationContext.getUtilities().formatJudgeName(i.name))
.concat(CHIEF_JUDGE)
.sort();

const queryString = qs.stringify({ judgeFilter });

return {
judges,
printUrl: `/reports/pending-report/printable?${queryString}`,
};
};
26 changes: 22 additions & 4 deletions web-client/src/presenter/computeds/pendingReportListHelper.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { CHIEF_JUDGE } from '@shared/business/entities/EntityConstants';
import { applicationContext } from '../../applicationContext';
import { cloneDeep } from 'lodash';
import { initialPendingReportsState } from '../state/pendingReportState';
import { pendingReportListHelper } from './pendingReportListHelper';
import { runCompute } from '@web-client/presenter/test.cerebral';
import { withAppContextDecorator } from '../../withAppContext';
Expand All @@ -9,8 +12,9 @@ describe('pendingReportListHelper', () => {
applicationContext,
);

it('should set showNoPendingItems to false when a judge is selected but no results come back', () => {
it('should return showNoPendingItems as false when a judge is selected but no results come back', () => {
const mockState = {
judges: [],
pendingReports: {
hasPendingItemsResults: false,
pendingItems: [{}],
Expand All @@ -25,8 +29,9 @@ describe('pendingReportListHelper', () => {
expect(showNoPendingItems).toBe(true);
});

it('should set showNoPendingItems to false when results come back and a judge is selected', () => {
it('should return showNoPendingItems as false when results come back and a judge is selected', () => {
const mockState = {
judges: [],
pendingReports: {
hasPendingItemsResults: true,
pendingItems: [{}],
Expand All @@ -41,8 +46,9 @@ describe('pendingReportListHelper', () => {
expect(showNoPendingItems).toBe(false);
});

it('should set showSelectJudgeText to true when no judge selected', () => {
it('should return showSelectJudgeText as true when no judge selected', () => {
const mockState = {
judges: [],
pendingReports: {
hasPendingItemsResults: true,
pendingItems: [{}],
Expand All @@ -57,8 +63,9 @@ describe('pendingReportListHelper', () => {
expect(showSelectJudgeText).toBe(true);
});

it('should set showSelectJudgeText to false when a judge is selected', () => {
it('should return showSelectJudgeText as false when a judge is selected', () => {
const mockState = {
judges: [],
pendingReports: {
hasPendingItemsResults: true,
pendingItems: [{}],
Expand All @@ -72,4 +79,15 @@ describe('pendingReportListHelper', () => {
});
expect(showSelectJudgeText).toBe(false);
});

it('should return a formatted and sorted list of judges', () => {
const mockState = {
judges: [{ name: 'Judge A' }, { name: 'Judge B' }],
pendingReports: cloneDeep(initialPendingReportsState),
};

const { judges } = runCompute(pendingReportList, { state: mockState });

expect(judges).toEqual(['A', 'B', CHIEF_JUDGE]);
});
});
9 changes: 9 additions & 0 deletions web-client/src/presenter/computeds/pendingReportListHelper.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { CHIEF_JUDGE } from '@shared/business/entities/EntityConstants';
import { Get } from 'cerebral';
import { formatJudgeName } from '@shared/business/utilities/getFormattedJudgeName';
import { state } from '@web-client/presenter/app.cerebral';

export const pendingReportListHelper = (
get: Get,
): {
showNoPendingItems: boolean;
showSelectJudgeText: boolean;
judges: string[];
} => {
const searchResultsCount = get(state.pendingReports.pendingItemsTotal);
const hasPendingItemsResults = get(
Expand All @@ -17,7 +20,13 @@ export const pendingReportListHelper = (
const showNoPendingItems =
searchResultsCount === 0 && !hasPendingItemsResults && !!judge;

const judges = get(state.judges)
.map(i => formatJudgeName(i.name))
.concat(CHIEF_JUDGE)
.sort();

return {
judges,
showNoPendingItems,
showSelectJudgeText,
};
Expand Down
9 changes: 4 additions & 5 deletions web-client/src/presenter/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ import { formattedDocument } from './computeds/formattedDocument';
import { formattedEligibleCasesHelper } from './computeds/formattedEligibleCasesHelper';
import { formattedMessageDetail } from './computeds/formattedMessageDetail';
import { formattedMessages } from './computeds/formattedMessages';
import { formattedPendingItemsHelper } from './computeds/formattedPendingItems';
import { formattedTrialSessionDetails } from './computeds/formattedTrialSessionDetails';
import { formattedWorkQueue } from './computeds/formattedWorkQueue';
import { getAllIrsPractitionersForSelectHelper } from '@web-client/presenter/computeds/TrialSession/getAllIrsPractitionersForSelectHelper';
Expand Down Expand Up @@ -120,6 +119,7 @@ import { partiesInformationHelper } from './computeds/partiesInformationHelper';
import { pdfPreviewModalHelper } from './computeds/PDFPreviewModal/pdfPreviewModalHelper';
import { pdfSignerHelper } from './computeds/pdfSignerHelper';
import { pendingMotionsHelper } from '@web-client/presenter/computeds/PendingMotions/pendingMotionsHelper';
import { pendingReportHelper } from './computeds/pendingReportHelper';
import { pendingReportListHelper } from './computeds/pendingReportListHelper';
import { petitionQcHelper } from './computeds/petitionQcHelper';
import { practitionerDetailHelper } from './computeds/practitionerDetailHelper';
Expand Down Expand Up @@ -378,10 +378,6 @@ export const computeds = {
formattedOpenCases: formattedOpenCases as unknown as ReturnType<
typeof formattedOpenCases
>,
formattedPendingItemsHelper:
formattedPendingItemsHelper as unknown as ReturnType<
typeof formattedPendingItemsHelper
>,
formattedTrialSessionDetails:
formattedTrialSessionDetails as unknown as ReturnType<
typeof formattedTrialSessionDetails
Expand Down Expand Up @@ -450,6 +446,9 @@ export const computeds = {
pendingMotionsHelper: pendingMotionsHelper as unknown as ReturnType<
typeof pendingMotionsHelper
>,
pendingReportHelper: pendingReportHelper as unknown as ReturnType<
typeof pendingReportHelper
>,
pendingReportListHelper: pendingReportListHelper as unknown as ReturnType<
typeof pendingReportListHelper
>,
Expand Down
6 changes: 3 additions & 3 deletions web-client/src/views/PendingReport/PendingReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import React, { useState } from 'react';
export const PendingReport = connect(
{
exportPendingReportSequence: sequences.exportPendingReportSequence,
formattedPendingItemsHelper: state.formattedPendingItemsHelper,
hasPendingItemsResults: state.pendingReports.hasPendingItemsResults,
pendingReportHelper: state.pendingReportHelper,
},
function PendingReport({
exportPendingReportSequence,
formattedPendingItemsHelper,
hasPendingItemsResults,
pendingReportHelper,
}) {
const [isSubmitDebounced, setIsSubmitDebounced] = useState(false);

Expand Down Expand Up @@ -61,7 +61,7 @@ export const PendingReport = connect(
aria-label="print pending report"
className="margin-top-2"
data-testid="print-pending-report"
href={formattedPendingItemsHelper.printUrl}
href={pendingReportHelper.printUrl}
icon="print"
>
Printable Report
Expand Down

0 comments on commit 2e96cf5

Please sign in to comment.