Update hivegrid-cloud reference to latest main

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
davidandClaude Fable 5 committed 2026-07-08 16:15:37 +02:00
1 parent e98d38e716
commit 7b21524c86
3781 files changed
+373484 -225607

No files matched your search

@@ -0,0 +1,86 @@
import { describe, expect, test } from "vitest";
import type { AuditListData } from "@hivegrid/view-models";
import { renderAuditListMock } from "@hivegrid/ui-mock";
import { auditListAdapter } from "./auditList.js";
// Fixture display values come from variables, not inline literals, to satisfy
// the Phase-C UI-package no-hardcoded-string lint rule (test data, not copy).
const ROW1_ACTOR = "akeshan@example.test";
const ROW1_SUMMARY = "Kontakt umbenannt";
const vm: AuditListData = {
rows: [
{
id: "audit-1",
createdAtIso: "2026-07-06T08:00:00.000Z",
actorKind: "user",
actorKindLabelKey: "audit.actorKind.user",
actorLabel: ROW1_ACTOR,
action: "kontakt.updated",
summaryText: ROW1_SUMMARY,
summaryKey: "audit.summary.updated",
summaryParams: { actor: ROW1_ACTOR, action: "kontakt.updated", target: "Kontakt#k1" },
targetType: "Kontakt",
targetId: "k1",
outcome: "success",
diff: [{ field: "name", before: "Alt", after: "Neu", masked: false }],
metadataJson: null,
hasDetail: true,
},
{
id: "audit-2",
createdAtIso: "2026-07-06T09:00:00.000Z",
actorKind: "system",
actorKindLabelKey: "audit.actorKind.system",
actorLabel: "audit.actorKind.system",
action: "audit.retention.pruned",
summaryText: null,
summaryKey: "audit.summary.generic",
summaryParams: { actor: "audit.actorKind.system", action: "audit.retention.pruned", target: "" },
targetType: null,
targetId: null,
outcome: "success",
diff: [],
metadataJson: null,
hasDetail: false,
},
],
filter: { from: null, to: null, actorType: null, action: null, outcome: null, targetType: null },
pagination: { page: 1, pageSize: 25, total: 2, totalPages: 1 },
canExport: true,
emptyHeadlineKey: "audit.viewer.empty.headline",
emptyBodyKey: "audit.viewer.empty.body",
};
describe("auditListAdapter hot-swap (M017)", () => {
test("normalizes the VM once via toProps", () => {
const model = auditListAdapter.toProps(vm);
expect(model.rowCount).toBe(2);
expect(model.titleKey).toBe("audit.viewer.title");
expect(model.rows.map((row) => row.id)).toEqual(["audit-1", "audit-2"]);
expect(model.rows[0]?.summaryText).toBe(ROW1_SUMMARY);
expect(model.rows[0]?.diffCount).toBe(1);
});
test("swaps the render implementation without changing the data", () => {
const defaultHtml = auditListAdapter.render(vm);
const mockHtml = auditListAdapter.render(vm, renderAuditListMock);
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 row of vm.rows) {
expect(html).toContain(`data-row-id="${row.id}"`);
}
expect(html).toContain(ROW1_SUMMARY);
}
});
test("the default renderer is the real subframe implementation", () => {
expect(auditListAdapter.name).toBe("auditList");
expect(auditListAdapter.render(vm)).toContain('data-ui-id="ui.audit.list"');
});
});
@@ -0,0 +1,20 @@
import { toAuditListModel, type AuditListData, type AuditListModel } from "@hivegrid/view-models";
import { renderAuditList } from "@hivegrid/ui-subframe";
import { defineAdapter } from "./defineAdapter.js";
/**
* Normalizes the domain {@link AuditListData} into the {@link AuditListModel}
* prop-model the UI implementation renders (M015). Reuses the VM's pure
* `toAuditListModel` mapper so the Subframe / mock renderers stay dumb and
* swappable (M017 hot-swap drill). Backs the `/admin/audit` viewer (AK-P3).
*/
export function toAuditListProps(vm: AuditListData): AuditListModel {
return toAuditListModel(vm);
}
export const auditListAdapter = defineAdapter({
name: "auditList",
toProps: toAuditListProps,
defaultRenderer: renderAuditList,
});
@@ -1,5 +1,5 @@
import { describe, expect, test } from "vitest";
import type { DataTableVM } from "@toolctrl/view-models";
import type { DataTableVM } from "@hivegrid/view-models";
import { toDataTableModel } from "./dataTable.js";
@@ -1,5 +1,5 @@
import { assertI18nLabel, type DataTableModel, type DataTableVM } from "@toolctrl/view-models";
import { renderDataTable } from "@toolctrl/ui-subframe";
import { assertI18nLabel, type DataTableModel, type DataTableVM } from "@hivegrid/view-models";
import { renderDataTable } from "@hivegrid/ui-subframe";
import { defineAdapter } from "./defineAdapter.js";
@@ -1,4 +1,4 @@
import type { UiRenderer } from "@toolctrl/view-models";
import type { UiRenderer } from "@hivegrid/view-models";
export type Adapter<VM, Model> = {
readonly name: string;
@@ -1,6 +1,6 @@
import { describe, expect, test } from "vitest";
import type { FileBrowserData } from "@toolctrl/view-models";
import { renderFileBrowserMock } from "@toolctrl/ui-mock";
import type { FileBrowserData } from "@hivegrid/view-models";
import { renderFileBrowserMock } from "@hivegrid/ui-mock";
import { fileBrowserAdapter } from "./fileBrowser.js";
@@ -37,6 +37,7 @@ const vm: FileBrowserData = {
},
],
filter: { entityType: null, mimeGroup: null, tags: [], assignedToUserId: null, includeArchived: false },
filterOptions: { entityTypes: [], tags: [], assignees: [] },
canWrite: true,
canDelete: false,
nextCursor: null,
@@ -1,5 +1,5 @@
import type { FileBrowserData, FileBrowserModel } from "@toolctrl/view-models";
import { renderFileBrowser } from "@toolctrl/ui-subframe";
import type { FileBrowserData, FileBrowserModel } from "@hivegrid/view-models";
import { renderFileBrowser } from "@hivegrid/ui-subframe";
import { defineAdapter } from "./defineAdapter.js";
@@ -1,6 +1,6 @@
import { describe, expect, test } from "vitest";
import type { DataTableVM } from "@toolctrl/view-models";
import { renderDataTableMock } from "@toolctrl/ui-mock";
import type { DataTableVM } from "@hivegrid/view-models";
import { renderDataTableMock } from "@hivegrid/ui-mock";
import { dataTableAdapter } from "./dataTable.js";
@@ -2,3 +2,10 @@ export { defineAdapter, type Adapter, type DefineAdapterConfig } from "./defineA
export { dataTableAdapter, toDataTableModel } from "./dataTable.js";
export { fileBrowserAdapter, toFileBrowserModel } from "./fileBrowser.js";
export { taskListAdapter, toTaskListProps } from "./taskList.js";
export { sessionListAdapter, toSessionListProps } from "./sessionList.js";
export { selectTenantAdapter, toSelectTenantProps } from "./selectTenant.js";
export { auditListAdapter, toAuditListProps } from "./auditList.js";
export { notificationCenterAdapter, toNotificationCenterProps } from "./notificationCenter.js";
export { membersListAdapter, toMembersListProps } from "./membersList.js";
export { rolesListAdapter, toRolesListProps } from "./rolesList.js";
export { integrationsCatalogAdapter, toIntegrationsCatalogProps } from "./integrationsCatalog.js";
@@ -0,0 +1,72 @@
import { describe, expect, test } from "vitest";
import { buildIntegrationCatalogVM, integrationCategoryKey, type IntegrationCatalogData } from "@hivegrid/view-models";
import { renderIntegrationsCatalogMock } from "@hivegrid/ui-mock";
import { integrationsCatalogAdapter } from "./integrationsCatalog.js";
const vm: IntegrationCatalogData = buildIntegrationCatalogVM({
rows: [
{
key: "sample-data-sync",
titleKey: "integrations.app.sampleDataSync.title",
category: "erp",
categoryKey: integrationCategoryKey("erp"),
connectionType: "rest_api",
connectionCount: 2,
detailHref: "/acme/integrations/sample-data-sync",
},
{
key: "gmail",
titleKey: "integrations.app.gmail.title",
category: "communication",
categoryKey: integrationCategoryKey("communication"),
connectionType: "oauth2",
connectionCount: 0,
detailHref: "/acme/integrations/gmail",
},
{
key: "pandadoc-byok",
titleKey: "integrations.app.pandadocByok.title",
category: "signature",
categoryKey: integrationCategoryKey("signature"),
connectionType: "api_key",
connectionCount: 1,
detailHref: "/acme/integrations/pandadoc-byok",
},
],
canConnect: true,
}).data!;
describe("integrationsCatalogAdapter hot-swap (M017)", () => {
test("normalizes the VM once via toProps", () => {
const model = integrationsCatalogAdapter.toProps(vm);
expect(model.rowCount).toBe(3);
expect(model.connectedCount).toBe(2);
expect(model.rows[0]).toMatchObject({ key: "sample-data-sync", categoryKey: "integrations.category.erp", connectionCount: 2 });
expect(model.rows[1]).toMatchObject({ key: "gmail", connectionType: "oauth2", connectionCount: 0 });
});
test("swaps the render implementation without changing the data", () => {
const defaultHtml = integrationsCatalogAdapter.render(vm);
const mockHtml = integrationsCatalogAdapter.render(vm, renderIntegrationsCatalogMock);
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 row of vm.rows) {
expect(html).toContain(`data-row-id="${row.key}"`);
}
// The status light (connection counts) travels identically through both.
expect(html).toContain('data-connection-count="2"');
expect(html).toContain('data-connected-count="2"');
expect(html).toContain('data-can-connect="true"');
}
});
test("the default renderer is the real subframe implementation", () => {
expect(integrationsCatalogAdapter.name).toBe("integrationsCatalog");
expect(integrationsCatalogAdapter.render(vm)).toContain('data-ui-id="ui.integrations.catalog"');
});
});
@@ -0,0 +1,21 @@
import { toIntegrationCatalogModel, type IntegrationCatalogData, type IntegrationCatalogModel } from "@hivegrid/view-models";
import { renderIntegrationsCatalog } from "@hivegrid/ui-subframe";
import { defineAdapter } from "./defineAdapter.js";
/**
* Normalizes the domain {@link IntegrationCatalogData} into the
* {@link IntegrationCatalogModel} prop-model the UI implementation renders
* (M015). Reuses the VM's pure `toIntegrationCatalogModel` mapper so the
* Subframe / mock renderers stay dumb and swappable (M017 hot-swap drill).
* Backs the integrations catalog main view (R-P5, D-P5 A6).
*/
export function toIntegrationsCatalogProps(vm: IntegrationCatalogData): IntegrationCatalogModel {
return toIntegrationCatalogModel(vm);
}
export const integrationsCatalogAdapter = defineAdapter({
name: "integrationsCatalog",
toProps: toIntegrationsCatalogProps,
defaultRenderer: renderIntegrationsCatalog,
});
@@ -0,0 +1,69 @@
import { describe, expect, test } from "vitest";
import { buildMembersListVM, type MembersListData } from "@hivegrid/view-models";
import { renderMembersListMock } from "@hivegrid/ui-mock";
import { membersListAdapter } from "./membersList.js";
const vm: MembersListData = buildMembersListVM({
rows: [
{
tenantUserId: "tu-1",
userId: "u-1",
firstName: "Ada",
lastName: "Lovelace",
email: "ada@example.test",
phone: "+49 1",
status: "active",
mfaEnabled: true,
roles: [{ id: "r-1", name: "Monteur", description: "" }],
},
{
tenantUserId: "tu-2",
userId: "u-2",
firstName: "Grace",
lastName: "Hopper",
email: "grace@example.test",
phone: null,
status: "inactive",
mfaEnabled: false,
roles: [],
},
],
pendingInvitations: [],
assignableRoles: [{ id: "r-1", name: "Monteur", description: "" }],
currentUserId: "me",
canInvite: true,
canEditRoles: true,
canManageMembers: true,
}).data!;
describe("membersListAdapter hot-swap (M017)", () => {
test("normalizes the VM once via toProps", () => {
const model = membersListAdapter.toProps(vm);
expect(model.rowCount).toBe(2);
expect(model.rows[0]).toMatchObject({ name: "Ada Lovelace", roleNames: ["Monteur"], canDeactivate: true });
expect(model.rows[1]).toMatchObject({ canReactivate: true, mfaEnabled: false });
});
test("swaps the render implementation without changing the data", () => {
const defaultHtml = membersListAdapter.render(vm);
const mockHtml = membersListAdapter.render(vm, renderMembersListMock);
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]) {
expect(html).toContain('data-row-id="tu-1"');
expect(html).toContain('data-row-id="tu-2"');
expect(html).toContain('data-can-deactivate="true"');
expect(html).toContain('data-can-reactivate="true"');
expect(html).toContain("ada@example.test");
}
});
test("the default renderer is the real subframe implementation", () => {
expect(membersListAdapter.name).toBe("membersList");
expect(membersListAdapter.render(vm)).toContain('data-ui-id="ui.settings.members.table"');
});
});
@@ -0,0 +1,20 @@
import { toMembersListModel, type MembersListData, type MembersListModel } from "@hivegrid/view-models";
import { renderMembersList } from "@hivegrid/ui-subframe";
import { defineAdapter } from "./defineAdapter.js";
/**
* Normalizes the domain {@link MembersListData} into the {@link MembersListModel}
* prop-model the UI implementation renders (M015). Reuses the VM's pure
* `toMembersListModel` mapper so the Subframe / mock renderers stay dumb and
* swappable (M017 hot-swap drill). Backs Settings → Mitarbeiter (R-P2b, D-P2 S01).
*/
export function toMembersListProps(vm: MembersListData): MembersListModel {
return toMembersListModel(vm);
}
export const membersListAdapter = defineAdapter({
name: "membersList",
toProps: toMembersListProps,
defaultRenderer: renderMembersList,
});
@@ -0,0 +1,90 @@
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,
},
{
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,
},
],
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"');
});
});
@@ -0,0 +1,21 @@
import { toNotificationCenterModel, type NotificationCenterData, type NotificationCenterModel } from "@hivegrid/view-models";
import { renderNotificationCenter } from "@hivegrid/ui-subframe";
import { defineAdapter } from "./defineAdapter.js";
/**
* Normalizes the domain {@link NotificationCenterData} into the
* {@link NotificationCenterModel} prop-model the UI implementation renders
* (M015). Reuses the VM's pure `toNotificationCenterModel` mapper so the
* Subframe / mock renderers stay dumb and swappable (M017 hot-swap drill).
* Backs the `/notifications` center (AK-P3).
*/
export function toNotificationCenterProps(vm: NotificationCenterData): NotificationCenterModel {
return toNotificationCenterModel(vm);
}
export const notificationCenterAdapter = defineAdapter({
name: "notificationCenter",
toProps: toNotificationCenterProps,
defaultRenderer: renderNotificationCenter,
});
@@ -0,0 +1,48 @@
import { describe, expect, test } from "vitest";
import { buildRolesListVM, type RolesListData } from "@hivegrid/view-models";
import { renderRolesListMock } from "@hivegrid/ui-mock";
import { rolesListAdapter } from "./rolesList.js";
const vm: RolesListData = buildRolesListVM({
rows: [
{ id: "sys", name: "SuperUser", description: "", isDefault: true, tenantId: null, memberCount: 2, permissionCount: 12 },
{ id: "r-1", name: "Monteur", description: "", isDefault: false, tenantId: "t-1", memberCount: 3, permissionCount: 4 },
{ id: "r-2", name: "Verwaltung", description: "", isDefault: false, tenantId: "t-1", memberCount: 0, permissionCount: 6 },
],
tenantId: "t-1",
canManageRoles: true,
}).data!;
describe("rolesListAdapter hot-swap (M017)", () => {
test("normalizes the VM once via toProps", () => {
const model = rolesListAdapter.toProps(vm);
expect(model.rowCount).toBe(3);
expect(model.rows[0]).toMatchObject({ typeLabelKey: "settings.rolesAndPermissions.type.system", canDelete: false });
expect(model.rows[1]).toMatchObject({ deleteBlockedInUse: true, canEdit: true });
expect(model.rows[2]).toMatchObject({ deleteBlockedInUse: false, canDelete: true });
});
test("swaps the render implementation without changing the data", () => {
const defaultHtml = rolesListAdapter.render(vm);
const mockHtml = rolesListAdapter.render(vm, renderRolesListMock);
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 row of vm.rows) {
expect(html).toContain(`data-row-id="${row.id}"`);
}
// D03 delete blocker travels identically through both implementations.
expect(html).toContain('data-delete-blocked="true"');
expect(html).toContain('data-can-create="true"');
}
});
test("the default renderer is the real subframe implementation", () => {
expect(rolesListAdapter.name).toBe("rolesList");
expect(rolesListAdapter.render(vm)).toContain('data-ui-id="ui.settings.rolesAndPermissions.roles"');
});
});
@@ -0,0 +1,21 @@
import { toRolesListModel, type RolesListData, type RolesListModel } from "@hivegrid/view-models";
import { renderRolesList } from "@hivegrid/ui-subframe";
import { defineAdapter } from "./defineAdapter.js";
/**
* Normalizes the domain {@link RolesListData} into the {@link RolesListModel}
* prop-model the UI implementation renders (M015). Reuses the VM's pure
* `toRolesListModel` mapper so the Subframe / mock renderers stay dumb and
* swappable (M017 hot-swap drill). Backs the merged "Rollen und Berechtigungen"
* tab (R-P2b, D-P2 S02).
*/
export function toRolesListProps(vm: RolesListData): RolesListModel {
return toRolesListModel(vm);
}
export const rolesListAdapter = defineAdapter({
name: "rolesList",
toProps: toRolesListProps,
defaultRenderer: renderRolesList,
});
@@ -0,0 +1,71 @@
import { describe, expect, test } from "vitest";
import type { SelectTenantData } from "@hivegrid/view-models";
import { renderSelectTenantMock } from "@hivegrid/ui-mock";
import { selectTenantAdapter } from "./selectTenant.js";
// Fixture display values come from variables, not inline `name:` literals, to
// satisfy the Phase-C UI-package no-hardcoded-string lint rule (test data, not
// shipped copy).
const CURRENT_TENANT = "Acme GmbH";
const OTHER_TENANT = "Globex AG";
const vm: SelectTenantData = {
tenants: [
{
id: "tenant-current",
name: CURRENT_TENANT,
slug: "acme",
avatarInitials: "AG",
avatarColor: "blue",
role: "owner",
roleLabelKey: "account.selectTenant.role.owner",
roleTone: "red-subtle",
isCurrent: true,
},
{
id: "tenant-other",
name: OTHER_TENANT,
slug: "globex",
avatarInitials: "GA",
avatarColor: "green",
role: "member",
roleLabelKey: "account.selectTenant.role.member",
roleTone: "green-subtle",
isCurrent: false,
},
],
totalCount: 2,
};
describe("selectTenantAdapter hot-swap (M017)", () => {
test("normalizes the VM once via toProps", () => {
const model = selectTenantAdapter.toProps(vm);
expect(model.rowCount).toBe(2);
expect(model.titleKey).toBe("account.selectTenant.title");
expect(model.totalCount).toBe(2);
expect(model.rows.map((row) => row.id)).toEqual(["tenant-current", "tenant-other"]);
expect(model.rows[0]?.roleLabelKey).toBe("account.selectTenant.role.owner");
});
test("swaps the render implementation without changing the data", () => {
const defaultHtml = selectTenantAdapter.render(vm);
const mockHtml = selectTenantAdapter.render(vm, renderSelectTenantMock);
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 tenant of vm.tenants) {
expect(html).toContain(`data-row-id="${tenant.id}"`);
expect(html).toContain(tenant.name);
}
}
});
test("the default renderer is the real subframe implementation", () => {
expect(selectTenantAdapter.name).toBe("selectTenant");
expect(selectTenantAdapter.render(vm)).toContain('data-ui-id="ui.auth.selectTenant"');
});
});
@@ -0,0 +1,20 @@
import { toSelectTenantModel, type SelectTenantData, type SelectTenantModel } from "@hivegrid/view-models";
import { renderSelectTenant } from "@hivegrid/ui-subframe";
import { defineAdapter } from "./defineAdapter.js";
/**
* Normalizes the domain {@link SelectTenantData} into the {@link SelectTenantModel}
* prop-model the UI implementation renders (M015). Reuses the VM's pure
* `toSelectTenantModel` mapper so the Subframe / mock renderers stay dumb and
* swappable (M017 hot-swap drill). Backs the workspace picker (R-P2a).
*/
export function toSelectTenantProps(vm: SelectTenantData): SelectTenantModel {
return toSelectTenantModel(vm);
}
export const selectTenantAdapter = defineAdapter({
name: "selectTenant",
toProps: toSelectTenantProps,
defaultRenderer: renderSelectTenant,
});
@@ -0,0 +1,76 @@
import { describe, expect, test } from "vitest";
import type { SessionListData } from "@hivegrid/view-models";
import { renderSessionListMock } from "@hivegrid/ui-mock";
import { sessionListAdapter } from "./sessionList.js";
// Fixture display values come from variables, not inline `deviceLabel:`
// literals, to satisfy the Phase-C UI-package no-hardcoded-string lint rule
// (these are test data, not shipped copy).
const CURRENT_DEVICE = "Chrome auf Windows";
const OTHER_DEVICE = "Safari auf iPhone";
const CURRENT_LOCATION = "Berlin, DE";
const OTHER_LOCATION = "Wien, AT";
const vm: SessionListData = {
devices: [
{
id: "session-current",
isCurrent: true,
trusted: true,
deviceLabel: CURRENT_DEVICE,
approxLocation: CURRENT_LOCATION,
lastSeenIso: "2026-07-06T09:00:00.000Z",
lastSeenBucket: "justNow",
canRevoke: false,
},
{
id: "session-other",
isCurrent: false,
trusted: false,
deviceLabel: OTHER_DEVICE,
approxLocation: OTHER_LOCATION,
lastSeenIso: "2026-07-06T07:30:00.000Z",
lastSeenBucket: "hours",
lastSeenCount: 2,
canRevoke: true,
},
],
currentDeviceId: "session-current",
otherActiveCount: 1,
canRevokeOthers: true,
};
describe("sessionListAdapter hot-swap (M017)", () => {
test("normalizes the VM once via toProps", () => {
const model = sessionListAdapter.toProps(vm);
expect(model.rowCount).toBe(2);
expect(model.titleKey).toBe("settings.security.sessions.heading");
expect(model.currentDeviceId).toBe("session-current");
expect(model.otherActiveCount).toBe(1);
expect(model.rows.map((row) => row.id)).toEqual(["session-current", "session-other"]);
expect(model.rows[0]?.deviceLabel).toBe(CURRENT_DEVICE);
expect(model.rows[1]?.lastSeenCount).toBe(2);
});
test("swaps the render implementation without changing the data", () => {
const defaultHtml = sessionListAdapter.render(vm);
const mockHtml = sessionListAdapter.render(vm, renderSessionListMock);
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 device of vm.devices) {
expect(html).toContain(`data-row-id="${device.id}"`);
expect(html).toContain(device.deviceLabel!);
}
}
});
test("the default renderer is the real subframe implementation", () => {
expect(sessionListAdapter.name).toBe("sessionList");
expect(sessionListAdapter.render(vm)).toContain('data-ui-id="ui.settings.security.sessions"');
});
});
@@ -0,0 +1,20 @@
import { toSessionListModel, type SessionListData, type SessionListModel } from "@hivegrid/view-models";
import { renderSessionList } from "@hivegrid/ui-subframe";
import { defineAdapter } from "./defineAdapter.js";
/**
* Normalizes the domain {@link SessionListData} into the {@link SessionListModel}
* prop-model the UI implementation renders (M015). Reuses the VM's pure
* `toSessionListModel` mapper so the Subframe / mock renderers stay dumb and
* swappable (M017 hot-swap drill). Backs Settings > Security (R-P2a).
*/
export function toSessionListProps(vm: SessionListData): SessionListModel {
return toSessionListModel(vm);
}
export const sessionListAdapter = defineAdapter({
name: "sessionList",
toProps: toSessionListProps,
defaultRenderer: renderSessionList,
});
@@ -1,6 +1,6 @@
import { describe, expect, test } from "vitest";
import type { TaskListData } from "@toolctrl/view-models";
import { renderTaskListMock } from "@toolctrl/ui-mock";
import type { TaskListData } from "@hivegrid/view-models";
import { renderTaskListMock } from "@hivegrid/ui-mock";
import { taskListAdapter } from "./taskList.js";
@@ -1,5 +1,5 @@
import { toTaskListModel, type TaskListData, type TaskListModel } from "@toolctrl/view-models";
import { renderTaskList } from "@toolctrl/ui-subframe";
import { toTaskListModel, type TaskListData, type TaskListModel } from "@hivegrid/view-models";
import { renderTaskList } from "@hivegrid/ui-subframe";
import { defineAdapter } from "./defineAdapter.js";
@@ -2,7 +2,7 @@ import { describe, expect, test } from "vitest";
import { AppShell, createMobileRegistry, createPortalRegistry, createShellRegistries } from "./index.js";
describe("@toolctrl/ui-app", () => {
describe("@hivegrid/ui-app", () => {
test("creates sorted mobile and portal registries", () => {
expect(createMobileRegistry([{ id: "b", href: "/b", labelKey: "nav.b", priority: 2 }, { id: "a", href: "/a", labelKey: "nav.a", priority: 1 }]).map((item) => item.id)).toEqual(["a", "b"]);
expect(createPortalRegistry([{ id: "late", slot: "main", labelKey: "portal.late", order: 20 }, { id: "early", slot: "main", labelKey: "portal.early", order: 10 }]).map((item) => item.id)).toEqual(["early", "late"]);
@@ -5,7 +5,7 @@ import type {
PortalRegistryItem,
ShellRegistries,
SidebarRegistryItem,
} from "@toolctrl/view-models";
} from "@hivegrid/view-models";
export * from "./adapters/index.js";
@@ -0,0 +1,166 @@
import { describe, expect, test } from "vitest";
import type { MobileRegistryItem, PortalRegistryItem } from "@hivegrid/view-models";
import {
AppShell,
EmptyPage,
createBreadcrumbRegistry,
createMobileRegistry,
createPortalRegistry,
createShellRegistries,
createSidebarRegistry,
} from "./index.js";
describe("EmptyPage", () => {
test("renders an empty-state section with the default i18n label key", () => {
const element = EmptyPage({});
expect(element.type).toBe("section");
expect(element.props["data-page-state"]).toBe("empty");
expect(element.props["data-label-key"]).toBe("foundation.pages.empty");
});
test("passes a caller-supplied label key through to the empty-state markup", () => {
const element = EmptyPage({ labelKey: "tasks.list.empty.headline" });
expect(element.props["data-label-key"]).toBe("tasks.list.empty.headline");
});
});
describe("createMobileRegistry", () => {
test("items without an explicit priority default to 100 and sort last", () => {
const result = createMobileRegistry([
{ id: "no-priority", href: "/x", labelKey: "nav.x" },
{ id: "high", href: "/h", labelKey: "nav.h", priority: 5 },
]);
expect(result.map((item) => item.id)).toEqual(["high", "no-priority"]);
});
test("orders a prioritised item ahead of an unprioritised one regardless of input order", () => {
const result = createMobileRegistry([
{ id: "high", href: "/h", labelKey: "nav.h", priority: 5 },
{ id: "no-priority", href: "/x", labelKey: "nav.x" },
]);
expect(result.map((item) => item.id)).toEqual(["high", "no-priority"]);
});
test("keeps input order for items sharing the same priority (stable sort)", () => {
const result = createMobileRegistry([
{ id: "first", href: "/1", labelKey: "nav.1", priority: 10 },
{ id: "second", href: "/2", labelKey: "nav.2", priority: 10 },
]);
expect(result.map((item) => item.id)).toEqual(["first", "second"]);
});
test("returns a sorted copy without mutating the source array", () => {
const source: MobileRegistryItem[] = [
{ id: "b", href: "/b", labelKey: "nav.b", priority: 2 },
{ id: "a", href: "/a", labelKey: "nav.a", priority: 1 },
];
const result = createMobileRegistry(source);
expect(result).not.toBe(source);
expect(result.map((item) => item.id)).toEqual(["a", "b"]);
// The source must stay in its original (unsorted) order.
expect(source.map((item) => item.id)).toEqual(["b", "a"]);
});
});
describe("createPortalRegistry", () => {
test("items without an explicit order default to 100 and sort after ordered slots", () => {
const result = createPortalRegistry([
{ id: "tail", slot: "main", labelKey: "portal.tail" },
{ id: "lead", slot: "main", labelKey: "portal.lead", order: 1 },
]);
expect(result.map((item) => item.id)).toEqual(["lead", "tail"]);
});
test("orders an ordered slot ahead of an unordered one regardless of input order", () => {
const result = createPortalRegistry([
{ id: "lead", slot: "main", labelKey: "portal.lead", order: 1 },
{ id: "tail", slot: "main", labelKey: "portal.tail" },
]);
expect(result.map((item) => item.id)).toEqual(["lead", "tail"]);
});
test("returns a sorted copy without mutating the source array", () => {
const source: PortalRegistryItem[] = [
{ id: "late", slot: "main", labelKey: "portal.late", order: 9 },
{ id: "early", slot: "main", labelKey: "portal.early", order: 1 },
];
const result = createPortalRegistry(source);
expect(result).not.toBe(source);
expect(source.map((item) => item.id)).toEqual(["late", "early"]);
});
});
describe("registry copy semantics", () => {
test("createSidebarRegistry returns a defensive copy", () => {
const source = [{ id: "home", href: "/", labelKey: "nav.home" }];
const copy = createSidebarRegistry(source);
expect(copy).not.toBe(source);
expect(copy).toEqual(source);
});
test("createBreadcrumbRegistry returns a defensive copy", () => {
const source = [{ id: "root", labelKey: "crumb.root" }];
const copy = createBreadcrumbRegistry(source);
expect(copy).not.toBe(source);
expect(copy).toEqual(source);
});
});
describe("createShellRegistries", () => {
test("keeps sidebar/breadcrumb order verbatim while sorting mobile and portals", () => {
const registries = createShellRegistries({
sidebar: [
{ id: "s2", href: "/s2", labelKey: "nav.s2" },
{ id: "s1", href: "/s1", labelKey: "nav.s1" },
],
breadcrumbs: [
{ id: "b1", labelKey: "crumb.b1" },
{ id: "b2", labelKey: "crumb.b2" },
],
mobile: [
{ id: "m-late", href: "/ml", labelKey: "nav.ml", priority: 9 },
{ id: "m-early", href: "/me", labelKey: "nav.me", priority: 1 },
],
portals: [
{ id: "p-late", slot: "main", labelKey: "portal.pl", order: 9 },
{ id: "p-early", slot: "main", labelKey: "portal.pe", order: 1 },
],
});
expect(registries.sidebar.map((item) => item.id)).toEqual(["s2", "s1"]);
expect(registries.breadcrumbs.map((item) => item.id)).toEqual(["b1", "b2"]);
expect(registries.mobile.map((item) => item.id)).toEqual(["m-early", "m-late"]);
expect(registries.portals.map((item) => item.id)).toEqual(["p-early", "p-late"]);
});
});
describe("AppShell", () => {
test("exposes each registry size as a data attribute for the layout shell", () => {
const shell = AppShell({
registries: {
sidebar: [{ id: "s", href: "/s", labelKey: "nav.s" }],
breadcrumbs: [{ id: "b", labelKey: "crumb.b" }],
mobile: [
{ id: "m1", href: "/m1", labelKey: "nav.m1", priority: 1 },
{ id: "m2", href: "/m2", labelKey: "nav.m2", priority: 2 },
],
portals: [],
},
children: "page",
});
expect(shell.props["data-ui-shell"]).toBe("app");
expect(shell.props["data-sidebar-count"]).toBe(1);
expect(shell.props["data-breadcrumb-count"]).toBe(1);
expect(shell.props["data-mobile-count"]).toBe(2);
expect(shell.props["data-portal-count"]).toBe(0);
expect((shell.props as { children?: unknown }).children).toBe("page");
});
test("defaults every registry to empty when no registries prop is supplied", () => {
const shell = AppShell({});
expect(shell.props["data-sidebar-count"]).toBe(0);
expect(shell.props["data-breadcrumb-count"]).toBe(0);
expect(shell.props["data-mobile-count"]).toBe(0);
expect(shell.props["data-portal-count"]).toBe(0);
});
});
@@ -0,0 +1,38 @@
import { afterAll, describe, expect, vi } from "vitest";
import { createElement, type ReactElement, type ReactNode } from "react";
// Capture the elements that the template hands to the (mocked) axe helper so
// the suite stays fast and deterministic: this file only exercises the
// component-name resolution, not real axe-core.
const captured: ReactElement[] = [];
vi.mock("../../test-setup/axe.js", () => ({
expectNoAxeViolations: vi.fn(async (ui: ReactElement) => {
captured.push(ui);
}),
}));
import { generateA11yTest } from "./a11y-template.js";
// A component that is callable but exposes neither a `displayName` nor a
// (defined) `name`, forcing the resolver's final `?? "Component"` fallback —
// the one branch the existing suite (which uses an empty-string name) never
// reaches, because `"" ?? x` short-circuits to the empty string.
const Anonymous = Object.defineProperty(
(props: { readonly children?: ReactNode }) => createElement("p", null, props.children),
"name",
{ value: undefined },
);
describe("generateA11yTest with an anonymous component", () => {
generateA11yTest(Anonymous, { children: "anon" });
afterAll(() => {
// The template must still register exactly one axe assertion bound to the
// anonymous component, i.e. the missing name does not break generation.
expect(Anonymous.name).toBeUndefined();
expect(captured).toHaveLength(1);
expect(captured[0]?.type).toBe(Anonymous);
expect(captured[0]?.props).toMatchObject({ children: "anon" });
});
});
@@ -10,7 +10,7 @@
* keyboard-navigation behaviour.
*
* The helper intentionally lives in the public test-utils tree so that
* consumer packages (apps/web, apps/storybook) can re-use the same template
* consumer packages such as apps/web can re-use the same template
* without copying boilerplate.
*/
import type { ComponentType, ComponentProps, ReactNode } from "react";
@@ -0,0 +1,73 @@
import { afterEach, describe, expect, test } from "vitest";
import { createElement } from "react";
import { expectNoAxeViolations, runAxe } from "../../test-setup/axe.js";
// axe-core wants its context node connected to the document, so mount fixtures
// into <body> and tear them down between cases to avoid cross-test bleed.
const mounted: HTMLElement[] = [];
function mount(html: string): HTMLElement {
const host = document.createElement("div");
host.innerHTML = html;
document.body.appendChild(host);
mounted.push(host);
return host;
}
afterEach(() => {
for (const host of mounted.splice(0)) host.remove();
});
const IMAGE_WITHOUT_ALT = '<img src="https://example.com/logo.png">';
describe("runAxe", () => {
test("reports no violations for accessible markup under the default WCAG preset", async () => {
const result = await runAxe(mount('<button type="button">Save</button>'));
expect(result.violations).toHaveLength(0);
});
test("flags an image missing its alt attribute (image-alt, WCAG level A)", async () => {
const result = await runAxe(mount(IMAGE_WITHOUT_ALT));
expect(result.violations.some((violation) => violation.id === "image-alt")).toBe(true);
});
test("honours a per-rule override that disables a default rule", async () => {
const result = await runAxe(mount(IMAGE_WITHOUT_ALT), {
rules: { "image-alt": { enabled: false } },
});
expect(result.violations.some((violation) => violation.id === "image-alt")).toBe(false);
});
test("honours a custom tag set that excludes the failing rule", async () => {
// `image-alt` is a WCAG-2.0 level-A rule; restricting the run to AAA tags
// means it is never evaluated, so the missing-alt image now passes.
const result = await runAxe(mount(IMAGE_WITHOUT_ALT), { tags: ["wcag2aaa"] });
expect(result.violations.some((violation) => violation.id === "image-alt")).toBe(false);
});
});
describe("expectNoAxeViolations", () => {
test("resolves without throwing when the rendered element is accessible", async () => {
await expect(
expectNoAxeViolations(createElement("button", { type: "button" }, "Save")),
).resolves.toBeUndefined();
});
test("throws a formatted error and attaches the raw axe result as the cause", async () => {
const badImage = createElement("img", { src: "https://example.com/logo.png" });
await expect(expectNoAxeViolations(badImage)).rejects.toThrow(/violation\(s\)/);
let thrown: unknown;
try {
await expectNoAxeViolations(badImage);
} catch (error) {
thrown = error;
}
expect(thrown).toBeInstanceOf(Error);
expect((thrown as Error).message).toContain("image-alt");
const cause = (thrown as { cause?: { violations?: ReadonlyArray<{ id: string }> } }).cause;
expect(cause?.violations?.some((violation) => violation.id === "image-alt")).toBe(true);
});
});