diff --git a/src/components/testCaseLanding/qdm/CreateCodeCoverageNavTabs.tsx b/src/components/testCaseLanding/qdm/CreateCodeCoverageNavTabs.tsx index c43aa1360..51a77b286 100644 --- a/src/components/testCaseLanding/qdm/CreateCodeCoverageNavTabs.tsx +++ b/src/components/testCaseLanding/qdm/CreateCodeCoverageNavTabs.tsx @@ -16,6 +16,7 @@ import { useFeatureFlags } from "@madie/madie-util"; import { useQdmExecutionContext } from "../../routes/qdm/QdmExecutionContext"; import RunTestButton from "../common/runTestsButton/RunTestsButton"; import { disableRunTestButtonText } from "../../../util/Utils"; +import KeyboardArrowRightIcon from "@mui/icons-material/KeyboardArrowRight"; export interface NavTabProps { activeTab: string; @@ -30,6 +31,7 @@ export interface NavTabProps { coveragePercentage: number; validTestCases: TestCase[]; selectedPopCriteria: Group; + onDeleteAllTestCases?: () => void; } const defaultStyle = { @@ -60,6 +62,7 @@ export default function CreateCodeCoverageNavTabs(props: NavTabProps) { coveragePercentage, validTestCases, selectedPopCriteria, + onDeleteAllTestCases, } = props; const featureFlags = useFeatureFlags(); @@ -156,36 +159,46 @@ export default function CreateCodeCoverageNavTabs(props: NavTabProps) { value="coverage" /> -
+
+ {featureFlags?.importTestCases && ( -
- -
- )} -
-
+ )} + { expect(nextState).toEqual(["BAD THINGS"]); }); + it("Should delete all existing test cases", async () => { + useTestCaseServiceMock.mockImplementation(() => { + return { + ...useTestCaseServiceMockResolved, + deleteTestCases: jest + .fn() + .mockResolvedValue("All Test cases are deleted successfully"), + } 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(); + + const continueButton = screen.getByRole("button", { name: "Yes, Delete" }); + userEvent.click(continueButton); + + const toastMessage = await screen.findByTestId("test-case-list-success"); + expect(toastMessage).toHaveTextContent("Test cases successfully deleted"); + expect(screen.queryByTestId("delete-dialog-body")).toBeNull(); + }); + + it("Should throw error message for delete all existing test cases", async () => { + useTestCaseServiceMock.mockReset().mockImplementation(() => { + return { + ...useTestCaseServiceMockResolved, + deleteTestCases: jest.fn().mockRejectedValue({ + response: { + data: { + message: "Unable to delete test cases.", + }, + }, + }), + } as unknown as TestCaseServiceApi; + }); + + let nextState; + setError.mockImplementation((callback) => { + nextState = callback([]); + }); + + 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(await screen.findByTestId("delete-dialog")).toBeInTheDocument(); + + const continueButton = screen.getByRole("button", { name: "Yes, Delete" }); + userEvent.click(continueButton); + + expect(screen.queryByTestId("delete-dialog-body")).toBeNull(); + + await waitFor(() => expect(setError).toHaveBeenCalled()); + expect(nextState).toEqual(["Unable to delete test cases."]); + }); + + it("Should disable delete all button", async () => { + measure.testCases = []; + renderTestCaseListComponent(); + + expect( + await screen.findByRole("button", { + name: "Delete All", + }) + ).toBeDisabled(); + }); + it("should navigate to the Test Case details page on edit button click for shared user", async () => { const { getByTestId } = renderTestCaseListComponent(); await waitFor(() => { diff --git a/src/components/testCaseLanding/qdm/TestCaseList.tsx b/src/components/testCaseLanding/qdm/TestCaseList.tsx index 7d1f9d7a2..eb77904f0 100644 --- a/src/components/testCaseLanding/qdm/TestCaseList.tsx +++ b/src/components/testCaseLanding/qdm/TestCaseList.tsx @@ -14,7 +14,11 @@ import { DetailedPopulationGroupResult } from "fqm-execution/build/types/Calcula import { checkUserCanEdit, measureStore } from "@madie/madie-util"; import CreateCodeCoverageNavTabs from "./CreateCodeCoverageNavTabs"; import CreateNewTestCaseDialog from "../../createTestCase/CreateNewTestCaseDialog"; -import { MadieSpinner, Toast } from "@madie/madie-design-system/dist/react"; +import { + MadieDeleteDialog, + MadieSpinner, + Toast, +} from "@madie/madie-design-system/dist/react"; import TestCaseListSideBarNav from "../common/TestCaseListSideBarNav"; import Typography from "@mui/material/Typography"; import { @@ -100,6 +104,8 @@ const TestCaseList = (props: TestCaseListProps) => { useState(false); const [coverageHTML, setCoverageHTML] = useState>(); const [coveragePercentage, setCoveragePercentage] = useState(0); + const [openDeleteAllTestCasesDialog, setOpenDeleteAllTestCasesDialog] = + useState(false); const [testCasePassFailStats, setTestCasePassFailStats] = useState({ passPercentage: undefined, @@ -281,6 +287,23 @@ const TestCaseList = (props: TestCaseListProps) => { ? Object.keys(calculationOutput).length : 0; + const deleteAllTestCases = () => { + const currentTestCaseIds = _.map(measure.testCases, "id"); + testCaseService.current + .deleteTestCases(measureId, currentTestCaseIds) + .then(() => { + retrieveTestCases(); + setOpenDeleteAllTestCasesDialog(false); + setToastOpen(true); + setToastType("success"); + setToastMessage("Test cases successfully deleted"); + }) + .catch((err) => { + setOpenDeleteAllTestCasesDialog(false); + setErrors((prevState) => [...prevState, err?.response?.data?.message]); + }); + }; + const onTestCaseImport = async (testCases: TestCaseImportRequest[]) => { setWarnings(null); setImportDialogState({ ...importDialogState, open: false }); @@ -336,12 +359,12 @@ const TestCaseList = (props: TestCaseListProps) => { {!loadingState.loading && ( <> { coveragePercentage={coveragePercentage} validTestCases={testCases?.filter((tc) => tc.validResource)} selectedPopCriteria={selectedPopCriteria} + onDeleteAllTestCases={() => + setOpenDeleteAllTestCasesDialog(true) + } />
@@ -451,6 +477,17 @@ const TestCaseList = (props: TestCaseListProps) => { {loadingState.message}
)} + { + deleteAllTestCases(); + }} + onClose={() => { + setOpenDeleteAllTestCasesDialog(false); + }} + dialogTitle="Delete All Test Cases" + name="All Test Cases" + />