Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: make cbc projects filter/sort by analyst status #3649

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 43 additions & 37 deletions app/components/AnalystDashboard/AllDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -425,46 +425,51 @@ const AllDashboardTable: React.FC<Props> = ({ 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',
zones: [],
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,
Expand All @@ -491,24 +496,25 @@ const AllDashboardTable: React.FC<Props> = ({ 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 = [
...new Set([
...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]);

Expand Down
56 changes: 56 additions & 0 deletions app/tests/pages/analyst/dashboard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});
Loading