From 3b1c360a07ba46c12ac03ff944fbc49c2f4afb94 Mon Sep 17 00:00:00 2001 From: R Ranathunga Date: Thu, 31 Oct 2024 10:17:14 -0700 Subject: [PATCH] chore: make cbc projects filter/sort by analyst status --- .../AnalystDashboard/AllDashboard.tsx | 80 ++++++++++--------- app/tests/pages/analyst/dashboard.test.tsx | 56 +++++++++++++ 2 files changed, 99 insertions(+), 37 deletions(-) diff --git a/app/components/AnalystDashboard/AllDashboard.tsx b/app/components/AnalystDashboard/AllDashboard.tsx index 08893c7112..0e120a2e84 100644 --- a/app/components/AnalystDashboard/AllDashboard.tsx +++ b/app/components/AnalystDashboard/AllDashboard.tsx @@ -425,22 +425,29 @@ const AllDashboardTable: React.FC = ({ query }) => { }; const tableData = useMemo(() => { - return [ - ...allApplications.edges.map((application) => ({ - ...application.node, - intakeNumber: application?.node?.ccbcNumber?.includes('000074') - ? '' - : application.node.intakeNumber, - projectId: application.node.ccbcNumber, - packageNumber: application.node.package, - projectTitle: application.node.projectName, - isCbcProject: false, - showLink: true, - externalStatusOrder: statusOrderMap[application.node.externalStatus], - internalStatusOrder: statusOrderMap[application.node.analystStatus], - })), - ...(showCbcProjects - ? allCbcData.edges.map((project) => ({ + const allCcbcApplications = allApplications.edges.map((application) => ({ + ...application.node, + intakeNumber: application?.node?.ccbcNumber?.includes('000074') + ? '' + : application.node.intakeNumber, + projectId: application.node.ccbcNumber, + packageNumber: application.node.package, + projectTitle: application.node.projectName, + isCbcProject: false, + showLink: true, + externalStatusOrder: statusOrderMap[application.node.externalStatus], + internalStatusOrder: statusOrderMap[application.node.analystStatus], + })); + + const allCbcApplications = showCbcProjects + ? allCbcData.edges.map((project) => { + const cbcStatus = project.node.jsonData.projectStatus + ? cbcProjectStatusConverter(project.node.jsonData.projectStatus) + : null; + const cbcStatusOrder = cbcStatus + ? statusOrderMap[cbcProjectStatusConverter(cbcStatus)] + : null; + return { rowId: project.node.cbcId, ...project.node.jsonData, program: 'CBC', @@ -448,23 +455,21 @@ const AllDashboardTable: React.FC = ({ query }) => { intakeNumber: project.node.jsonData?.intake || 'N/A', projectId: project.node.projectNumber, internalStatus: null, - externalStatus: project.node.jsonData.projectStatus - ? cbcProjectStatusConverter(project.node.jsonData.projectStatus) - : null, - externalStatusOrder: project.node.jsonData.projectStatus - ? statusOrderMap[ - cbcProjectStatusConverter(project.node.jsonData.projectStatus) - ] - : null, + externalStatus: cbcStatus, + analystStatus: cbcStatus, + externalStatusOrder: cbcStatusOrder, + internalStatusOrder: cbcStatusOrder, packageNumber: null, organizationName: project.node.jsonData.currentOperatingName || null, lead: null, isCbcProject: true, showLink: showCbcProjectsLink, - })) ?? [] - : []), - ]; + }; + }) ?? [] + : []; + + return [...allCcbcApplications, ...allCbcApplications]; }, [ allApplications.edges, allCbcData.edges, @@ -491,12 +496,17 @@ const AllDashboardTable: React.FC = ({ query }) => { .map((zone) => zone.toString()) .sort((a, b) => Number(a) - Number(b)); + const allCbcStatuses = allCbcData.edges + .map((edge) => edge.node?.jsonData?.projectStatus) + .map((status) => normalizeStatusName(cbcProjectStatusConverter(status))); + const analystStatuses = [ - ...new Set( - allApplications.edges.map((edge) => { - return normalizeStatusName(edge.node.analystStatus); - }) - ), + ...new Set([ + ...allApplications.edges.map((edge) => + normalizeStatusName(edge.node.analystStatus) + ), + ...allCbcStatuses, + ]), ].toSorted((a, b) => statusOrderMap[a] - statusOrderMap[b]); const externalStatuses = [ @@ -504,11 +514,7 @@ const AllDashboardTable: React.FC = ({ query }) => { ...allApplications.edges.map((edge) => normalizeStatusName(edge.node.externalStatus) ), - ...allCbcData.edges - .map((edge) => edge.node?.jsonData?.projectStatus) - .map((status) => - normalizeStatusName(cbcProjectStatusConverter(status)) - ), + ...allCbcStatuses, ]), ].toSorted((a, b) => statusOrderMap[a] - statusOrderMap[b]); diff --git a/app/tests/pages/analyst/dashboard.test.tsx b/app/tests/pages/analyst/dashboard.test.tsx index df5c957162..863d8af7ab 100644 --- a/app/tests/pages/analyst/dashboard.test.tsx +++ b/app/tests/pages/analyst/dashboard.test.tsx @@ -747,4 +747,60 @@ describe('The index page', () => { expect(cbcFilterCheckbox).toBeChecked(); expect(screen.queryByText('5555')).toBeInTheDocument(); }); + + it('cbc statuses are duplicated for both analyst and external statuses', async () => { + jest + .spyOn(moduleApi, 'useFeature') + .mockReturnValue(mockShowCbcProjects(true)); + + pageTestingHelper.loadQuery(); + pageTestingHelper.renderPage(); + + expect(screen.getAllByText('Reporting complete')).toHaveLength(6); + }); + + it('internal status filter works correctly on cbc projects', async () => { + jest + .spyOn(moduleApi, 'useFeature') + .mockReturnValue(mockShowCbcProjects(true)); + + pageTestingHelper.loadQuery(); + pageTestingHelper.renderPage(); + + expect(screen.getAllByText('Reporting complete')).toHaveLength(6); + }); + + it('should correctly filter the cbc projects by analyst status filter', async () => { + jest + .spyOn(moduleApi, 'useFeature') + .mockReturnValue(mockShowCbcProjects(true)); + + pageTestingHelper.loadQuery(); + pageTestingHelper.renderPage(); + + expect(screen.getByText('4444')).toBeVisible(); + expect(screen.getByText('5555')).toBeVisible(); + + const columnActions = document.querySelectorAll( + '[aria-label="Show/Hide filters"]' + )[0]; + + await act(async () => { + fireEvent.click(columnActions); + }); + + const zoneFilter = screen.getAllByText('Filter by Internal Status')[0]; + + await act(async () => { + fireEvent.keyDown(zoneFilter, { key: 'Enter', code: 'Enter' }); + }); + + const option = screen.getByRole('option', { name: 'Agreement signed' }); + fireEvent.click(option); + + waitFor(() => { + expect(screen.getByText('4444')).toBeInTheDocument(); + expect(screen.queryByText('5555')).not.toBeInTheDocument(); + }); + }); });