Implements DialogRoot, Content, Title, Description, Trigger, Close, Portal, and Overlay parts with full context wiring, focus trap, scroll lock, and dismiss. Also fixes pre-existing TS6 exactOptionalPropertyTypes errors in create-disclosure-state and presence, and silences TS6.0 deprecation warnings via ignoreDeprecations.
66 lines
1.9 KiB
TypeScript
66 lines
1.9 KiB
TypeScript
// packages/core/tests/components/dialog/dialog-rendering.test.tsx
|
|
import { render, screen } from "@solidjs/testing-library";
|
|
import { createSignal } from "solid-js";
|
|
import { describe, expect, it } from "vitest";
|
|
import { Dialog } from "../../../src/components/dialog/index";
|
|
|
|
describe("Dialog rendering", () => {
|
|
it("renders children", () => {
|
|
render(() => (
|
|
<Dialog defaultOpen>
|
|
<Dialog.Content>
|
|
<Dialog.Title>Hello</Dialog.Title>
|
|
</Dialog.Content>
|
|
</Dialog>
|
|
));
|
|
expect(screen.getByText("Hello")).toBeTruthy();
|
|
});
|
|
|
|
it("does not render content when closed by default", () => {
|
|
render(() => (
|
|
<Dialog>
|
|
<Dialog.Content>
|
|
<Dialog.Title>Hidden</Dialog.Title>
|
|
</Dialog.Content>
|
|
</Dialog>
|
|
));
|
|
expect(screen.queryByText("Hidden")).toBeNull();
|
|
});
|
|
|
|
it("renders content when defaultOpen is true", () => {
|
|
render(() => (
|
|
<Dialog defaultOpen>
|
|
<Dialog.Content>
|
|
<Dialog.Title>Visible</Dialog.Title>
|
|
</Dialog.Content>
|
|
</Dialog>
|
|
));
|
|
expect(screen.getByText("Visible")).toBeTruthy();
|
|
});
|
|
|
|
it("renders content when controlled open is true", () => {
|
|
render(() => (
|
|
<Dialog open={true} onOpenChange={() => {}}>
|
|
<Dialog.Content>
|
|
<Dialog.Title>Controlled</Dialog.Title>
|
|
</Dialog.Content>
|
|
</Dialog>
|
|
));
|
|
expect(screen.getByText("Controlled")).toBeTruthy();
|
|
});
|
|
|
|
it("closes when controlled open is set to false", () => {
|
|
const [open, setOpen] = createSignal(true);
|
|
render(() => (
|
|
<Dialog open={open()} onOpenChange={setOpen}>
|
|
<Dialog.Content>
|
|
<Dialog.Title>Toggled</Dialog.Title>
|
|
</Dialog.Content>
|
|
</Dialog>
|
|
));
|
|
expect(screen.getByText("Toggled")).toBeTruthy();
|
|
setOpen(false);
|
|
expect(screen.queryByText("Toggled")).toBeNull();
|
|
});
|
|
});
|