45 lines
1.5 KiB
TypeScript
45 lines
1.5 KiB
TypeScript
import { render } from "@testing-library/react";
|
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const { sonnerToaster } = vi.hoisted(() => ({
|
|
sonnerToaster: vi.fn(() => null),
|
|
}));
|
|
|
|
vi.mock("sonner", () => ({
|
|
Toaster: (props: unknown) => sonnerToaster(props),
|
|
}));
|
|
|
|
import { GLOBAL_TOAST_DURATION_MS, Toaster } from "./sonner";
|
|
|
|
describe("global toast presentation", () => {
|
|
beforeEach(() => sonnerToaster.mockClear());
|
|
|
|
it("uses the same position, duration and semantic skin on every surface", () => {
|
|
render(<Toaster />);
|
|
|
|
expect(sonnerToaster).toHaveBeenCalledOnce();
|
|
expect(sonnerToaster).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
position: "top-center",
|
|
duration: GLOBAL_TOAST_DURATION_MS,
|
|
toastOptions: expect.objectContaining({
|
|
classNames: expect.objectContaining({
|
|
success: expect.stringContaining("bg-surface-feedback-subtle-positive!"),
|
|
error: expect.stringContaining("bg-surface-feedback-subtle-negative!"),
|
|
warning: expect.stringContaining("bg-surface-feedback-subtle-warning!"),
|
|
info: expect.stringContaining("bg-surface-feedback-subtle-information!"),
|
|
}),
|
|
}),
|
|
})
|
|
);
|
|
});
|
|
|
|
it("keeps an explicit duration override without changing the global position", () => {
|
|
render(<Toaster duration={9000} />);
|
|
|
|
expect(sonnerToaster).toHaveBeenCalledWith(
|
|
expect.objectContaining({ position: "top-center", duration: 9000 })
|
|
);
|
|
});
|
|
});
|