Skip to content

Commit

Permalink
Merge pull request #5532 from flexion/10525-test
Browse files Browse the repository at this point in the history
10525: Full Spectrum Docket Sorting TO TEST
  • Loading branch information
cruzjone-flexion authored Nov 11, 2024
2 parents 8bfbf92 + b390d6d commit d8b60a8
Show file tree
Hide file tree
Showing 23 changed files with 589 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,25 @@ describe('Docket clerk views consolidated case', function () {
});

it('should persist the selected sort filter by navigating away from the tab', () => {
cy.get('select[name="docketRecordSort.111-19"]').should(
'have.value',
'byDate',
);
cy.get('select[name="docketRecordSort.111-19"]').select('Newest');
cy.get('[data-testid="descriptionDisplay-sortable-button"]')
.find('svg')
.invoke('attr', 'data-icon')
.should('equal', 'exchange-alt');

cy.get('[data-testid="descriptionDisplay-sortable-button"]').click();

cy.get('[data-testid="descriptionDisplay-sortable-button"]')
.find('svg')
.invoke('attr', 'data-icon')
.should('equal', 'long-arrow-alt-up');

cy.get('#tab-document-view').click();
cy.get('#tab-docket-sub-record').click();
cy.get('select[name="docketRecordSort.111-19"]').should(
'have.value',
'byDateDesc',
);

cy.get('[data-testid="descriptionDisplay-sortable-button"]')
.find('svg')
.invoke('attr', 'data-icon')
.should('equal', 'long-arrow-alt-up');
});

