Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bangbay-bluetiger committed Jan 15, 2025
1 parent 23d97e5 commit 8097477
Show file tree
Hide file tree
Showing 8 changed files with 288 additions and 82 deletions.
240 changes: 219 additions & 21 deletions services/ui-src/src/components/pages/Dashboard/DashboardPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,53 @@ const naaarDashboardViewEmpty = (
</RouterWrappedComponent>
);

const { report, ...rest } = mockMcparReportStore;

const multiSubmissionCount = {
...report,
submissionCount: 123,
};

const multiSubmissionCountStore = {
...rest,
report: multiSubmissionCount,
reportsByState: [multiSubmissionCount],
};

const zeroSubmissionCountReport = {
...report,
submissionCount: 0,
};

const zeroSubmissionCountStore = {
...rest,
report: zeroSubmissionCountReport,
reportsByState: [zeroSubmissionCountReport],
};

const archivedReport = {
...report,
archived: true,
};

const archivedReportStore = {
...rest,
report: archivedReport,
reportsByState: [archivedReport],
};

const noAlteredByReport = {
...report,
};

delete noAlteredByReport.lastAlteredBy;

const noAlteredByReportStore = {
...rest,
report: noAlteredByReport,
reportsByState: [noAlteredByReport],
};

describe("Test Report Dashboard view (with reports, desktop view)", () => {
beforeEach(async () => {
mockedUseStore.mockReturnValue({
Expand All @@ -132,7 +179,9 @@ describe("Test Report Dashboard view (with reports, desktop view)", () => {
await render(dashboardViewWithReports);
});
expect(screen.getByText(mcparVerbiage.intro.header)).toBeVisible();
expect(screen.getAllByText("testProgram")[0]).toBeVisible();
expect(
screen.getAllByRole("gridcell", { name: "testProgram" })[0]
).toBeVisible();
expect(
screen.queryByText(mcparVerbiage.body.empty)
).not.toBeInTheDocument();
Expand All @@ -148,7 +197,9 @@ describe("Test Report Dashboard view (with reports, desktop view)", () => {
await render(mlrDashboardViewWithReports);
});
expect(screen.getByText(mlrVerbiage.intro.header)).toBeVisible();
expect(screen.getAllByText("testSubmission")[0]).toBeVisible();
expect(
screen.getAllByRole("gridcell", { name: "testSubmission" })[0]
).toBeVisible();
expect(screen.queryByText("Leave form")).not.toBeInTheDocument();
});

Expand All @@ -169,7 +220,9 @@ describe("Test Report Dashboard view (with reports, desktop view)", () => {
await render(dashboardViewWithReports);
});
mockMcparReportContext.fetchReport.mockReturnValueOnce(mockMcparReport);
const enterReportButton = screen.getAllByText("Edit")[0];
const enterReportButton = screen.getAllByRole("button", {
name: "Edit",
})[0];
expect(enterReportButton).toBeVisible();
await userEvent.click(enterReportButton);
expect(mockMcparReportContext.setReportSelection).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -208,11 +261,57 @@ describe("Test Report Dashboard view (with reports, desktop view)", () => {
const addReportButtons = screen.queryAllByAltText("Edit Report");
expect(addReportButtons).toHaveLength(0);
});

test("Shows submissionCount to admin", async () => {
mockedUseStore.mockReturnValue({
...mockAdminUserStore,
...multiSubmissionCountStore,
});
await act(async () => {
await render(dashboardViewWithReports);
});
expect(screen.getAllByRole("gridcell", { name: "123" })[0]).toBeVisible();
});

test("Shows submissionCount as 1", async () => {
mockedUseStore.mockReturnValue({
...mockAdminUserStore,
...zeroSubmissionCountStore,
});
await act(async () => {
await render(dashboardViewWithReports);
});
expect(screen.getAllByRole("gridcell", { name: "1" })[0]).toBeVisible();
});

test("Hides submissionCount to state user", async () => {
mockedUseStore.mockReturnValue({
...mockStateUserStore,
...multiSubmissionCountStore,
});
await act(async () => {
await render(dashboardViewWithReports);
});
expect(
screen.queryByRole("gridcell", { name: "123" })
).not.toBeInTheDocument();
});

test("Shows lastAlteredBy as -", async () => {
mockedUseStore.mockReturnValue({
...mockAdminUserStore,
...noAlteredByReportStore,
});
await act(async () => {
await render(dashboardViewWithReports);
});
expect(screen.getAllByText("-")[0]).toBeVisible();
});
});

describe("Test Report Dashboard with Sortable Table", () => {
beforeEach(async () => {
mockLDFlags.set({ sortableTable: true });
mockLDFlags.set({ sortableDashboardTable: true });
mockedUseStore.mockReturnValue({
...mockStateUserStore,
...mockMcparReportStore,
Expand All @@ -232,7 +331,9 @@ describe("Test Report Dashboard with Sortable Table", () => {
await render(dashboardViewWithReports);
});
expect(screen.getByText(mcparVerbiage.intro.header)).toBeVisible();
expect(screen.getAllByText("testProgram")[0]).toBeVisible();
expect(
screen.getAllByRole("gridcell", { name: "testProgram" })[0]
).toBeVisible();
expect(
screen.queryByText(mcparVerbiage.body.empty)
).not.toBeInTheDocument();
Expand All @@ -248,7 +349,9 @@ describe("Test Report Dashboard with Sortable Table", () => {
await render(mlrDashboardViewWithReports);
});
expect(screen.getByText(mlrVerbiage.intro.header)).toBeVisible();
expect(screen.getAllByText("testSubmission")[0]).toBeVisible();
expect(
screen.getAllByRole("gridcell", { name: "testSubmission" })[0]
).toBeVisible();
expect(screen.queryByText("Leave form")).not.toBeInTheDocument();
});

Expand All @@ -263,6 +366,67 @@ describe("Test Report Dashboard with Sortable Table", () => {
expect(screen.getByText(naaarVerbiage.intro.header)).toBeVisible();
expect(screen.queryByText("Leave form")).not.toBeInTheDocument();
});

test("Clicking 'Edit' button on a report row fetches the field data, then navigates to report", async () => {
await act(async () => {
await render(dashboardViewWithReports);
});
mockMcparReportContext.fetchReport.mockReturnValueOnce(mockMcparReport);
const enterReportButton = screen.getAllByRole("button", {
name: "Edit",
})[0];
expect(enterReportButton).toBeVisible();
await userEvent.click(enterReportButton);
expect(mockMcparReportContext.setReportSelection).toHaveBeenCalledTimes(1);
expect(mockUseNavigate).toBeCalledTimes(1);
expect(mockUseNavigate).toBeCalledWith("/mock/mock-route-1");
});

test("Shows submissionCount to admin", async () => {
mockedUseStore.mockReturnValue({
...mockAdminUserStore,
...multiSubmissionCountStore,
});
await act(async () => {
await render(dashboardViewWithReports);
});
expect(screen.getAllByRole("gridcell", { name: "123" })[0]).toBeVisible();
});

test("Shows submissionCount as 1", async () => {
mockedUseStore.mockReturnValue({
...mockAdminUserStore,
...zeroSubmissionCountStore,
});
await act(async () => {
await render(dashboardViewWithReports);
});
expect(screen.getAllByRole("gridcell", { name: "1" })[0]).toBeVisible();
});

test("Hides submissionCount to state user", async () => {
mockedUseStore.mockReturnValue({
...mockStateUserStore,
...multiSubmissionCountStore,
});
await act(async () => {
await render(dashboardViewWithReports);
});
expect(
screen.queryByRole("gridcell", { name: "123" })
).not.toBeInTheDocument();
});

test("Shows lastAlteredBy as -", async () => {
mockedUseStore.mockReturnValue({
...mockAdminUserStore,
...noAlteredByReportStore,
});
await act(async () => {
await render(dashboardViewWithReports);
});
expect(screen.getAllByText("-")[0]).toBeVisible();
});
});

describe("Test Dashboard view (with reports, mobile view)", () => {
Expand Down Expand Up @@ -294,7 +458,9 @@ describe("Test Dashboard view (with reports, mobile view)", () => {

test("Clicking 'Edit' button on a report navigates to first page of report", async () => {
mockMcparReportContext.fetchReport.mockReturnValueOnce(mockMcparReport);
const enterReportButton = screen.getAllByText("Edit")[0];
const enterReportButton = screen.getAllByRole("button", {
name: "Edit",
})[0];
expect(enterReportButton).toBeVisible();
await userEvent.click(enterReportButton);
expect(mockUseNavigate).toBeCalledTimes(1);
Expand All @@ -307,6 +473,52 @@ describe("Test Dashboard view (with reports, mobile view)", () => {
await userEvent.click(addReportButton);
expect(screen.getByTestId("add-edit-report-form")).toBeVisible();
});

test("Shows submissionCount to admin", async () => {
mockedUseStore.mockReturnValue({
...mockAdminUserStore,
...multiSubmissionCountStore,
});
await act(async () => {
await render(dashboardViewWithReports);
});
expect(screen.getAllByText("123")[0]).toBeVisible();
});

test("Shows submissionCount as 1", async () => {
mockedUseStore.mockReturnValue({
...mockAdminUserStore,
...zeroSubmissionCountStore,
});
await act(async () => {
await render(dashboardViewWithReports);
});
expect(screen.getAllByText("1")[0]).toBeVisible();
});

test("Hides submissionCount to state user", async () => {
mockedUseStore.mockReturnValue({
...mockStateUserStore,
...multiSubmissionCountStore,
});
await act(async () => {
await render(dashboardViewWithReports);
});
expect(
screen.queryByRole("gridcell", { name: "123" })
).not.toBeInTheDocument();
});

test("Shows lastAlteredBy as -", async () => {
mockedUseStore.mockReturnValue({
...mockAdminUserStore,
...noAlteredByReportStore,
});
await act(async () => {
await render(dashboardViewWithReports);
});
expect(screen.getAllByText("-")[0]).toBeVisible();
});
});

describe("Test Dashboard report archiving privileges (desktop)", () => {
Expand Down Expand Up @@ -340,20 +552,6 @@ describe("Test Dashboard report archiving privileges (desktop)", () => {
});

test("Admin user can unarchive reports", async () => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { report, reportsByState, ...rest } = mockMcparReportStore;

const archivedReport = {
...report,
archived: true,
};

const archivedReportStore = {
report: archivedReport,
reportsByState: [archivedReport],
...rest,
};

mockedUseStore.mockReturnValue({
...mockAdminUserStore,
...archivedReportStore,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,13 @@ export const DashboardPage = ({ reportType }: Props) => {
state: selectedState,
id: report.id,
};
await releaseReport!(reportKeys);
await releaseReport(reportKeys);
await fetchReportsByState(reportType, activeState);
setReportId(undefined);
setReleasing(false);
};

const sortableTable = useFlags()?.sortableTable;
const sortableTable = useFlags()?.sortableDashboardTable;

const DesktopDashboardTable = (props: DashboardTableProps) => {
return sortableTable ? (
Expand Down
Loading

0 comments on commit 8097477

Please sign in to comment.