// packages/core/tests/components/alert-dialog/alert-dialog.test.tsx import { fireEvent, render, screen } from "@solidjs/testing-library"; import { describe, expect, it } from "vitest"; import { AlertDialog } from "../../../src/components/alert-dialog/index"; describe("AlertDialog", () => { it("content has role=alertdialog", () => { render(() => ( Confirm Are you sure? )); expect(screen.getByRole("alertdialog")).toBeTruthy(); }); it("content has aria-modal=true", () => { render(() => ( Confirm )); expect(screen.getByRole("alertdialog").getAttribute("aria-modal")).toBe("true"); }); it("content is linked to title via aria-labelledby", () => { render(() => ( Delete file? )); const dialog = screen.getByRole("alertdialog"); const title = screen.getByText("Delete file?"); expect(dialog.getAttribute("aria-labelledby")).toBe(title.id); }); it("content is linked to description via aria-describedby", () => { render(() => ( Confirm This cannot be undone. )); const dialog = screen.getByRole("alertdialog"); const desc = screen.getByText("This cannot be undone."); expect(dialog.getAttribute("aria-describedby")).toBe(desc.id); }); it("trigger opens the dialog", () => { render(() => ( Delete Confirm )); expect(screen.queryByRole("alertdialog")).toBeNull(); fireEvent.click(screen.getByText("Delete")); expect(screen.getByRole("alertdialog")).toBeTruthy(); }); it("Cancel button closes the dialog", () => { render(() => ( Confirm Cancel )); fireEvent.click(screen.getByText("Cancel")); expect(screen.queryByRole("alertdialog")).toBeNull(); }); it("Action button closes the dialog", () => { render(() => ( Are you sure? Confirm )); fireEvent.click(screen.getByText("Confirm")); expect(screen.queryByRole("alertdialog")).toBeNull(); }); it("Escape key does NOT close alert dialog", () => { render(() => ( Confirm )); fireEvent.keyDown(document, { key: "Escape" }); expect(screen.getByRole("alertdialog")).toBeTruthy(); }); });