91 lines
3.0 KiB
TypeScript
91 lines
3.0 KiB
TypeScript
// @vitest-environment jsdom
|
|
import "@testing-library/jest-dom/vitest";
|
|
import { cleanup, render } from "@testing-library/react";
|
|
import { afterEach, describe, expect, it } from "vitest";
|
|
import { Description as RadixDialogDescription, Title as RadixDialogTitle } from "@radix-ui/react-dialog";
|
|
import { Drawer } from "../Drawer";
|
|
import { FullscreenDialog } from "../FullscreenDialog";
|
|
import { ModalBlank } from "../ModalBlank";
|
|
import { Select } from "../Select";
|
|
import { Dialog } from ".";
|
|
|
|
afterEach(cleanup);
|
|
|
|
function expectModalLayer() {
|
|
const layer = document.querySelector<HTMLElement>('[data-ui-layer="modal"]');
|
|
expect(layer).not.toBeNull();
|
|
expect(layer).toHaveClass("z-[60]");
|
|
return layer!;
|
|
}
|
|
|
|
describe("Subframe modal layering", () => {
|
|
it("places dialogs above the app sidebar", () => {
|
|
render(
|
|
<Dialog open>
|
|
<Dialog.Content>Dialog content</Dialog.Content>
|
|
</Dialog>,
|
|
);
|
|
|
|
const layer = expectModalLayer();
|
|
expect(layer).toHaveClass("bg-black/35", "backdrop-blur-[4px]", "data-[state=open]:duration-300");
|
|
expect(document.querySelector('[data-state="open"][role="dialog"]')).toHaveClass(
|
|
"data-[state=open]:zoom-in-[0.98]",
|
|
"data-[state=open]:slide-in-from-bottom-1",
|
|
"motion-reduce:animate-none",
|
|
);
|
|
});
|
|
|
|
it("uses the same modal layer for blank modals, drawers and fullscreen dialogs", () => {
|
|
const { unmount: unmountModal } = render(
|
|
<ModalBlank open>
|
|
<ModalBlank.Content>Modal content</ModalBlank.Content>
|
|
</ModalBlank>,
|
|
);
|
|
expectModalLayer();
|
|
unmountModal();
|
|
|
|
const { unmount: unmountDrawer } = render(
|
|
<Drawer open>
|
|
<Drawer.Content>Drawer content</Drawer.Content>
|
|
</Drawer>,
|
|
);
|
|
const drawerLayer = expectModalLayer();
|
|
expect(drawerLayer).toHaveClass("hg-drawer-backdrop", "backdrop-blur-[4px]");
|
|
expect(drawerLayer).not.toHaveClass("data-[state=closed]:fade-out-0");
|
|
expect(document.querySelector('[data-state="open"][role="dialog"]')).toHaveClass(
|
|
"data-[state=open]:slide-in-from-right",
|
|
"data-[state=closed]:slide-out-to-right",
|
|
"data-[state=open]:duration-[360ms]",
|
|
"motion-reduce:animate-none",
|
|
);
|
|
unmountDrawer();
|
|
|
|
render(
|
|
<FullscreenDialog open>
|
|
<div>
|
|
<RadixDialogTitle className="sr-only">Fullscreen title</RadixDialogTitle>
|
|
<RadixDialogDescription className="sr-only">Fullscreen description</RadixDialogDescription>
|
|
Fullscreen content
|
|
</div>
|
|
</FullscreenDialog>,
|
|
);
|
|
expectModalLayer();
|
|
});
|
|
|
|
it("keeps portalled select menus above an open modal", () => {
|
|
render(
|
|
<Dialog open>
|
|
<Dialog.Content>
|
|
<Select open value="one" onValueChange={() => undefined}>
|
|
<Select.Item value="one">One</Select.Item>
|
|
</Select>
|
|
</Dialog.Content>
|
|
</Dialog>,
|
|
);
|
|
|
|
const floatingLayer = document.querySelector<HTMLElement>('[data-ui-layer="modal-floating"]');
|
|
expect(floatingLayer).not.toBeNull();
|
|
expect(floatingLayer).toHaveClass("z-[70]");
|
|
});
|
|
});
|