it('should persist the populated consolidated cases in the overview tab when petitioner counsel is added to parties', () => {
Expand Down
17 changes: 13 additions & 4 deletions shared/src/business/entities/EntityConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import courtIssuedEventCodesJson from '../../tools/courtIssuedEventCodes.json';
import externalFilingEventsJson from '../../tools/externalFilingEvents.json';
import internalFilingEventsJson from '../../tools/internalFilingEvents.json';

export const KEYS = {
DOCKET_RECORD_TABLE_SORT: 'DOCKET_RECORD_TABLE_SORT',
};

export const DEBOUNCE_TIME_MILLISECONDS = 500;

interface FilingEvent {
Expand Down Expand Up @@ -1654,10 +1658,15 @@ export const DOCKET_ENTRY_SEALED_TO_TYPES = {
export const ASCENDING: 'asc' = 'asc';
export const DESCENDING: 'desc' = 'desc';

export const CHRONOLOGICALLY_ASCENDING = 'Oldest to newest';
export const CHRONOLOGICALLY_DESCENDING = 'Newest to oldest';
export const ALPHABETICALLY_ASCENDING = 'In A-Z ascending order';
export const ALPHABETICALLY_DESCENDING = 'In Z-A descending order';
export const SORT_ASCENDING_TEXT = {
date: 'Oldest to newest',
string: 'In A-Z ascending order',
};

export const SORT_DESCENDING_TEXT = {
date: 'Newest to oldest',
string: 'In Z-A descending order',
};

export const PRACTITIONER_DOCUMENT_TYPES_MAP = {
APPLICATION_PACKAGE: 'Application Package',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,4 +310,24 @@ describe('formatDocketEntry', () => {
},
);
});

describe('sortingFilingDate', () => {
it('should set the property "sortingFilingDate" correctly using filingDate', () => {
const result = formatDocketEntry(applicationContext, {
createdAt: '2020-03-01T21:40:46.415Z',
filingDate: '2019-03-01T21:40:46.415Z',
isOnDocketRecord: true,
isUnservable: true,
});
expect(result.sortingFilingDate).toEqual('20190301');
});
it('should set the property "sortingFilingDate" correctly using createdAt', () => {
const result = formatDocketEntry(applicationContext, {
createdAt: '2020-03-01T21:40:46.415Z',
filingDate: '2019-03-01T21:40:46.415Z',
isOnDocketRecord: false,
});
expect(result.sortingFilingDate).toEqual('20200301');
});
});
});
6 changes: 6 additions & 0 deletions shared/src/business/utilities/getFormattedCaseDetail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,16 @@ export const formatDocketEntry = (applicationContext, docketEntry) => {
formattedEntry.createdAtFormatted = applicationContext
.getUtilities()
.formatDateString(formattedEntry.filingDate, 'MMDDYY');
formattedEntry.sortingFilingDate = applicationContext
.getUtilities()
.formatDateString(formattedEntry.filingDate, 'YYYYMMDD_NUMERIC');
} else {
formattedEntry.createdAtFormatted = applicationContext
.getUtilities()
.formatDateString(formattedEntry.createdAt, 'MMDDYY');
formattedEntry.sortingFilingDate = applicationContext
.getUtilities()
.formatDateString(formattedEntry.createdAt, 'YYYYMMDD_NUMERIC');
}

formattedEntry.filingsAndProceedings =
Expand Down
2 changes: 2 additions & 0 deletions shared/src/proxies/generateDocketRecordPdfProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const generateDocketRecordPdfInteractor = (
{
docketNumber,
docketRecordSort,
docketRecordTableSort,
includePartyDetail,
isIndirectlyAssociated,
},
Expand All @@ -22,6 +23,7 @@ export const generateDocketRecordPdfInteractor = (
body: {
docketNumber,
docketRecordSort,
docketRecordTableSort,
includePartyDetail,
isIndirectlyAssociated,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,82 @@ describe('generateDocketRecordPdfInteractor', () => {

expect(result).toEqual(mockPdfUrlAndID);
});

describe('sorting', () => {
it('should pass in entries sorted by the provided property and orderType "asc"', async () => {
caseDetail.docketEntries = [
{
eventCode: 'D',
isOnDocketRecord: true,
},
{ eventCode: 'B', isOnDocketRecord: true },
{ eventCode: 'C', isOnDocketRecord: true },
{ eventCode: 'A', isOnDocketRecord: true },
];

await generateDocketRecordPdfInteractor(
applicationContext,
{
docketNumber: caseDetail.docketNumber,
docketRecordTableSort: { sortField: 'eventCode', sortOrder: 'asc' },
isIndirectlyAssociated: true,
} as any,
mockPetitionerUser,
);

const docketRecordCalls =
applicationContext.getDocumentGenerators().docketRecord.mock.calls;
expect(docketRecordCalls.length).toEqual(1);

const {
data: { entries },
} = docketRecordCalls[0][0];
expect(entries).toMatchObject([
{
eventCode: 'A',
},
{ eventCode: 'B' },
{ eventCode: 'C' },
{ eventCode: 'D' },
]);
});

it('should pass in entries sorted by the provided property and orderType "des"', async () => {
caseDetail.docketEntries = [
{
eventCode: 'D',
isOnDocketRecord: true,
},
{ eventCode: 'B', isOnDocketRecord: true },
{ eventCode: 'C', isOnDocketRecord: true },
{ eventCode: 'A', isOnDocketRecord: true },
];

await generateDocketRecordPdfInteractor(
applicationContext,
{
docketNumber: caseDetail.docketNumber,
docketRecordTableSort: { sortField: 'eventCode', sortOrder: 'desc' },
isIndirectlyAssociated: true,
} as any,
mockPetitionerUser,
);

const docketRecordCalls =
applicationContext.getDocumentGenerators().docketRecord.mock.calls;
expect(docketRecordCalls.length).toEqual(1);

const {
data: { entries },
} = docketRecordCalls[0][0];
expect(entries).toMatchObject([
{ eventCode: 'D' },
{ eventCode: 'C' },
{ eventCode: 'B' },
{
eventCode: 'A',
},
]);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@ import { ServerApplicationContext } from '@web-api/applicationContext';
import { UnauthorizedError } from '@web-api/errors/errors';
import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser';
import { getCaseCaptionMeta } from '../../../../shared/src/business/utilities/getCaseCaptionMeta';
import { sortDocketEntryTable } from '@web-client/presenter/computeds/formattedDocketEntries';

export const generateDocketRecordPdfInteractor = async (
applicationContext: ServerApplicationContext,
{
docketNumber,
docketRecordSort,
docketRecordTableSort,
includePartyDetail = false,
isIndirectlyAssociated = false,
}: {
docketNumber: string;
docketRecordSort?: string;
docketRecordTableSort?: { sortField: string; sortOrder: string };
includePartyDetail: boolean;
isIndirectlyAssociated?: boolean;
},
Expand Down Expand Up @@ -71,7 +74,6 @@ export const generateDocketRecordPdfInteractor = async (
} else {
caseEntity = new Case(caseSource, { authorizedUser });
}

const formattedCaseDetail = applicationContext
.getUtilities()
.getFormattedCaseDetail({
Expand All @@ -81,6 +83,14 @@ export const generateDocketRecordPdfInteractor = async (
docketRecordSort,
});

const sortedDocketEntries = sortDocketEntryTable(
formattedCaseDetail.docketEntries,
docketRecordTableSort && docketRecordTableSort.sortField,
docketRecordTableSort && docketRecordTableSort.sortOrder,
);

formattedCaseDetail.formattedDocketEntries = sortedDocketEntries;

formattedCaseDetail.petitioners.forEach(petitioner => {
petitioner.counselDetails = [];

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { clearDocketRecordTableSortAction } from '@web-client/presenter/actions/clearDocketRecordTableSortAction';
import { runAction } from '@web-client/presenter/test.cerebral';

describe('clearDocketRecordTableSortAction', () => {
it('should clear docket record table sort', async () => {
const { state } = await runAction(clearDocketRecordTableSortAction, {
state: {
DOCKET_RECORD_TABLE_SORT: {
sortField: 'TEST_sortField',
sortOrder: 'TEST_sortOrder',
},
},
});

expect(state['DOCKET_RECORD_TABLE_SORT'].sortField).toEqual(undefined);
expect(state['DOCKET_RECORD_TABLE_SORT'].sortOrder).toEqual(undefined);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { KEYS } from '@shared/business/entities/EntityConstants';
import { state } from '@web-client/presenter/app.cerebral';

export const clearDocketRecordTableSortAction = ({ store }: ActionProps) => {
store.unset(state[KEYS.DOCKET_RECORD_TABLE_SORT].sortField);
store.unset(state[KEYS.DOCKET_RECORD_TABLE_SORT].sortOrder);
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { KEYS } from '@shared/business/entities/EntityConstants';
import { applicationContextForClient as applicationContext } from '@web-client/test/createClientTestApplicationContext';
import { generateDocketRecordPdfUrlAction } from './generateDocketRecordPdfUrlAction';
import { presenter } from '../presenter-mock';
Expand Down Expand Up @@ -105,4 +106,37 @@ describe('generateDocketRecordPdfUrlAction', () => {
isIndirectlyAssociated: false,
});
});

it('should call the interactor with the correct table sort information from state', async () => {
await runAction(generateDocketRecordPdfUrlAction, {
modules: {
presenter,
},
props: {
contentHtml:
'<!doctype html><html><head></head><body>Hello World</body></html>',
docketNumber: '123-45',
isAssociated: false,
},
state: {
caseDetail: {
docketNumber: '123-45',
},
[KEYS.DOCKET_RECORD_TABLE_SORT]: {
sortField: 'sortField_test',
sortOrder: 'sortOrder_test',
},
},
});

expect(
applicationContext.getUseCases().generateDocketRecordPdfInteractor.mock
.calls[0][1],
).toMatchObject({
docketRecordTableSort: {
sortField: 'sortField_test',
sortOrder: 'sortOrder_test',
},
});
});
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { KEYS } from '@shared/business/entities/EntityConstants';
import { state } from '@web-client/presenter/app.cerebral';
/**
* get the pdf file and pdf blob url from the passed in htmlString
Expand All @@ -15,6 +16,14 @@ export const generateDocketRecordPdfUrlAction = async ({
const docketRecordSort = get(
state.sessionMetadata.docketRecordSort[caseDetail.docketNumber],
);

const docketRecordSortField = get(
state[KEYS.DOCKET_RECORD_TABLE_SORT].sortField,
);
const docketRecordSortOrder = get(
state[KEYS.DOCKET_RECORD_TABLE_SORT].sortOrder,
);

const { isAssociated } = props;

let includePartyDetail = false;
Expand All @@ -29,6 +38,10 @@ export const generateDocketRecordPdfUrlAction = async ({
.generateDocketRecordPdfInteractor(applicationContext, {
docketNumber: caseDetail.docketNumber,
docketRecordSort,
docketRecordTableSort: {
sortField: docketRecordSortField,
sortOrder: docketRecordSortOrder,
},
includePartyDetail,
isIndirectlyAssociated,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,22 @@ describe('setTableSortConfigurationAction', () => {
sortOrder: ASCENDING,
});
});

it('should set the field to sort and the sort order in the correct root', async () => {
const TEST_ROOT = 'TEST_ROOT';
const { state } = await runAction(setTableSortConfigurationAction, {
props: { root: TEST_ROOT, sortField: 'createdAt', sortOrder: ASCENDING },
state: {
tableSort: {
sortField: 'recievedAt',
sortOrder: DESCENDING,
},
},
});

expect(state[TEST_ROOT]).toEqual({
sortField: 'createdAt',
sortOrder: ASCENDING,
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ export const setTableSortConfigurationAction = ({
}: ActionProps<{
sortField: string;
sortOrder: 'asc' | 'desc';
root?: string;
}>) => {
store.set(state.tableSort.sortField, props.sortField);
store.set(state.tableSort.sortOrder, props.sortOrder);
const { root, sortField, sortOrder } = props;

const ROOT = root || 'tableSort';
store.set(state[ROOT].sortField, sortField);
store.set(state[ROOT].sortOrder, sortOrder);
};
Loading

0 comments on commit d8b60a8

Please sign in to comment.