diff --git a/src/components/testCaseLanding/common/TestCaseTable/TestCaseTable.tsx b/src/components/testCaseLanding/common/TestCaseTable/TestCaseTable.tsx index 16915bda4..3c4be8b04 100644 --- a/src/components/testCaseLanding/common/TestCaseTable/TestCaseTable.tsx +++ b/src/components/testCaseLanding/common/TestCaseTable/TestCaseTable.tsx @@ -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; } @@ -57,6 +58,7 @@ const TestCaseTable = (props: TestCaseTableProps) => { onCloneTestCase, measure, onTestCaseShiftDates, + handleQiCloneTestCase, sorting, setSorting, } = props; @@ -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. */} diff --git a/src/components/testCaseLanding/common/TestCaseTable/TestCaseTablePopover.tsx b/src/components/testCaseLanding/common/TestCaseTable/TestCaseTablePopover.tsx index 9ad794149..ac1490bdb 100644 --- a/src/components/testCaseLanding/common/TestCaseTable/TestCaseTablePopover.tsx +++ b/src/components/testCaseLanding/common/TestCaseTable/TestCaseTablePopover.tsx @@ -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) => { @@ -40,6 +41,7 @@ const TestCaseTablePopover = (props: TestCaseTablePopoverProps) => { shiftDatesDialogOpen, setShiftDatesDialogOpen, onTestCaseShiftDates, + handleQiCloneTestCase, } = props; const editTestCaseUrl = _.isEmpty(props.groups) ? `../${selectedTestCase?.id}` @@ -172,17 +174,32 @@ const TestCaseTablePopover = (props: TestCaseTablePopoverProps) => { )} {canEdit && ( - + <> + + {model.startsWith("QI-Core") && ( + + )} + > )} {canEdit && featureFlags?.ShiftTestCasesDates && ( diff --git a/src/components/testCaseLanding/qiCore/TestCaseList.test.tsx b/src/components/testCaseLanding/qiCore/TestCaseList.test.tsx index ac3c725a9..948c68070 100644 --- a/src/components/testCaseLanding/qiCore/TestCaseList.test.tsx +++ b/src/components/testCaseLanding/qiCore/TestCaseList.test.tsx @@ -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", () => { diff --git a/src/components/testCaseLanding/qiCore/TestCaseList.tsx b/src/components/testCaseLanding/qiCore/TestCaseList.tsx index 6348e9706..4f53345b4 100644 --- a/src/components/testCaseLanding/qiCore/TestCaseList.tsx +++ b/src/components/testCaseLanding/qiCore/TestCaseList.tsx @@ -16,6 +16,7 @@ import { CalculationOutput, DetailedPopulationGroupResult, } from "fqm-execution/build/types/Calculator"; +import { ObjectID } from "bson"; import { checkUserCanEdit, measureStore, @@ -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 (