diff --git a/ui/components/shadcn/dialog.test.tsx b/ui/components/shadcn/dialog.test.tsx new file mode 100644 index 0000000000..8ccb72de42 --- /dev/null +++ b/ui/components/shadcn/dialog.test.tsx @@ -0,0 +1,84 @@ +import { render, screen } from "@testing-library/react"; +import { describe, expect, it } from "vitest"; + +import { + Dialog, + DialogContent, + DialogDescription, + DialogTitle, + DialogTrigger, +} from "./dialog"; + +function renderOpenDialog() { + return render( + + Open modal + + Launch scan + Configure scan settings + + , + ); +} + +describe("Dialog", () => { + it("renders controlled content through the Radix Dialog API", () => { + // Given + renderOpenDialog(); + + // When + const dialog = screen.getByRole("dialog", { name: "Launch scan" }); + + // Then + expect(dialog).toBeVisible(); + expect(dialog).toHaveAttribute("data-slot", "dialog-content"); + expect(screen.getByText("Configure scan settings")).toBeVisible(); + }); + + it("uses an intentional overlay motion contract", () => { + // Given + renderOpenDialog(); + + // When + const overlay = document.querySelector("[data-slot='dialog-overlay']"); + + // Then + expect(overlay).toHaveClass( + "duration-200", + "ease-out", + "data-[state=open]:animate-in", + "data-[state=open]:fade-in-0", + "data-[state=closed]:animate-out", + "data-[state=closed]:fade-out-0", + "data-[state=closed]:duration-100", + "data-[state=closed]:ease-in", + "motion-reduce:animate-none", + "motion-reduce:transition-none", + ); + }); + + it("uses an intentional content motion contract", () => { + // Given + renderOpenDialog(); + + // When + const dialog = screen.getByRole("dialog", { name: "Launch scan" }); + + // Then + expect(dialog).toHaveClass( + "duration-200", + "ease-out", + "data-[state=open]:animate-in", + "data-[state=open]:fade-in-0", + "data-[state=open]:zoom-in-95", + "data-[state=closed]:animate-out", + "data-[state=closed]:fade-out-0", + "data-[state=closed]:zoom-out-95", + "data-[state=closed]:duration-100", + "data-[state=closed]:ease-in", + "motion-reduce:animate-none", + "motion-reduce:transform-none", + "motion-reduce:transition-none", + ); + }); +}); diff --git a/ui/components/shadcn/dialog.tsx b/ui/components/shadcn/dialog.tsx index 63721874a1..ee275f5c5f 100644 --- a/ui/components/shadcn/dialog.tsx +++ b/ui/components/shadcn/dialog.tsx @@ -37,7 +37,7 @@ function DialogOverlay({ e.stopPropagation()}