diff --git a/app/components/AnalystDashboard/AllDashboard.tsx b/app/components/AnalystDashboard/AllDashboard.tsx index d9e448a53..62d08b2c2 100644 --- a/app/components/AnalystDashboard/AllDashboard.tsx +++ b/app/components/AnalystDashboard/AllDashboard.tsx @@ -156,6 +156,9 @@ const ApplicantStatusCell = ({ cell }) => { const filterOutNullishs = (val) => val !== undefined && val !== null; +const toLabelValuePair = (value) => + value ? { label: value, value } : { label: 'Unassigned', value: ' ' }; + const accessorFunctionGeneratorInjectsEmptyString = (accessorKey) => { return (row) => row[accessorKey] ?? ''; }; @@ -579,8 +582,8 @@ const AllDashboardTable: React.FC = ({ query }) => { allApplications.edges.map((edge) => edge.node.package?.toString()) ), ] - .filter(filterOutNullishs) - .toSorted((a, b) => Number(a) - Number(b)); + .map(toLabelValuePair) + .toSorted((a, b) => Number(a.value) - Number(b.value)); return [ { diff --git a/app/tests/pages/analyst/dashboard.test.tsx b/app/tests/pages/analyst/dashboard.test.tsx index b050c202c..3c743cebc 100644 --- a/app/tests/pages/analyst/dashboard.test.tsx +++ b/app/tests/pages/analyst/dashboard.test.tsx @@ -34,6 +34,7 @@ const mockQueryPayload = { zones: [1, 2], program: 'CCBC', status: 'received', + package: '1', applicationFormTemplate9DataByApplicationId: { nodes: [ { @@ -64,6 +65,7 @@ const mockQueryPayload = { zones: [], program: 'CCBC', status: 'approved', + package: null, applicationFormTemplate9DataByApplicationId: { nodes: [ { @@ -113,6 +115,7 @@ const mockQueryPayload = { zone: null, zones: [], program: 'CCBC', + package: null, }, }, { @@ -128,6 +131,7 @@ const mockQueryPayload = { zone: null, zones: [], program: 'CCBC', + package: null, }, }, { @@ -143,6 +147,7 @@ const mockQueryPayload = { zone: null, zones: [], program: 'OTHER', + package: null, }, }, ], @@ -910,4 +915,40 @@ describe('The index page', () => { expect(screen.queryByText('5555')).not.toBeInTheDocument(); }); }); + + it('should correctly filter by package filter', async () => { + jest + .spyOn(moduleApi, 'useFeature') + .mockReturnValue(mockShowCbcProjects(true)); + + pageTestingHelper.loadQuery(); + pageTestingHelper.renderPage(); + + expect(screen.getByText('CCBC-010001')).toBeVisible(); + expect(screen.getByText('CCBC-010002')).toBeVisible(); + + const columnActions = document.querySelectorAll( + '[aria-label="Show/Hide filters"]' + )[0]; + + await act(async () => { + fireEvent.click(columnActions); + }); + + const packageFilter = screen.getAllByText('Filter by Package')[0]; + + expect(packageFilter).toBeInTheDocument(); + + await act(async () => { + fireEvent.keyDown(packageFilter, { key: 'Enter', code: 'Enter' }); + }); + + const option = screen.getByRole('option', { name: 'Unassigned' }); + fireEvent.click(option); + + waitFor(() => { + expect(screen.getByText('CCBC-010002')).toBeInTheDocument(); + expect(screen.queryByText('CCBC-010001')).not.toBeInTheDocument(); + }); + }); });