Skip to content

Commit 7e005fc

Browse files
authored
Merge branch 'develop' into MAT-7753
2 parents 6c054b9 + 039470a commit 7e005fc

File tree

7 files changed

+151
-35
lines changed

7 files changed

+151
-35
lines changed

src/components/editMeasure/testCases/components/routes/qiCore/TestCaseRoutes.test.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ jest.mock("@madie/madie-util", () => ({
9292
useFeatureFlags: jest.fn().mockImplementation(() => ({
9393
applyDefaults: false,
9494
qiCoreBonnieTestCases: false,
95+
TestCaseListActionCenter: false,
9596
})),
9697
useOktaTokens: () => ({
9798
getAccessToken: () => "test.jwt",

src/components/editMeasure/testCases/components/testCaseLanding/common/ActionCenter/ActionCenter.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ interface ActionCenterProps {
2626
selectedTestCases: any;
2727
canEdit: boolean;
2828
isQDM: boolean;
29+
setDeleteDialogModalOpen: Function;
2930
onCloneTestCase?: (testCase: TestCase) => void;
3031
exportTestCases?: Function;
3132
onExportQRDA?: Function;
@@ -43,6 +44,7 @@ export default function ActionCenter(props: ActionCenterProps) {
4344
canEdit,
4445
isQDM,
4546
onCloneTestCase,
47+
setDeleteDialogModalOpen,
4648
exportTestCases,
4749
onExportQRDA,
4850
onExportExcel,
@@ -249,7 +251,7 @@ export default function ActionCenter(props: ActionCenterProps) {
249251
</div>
250252

251253
{/* Action Buttons (Delete, Clone, Export) */}
252-
{featureFlags.TestCaseListActionCenter && (
254+
{featureFlags?.TestCaseListActionCenter && (
253255
<div tw="flex items-center">
254256
{canEdit && (
255257
<div tw="flex items-center">
@@ -265,7 +267,9 @@ export default function ActionCenter(props: ActionCenterProps) {
265267
>
266268
<span>
267269
<IconButton
268-
onClick={() => {}}
270+
onClick={() => {
271+
setDeleteDialogModalOpen(true);
272+
}}
269273
disabled={disableDeleteBtn}
270274
data-testid="delete-action-btn"
271275
>

src/components/editMeasure/testCases/components/testCaseLanding/common/TestCaseTable/TestCaseTable.test.tsx

+105-16
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,32 @@ const measures = [
129129
},
130130
] as unknown as Measure[];
131131

132+
const defaultMeasure = {
133+
id: "m1234",
134+
measureScoring: MeasureScoring.COHORT,
135+
createdBy: "testuser",
136+
groups: [
137+
{
138+
groupId: "Group1_ID",
139+
scoring: "Cohort",
140+
populations: [
141+
{
142+
id: "id-1",
143+
name: PopulationType.INITIAL_POPULATION,
144+
definition: "Pop1",
145+
},
146+
],
147+
stratifications: [
148+
{
149+
id: "strat-id-1",
150+
},
151+
],
152+
},
153+
],
154+
model: "QI-Core v4.1.1",
155+
acls: [{ userId: "[email protected]", roles: ["SHARED_WITH"] }],
156+
} as unknown as Measure;
157+
132158
let mockApplyDefaults = false;
133159
jest.mock("@madie/madie-util", () => ({
134160
useFeatureFlags: jest.fn().mockImplementation(() => ({
@@ -151,8 +177,11 @@ const renderWithTestCase = (
151177
exportTestCase,
152178
onCloneTestCase,
153179
measure,
154-
setSelectedTestCases = jest.fn(), // Default to mock function
155-
setSorting = undefined
180+
setSelectedTestCases = jest.fn(),
181+
setSorting = undefined,
182+
selectedTestCases,
183+
deleteDialogModalOpen = false,
184+
setDeleteDialogModalOpen = jest.fn()
156185
) => {
157186
return render(
158187
<MemoryRouter>
@@ -165,7 +194,10 @@ const renderWithTestCase = (
165194
exportTestCase={exportTestCase}
166195
onCloneTestCase={onCloneTestCase}
167196
measure={measure}
168-
setSelectedTestCases={setSelectedTestCases} // Always pass mock function
197+
setSelectedTestCases={setSelectedTestCases}
198+
selectedTestCases={selectedTestCases}
199+
deleteDialogModalOpen={deleteDialogModalOpen}
200+
setDeleteDialogModalOpen={setDeleteDialogModalOpen}
169201
/>
170202
</MemoryRouter>
171203
);
@@ -213,19 +245,6 @@ describe("TestCase component", () => {
213245
expect(screen.getByText("export collection bundle")).toBeInTheDocument();
214246
expect(screen.getByText("delete")).toBeInTheDocument();
215247
expect(screen.getByText("Shift Test Case dates")).toBeInTheDocument();
216-
217-
const deleteButton = screen.getByText("delete");
218-
fireEvent.click(deleteButton);
219-
220-
expect(screen.getByText("Delete Test Case")).toBeInTheDocument();
221-
expect(screen.getByText("Cancel")).toBeInTheDocument();
222-
expect(screen.getByText("Yes, Delete")).toBeInTheDocument();
223-
224-
fireEvent.click(screen.getByText("Cancel"));
225-
await waitFor(() => {
226-
const submitButton = screen.queryByText("Yes, Delete");
227-
expect(submitButton).not.toBeInTheDocument();
228-
});
229248
});
230249

231250
it("should render test case table with case numbers", async () => {
@@ -366,6 +385,76 @@ describe("TestCase component", () => {
366385
expect(setSelectedTestCasesMock).toHaveBeenCalled();
367386
});
368387

388+
it("should show the delete confirmation dialog when delete button is clicked", async () => {
389+
const deleteTestCase = jest.fn();
390+
const exportTestCase = jest.fn();
391+
const onCloneTestCase = jest.fn();
392+
const setSelectedTestCasesMock = jest.fn();
393+
394+
let deleteDialogModalOpen = false;
395+
396+
const { rerender } = renderWithTestCase(
397+
testCases,
398+
true,
399+
deleteTestCase,
400+
exportTestCase,
401+
onCloneTestCase,
402+
defaultMeasure,
403+
setSelectedTestCasesMock,
404+
undefined,
405+
[],
406+
deleteDialogModalOpen,
407+
(value) => {
408+
deleteDialogModalOpen = value;
409+
}
410+
);
411+
412+
const selectButton = await screen.findByTestId("select-action-ID");
413+
expect(selectButton).toBeInTheDocument();
414+
415+
fireEvent.click(selectButton);
416+
417+
const deleteButton = await screen.findByText("delete");
418+
expect(deleteButton).toBeInTheDocument();
419+
420+
fireEvent.click(deleteButton);
421+
422+
expect(deleteDialogModalOpen).toBe(true);
423+
424+
rerender(
425+
<MemoryRouter>
426+
<TestCaseTable
427+
sorting={[]}
428+
setSorting={undefined}
429+
testCases={testCases}
430+
canEdit={true}
431+
deleteTestCase={deleteTestCase}
432+
exportTestCase={exportTestCase}
433+
onCloneTestCase={onCloneTestCase}
434+
measure={defaultMeasure}
435+
setSelectedTestCases={setSelectedTestCasesMock}
436+
selectedTestCases={[]}
437+
deleteDialogModalOpen={true}
438+
setDeleteDialogModalOpen={(value) => {
439+
deleteDialogModalOpen = value;
440+
}}
441+
/>
442+
</MemoryRouter>
443+
);
444+
445+
const deleteDialog = screen.getByText("Delete Test Case");
446+
expect(deleteDialog).toBeInTheDocument();
447+
448+
const cancelButton = screen.getByText("Cancel");
449+
const confirmButton = screen.getByText("Yes, Delete");
450+
451+
expect(cancelButton).toBeInTheDocument();
452+
expect(confirmButton).toBeInTheDocument();
453+
454+
fireEvent.click(confirmButton);
455+
expect(deleteTestCase).toHaveBeenCalled();
456+
});
457+
369458
it("should display View button if the measure is not a draft and the TestCaseListActionCenter feature flag is true", async () => {
370459
(useFeatureFlags as jest.Mock).mockImplementation(() => ({
371460
TestCaseListActionCenter: true,

src/components/editMeasure/testCases/components/testCaseLanding/common/TestCaseTable/TestCaseTable.tsx

+14-6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ interface TestCaseTableProps {
3838
sorting: any;
3939
setSorting: any;
4040
setSelectedTestCases: any;
41+
selectedTestCases: any;
42+
deleteDialogModalOpen: any;
43+
setDeleteDialogModalOpen: any;
4144
}
4245

4346
export const convertDate = (date: string) => {
@@ -76,10 +79,11 @@ const TestCaseTable = (props: TestCaseTableProps) => {
7679
sorting,
7780
setSorting,
7881
setSelectedTestCases,
82+
selectedTestCases,
83+
deleteDialogModalOpen,
84+
setDeleteDialogModalOpen,
7985
} = props;
8086
const viewOrEdit = canEdit ? "edit" : "view";
81-
const [deleteDialogModalOpen, setDeleteDialogModalOpen] =
82-
useState<boolean>(false);
8387
const [toastOpen, setToastOpen] = useState<boolean>(false);
8488
const [toastMessage, setToastMessage] = useState<string>("");
8589
const [toastType, setToastType] = useState<string>("danger");
@@ -96,7 +100,6 @@ const TestCaseTable = (props: TestCaseTableProps) => {
96100
useState<boolean>(false);
97101
const featureFlags = useFeatureFlags();
98102
const navigate = useNavigate();
99-
100103
const handleOpen = (
101104
selected: TestCase,
102105
event: React.MouseEvent<HTMLButtonElement>
@@ -149,7 +152,7 @@ const TestCaseTable = (props: TestCaseTableProps) => {
149152

150153
const columns = useMemo<ColumnDef<TCRow>[]>(() => {
151154
const columnDefs = [];
152-
if (featureFlags.TestCaseListActionCenter) {
155+
if (featureFlags?.TestCaseListActionCenter) {
153156
columnDefs.push({
154157
id: "select",
155158
header: ({ table }) => (
@@ -272,7 +275,7 @@ const TestCaseTable = (props: TestCaseTableProps) => {
272275
enableSorting: false,
273276
},
274277
];
275-
}, [testCases]);
278+
}, [testCases, featureFlags?.TestCaseListActionCenter]);
276279

277280
const table = useReactTable({
278281
data,
@@ -414,7 +417,12 @@ const TestCaseTable = (props: TestCaseTableProps) => {
414417
<MadieDeleteDialog
415418
open={deleteDialogModalOpen}
416419
onContinue={() => {
417-
deleteTestCase(selectedTestCase.id);
420+
if (featureFlags?.TestCaseListActionCenter) {
421+
deleteTestCase(selectedTestCases[0].id);
422+
setDeleteDialogModalOpen(false);
423+
} else {
424+
deleteTestCase(selectedTestCase.id);
425+
}
418426
}}
419427
onClose={() => {
420428
setDeleteDialogModalOpen(false);

src/components/editMeasure/testCases/components/testCaseLanding/common/TestCaseTable/TestCaseTablePopover.tsx

+13-11
Original file line numberDiff line numberDiff line change
@@ -175,17 +175,19 @@ const TestCaseTablePopover = (props: TestCaseTablePopoverProps) => {
175175

176176
{canEdit && (
177177
<>
178-
<button
179-
id={`delete-test-case-btn-${selectedTestCase?.id}`}
180-
aria-label={`delete-test-case-${selectedTestCase?.title}`}
181-
data-testid={`delete-test-case-btn-${selectedTestCase?.id}`}
182-
onClick={() => {
183-
setDeleteDialogModalOpen(true);
184-
setOptionsOpen(false);
185-
}}
186-
>
187-
delete
188-
</button>
178+
{!featureFlags.TestCaseListActionCenter && (
179+
<button
180+
id={`delete-test-case-btn-${selectedTestCase?.id}`}
181+
aria-label={`delete-test-case-${selectedTestCase?.title}`}
182+
data-testid={`delete-test-case-btn-${selectedTestCase?.id}`}
183+
onClick={() => {
184+
setDeleteDialogModalOpen(true);
185+
setOptionsOpen(false);
186+
}}
187+
>
188+
delete
189+
</button>
190+
)}
189191
{model.startsWith("QI-Core") &&
190192
selectedTestCase &&
191193
selectedTestCase.executionStatus != "Invalid" && (

src/components/editMeasure/testCases/components/testCaseLanding/qdm/TestCaseList.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ const TestCaseList = (props: TestCaseListProps) => {
165165
const [selectedTestCases, setSelectedTestCases] = useState<any>();
166166
const [exportExecuting, setExportExecuting] = useState(false);
167167
const [optionsOpen, setOptionsOpen] = useState<boolean>(false);
168+
const [deleteDialogModalOpen, setDeleteDialogModalOpen] =
169+
useState<boolean>(false);
168170
const featureFlags = useFeatureFlags();
169171
const qdmCqlParsingService = useRef(useQdmCqlParsingService());
170172
const [exportOptionsOpen, setExportOptionsOpen] = useState<boolean>(false);
@@ -793,6 +795,7 @@ const TestCaseList = (props: TestCaseListProps) => {
793795
selectedTestCases={selectedTestCases}
794796
canEdit={canEdit}
795797
isQDM={true}
798+
setDeleteDialogModalOpen={setDeleteDialogModalOpen}
796799
onCloneTestCase={handleCloneTestCase}
797800
onExportExcel={exportExcel}
798801
onExportQRDA={exportQRDA}
@@ -811,6 +814,9 @@ const TestCaseList = (props: TestCaseListProps) => {
811814
measure={measure}
812815
onTestCaseShiftDates={onTestCaseShiftDates}
813816
setSelectedTestCases={setSelectedTestCases}
817+
deleteDialogModalOpen={deleteDialogModalOpen}
818+
selectedTestCases={selectedTestCases}
819+
setDeleteDialogModalOpen={setDeleteDialogModalOpen}
814820
/>
815821
<Pagination
816822
totalItems={totalItems}

src/components/editMeasure/testCases/components/testCaseLanding/qiCore/TestCaseList.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ const TestCaseList = (props: TestCaseListProps) => {
157157
useState<boolean>(false);
158158
const abortController = useRef(null);
159159
const [createOpen, setCreateOpen] = useState<boolean>(false);
160+
const [deleteDialogModalOpen, setDeleteDialogModalOpen] =
161+
useState<boolean>(false);
160162
const featureFlags = useFeatureFlags();
161163
const [exportOptionsOpen, setExportOptionsOpen] = useState<boolean>(false);
162164

@@ -638,6 +640,7 @@ const TestCaseList = (props: TestCaseListProps) => {
638640
selectedTestCases={selectedTestCases}
639641
canEdit={canEdit}
640642
isQDM={false}
643+
setDeleteDialogModalOpen={setDeleteDialogModalOpen}
641644
onCloneTestCase={handleQiCloneTestCase}
642645
exportTestCases={exportTestCases}
643646
exportOptionsOpen={exportOptionsOpen}
@@ -655,6 +658,9 @@ const TestCaseList = (props: TestCaseListProps) => {
655658
onTestCaseShiftDates={onTestCaseShiftDates}
656659
handleQiCloneTestCase={handleQiCloneTestCase}
657660
setSelectedTestCases={setSelectedTestCases}
661+
selectedTestCases={selectedTestCases}
662+
deleteDialogModalOpen={deleteDialogModalOpen}
663+
setDeleteDialogModalOpen={setDeleteDialogModalOpen}
658664
/>
659665
{currentSlice?.length > 0 && (
660666
<Pagination

0 commit comments

Comments
 (0)