Files
heroui-inc--heroui/packages/react/tests/components/alert/alert.test.tsx
T
WK bb9c4b5582 V3.2.4 (#6758)
* fix(tabs): clamp ListContainer chevron scrolling to the scrollable range (#6749)

* chore(deps): bump react-aria dependencies (#6752)

* chore(deps): bump tailwind-variants to v3.3.1 (#6760)

* chore(docs): release note for 3.2.4

* test(react): behavioral testing infra (#6754)

* fix(link): expose data-slot on link root

* fix(react): put style export condition before default

* test(react): behavioral testing infra and suites

* chore(testing): own vitest-browser-react and clarify coverage gates

* chore: remove pinned version

* fix(autocomplete): prevent popover from clipping the last options (#6766)

* chore(docs): update release note

* fix(styles): prevent subpixel border overflow on badge (#6768)

* chore(docs): update release note

* fix(styles): allow backdrop click to dismiss modal with scroll outside (#6770)

* chore(docs): update release note

* fix(tooltip): restore exit animation when swapping between tooltips (#6772)

* chore(docs): update release note

---------

Co-authored-by: Tyler <56234978+runnerboy22@users.noreply.github.com>
Co-authored-by: Tianen Pang <32772271+tianenpang@users.noreply.github.com>
2026-08-07 06:19:12 -07:00

101 lines
3.0 KiB
TypeScript

import {render, screen} from "@heroui/testing/helpers";
import {Alert} from "@/components/alert";
describe("Alert", () => {
it("exposes data-slot and BEM block", () => {
render(
<Alert>
<Alert.Indicator />
<Alert.Content>
<Alert.Title>New features available</Alert.Title>
<Alert.Description>Check out our latest updates.</Alert.Description>
</Alert.Content>
</Alert>,
);
const root = document.querySelector('[data-slot="alert-root"]');
expect(root).not.toBeNull();
expect(root?.className).toEqual(expect.stringContaining("alert"));
expect(document.querySelector('[data-slot="alert-indicator"]')).not.toBeNull();
expect(document.querySelector('[data-slot="alert-content"]')).not.toBeNull();
expect(screen.getByText("New features available")).toBeInTheDocument();
expect(screen.getByText("Check out our latest updates.")).toBeInTheDocument();
});
it("exposes default status BEM modifier", () => {
render(
<Alert>
<Alert.Content>
<Alert.Title>Default</Alert.Title>
</Alert.Content>
</Alert>,
);
expect(document.querySelector('[data-slot="alert-root"]')?.className).toEqual(
expect.stringContaining("alert--default"),
);
});
it.each(["accent", "success", "warning", "danger"] as const)(
"maps status=%s to the matching BEM modifier",
(status) => {
render(
<Alert status={status}>
<Alert.Content>
<Alert.Title>Status alert</Alert.Title>
</Alert.Content>
</Alert>,
);
expect(document.querySelector('[data-slot="alert-root"]')?.className).toEqual(
expect.stringContaining(`alert--${status}`),
);
},
);
it("renders a default icon per status when no indicator children are given", () => {
render(
<Alert status="danger">
<Alert.Indicator />
<Alert.Content>
<Alert.Title>Unable to connect</Alert.Title>
</Alert.Content>
</Alert>,
);
expect(document.querySelector('[data-slot="alert-default-icon"]')).not.toBeNull();
});
it("renders custom indicator children instead of the default icon", () => {
render(
<Alert status="accent">
<Alert.Indicator>
<span data-testid="custom-indicator">Loading</span>
</Alert.Indicator>
<Alert.Content>
<Alert.Title>Processing</Alert.Title>
</Alert.Content>
</Alert>,
);
expect(screen.getByTestId("custom-indicator")).toBeInTheDocument();
expect(document.querySelector('[data-slot="alert-default-icon"]')).toBeNull();
});
it("renders without a description", () => {
render(
<Alert status="success">
<Alert.Indicator />
<Alert.Content>
<Alert.Title>Profile updated successfully</Alert.Title>
</Alert.Content>
</Alert>,
);
expect(screen.getByText("Profile updated successfully")).toBeInTheDocument();
expect(document.querySelector('[data-slot="alert-description"]')).toBeNull();
});
});