60 lines
2.4 KiB
TypeScript
60 lines
2.4 KiB
TypeScript
import { vi, describe, it, expect } from "vitest";
|
|
import "@testing-library/jest-dom";
|
|
import { fireEvent, render } from "@testing-library/react";
|
|
import { toNotificationCenterItemVM, type NotificationCenterItemVM } from "@hivegrid/view-models";
|
|
|
|
import { NotificationsDrawer } from "./NotificationsDrawer";
|
|
|
|
vi.mock("react-i18next", () => ({
|
|
useTranslation: () => ({
|
|
t: (str: string) => str,
|
|
i18n: { language: "de", exists: (key: string) => key === "team.invite.created" },
|
|
}),
|
|
}));
|
|
|
|
function item(overrides: Partial<Parameters<typeof toNotificationCenterItemVM>[0]> = {}): NotificationCenterItemVM {
|
|
return toNotificationCenterItemVM({
|
|
id: "delivery_1",
|
|
messageKey: "team.invite.created",
|
|
category: "team",
|
|
channel: "IN_APP",
|
|
status: "SENT",
|
|
attemptsMade: 1,
|
|
createdAtIso: "2026-07-01T10:00:00.000Z",
|
|
sentAtIso: "2026-07-01T10:01:00.000Z",
|
|
...overrides,
|
|
});
|
|
}
|
|
|
|
describe("NotificationsDrawer (interim-UI)", () => {
|
|
it("renders items with unread badge and deeplink when open", () => {
|
|
render(
|
|
<NotificationsDrawer
|
|
open
|
|
items={[item({ payloadMetadata: { deeplink: "/acme/settings/members" } }), item({ id: "d2", status: "READ" })]}
|
|
allHref="/acme/notifications"
|
|
onClose={vi.fn()}
|
|
/>,
|
|
);
|
|
|
|
expect(document.querySelector('[data-ui-id="ui.notifications.drawer"]')).toBeInTheDocument();
|
|
expect(document.querySelector('[data-row-id="delivery_1"]')).toHaveAttribute("data-read", "false");
|
|
expect(document.querySelector('[data-ui-id="ui.notifications.drawer.deeplink"]')).toHaveAttribute("href", "/acme/settings/members");
|
|
expect(document.querySelector('[data-ui-id="ui.notifications.drawer.showAll"]')).toHaveAttribute("href", "/acme/notifications");
|
|
});
|
|
|
|
it("shows the empty state and closes via the close button", () => {
|
|
const onClose = vi.fn();
|
|
render(<NotificationsDrawer open items={[]} allHref="/acme/notifications" onClose={onClose} />);
|
|
|
|
expect(document.querySelector('[data-ui-id="ui.notifications.drawer.empty"]')).toBeInTheDocument();
|
|
fireEvent.click(document.querySelector('[data-ui-id="ui.notifications.drawer.close"]')!);
|
|
expect(onClose).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it("renders nothing visible when closed", () => {
|
|
render(<NotificationsDrawer open={false} items={[item()]} allHref="/acme/notifications" onClose={vi.fn()} />);
|
|
expect(document.querySelector('[data-ui-id="ui.notifications.drawer"]')).not.toBeInTheDocument();
|
|
});
|
|
});
|