Skip to content

Commit

Permalink
chore: filter package by null
Browse files Browse the repository at this point in the history
  • Loading branch information
RRanath authored and ccbc-service-account committed Nov 26, 2024
1 parent 0d5bdb5 commit b122bde
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
7 changes: 5 additions & 2 deletions app/components/AnalystDashboard/AllDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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] ?? '';
};
Expand Down Expand Up @@ -579,8 +582,8 @@ const AllDashboardTable: React.FC<Props> = ({ 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 [
{
Expand Down
41 changes: 41 additions & 0 deletions app/tests/pages/analyst/dashboard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const mockQueryPayload = {
zones: [1, 2],
program: 'CCBC',
status: 'received',
package: '1',
applicationFormTemplate9DataByApplicationId: {
nodes: [
{
Expand Down Expand Up @@ -64,6 +65,7 @@ const mockQueryPayload = {
zones: [],
program: 'CCBC',
status: 'approved',
package: null,
applicationFormTemplate9DataByApplicationId: {
nodes: [
{
Expand Down Expand Up @@ -113,6 +115,7 @@ const mockQueryPayload = {
zone: null,
zones: [],
program: 'CCBC',
package: null,
},
},
{
Expand All @@ -128,6 +131,7 @@ const mockQueryPayload = {
zone: null,
zones: [],
program: 'CCBC',
package: null,
},
},
{
Expand All @@ -143,6 +147,7 @@ const mockQueryPayload = {
zone: null,
zones: [],
program: 'OTHER',
package: null,
},
},
],
Expand Down Expand Up @@ -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();
});
});
});

0 comments on commit b122bde

Please sign in to comment.