Update and refine alert modals

This commit is contained in:
adilallo
2026-04-26 08:08:02 -06:00
parent 0ce05372bf
commit 9962f44ff1
15 changed files with 508 additions and 157 deletions
+32
View File
@@ -1,6 +1,10 @@
import React from "react";
import { describe, expect, it, vi } from "vitest";
import { screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import Alert from "../../app/components/modals/Alert";
import { componentTestSuite } from "../utils/componentTestSuite";
import { renderWithProviders as render } from "../utils/test-utils";
type AlertProps = React.ComponentProps<typeof Alert>;
@@ -16,6 +20,7 @@ componentTestSuite<AlertProps>({
description: "Optional description",
status: "positive",
type: "banner",
size: "m",
},
primaryRole: "alert",
testCases: {
@@ -26,3 +31,30 @@ componentTestSuite<AlertProps>({
errorState: false,
},
});
describe("Alert dismiss control", () => {
it("omits close button when onClose is absent", () => {
render(<Alert title="T" description="D" />);
expect(
screen.queryByRole("button", { name: "Close alert" }),
).not.toBeInTheDocument();
});
it("renders close when onClose is provided", async () => {
const user = userEvent.setup();
const onClose = vi.fn();
render(<Alert title="T" onClose={onClose} />);
await user.click(screen.getByRole("button", { name: "Close alert" }));
expect(onClose).toHaveBeenCalledTimes(1);
});
it("omits close when hasTrailingIcon is false even if onClose exists", () => {
const onClose = vi.fn();
render(
<Alert title="T" onClose={onClose} hasTrailingIcon={false} />,
);
expect(
screen.queryByRole("button", { name: "Close alert" }),
).not.toBeInTheDocument();
});
});