From cdd61533ab09ce27224383bea46d964a52673ce9 Mon Sep 17 00:00:00 2001 From: Ethan Kaplan Date: Fri, 18 Oct 2024 11:23:41 -0700 Subject: [PATCH] MAT-6808 add clone test case to qicore --- .../common/TestCaseTable/TestCaseTable.tsx | 3 ++ .../TestCaseTable/TestCaseTablePopover.tsx | 39 +++++++++++++------ .../qiCore/TestCaseList.test.tsx | 36 +++++++++++++++++ .../testCaseLanding/qiCore/TestCaseList.tsx | 20 ++++++++++ 4 files changed, 87 insertions(+), 11 deletions(-) diff --git a/src/components/testCaseLanding/common/TestCaseTable/TestCaseTable.tsx b/src/components/testCaseLanding/common/TestCaseTable/TestCaseTable.tsx index 33f219369..ba856dcf0 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; } export const convertDate = (date: string) => { @@ -55,6 +56,7 @@ const TestCaseTable = (props: TestCaseTableProps) => { onCloneTestCase, measure, onTestCaseShiftDates, + handleQiCloneTestCase, } = props; const viewOrEdit = canEdit ? "edit" : "view"; const [deleteDialogModalOpen, setDeleteDialogModalOpen] = @@ -347,6 +349,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 d6d8fb88c..3bae3710d 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, @@ -522,6 +523,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 (
{!loadingState.loading && ( @@ -609,6 +628,7 @@ const TestCaseList = (props: TestCaseListProps) => { exportTestCase={exportTestCase} measure={measure} onTestCaseShiftDates={onTestCaseShiftDates} + handleQiCloneTestCase={handleQiCloneTestCase} /> {currentSlice?.length > 0 && (