Update hivegrid-cloud reference to latest main
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e98d38e716
commit
7b21524c86
3781 files changed
+373484
-225607
No files matched your search
@@ -10,7 +10,7 @@ import {
|
||||
generateMockPageHtml,
|
||||
} from "./index.js";
|
||||
|
||||
describe("@toolctrl/ui-mock", () => {
|
||||
describe("@hivegrid/ui-mock", () => {
|
||||
test("builds route-addressable hot-swap mock pages", () => {
|
||||
const page = createMockPage({ id: "empty", route: "/empty", state: { status: "empty" } });
|
||||
const registry = createMockRegistry([page]);
|
||||
|
||||
@@ -1,4 +1,17 @@
|
||||
import type { DataTableModel, FileBrowserModel, ShellRegistries, TaskListModel, VMState } from "@toolctrl/view-models";
|
||||
import type {
|
||||
AuditListModel,
|
||||
IntegrationCatalogModel,
|
||||
DataTableModel,
|
||||
FileBrowserModel,
|
||||
MembersListModel,
|
||||
NotificationCenterModel,
|
||||
RolesListModel,
|
||||
SelectTenantModel,
|
||||
SessionListModel,
|
||||
ShellRegistries,
|
||||
TaskListModel,
|
||||
VMState,
|
||||
} from "@hivegrid/view-models";
|
||||
|
||||
export type MockPage<T = unknown> = {
|
||||
readonly id: string;
|
||||
@@ -109,7 +122,7 @@ export function generateMockPageHtml<T>(page: MockPage<T>): string {
|
||||
`<body data-ui-mock-route="${escapeAttribute(page.route)}" data-ui-mock-status="${escapeAttribute(page.state.status)}">`,
|
||||
` <div class="mock-shell" data-ui-mock-page="${escapeAttribute(page.id)}">`,
|
||||
` <nav class="mock-nav" aria-label="${escapeAttribute(translateMockText("mock.ui.sidebarAria", "Mock sidebar"))}">`,
|
||||
` <div class="mock-brand">${escapeHtml(translateMockText("mock.ui.brand", "Toolctrl mock"))}</div>`,
|
||||
` <div class="mock-brand">${escapeHtml(translateMockText("mock.ui.brand", "HiveGrid mock"))}</div>`,
|
||||
...sidebarItems.map(
|
||||
(item) =>
|
||||
` <a class="mock-link" data-active="${item.href === page.route ? "true" : "false"}" href="${escapeAttribute(item.href)}">${escapeHtml(translateMockText(item.labelKey, item.labelKey))}</a>`
|
||||
@@ -176,7 +189,7 @@ const defaultMockTranslations: Record<string, string> = {
|
||||
"mock.phase-c.hot-swap.activity.registrySwap": "Registry swap",
|
||||
"mock.ui.documentTitle": "UI Mock",
|
||||
"mock.ui.sidebarAria": "Mock sidebar",
|
||||
"mock.ui.brand": "Toolctrl mock",
|
||||
"mock.ui.brand": "HiveGrid mock",
|
||||
"mock.ui.metricsAria": "Mock metrics",
|
||||
"mock.ui.activityAria": "Mock activity",
|
||||
"mock.ui.stateAria": "Mock state payload",
|
||||
@@ -327,6 +340,44 @@ export function renderTaskListMock(model: TaskListModel): string {
|
||||
return `<div data-ui-impl="mock" data-ui-id="ui.tasks.list" data-row-count="${model.rowCount}"><div data-row="head" data-i18n-key="${escapeHtml(model.titleKey)}"></div>${rows}</div>`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock render implementation for the session device list. Same normalized
|
||||
* {@link SessionListModel} data as the real Subframe impl, deliberately different
|
||||
* minimal chrome — proves the renderer is swappable (hot-swap drill, M017).
|
||||
*/
|
||||
export function renderSessionListMock(model: SessionListModel): string {
|
||||
const rows =
|
||||
model.rowCount === 0
|
||||
? `<div data-row="empty" data-empty="true" data-i18n-key="${escapeHtml(model.emptyHeadlineKey)}"></div>`
|
||||
: model.rows
|
||||
.map((row) => {
|
||||
const label = row.deviceLabel ? escapeHtml(row.deviceLabel) : "";
|
||||
return `<div data-row="body" data-row-id="${escapeHtml(row.id)}" data-current="${row.isCurrent}" data-trusted="${row.trusted}" data-last-seen-bucket="${escapeHtml(row.lastSeenBucket)}">${label}</div>`;
|
||||
})
|
||||
.join("");
|
||||
|
||||
return `<div data-ui-impl="mock" data-ui-id="ui.settings.security.sessions" data-row-count="${model.rowCount}"><div data-row="head" data-i18n-key="${escapeHtml(model.titleKey)}"></div>${rows}</div>`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock render implementation for the tenant/workspace picker. Same normalized
|
||||
* {@link SelectTenantModel} data as the real Subframe impl, deliberately different
|
||||
* minimal chrome — proves the renderer is swappable (hot-swap drill, M017).
|
||||
*/
|
||||
export function renderSelectTenantMock(model: SelectTenantModel): string {
|
||||
const rows =
|
||||
model.rowCount === 0
|
||||
? `<div data-row="empty" data-empty="true" data-i18n-key="${escapeHtml(model.emptyHeadlineKey)}"></div>`
|
||||
: model.rows
|
||||
.map(
|
||||
(row) =>
|
||||
`<div data-row="body" data-row-id="${escapeHtml(row.id)}" data-slug="${escapeHtml(row.slug)}" data-current="${row.isCurrent}">${escapeHtml(row.name)}</div>`
|
||||
)
|
||||
.join("");
|
||||
|
||||
return `<div data-ui-impl="mock" data-ui-id="ui.auth.selectTenant" data-row-count="${model.rowCount}"><div data-row="head" data-i18n-key="${escapeHtml(model.titleKey)}"></div>${rows}</div>`;
|
||||
}
|
||||
|
||||
function isHotSwapDrillData(value: unknown): value is HotSwapDrillData {
|
||||
if (!value || typeof value !== "object") return false;
|
||||
const candidate = value as Partial<HotSwapDrillData>;
|
||||
@@ -381,3 +432,98 @@ function escapeHtml(value: string): string {
|
||||
function escapeAttribute(value: string): string {
|
||||
return escapeHtml(value).replaceAll("'", "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock render implementation for the Audit-Viewer list (AK-P3). Same
|
||||
* normalized {@link AuditListModel} data as the real Subframe impl,
|
||||
* deliberately different minimal chrome (M017 hot-swap drill proof).
|
||||
*/
|
||||
export function renderAuditListMock(model: AuditListModel): string {
|
||||
const rows =
|
||||
model.rowCount === 0
|
||||
? `<div data-row="empty" data-empty="true" data-i18n-key="${escapeHtml(model.emptyHeadlineKey)}"></div>`
|
||||
: model.rows
|
||||
.map((row) => {
|
||||
const summary = row.summaryText ? escapeHtml(row.summaryText) : "";
|
||||
return `<div data-row="body" data-row-id="${escapeHtml(row.id)}" data-actor-kind-key="${escapeHtml(row.actorKindLabelKey)}" data-outcome="${escapeHtml(row.outcome)}" data-diff-count="${row.diffCount}" data-has-detail="${row.hasDetail}">${escapeHtml(row.actorLabel)} ${escapeHtml(row.action)} ${summary}</div>`;
|
||||
})
|
||||
.join("");
|
||||
|
||||
return `<div data-ui-impl="mock" data-ui-id="ui.audit.list" data-row-count="${model.rowCount}" data-page="${model.page}" data-can-export="${model.canExport}"><div data-row="head" data-i18n-key="${escapeHtml(model.titleKey)}"></div>${rows}</div>`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock render implementation for the Notification-Center list (AK-P3). Same
|
||||
* normalized {@link NotificationCenterModel} data, minimal div chrome; labels
|
||||
* stay i18n keys (no hardcoded copy in the mock).
|
||||
*/
|
||||
export function renderNotificationCenterMock(model: NotificationCenterModel): string {
|
||||
const rows =
|
||||
model.totalCount === 0
|
||||
? `<div data-row="empty" data-empty="true" data-i18n-key="${escapeHtml(model.emptyHeadlineKey)}"></div>`
|
||||
: model.items
|
||||
.map(
|
||||
(item) =>
|
||||
`<div data-row="body" data-row-id="${escapeHtml(item.id)}" data-read="${item.isRead}" data-status-key="${escapeHtml(item.statusKey)}" data-category-key="${escapeHtml(item.categoryKey)}" data-i18n-key="${escapeHtml(item.messageKey)}"${item.deeplinkHref ? ` data-deeplink="${escapeHtml(item.deeplinkHref)}"` : ""}${item.bounceKey ? ` data-bounce-key="${escapeHtml(item.bounceKey)}"` : ""}></div>`
|
||||
)
|
||||
.join("");
|
||||
|
||||
return `<div data-ui-impl="mock" data-ui-id="ui.notifications.center" data-row-count="${model.totalCount}" data-unread-count="${model.unreadCount}"><div data-row="head" data-i18n-key="${escapeHtml(model.titleKey)}"></div>${rows}</div>`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock render implementation for the members admin list (R-P2b). Same
|
||||
* normalized {@link MembersListModel} data as the real Subframe impl,
|
||||
* deliberately different minimal chrome (M017 hot-swap drill proof).
|
||||
*/
|
||||
export function renderMembersListMock(model: MembersListModel): string {
|
||||
const rows =
|
||||
model.rowCount === 0
|
||||
? `<div data-row="empty" data-empty="true" data-i18n-key="${escapeHtml(model.emptyHeadlineKey)}"></div>`
|
||||
: model.rows
|
||||
.map(
|
||||
(row) =>
|
||||
`<div data-row="body" data-row-id="${escapeHtml(row.tenantUserId)}" data-status-key="${escapeHtml(row.statusLabelKey)}" data-mfa="${row.mfaEnabled}" data-can-deactivate="${row.canDeactivate}" data-can-reactivate="${row.canReactivate}">${escapeHtml(row.name)} ${escapeHtml(row.email)} ${escapeHtml(row.roleNames.join(", "))}</div>`
|
||||
)
|
||||
.join("");
|
||||
|
||||
return `<div data-ui-impl="mock" data-ui-id="ui.settings.members.table" data-row-count="${model.rowCount}" data-can-invite="${model.canInvite}"><div data-row="head" data-i18n-key="${escapeHtml(model.titleKey)}"></div>${rows}</div>`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock render implementation for the merged roles list (R-P2b). Same
|
||||
* normalized {@link RolesListModel} data, minimal div chrome; type labels stay
|
||||
* i18n keys, capabilities + the D03 delete blocker ride as data-attributes.
|
||||
*/
|
||||
export function renderRolesListMock(model: RolesListModel): string {
|
||||
const rows =
|
||||
model.rowCount === 0
|
||||
? `<div data-row="empty" data-empty="true" data-i18n-key="${escapeHtml(model.emptyHeadlineKey)}"></div>`
|
||||
: model.rows
|
||||
.map(
|
||||
(row) =>
|
||||
`<div data-row="body" data-row-id="${escapeHtml(row.id)}" data-type-key="${escapeHtml(row.typeLabelKey)}" data-member-count="${row.memberCount}" data-permission-count="${row.permissionCount}" data-can-edit="${row.canEdit}" data-can-delete="${row.canDelete}" data-delete-blocked="${row.deleteBlockedInUse}">${escapeHtml(row.name)}</div>`
|
||||
)
|
||||
.join("");
|
||||
|
||||
return `<div data-ui-impl="mock" data-ui-id="ui.settings.rolesAndPermissions.roles" data-row-count="${model.rowCount}" data-can-create="${model.canCreate}"><div data-row="head" data-i18n-key="${escapeHtml(model.titleKey)}"></div>${rows}</div>`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock render implementation for the integrations catalog (R-P5). Same
|
||||
* normalized {@link IntegrationCatalogModel} data, minimal div chrome; titles
|
||||
* and categories stay i18n keys, connection counts ride as data-attributes.
|
||||
*/
|
||||
export function renderIntegrationsCatalogMock(model: IntegrationCatalogModel): string {
|
||||
const rows =
|
||||
model.rowCount === 0
|
||||
? `<div data-row="empty" data-empty="true" data-i18n-key="${escapeHtml(model.emptyHeadlineKey)}"></div>`
|
||||
: model.rows
|
||||
.map(
|
||||
(row) =>
|
||||
`<div data-row="body" data-row-id="${escapeHtml(row.key)}" data-title-key="${escapeHtml(row.titleKey)}" data-category-key="${escapeHtml(row.categoryKey)}" data-connection-type="${escapeHtml(row.connectionType)}" data-connection-count="${row.connectionCount}" data-detail-href="${escapeHtml(row.detailHref)}"></div>`
|
||||
)
|
||||
.join("");
|
||||
|
||||
return `<div data-ui-impl="mock" data-ui-id="ui.integrations.catalog" data-row-count="${model.rowCount}" data-connected-count="${model.connectedCount}" data-can-connect="${model.canConnect}"><div data-row="head" data-i18n-key="${escapeHtml(model.titleKey)}"></div>${rows}</div>`;
|
||||
}
|
||||
+183
@@ -0,0 +1,183 @@
|
||||
/* eslint-disable no-restricted-syntax -- test fixtures use real display strings, not i18n UI descriptors */
|
||||
import { Buffer } from "node:buffer";
|
||||
|
||||
import { describe, expect, test } from "vitest";
|
||||
import type { DataTableModel } from "@hivegrid/view-models";
|
||||
|
||||
import {
|
||||
createMockPage,
|
||||
createVisualSnapshot,
|
||||
generateMockArtifacts,
|
||||
generateMockPageHtml,
|
||||
renderDataTableMock,
|
||||
type HotSwapDrillData,
|
||||
} from "./index.js";
|
||||
|
||||
describe("createVisualSnapshot byte accounting", () => {
|
||||
test("counts plain ASCII output as one byte per character", () => {
|
||||
const page = createMockPage<HotSwapDrillData>({
|
||||
id: "ascii",
|
||||
route: "/ascii",
|
||||
title: "Plain",
|
||||
description: "ascii only",
|
||||
state: {
|
||||
status: "ready",
|
||||
data: {
|
||||
cards: [{ labelKey: "mock.trend.up", value: "100", trend: "up" }],
|
||||
activity: [{ labelKey: "mock.trend.flat", meta: "x" }],
|
||||
},
|
||||
},
|
||||
});
|
||||
const { html, module, snapshot } = generateMockArtifacts(page);
|
||||
|
||||
// For pure ASCII, the custom byteLength must equal the JS string length.
|
||||
expect(snapshot.metrics.htmlBytes).toBe(html.length);
|
||||
expect(snapshot.metrics.moduleBytes).toBe(module.length);
|
||||
// And it must agree with the UTF-8 reference implementation.
|
||||
expect(snapshot.metrics.htmlBytes).toBe(Buffer.byteLength(html, "utf8"));
|
||||
expect(snapshot.metrics.moduleBytes).toBe(Buffer.byteLength(module, "utf8"));
|
||||
});
|
||||
|
||||
test("matches UTF-8 byte length for 2-, 3- and 4-byte code points", () => {
|
||||
// "é" = 2 bytes (U+00E9), "€" = 3 bytes (U+20AC), "🚀" = 4 bytes (surrogate pair).
|
||||
const page = createMockPage<HotSwapDrillData>({
|
||||
id: "utf8",
|
||||
route: "/utf8",
|
||||
title: "café €5 🚀",
|
||||
description: "Übersicht — 🚀 launch",
|
||||
state: {
|
||||
status: "ready",
|
||||
data: {
|
||||
cards: [{ labelKey: "mock.trend.up", value: "naïve €1.234,56 🚀", trend: "up" }],
|
||||
activity: [{ labelKey: "mock.trend.flat", meta: "déjà 🚀" }],
|
||||
},
|
||||
},
|
||||
});
|
||||
const { html, module, snapshot } = generateMockArtifacts(page);
|
||||
|
||||
// Reference UTF-8 byte length must be reproduced exactly across all branches.
|
||||
expect(snapshot.metrics.htmlBytes).toBe(Buffer.byteLength(html, "utf8"));
|
||||
expect(snapshot.metrics.moduleBytes).toBe(Buffer.byteLength(module, "utf8"));
|
||||
// Multi-byte chars make the byte count exceed the JS string length.
|
||||
expect(snapshot.metrics.htmlBytes).toBeGreaterThan(html.length);
|
||||
expect(snapshot.metrics.moduleBytes).toBeGreaterThan(module.length);
|
||||
});
|
||||
|
||||
test("reports zero shell metrics for a page without registries", () => {
|
||||
const page = createMockPage({ id: "bare", route: "/bare", state: { status: "empty" } });
|
||||
const snapshot = createVisualSnapshot(page);
|
||||
expect(snapshot.metrics.sidebarItems).toBe(0);
|
||||
expect(snapshot.metrics.breadcrumbItems).toBe(0);
|
||||
expect(snapshot.metrics.mobileItems).toBe(0);
|
||||
expect(snapshot.metrics.portalItems).toBe(0);
|
||||
});
|
||||
|
||||
test("counts only the registry slots that are present", () => {
|
||||
const page = createMockPage({
|
||||
id: "partial",
|
||||
route: "/partial",
|
||||
state: { status: "empty" },
|
||||
registries: {
|
||||
sidebar: [
|
||||
{ id: "a", href: "/a", labelKey: "mock.root" },
|
||||
{ id: "b", href: "/b", labelKey: "mock.root" },
|
||||
],
|
||||
// breadcrumbs/mobile/portals deliberately omitted -> must fall back to 0.
|
||||
},
|
||||
});
|
||||
const snapshot = createVisualSnapshot(page);
|
||||
expect(snapshot.metrics.sidebarItems).toBe(2);
|
||||
expect(snapshot.metrics.breadcrumbItems).toBe(0);
|
||||
expect(snapshot.metrics.mobileItems).toBe(0);
|
||||
expect(snapshot.metrics.portalItems).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("generateMockPageHtml title/description resolution", () => {
|
||||
test("prefers literal title/description over the id fallback", () => {
|
||||
const page = createMockPage({
|
||||
id: "lit",
|
||||
route: "/lit",
|
||||
title: "Literal Title",
|
||||
description: "Literal Description",
|
||||
state: { status: "empty" },
|
||||
});
|
||||
const html = generateMockPageHtml(page);
|
||||
expect(html).toContain("<h1 class=\"mock-title\">Literal Title</h1>");
|
||||
expect(html).toContain("<p class=\"mock-description\">Literal Description</p>");
|
||||
});
|
||||
|
||||
test("falls back to the page id and a static description key", () => {
|
||||
const page = createMockPage({ id: "fallback-id", route: "/f", state: { status: "empty" } });
|
||||
const html = generateMockPageHtml(page);
|
||||
expect(html).toContain("<h1 class=\"mock-title\">fallback-id</h1>");
|
||||
expect(html).toContain("mock.static.fallback-id");
|
||||
});
|
||||
});
|
||||
|
||||
describe("generateMockPageHtml hot-swap data detection", () => {
|
||||
test("omits cards/activity when state.data is absent", () => {
|
||||
const page = createMockPage({ id: "no-data", route: "/n", state: { status: "empty" } });
|
||||
const html = generateMockPageHtml(page);
|
||||
expect(html).not.toContain('class="mock-card-value"');
|
||||
// The serialized state summary (HTML-escaped) reports both counts as zero.
|
||||
expect(html).toContain(""cards": 0");
|
||||
expect(html).toContain(""activity": 0");
|
||||
});
|
||||
|
||||
test("rejects partial shapes where activity is not an array", () => {
|
||||
// cards is an array but activity is not -> not HotSwapDrillData, no cards render.
|
||||
const page = createMockPage({
|
||||
id: "partial-data",
|
||||
route: "/p",
|
||||
state: { status: "ready", data: { cards: [{ labelKey: "mock.trend.up", value: "9", trend: "up" }], activity: "nope" } },
|
||||
});
|
||||
const html = generateMockPageHtml(page);
|
||||
expect(html).not.toContain('class="mock-card-value"');
|
||||
expect(html).toContain(""cards": 0");
|
||||
});
|
||||
|
||||
test("rejects partial shapes where cards is not an array", () => {
|
||||
const page = createMockPage({
|
||||
id: "partial-data-2",
|
||||
route: "/p2",
|
||||
state: { status: "ready", data: { cards: "nope", activity: [{ labelKey: "mock.trend.flat", meta: "m" }] } },
|
||||
});
|
||||
const html = generateMockPageHtml(page);
|
||||
expect(html).not.toContain('class="mock-card-value"');
|
||||
expect(html).toContain(""activity": 0");
|
||||
});
|
||||
});
|
||||
|
||||
describe("renderDataTableMock edge cases", () => {
|
||||
const base: DataTableModel = {
|
||||
columns: [
|
||||
{ key: "name", labelKey: "ui.data-table.column.name", align: "left" },
|
||||
{ key: "amount", labelKey: "ui.data-table.column.amount", align: "right" },
|
||||
],
|
||||
rows: [{ id: "row-1", cells: { name: "Alpha", amount: "10" } }],
|
||||
emptyLabelKey: "ui.data-table.empty",
|
||||
rowCount: 1,
|
||||
};
|
||||
|
||||
test("omits the caption row when captionKey is absent", () => {
|
||||
const html = renderDataTableMock(base);
|
||||
expect(html).not.toContain('data-row="caption"');
|
||||
});
|
||||
|
||||
test("emits the caption row when captionKey is present", () => {
|
||||
const html = renderDataTableMock({ ...base, captionKey: "ui.data-table.caption" });
|
||||
expect(html).toContain('data-row="caption" data-i18n-key="ui.data-table.caption"');
|
||||
});
|
||||
|
||||
test("renders an empty cell when a row is missing a column value", () => {
|
||||
const html = renderDataTableMock({
|
||||
...base,
|
||||
rows: [{ id: "row-gap", cells: { name: "Alpha" } as Record<string, string> }],
|
||||
});
|
||||
expect(html).toContain('data-row-id="row-gap"');
|
||||
// The missing "amount" cell collapses to an empty body span, not "undefined".
|
||||
expect(html).toContain('<span data-cell="body" data-align="right"></span>');
|
||||
expect(html).not.toContain("undefined");
|
||||
});
|
||||
});
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
/* eslint-disable no-restricted-syntax -- test fixtures use real display strings, not i18n UI descriptors */
|
||||
import { describe, expect, test } from "vitest";
|
||||
import type { AuditListModel } from "@hivegrid/view-models";
|
||||
|
||||
import { renderAuditListMock } from "./index.js";
|
||||
|
||||
const model: AuditListModel = {
|
||||
titleKey: "audit.viewer.title",
|
||||
emptyHeadlineKey: "audit.viewer.empty.headline",
|
||||
emptyBodyKey: "audit.viewer.empty.body",
|
||||
canExport: true,
|
||||
page: 1,
|
||||
totalPages: 2,
|
||||
rows: [
|
||||
{
|
||||
id: "audit-1",
|
||||
createdAtIso: "2026-07-06T08:00:00.000Z",
|
||||
actorKindLabelKey: "audit.actorKind.user",
|
||||
actorLabel: "akeshan@example.test",
|
||||
action: "kontakt.updated",
|
||||
outcome: "success",
|
||||
summaryText: "Kontakt umbenannt",
|
||||
summaryKey: "audit.summary.updated",
|
||||
diffCount: 2,
|
||||
hasDetail: true,
|
||||
},
|
||||
],
|
||||
rowCount: 1,
|
||||
};
|
||||
|
||||
describe("renderAuditListMock (mock impl)", () => {
|
||||
test("carries the impl marker, row data-attributes and the persisted summary", () => {
|
||||
const html = renderAuditListMock(model);
|
||||
expect(html).toContain('data-ui-impl="mock"');
|
||||
expect(html).toContain('data-ui-id="ui.audit.list"');
|
||||
expect(html).toContain('data-row-id="audit-1"');
|
||||
expect(html).toContain('data-diff-count="2"');
|
||||
expect(html).toContain("Kontakt umbenannt");
|
||||
expect(html).toContain('data-i18n-key="audit.viewer.title"');
|
||||
});
|
||||
|
||||
test("renders the empty marker without rows", () => {
|
||||
const html = renderAuditListMock({ ...model, rows: [], rowCount: 0 });
|
||||
expect(html).toContain('data-empty="true"');
|
||||
expect(html).toContain('data-i18n-key="audit.viewer.empty.headline"');
|
||||
});
|
||||
});
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
import type { DataTableModel } from "@toolctrl/view-models";
|
||||
import type { DataTableModel } from "@hivegrid/view-models";
|
||||
|
||||
import { renderDataTableMock } from "./index.js";
|
||||
|
||||
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
import type { FileBrowserModel } from "@hivegrid/view-models";
|
||||
|
||||
import { renderFileBrowserMock } from "./index.js";
|
||||
|
||||
const model: FileBrowserModel = {
|
||||
titleKey: "ui.files.browser.title",
|
||||
emptyHeadlineKey: "ui.files.browser.empty.headline",
|
||||
emptyBodyKey: "ui.files.browser.empty.body",
|
||||
canWrite: true,
|
||||
rows: [
|
||||
{
|
||||
id: "file-1",
|
||||
displayName: "Quartalsbericht.pdf",
|
||||
mimeType: "application/pdf",
|
||||
sizeBytes: 2048,
|
||||
detailHref: "/files/file-1",
|
||||
thumbnailUrl: null,
|
||||
},
|
||||
{
|
||||
id: "file-2",
|
||||
displayName: "logo.png",
|
||||
mimeType: "image/png",
|
||||
sizeBytes: 512,
|
||||
detailHref: "/files/file-2",
|
||||
thumbnailUrl: "/thumb/file-2",
|
||||
},
|
||||
],
|
||||
rowCount: 2,
|
||||
};
|
||||
|
||||
describe("renderFileBrowserMock (mock impl)", () => {
|
||||
test("carries the impl marker, title key and one body row per file", () => {
|
||||
const html = renderFileBrowserMock(model);
|
||||
expect(html).toContain('data-ui-impl="mock"');
|
||||
expect(html).toContain('data-ui-id="ui.files.browser"');
|
||||
expect(html).toContain('data-row-count="2"');
|
||||
// Header carries the i18n key, never a resolved label.
|
||||
expect(html).toContain('data-row="head" data-i18n-key="ui.files.browser.title"');
|
||||
// Exactly two body rows, no empty marker when rows exist.
|
||||
expect(html.match(/data-row="body"/g)).toHaveLength(2);
|
||||
expect(html).not.toContain('data-empty="true"');
|
||||
});
|
||||
|
||||
test("emits mime type and raw byte size as data-attributes per row", () => {
|
||||
const html = renderFileBrowserMock(model);
|
||||
expect(html).toContain('data-row-id="file-1"');
|
||||
expect(html).toContain('data-mime="application/pdf"');
|
||||
expect(html).toContain('data-size="2048"');
|
||||
expect(html).toContain("Quartalsbericht.pdf");
|
||||
expect(html).toContain('data-row-id="file-2"');
|
||||
expect(html).toContain('data-mime="image/png"');
|
||||
expect(html).toContain('data-size="512"');
|
||||
});
|
||||
|
||||
test("renders the empty headline marker when there are no rows", () => {
|
||||
const html = renderFileBrowserMock({ ...model, rows: [], rowCount: 0 });
|
||||
expect(html).toContain('data-row-count="0"');
|
||||
expect(html).toContain('data-empty="true"');
|
||||
expect(html).toContain('data-i18n-key="ui.files.browser.empty.headline"');
|
||||
expect(html).not.toContain('data-row="body"');
|
||||
});
|
||||
|
||||
test("escapes HTML metacharacters in display name and mime type", () => {
|
||||
const html = renderFileBrowserMock({
|
||||
...model,
|
||||
rows: [
|
||||
{
|
||||
id: "x&y",
|
||||
displayName: '<script>"alert"</script>',
|
||||
mimeType: 'text/x-"weird"',
|
||||
sizeBytes: 1,
|
||||
detailHref: "/files/x",
|
||||
thumbnailUrl: null,
|
||||
},
|
||||
],
|
||||
rowCount: 1,
|
||||
});
|
||||
// No raw angle brackets or quotes from user data leak into the markup.
|
||||
expect(html).toContain("<script>"alert"</script>");
|
||||
expect(html).toContain('data-row-id="x&y"');
|
||||
expect(html).toContain('data-mime="text/x-"weird""');
|
||||
expect(html).not.toContain("<script>");
|
||||
});
|
||||
});
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
import type { IntegrationCatalogModel } from "@hivegrid/view-models";
|
||||
|
||||
import { renderIntegrationsCatalogMock } from "./index.js";
|
||||
|
||||
const model: IntegrationCatalogModel = {
|
||||
titleKey: "integrations.catalog.title",
|
||||
emptyHeadlineKey: "integrations.catalog.empty.headline",
|
||||
emptyBodyKey: "integrations.catalog.empty.body",
|
||||
canConnect: true,
|
||||
rowCount: 2,
|
||||
connectedCount: 1,
|
||||
rows: [
|
||||
{
|
||||
key: "sample-data-sync",
|
||||
titleKey: "integrations.app.sampleDataSync.title",
|
||||
category: "erp",
|
||||
categoryKey: "integrations.category.erp",
|
||||
connectionType: "rest_api",
|
||||
connectionCount: 2,
|
||||
detailHref: "/acme/integrations/sample-data-sync",
|
||||
},
|
||||
{
|
||||
key: "gmail",
|
||||
titleKey: "integrations.app.gmail.title",
|
||||
category: "communication",
|
||||
categoryKey: "integrations.category.communication",
|
||||
connectionType: "oauth2",
|
||||
connectionCount: 0,
|
||||
detailHref: "/acme/integrations/gmail",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
describe("renderIntegrationsCatalogMock (M017)", () => {
|
||||
test("renders normalized app rows with catalog data-attributes", () => {
|
||||
const html = renderIntegrationsCatalogMock(model);
|
||||
expect(html).toContain('data-ui-impl="mock"');
|
||||
expect(html).toContain('data-ui-id="ui.integrations.catalog"');
|
||||
expect(html).toContain('data-row-id="sample-data-sync"');
|
||||
expect(html).toContain('data-category-key="integrations.category.communication"');
|
||||
expect(html).toContain('data-connection-count="2"');
|
||||
expect(html).toContain('data-connected-count="1"');
|
||||
expect(html).toContain('data-can-connect="true"');
|
||||
});
|
||||
|
||||
test("renders the empty state as an i18n key", () => {
|
||||
const html = renderIntegrationsCatalogMock({ ...model, rows: [], rowCount: 0, connectedCount: 0 });
|
||||
expect(html).toContain('data-empty="true"');
|
||||
expect(html).toContain('data-i18n-key="integrations.catalog.empty.headline"');
|
||||
});
|
||||
});
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
import type { MembersListModel } from "@hivegrid/view-models";
|
||||
|
||||
import { renderMembersListMock } from "./index.js";
|
||||
|
||||
const model: MembersListModel = {
|
||||
titleKey: "settings.members.title",
|
||||
emptyHeadlineKey: "settings.members.empty.headline",
|
||||
emptyBodyKey: "settings.members.empty.body",
|
||||
canInvite: true,
|
||||
rowCount: 1,
|
||||
rows: [
|
||||
{
|
||||
tenantUserId: "tu-1",
|
||||
name: "Ada Lovelace",
|
||||
email: "ada@example.test",
|
||||
statusLabelKey: "settings.members.status.active",
|
||||
mfaEnabled: true,
|
||||
roleNames: ["Monteur"],
|
||||
canDeactivate: true,
|
||||
canReactivate: false,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
describe("renderMembersListMock (M017)", () => {
|
||||
test("renders normalized rows with data-attributes and mock chrome", () => {
|
||||
const html = renderMembersListMock(model);
|
||||
expect(html).toContain('data-ui-impl="mock"');
|
||||
expect(html).toContain('data-ui-id="ui.settings.members.table"');
|
||||
expect(html).toContain('data-row-id="tu-1"');
|
||||
expect(html).toContain('data-status-key="settings.members.status.active"');
|
||||
expect(html).toContain('data-can-deactivate="true"');
|
||||
expect(html).toContain("Ada Lovelace");
|
||||
});
|
||||
|
||||
test("renders the empty state as an i18n key", () => {
|
||||
const html = renderMembersListMock({ ...model, rows: [], rowCount: 0 });
|
||||
expect(html).toContain('data-empty="true"');
|
||||
expect(html).toContain('data-i18n-key="settings.members.empty.headline"');
|
||||
});
|
||||
});
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
import type { NotificationCenterModel } from "@hivegrid/view-models";
|
||||
|
||||
import { renderNotificationCenterMock } from "./index.js";
|
||||
|
||||
const model: NotificationCenterModel = {
|
||||
titleKey: "notifications.center.title",
|
||||
emptyHeadlineKey: "notifications.center.empty",
|
||||
emptyBodyKey: "notifications.center.emptyHelper",
|
||||
totalCount: 2,
|
||||
unreadCount: 1,
|
||||
items: [
|
||||
{
|
||||
id: "delivery-1",
|
||||
messageKey: "team.invite.created",
|
||||
statusKey: "notifications.center.statuses.sent",
|
||||
categoryKey: "notifications.center.categories.team",
|
||||
isRead: false,
|
||||
bounceKey: null,
|
||||
deeplinkHref: "/acme/settings/members",
|
||||
},
|
||||
{
|
||||
id: "delivery-2",
|
||||
messageKey: "billing.invoice.failed",
|
||||
statusKey: "notifications.center.statuses.read",
|
||||
categoryKey: "notifications.center.categories.billing",
|
||||
isRead: true,
|
||||
bounceKey: "notifications.center.bounce.rateLimited",
|
||||
deeplinkHref: null,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
describe("renderNotificationCenterMock (mock impl)", () => {
|
||||
test("carries the impl marker, unread count, deeplink and bounce key attributes", () => {
|
||||
const html = renderNotificationCenterMock(model);
|
||||
expect(html).toContain('data-ui-impl="mock"');
|
||||
expect(html).toContain('data-ui-id="ui.notifications.center"');
|
||||
expect(html).toContain('data-unread-count="1"');
|
||||
expect(html).toContain('data-deeplink="/acme/settings/members"');
|
||||
expect(html).toContain('data-bounce-key="notifications.center.bounce.rateLimited"');
|
||||
expect(html).toContain('data-i18n-key="team.invite.created"');
|
||||
});
|
||||
|
||||
test("renders the empty marker without items", () => {
|
||||
const html = renderNotificationCenterMock({ ...model, items: [], totalCount: 0, unreadCount: 0 });
|
||||
expect(html).toContain('data-empty="true"');
|
||||
expect(html).toContain('data-i18n-key="notifications.center.empty"');
|
||||
});
|
||||
});
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
import type { RolesListModel } from "@hivegrid/view-models";
|
||||
|
||||
import { renderRolesListMock } from "./index.js";
|
||||
|
||||
const model: RolesListModel = {
|
||||
titleKey: "settings.members.tabs.rolesAndPermissions",
|
||||
emptyHeadlineKey: "settings.rolesAndPermissions.empty.title",
|
||||
emptyBodyKey: "settings.rolesAndPermissions.empty.description",
|
||||
canCreate: true,
|
||||
rowCount: 2,
|
||||
rows: [
|
||||
{
|
||||
id: "sys",
|
||||
name: "SuperUser",
|
||||
typeLabelKey: "settings.rolesAndPermissions.type.system",
|
||||
memberCount: 2,
|
||||
permissionCount: 12,
|
||||
canEdit: false,
|
||||
canDelete: false,
|
||||
deleteBlockedInUse: false,
|
||||
},
|
||||
{
|
||||
id: "r-1",
|
||||
name: "Monteur",
|
||||
typeLabelKey: "settings.rolesAndPermissions.type.custom",
|
||||
memberCount: 3,
|
||||
permissionCount: 4,
|
||||
canEdit: true,
|
||||
canDelete: true,
|
||||
deleteBlockedInUse: true,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
describe("renderRolesListMock (M017)", () => {
|
||||
test("renders normalized rows with capability data-attributes", () => {
|
||||
const html = renderRolesListMock(model);
|
||||
expect(html).toContain('data-ui-impl="mock"');
|
||||
expect(html).toContain('data-ui-id="ui.settings.rolesAndPermissions.roles"');
|
||||
expect(html).toContain('data-row-id="sys"');
|
||||
expect(html).toContain('data-type-key="settings.rolesAndPermissions.type.custom"');
|
||||
expect(html).toContain('data-delete-blocked="true"');
|
||||
expect(html).toContain('data-can-create="true"');
|
||||
});
|
||||
|
||||
test("renders the empty state as an i18n key", () => {
|
||||
const html = renderRolesListMock({ ...model, rows: [], rowCount: 0 });
|
||||
expect(html).toContain('data-empty="true"');
|
||||
expect(html).toContain('data-i18n-key="settings.rolesAndPermissions.empty.title"');
|
||||
});
|
||||
});
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
/* eslint-disable no-restricted-syntax -- test fixtures use real display strings, not i18n UI descriptors */
|
||||
import { describe, expect, test } from "vitest";
|
||||
import type { TaskListModel } from "@hivegrid/view-models";
|
||||
|
||||
import { renderTaskListMock } from "./index.js";
|
||||
|
||||
const model: TaskListModel = {
|
||||
titleKey: "ui.tasks.list.title",
|
||||
emptyHeadlineKey: "ui.tasks.list.empty.headline",
|
||||
emptyBodyKey: "ui.tasks.list.empty.body",
|
||||
canWrite: true,
|
||||
createHref: "/tasks/new",
|
||||
rows: [
|
||||
{
|
||||
id: "task-1",
|
||||
title: "Angebot prüfen",
|
||||
statusKey: "ui.tasks.status.open",
|
||||
priorityKey: "ui.tasks.priority.high",
|
||||
deadlineIso: "2026-07-01T00:00:00.000Z",
|
||||
isOverdue: true,
|
||||
assigneeLabel: "Raffael",
|
||||
detailHref: "/tasks/task-1",
|
||||
},
|
||||
{
|
||||
id: "task-2",
|
||||
title: "Rechnung senden",
|
||||
statusKey: "ui.tasks.status.done",
|
||||
priorityKey: "ui.tasks.priority.low",
|
||||
deadlineIso: null,
|
||||
isOverdue: false,
|
||||
assigneeLabel: null,
|
||||
detailHref: "/tasks/task-2",
|
||||
},
|
||||
],
|
||||
rowCount: 2,
|
||||
};
|
||||
|
||||
describe("renderTaskListMock (mock impl)", () => {
|
||||
test("carries the impl marker, title key and one body row per task", () => {
|
||||
const html = renderTaskListMock(model);
|
||||
expect(html).toContain('data-ui-impl="mock"');
|
||||
expect(html).toContain('data-ui-id="ui.tasks.list"');
|
||||
expect(html).toContain('data-row-count="2"');
|
||||
expect(html).toContain('data-row="head" data-i18n-key="ui.tasks.list.title"');
|
||||
expect(html.match(/data-row="body"/g)).toHaveLength(2);
|
||||
expect(html).not.toContain('data-empty="true"');
|
||||
});
|
||||
|
||||
test("projects status key and the overdue flag onto each row", () => {
|
||||
const html = renderTaskListMock(model);
|
||||
// Overdue task: boolean serialized literally as "true".
|
||||
expect(html).toContain('data-row-id="task-1"');
|
||||
expect(html).toContain('data-status-key="ui.tasks.status.open"');
|
||||
expect(html).toContain('data-overdue="true"');
|
||||
expect(html).toContain("Angebot prüfen");
|
||||
// Non-overdue task: boolean serialized literally as "false".
|
||||
expect(html).toContain('data-row-id="task-2"');
|
||||
expect(html).toContain('data-status-key="ui.tasks.status.done"');
|
||||
expect(html).toContain('data-overdue="false"');
|
||||
});
|
||||
|
||||
test("renders the empty headline marker when there are no rows", () => {
|
||||
const html = renderTaskListMock({ ...model, rows: [], rowCount: 0 });
|
||||
expect(html).toContain('data-row-count="0"');
|
||||
expect(html).toContain('data-empty="true"');
|
||||
expect(html).toContain('data-i18n-key="ui.tasks.list.empty.headline"');
|
||||
expect(html).not.toContain('data-row="body"');
|
||||
});
|
||||
|
||||
test("escapes HTML metacharacters in the task title", () => {
|
||||
const html = renderTaskListMock({
|
||||
...model,
|
||||
rows: [
|
||||
{
|
||||
id: "task-x",
|
||||
title: '<b>"drop"</b> & <i>run</i>',
|
||||
statusKey: "ui.tasks.status.open",
|
||||
priorityKey: "ui.tasks.priority.high",
|
||||
deadlineIso: null,
|
||||
isOverdue: false,
|
||||
assigneeLabel: null,
|
||||
detailHref: "/tasks/task-x",
|
||||
},
|
||||
],
|
||||
rowCount: 1,
|
||||
});
|
||||
expect(html).toContain("<b>"drop"</b> & <i>run</i>");
|
||||
expect(html).not.toContain("<b>");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user