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

Feature/mat 6516 delete all qdm tcs #516

Merged
merged 2 commits into from
Dec 6, 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
63 changes: 38 additions & 25 deletions src/components/testCaseLanding/qdm/CreateCodeCoverageNavTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,6 +31,7 @@ export interface NavTabProps {
coveragePercentage: number;
validTestCases: TestCase[];
selectedPopCriteria: Group;
onDeleteAllTestCases?: () => void;
}

const defaultStyle = {
Expand Down Expand Up @@ -60,6 +62,7 @@ export default function CreateCodeCoverageNavTabs(props: NavTabProps) {
coveragePercentage,
validTestCases,
selectedPopCriteria,
onDeleteAllTestCases,
} = props;

const featureFlags = useFeatureFlags();
Expand Down Expand Up @@ -156,36 +159,46 @@ export default function CreateCodeCoverageNavTabs(props: NavTabProps) {
value="coverage"
/>
</Tabs>
<div style={{ margin: "6px 0 0 auto", display: "flex" }}>
<div style={{ margin: "6px 0 0 auto", display: "flex", gap: "10px" }}>
<Button
variant="danger-primary"
disabled={!canEdit || measure?.testCases?.length === 0}
onClick={() =>
onDeleteAllTestCases ? onDeleteAllTestCases() : null
}
data-testid="delete-all-test-cases-button"
>
<KeyboardArrowRightIcon
style={{ margin: "0 5px 0 -2px" }}
fontSize="small"
/>
Delete All
</Button>
{featureFlags?.importTestCases && (
<div>
<Button
onClick={() => {
if (onImportTestCases) {
onImportTestCases();
}
}}
disabled={!canEdit}
data-testid="show-import-test-cases-button"
>
<FileUploadIcon
style={{ margin: "0 5px 0 -2px" }}
fontSize="small"
/>
Import Test Cases
</Button>
</div>
)}
<div style={{ margin: "0 6px 0 26px" }}>
<Button
onClick={() => {
if (onImportTestCases) {
onImportTestCases();
}
}}
disabled={!canEdit}
onClick={createNewTestCase}
data-testid="create-new-test-case-button"
data-testid="show-import-test-cases-button"
>
<AddIcon style={{ margin: "0 5px 0 -2px" }} fontSize="small" />
New Test Case
<FileUploadIcon
style={{ margin: "0 5px 0 -2px" }}
fontSize="small"
/>
Import Test Cases
</Button>
</div>
)}
<Button
disabled={!canEdit}
onClick={createNewTestCase}
data-testid="create-new-test-case-button"
>
<AddIcon style={{ margin: "0 5px 0 -2px" }} fontSize="small" />
New Test Case
</Button>
<RunTestButton
hasErrors={hasErrors}
isExecutionContextReady={executionContextReady}
Expand Down
76 changes: 76 additions & 0 deletions src/components/testCaseLanding/qdm/TestCaseList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,82 @@ describe("TestCaseList component", () => {
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(() => {
Expand Down
45 changes: 41 additions & 4 deletions src/components/testCaseLanding/qdm/TestCaseList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
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 {
Expand Down Expand Up @@ -100,6 +104,8 @@
useState<boolean>(false);
const [coverageHTML, setCoverageHTML] = useState<Record<string, string>>();
const [coveragePercentage, setCoveragePercentage] = useState<number>(0);
const [openDeleteAllTestCasesDialog, setOpenDeleteAllTestCasesDialog] =
useState<boolean>(false);
const [testCasePassFailStats, setTestCasePassFailStats] =
useState<TestCasesPassingDetailsProps>({
passPercentage: undefined,
Expand Down Expand Up @@ -281,6 +287,23 @@
? 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 });
Expand Down Expand Up @@ -336,12 +359,12 @@
{!loadingState.loading && (
<>
<Toast
toastKey="population-criteria-toast"
toastKey="test-case-list-toast"
toastType={toastType}
testId={
toastType === "danger"
? `population-criteria-error`
: `population-criteria-success`
? `test-case-list-error`
: `test-case-list-success`
}
open={toastOpen}
message={toastMessage}
Expand Down Expand Up @@ -378,6 +401,9 @@
coveragePercentage={coveragePercentage}
validTestCases={testCases?.filter((tc) => tc.validResource)}
selectedPopCriteria={selectedPopCriteria}
onDeleteAllTestCases={() =>
setOpenDeleteAllTestCasesDialog(true)
}
/>
</div>
<CreateNewTestCaseDialog open={createOpen} onClose={handleClose} />
Expand Down Expand Up @@ -451,6 +477,17 @@
<Typography color="inherit">{loadingState.message}</Typography>
</div>
)}
<MadieDeleteDialog
open={openDeleteAllTestCasesDialog}
onContinue={() => {
deleteAllTestCases();
}}
onClose={() => {
setOpenDeleteAllTestCasesDialog(false);

Check warning on line 486 in src/components/testCaseLanding/qdm/TestCaseList.tsx

View check run for this annotation

Codecov / codecov/patch

src/components/testCaseLanding/qdm/TestCaseList.tsx#L486

Added line #L486 was not covered by tests
}}
dialogTitle="Delete All Test Cases"
name="All Test Cases"
/>
<TestCaseImportFromBonnieDialogQDM
openDialog={importDialogState.open}
onImport={onTestCaseImport}
Expand Down
Loading