ARES - authorized red-team engagement automation with dashboard, campaign scope, module orchestration, OPSEC controls, encrypted vault, and reporting.
Python active-directorycloud-securitydefensive-validationfastapigood-first-issuemitre-attackopsecreactred-teamreportingsecurity
// @vitest-environment jsdom
import "../../test/setup";
import { cleanup, fireEvent, render, screen } from "@testing-library/react";
import { afterEach, describe, expect, it, vi } from "vitest";
import { ConfirmModal } from "./ConfirmModal";
describe("ConfirmModal", () => {
afterEach(() => {
cleanup();
});
it("does not render when open is false", () => {
const onConfirm = vi.fn();
const onCancel = vi.fn();
render(
<ConfirmModal
open={false}
title="Delete Key"
description="Are you sure?"
onConfirm={onConfirm}
onCancel={onCancel}
/>
);
expect(screen.queryByRole("dialog")).toBeNull();
});
it("renders title, description and calls onConfirm on confirm click", () => {
const onConfirm = vi.fn();
const onCancel = vi.fn();
render(
<ConfirmModal
open={true}
title="Delete API Key"
description="This action cannot be undone."
confirmLabel="Yes, Delete"
cancelLabel="No, Keep"
onConfirm={onConfirm}
onCancel={onCancel}
/>
);
expect(screen.getByRole("dialog")).toBeInTheDocument();
expect(screen.getByText("Delete API Key")).toBeInTheDocument();
expect(screen.getByText("This action cannot be undone.")).toBeInTheDocument();
const confirmBtn = screen.getByRole("button", { name: "Yes, Delete" });
fireEvent.click(confirmBtn);
expect(onConfirm).toHaveBeenCalledTimes(1);
expect(onCancel).not.toHaveBeenCalled();
});
it("calls onCancel when cancel button or close button is clicked", () => {
const onConfirm = vi.fn();
const onCancel = vi.fn();
render(
<ConfirmModal
open={true}
title="Delete Item"
description="Confirm deletion"
onConfirm={onConfirm}
onCancel={onCancel}
/>
);
const cancelBtn = screen.getByRole("button", { name: "Cancel" });
fireEvent.click(cancelBtn);
expect(onCancel).toHaveBeenCalledTimes(1);
const closeBtn = screen.getByRole("button", { name: "Close dialog" });
fireEvent.click(closeBtn);
expect(onCancel).toHaveBeenCalledTimes(2);
});
it("closes on Escape key press", () => {
const onConfirm = vi.fn();
const onCancel = vi.fn();
render(
<ConfirmModal
open={true}
title="Escape Test"
description="Test escape key"
onConfirm={onConfirm}
onCancel={onCancel}
/>
);
fireEvent.keyDown(window, { key: "Escape" });
expect(onCancel).toHaveBeenCalledTimes(1);
});
});