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 Dec 4, 2024
1 parent ddf4ba5 commit 1a3e90d
Show file tree
Hide file tree
Showing 2 changed files with 45 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 @@ -157,6 +157,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 @@ -609,8 +612,8 @@ const AllDashboardTable: React.FC<Props> = ({ query }) => {
allApplications.edges.map((edge) => edge.node.package?.toString())
),
]
.filter(filterOutNullishs)
.sort((a, b) => Number(a) - Number(b));
.map(toLabelValuePair)
.toSorted((a, b) => Number(a.value) - Number(b.value));

return [
{
Expand Down
40 changes: 40 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 @@ -931,6 +933,44 @@ describe('The index page', () => {
expect(screen.getAllByText('Reporting complete')).toHaveLength(6);
});

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' });
await act(async () => {
fireEvent.click(option);
});

await waitFor(() => {
expect(screen.getByText('CCBC-010002')).toBeInTheDocument();
expect(screen.queryByText('CCBC-010001')).not.toBeInTheDocument();
});
});

it('should correctly filter the cbc projects by analyst status filter', async () => {
jest
.spyOn(moduleApi, 'useFeature')
Expand Down

0 comments on commit 1a3e90d

Please sign in to comment.