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

MAT-6808: add clone test case to qicore #736

Merged
merged 2 commits into from
Oct 18, 2024
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 @@ -33,6 +33,7 @@ interface TestCaseTableProps {
onCloneTestCase?: (testCase: TestCase) => void;
measure: Measure;
onTestCaseShiftDates?: (testCase: TestCase, shifted: number) => void;
handleQiCloneTestCase?: (testCase: TestCase) => void;
sorting: any;
setSorting: any;
}
Expand All @@ -57,6 +58,7 @@ const TestCaseTable = (props: TestCaseTableProps) => {
onCloneTestCase,
measure,
onTestCaseShiftDates,
handleQiCloneTestCase,
sorting,
setSorting,
} = props;
Expand Down Expand Up @@ -330,6 +332,7 @@ const TestCaseTable = (props: TestCaseTableProps) => {
shiftDatesDialogOpen={shiftDatesDialogOpen}
setShiftDatesDialogOpen={setShiftDatesDialogOpen}
onTestCaseShiftDates={onTestCaseShiftDates}
handleQiCloneTestCase={handleQiCloneTestCase}
/>

{/* This sees to have gotten disconnected at some point in the past. */}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface TestCaseTablePopoverProps {
shiftDatesDialogOpen: boolean;
setShiftDatesDialogOpen: (boolean) => void;
onTestCaseShiftDates?: (testCase: TestCase, shifted: number) => void;
handleQiCloneTestCase?: (testCase: TestCase) => void;
}

const TestCaseTablePopover = (props: TestCaseTablePopoverProps) => {
Expand All @@ -40,6 +41,7 @@ const TestCaseTablePopover = (props: TestCaseTablePopoverProps) => {
shiftDatesDialogOpen,
setShiftDatesDialogOpen,
onTestCaseShiftDates,
handleQiCloneTestCase,
} = props;
const editTestCaseUrl = _.isEmpty(props.groups)
? `../${selectedTestCase?.id}`
Expand Down Expand Up @@ -172,17 +174,32 @@ const TestCaseTablePopover = (props: TestCaseTablePopoverProps) => {
)}

{canEdit && (
<button
id={`delete-test-case-btn-${selectedTestCase?.id}`}
aria-label={`delete-test-case-${selectedTestCase?.title}`}
data-testid={`delete-test-case-btn-${selectedTestCase?.id}`}
onClick={() => {
setDeleteDialogModalOpen(true);
setOptionsOpen(false);
}}
>
delete
</button>
<>
<button
id={`delete-test-case-btn-${selectedTestCase?.id}`}
aria-label={`delete-test-case-${selectedTestCase?.title}`}
data-testid={`delete-test-case-btn-${selectedTestCase?.id}`}
onClick={() => {
setDeleteDialogModalOpen(true);
setOptionsOpen(false);
}}
>
delete
</button>
{model.startsWith("QI-Core") && (
<button
id={`clone-test-case-btn-${selectedTestCase?.id}`}
aria-label={`clone-test-case-btn-${selectedTestCase?.title}`}
data-testid={`clone-test-case-btn-${selectedTestCase?.id}`}
onClick={() => {
handleQiCloneTestCase(selectedTestCase);
setOptionsOpen(false);
}}
>
clone test case
</button>
)}
</>
)}

{canEdit && featureFlags?.ShiftTestCasesDates && (
Expand Down
36 changes: 36 additions & 0 deletions src/components/testCaseLanding/qiCore/TestCaseList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1833,6 +1833,42 @@ describe("TestCaseList component", () => {
expect(setWarnings).toHaveBeenCalledWith(mockedOutcome);
});
});
describe("clone test case", () => {
it("should clone a test case when the clone button is clicked", async () => {
const createTestCaseApiMock = jest.fn().mockResolvedValue({});
const getTestCasesByMeasureIdMock = jest
.fn()
.mockResolvedValue(testCases);
useTestCaseServiceMock.mockImplementation(() => {
return {
...useTestCaseServiceMockResolved,
getTestCasesByMeasureId: getTestCasesByMeasureIdMock,
createTestCase: createTestCaseApiMock,
} as unknown as TestCaseServiceApi;
});
renderTestCaseListComponent();
await waitFor(() => {
expect(getTestCasesByMeasureIdMock).toHaveBeenCalled();
const selectButton = screen.getByTestId(
`select-action-${testCases[0].id}`
);
expect(selectButton).toBeInTheDocument();
userEvent.click(selectButton);
});
const cloneButton = screen.getByTestId(
`clone-test-case-btn-${testCases[0].id}`
);
userEvent.click(cloneButton);

await waitFor(() => {
expect(createTestCaseApiMock).toHaveBeenCalled();
expect(getTestCasesByMeasureIdMock).toHaveBeenCalled();
expect(
screen.getByText("Test case cloned successfully")
).toBeInTheDocument();
});
});
});
});

describe("retrieve coverage value from HTML coverage", () => {
Expand Down
20 changes: 20 additions & 0 deletions src/components/testCaseLanding/qiCore/TestCaseList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
CalculationOutput,
DetailedPopulationGroupResult,
} from "fqm-execution/build/types/Calculator";
import { ObjectID } from "bson";
import {
checkUserCanEdit,
measureStore,
Expand Down Expand Up @@ -524,6 +525,24 @@ const TestCaseList = (props: TestCaseListProps) => {
});
};

const handleQiCloneTestCase = async (testCase: TestCase) => {
const clonedTestCase = testCase;
clonedTestCase.title =
clonedTestCase.title + "-" + new ObjectID().toString();
try {
await testCaseService.current.createTestCase(clonedTestCase, measureId);
setToastOpen(true);
setToastType("success");
setToastMessage("Test case cloned successfully");
retrieveTestCases();
} catch (error) {
setToastOpen(true);
setToastMessage(
`An error occurred while cloning the test case: ${error.message}`
);
}
};

return (
<div>
{!loadingState.loading && (
Expand Down Expand Up @@ -614,6 +633,7 @@ const TestCaseList = (props: TestCaseListProps) => {
exportTestCase={exportTestCase}
measure={measure}
onTestCaseShiftDates={onTestCaseShiftDates}
handleQiCloneTestCase={handleQiCloneTestCase}
/>
{currentSlice?.length > 0 && (
<Pagination
Expand Down
Loading