Skip to content

Commit

Permalink
better unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
ailZhou committed Feb 6, 2025
1 parent 104f6bc commit e41a089
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
22 changes: 19 additions & 3 deletions services/ui-src/src/components/report/MeasureFooter.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,39 @@ describe("Measure Footer", () => {
/>
);

//click previous
const previousLink = screen.getByRole("button", {
name: "Previous",
});
await userEvent.click(previousLink);
const prevRoute = "/report/QMS/CO/undefined/mock-prev-link";
expect(mockUseNavigate).toHaveBeenCalledWith(prevRoute);

//click next
const nextLink = screen.getByRole("button", {
name: "Next",
});
await userEvent.click(nextLink);
const nextRoute = "/report/QMS/CO/undefined/mock-next-link";
expect(mockUseNavigate).toHaveBeenCalledWith(nextRoute);

expect(screen.getByText("Clear measure data")).toBeInTheDocument();
expect(screen.getByText("Complete section")).toBeInTheDocument();
expect(screen.getByText("Complete measure")).toBeInTheDocument();
//click clear
const clearBtn = screen.getByRole("button", {
name: "Clear measure data",
});
await userEvent.click(clearBtn);

//click complete measure
const completeMeasureBtn = screen.getByRole("button", {
name: "Complete measure",
});
await userEvent.click(completeMeasureBtn);

//click complete section
const completeSectionBtn = screen.getByRole("button", {
name: "Complete section",
});
await userEvent.click(completeSectionBtn);
});

it("Test Measure Footer component without optional fields", () => {
Expand Down
4 changes: 2 additions & 2 deletions services/ui-src/src/components/report/MeasureFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ export const MeasureFooterElement = (props: PageElementProps) => {
</Button>
)}
{footer.completeMeasure && (
<Button disabled={true} onClick={() => onCompleteMeasure()}>
<Button onClick={() => onCompleteMeasure()}>
Complete measure
</Button>
)}
{footer.completeSection && (
<Button disabled={true} onClick={() => onCompleteSection()}>
<Button onClick={() => onCompleteSection()}>
Complete section
</Button>
)}
Expand Down

0 comments on commit e41a089

Please sign in to comment.