Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

toast.browser.test.tsx

34 lines1.4 KB

1import { describe, expect, it } from "vite-plus/test";
2import { page } from "vite-plus/test/browser";
3​
4import { render } from "../../../test/render";
5import { AnchoredToastProvider, ToastProvider, toastManager } from "./toast";
6​
7describe("toastManager", () => {
8 it("shows a toast added before any provider mounted", async () => {
9 toastManager.add({ type: "info", title: "Raised before the first render" });
10​
11 await using _screen = await render(<ToastProvider>{null}</ToastProvider>);
12​
13 await expect.element(page.getByText("Raised before the first render")).toBeVisible();
14 });
15​
16 it("exposes one Notifications landmark when both toast providers mount", async () => {
17 await using _screen = await render(
18 <ToastProvider>
19 <AnchoredToastProvider>{null}</AnchoredToastProvider>
20 </ToastProvider>,
21 );
22​
23 const notifications = page.getByRole("region", { name: "Notifications" });
24 await expect.element(notifications.first()).toBeInTheDocument();
25 expect(
26 notifications.elements(),
27 "only the corner toast viewport should be a Notifications landmark",
28 ).toHaveLength(1);
29 await expect.element(notifications).toHaveAttribute("data-slot", "toast-viewport");
30​
31 const anchoredViewport = document.querySelector("[data-slot=toast-viewport-anchored]");
32 expect(anchoredViewport).toHaveAttribute("aria-live", "polite");
33 });
34});