diff --git a/shared/src/business/utilities/formatPendingItem.test.ts b/shared/src/business/utilities/formatPendingItem.test.ts index 193958f8da7..477d22d97c5 100644 --- a/shared/src/business/utilities/formatPendingItem.test.ts +++ b/shared/src/business/utilities/formatPendingItem.test.ts @@ -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'; diff --git a/web-client/src/presenter/computeds/formattedPendingItems.test.ts b/web-client/src/presenter/computeds/pendingReportHelper.test.ts similarity index 53% rename from web-client/src/presenter/computeds/formattedPendingItems.test.ts rename to web-client/src/presenter/computeds/pendingReportHelper.test.ts index 1538f84bd9d..5196ace8c7d 100644 --- a/web-client/src/presenter/computeds/formattedPendingItems.test.ts +++ b/web-client/src/presenter/computeds/pendingReportHelper.test.ts @@ -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, @@ -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, diff --git a/web-client/src/presenter/computeds/formattedPendingItems.ts b/web-client/src/presenter/computeds/pendingReportHelper.ts similarity index 53% rename from web-client/src/presenter/computeds/formattedPendingItems.ts rename to web-client/src/presenter/computeds/pendingReportHelper.ts index 2b6b4ba795d..7761d3fb3ea 100644 --- a/web-client/src/presenter/computeds/formattedPendingItems.ts +++ b/web-client/src/presenter/computeds/pendingReportHelper.ts @@ -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}`, }; }; diff --git a/web-client/src/presenter/computeds/pendingReportListHelper.test.ts b/web-client/src/presenter/computeds/pendingReportListHelper.test.ts index ec2df238325..320a6b2cfcc 100644 --- a/web-client/src/presenter/computeds/pendingReportListHelper.test.ts +++ b/web-client/src/presenter/computeds/pendingReportListHelper.test.ts @@ -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'; @@ -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: [{}], @@ -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: [{}], @@ -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: [{}], @@ -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: [{}], @@ -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]); + }); }); diff --git a/web-client/src/presenter/computeds/pendingReportListHelper.ts b/web-client/src/presenter/computeds/pendingReportListHelper.ts index 71b95706af9..5b7eb09709d 100644 --- a/web-client/src/presenter/computeds/pendingReportListHelper.ts +++ b/web-client/src/presenter/computeds/pendingReportListHelper.ts @@ -1,4 +1,6 @@ +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 = ( @@ -6,6 +8,7 @@ export const pendingReportListHelper = ( ): { showNoPendingItems: boolean; showSelectJudgeText: boolean; + judges: string[]; } => { const searchResultsCount = get(state.pendingReports.pendingItemsTotal); const hasPendingItemsResults = get( @@ -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, }; diff --git a/web-client/src/presenter/state.ts b/web-client/src/presenter/state.ts index 1b9d19948c9..458a4598806 100644 --- a/web-client/src/presenter/state.ts +++ b/web-client/src/presenter/state.ts @@ -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'; @@ -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'; @@ -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 @@ -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 >, diff --git a/web-client/src/views/PendingReport/PendingReport.tsx b/web-client/src/views/PendingReport/PendingReport.tsx index 39206d71532..f6cb07c1881 100644 --- a/web-client/src/views/PendingReport/PendingReport.tsx +++ b/web-client/src/views/PendingReport/PendingReport.tsx @@ -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); @@ -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