Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/packages/ui-app/src/adapters/notificationCenter.hot-swap.test.ts
T

97 lines
3.3 KiB
TypeScript

import { describe, expect, test } from "vitest";
import type { NotificationCenterData } from "@hivegrid/view-models";
import { renderNotificationCenterMock } from "@hivegrid/ui-mock";
import { notificationCenterAdapter } from "./notificationCenter.js";
const DEEPLINK = "/acme/settings/members";
const vm: NotificationCenterData = {
items: [
{
id: "delivery-1",
messageKey: "team.invite.created",
category: "team",
categoryKey: "notifications.center.categories.team",
channel: "IN_APP",
channelKey: "notifications.center.channels.in_app",
status: "SENT",
statusKey: "notifications.center.statuses.sent",
isRead: false,
attemptsMade: 1,
createdAtIso: "2026-07-06T08:00:00.000Z",
updatedAtIso: "2026-07-06T08:01:00.000Z",
sentAtIso: "2026-07-06T08:01:00.000Z",
readAtIso: null,
sortTimestamp: 1783069260000,
bounceKey: null,
lastErrorRedacted: null,
deeplinkHref: DEEPLINK,
subjectLabel: null,
tagKey: null,
tagTone: null,
},
{
id: "delivery-2",
messageKey: "billing.invoice.failed",
category: "billing",
categoryKey: "notifications.center.categories.billing",
channel: "IN_APP",
channelKey: "notifications.center.channels.in_app",
status: "READ",
statusKey: "notifications.center.statuses.read",
isRead: true,
attemptsMade: 3,
createdAtIso: "2026-07-05T08:00:00.000Z",
updatedAtIso: "2026-07-05T08:05:00.000Z",
sentAtIso: null,
readAtIso: "2026-07-05T08:05:00.000Z",
sortTimestamp: 1782982500000,
bounceKey: "notifications.center.bounce.rateLimited",
lastErrorRedacted: null,
deeplinkHref: null,
subjectLabel: null,
tagKey: null,
tagTone: null,
},
],
totalCount: 2,
unreadCount: 1,
emptyHeadlineKey: "notifications.center.empty",
emptyBodyKey: "notifications.center.emptyHelper",
unreadEmptyKey: "notifications.center.unreadEmpty",
streamAvailable: true,
};
describe("notificationCenterAdapter hot-swap (M017)", () => {
test("normalizes the VM once via toProps", () => {
const model = notificationCenterAdapter.toProps(vm);
expect(model.totalCount).toBe(2);
expect(model.unreadCount).toBe(1);
expect(model.items[0]?.deeplinkHref).toBe(DEEPLINK);
expect(model.items[1]?.bounceKey).toBe("notifications.center.bounce.rateLimited");
});
test("swaps the render implementation without changing the data", () => {
const defaultHtml = notificationCenterAdapter.render(vm);
const mockHtml = notificationCenterAdapter.render(vm, renderNotificationCenterMock);
expect(defaultHtml).toContain('data-ui-impl="subframe"');
expect(mockHtml).toContain('data-ui-impl="mock"');
expect(defaultHtml).not.toBe(mockHtml);
for (const html of [defaultHtml, mockHtml]) {
for (const item of vm.items) {
expect(html).toContain(`data-row-id="${item.id}"`);
}
expect(html).toContain(DEEPLINK);
expect(html).toContain('data-unread-count="1"');
}
});
test("the default renderer is the real subframe implementation", () => {
expect(notificationCenterAdapter.name).toBe("notificationCenter");
expect(notificationCenterAdapter.render(vm)).toContain('data-ui-id="ui.notifications.center"');
});
});