Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

MAT-6516: adding test coverage #517

Merged
merged 1 commit into from
Dec 7, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface NavTabProps {
coveragePercentage: number;
validTestCases: TestCase[];
selectedPopCriteria: Group;
onDeleteAllTestCases?: () => void;
onDeleteAllTestCases: () => void;
}

const defaultStyle = {
Expand Down Expand Up @@ -163,9 +163,7 @@ export default function CreateCodeCoverageNavTabs(props: NavTabProps) {
<Button
variant="danger-primary"
disabled={!canEdit || measure?.testCases?.length === 0}
onClick={() =>
onDeleteAllTestCases ? onDeleteAllTestCases() : null
}
onClick={onDeleteAllTestCases}
data-testid="delete-all-test-cases-button"
>
<KeyboardArrowRightIcon
Expand Down
41 changes: 38 additions & 3 deletions src/components/testCaseLanding/qdm/TestCaseList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -979,12 +979,13 @@ describe("TestCaseList component", () => {
});

it("Should delete all existing test cases", async () => {
const deleteTestCasesApiMock = jest
.fn()
.mockResolvedValue("All Test cases are deleted successfully");
useTestCaseServiceMock.mockImplementation(() => {
return {
...useTestCaseServiceMockResolved,
deleteTestCases: jest
.fn()
.mockResolvedValue("All Test cases are deleted successfully"),
deleteTestCases: deleteTestCasesApiMock,
} as unknown as TestCaseServiceApi;
});
renderTestCaseListComponent();
Expand All @@ -1003,6 +1004,40 @@ describe("TestCaseList component", () => {
const toastMessage = await screen.findByTestId("test-case-list-success");
expect(toastMessage).toHaveTextContent("Test cases successfully deleted");
expect(screen.queryByTestId("delete-dialog-body")).toBeNull();
expect(deleteTestCasesApiMock).toHaveBeenCalled();
});

it("Should hide delete all dialogue when cancel is clicked", async () => {
const deleteTestCasesApiMock = jest
.fn()
.mockResolvedValue("All Test cases are deleted successfully");
useTestCaseServiceMock.mockImplementation(() => {
return {
...useTestCaseServiceMockResolved,
deleteTestCases: deleteTestCasesApiMock,
} as unknown as TestCaseServiceApi;
});
renderTestCaseListComponent();

const table = await screen.findByTestId("test-case-tbl");
const tableRows = table.querySelectorAll("tbody tr");
expect(tableRows.length).toBe(3);

const deleteAllButton = screen.getByRole("button", { name: "Delete All" });
userEvent.click(deleteAllButton);
expect(screen.getByTestId("delete-dialog")).toBeInTheDocument();
expect(screen.getByText("Yes, Delete")).toBeInTheDocument();

expect(screen.getByText("Delete All Test Cases")).toBeInTheDocument();
const cancelButton = screen.getByRole("button", { name: "Cancel" });
userEvent.click(cancelButton);

await waitFor(() =>
expect(
screen.queryByText("Delete All Test Cases")
).not.toBeInTheDocument()
);
expect(deleteTestCasesApiMock).not.toHaveBeenCalled();
});

it("Should throw error message for delete all existing test cases", async () => {
Expand Down
Loading