Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/packages/ui-app/src/adapters/rolesList.hot-swap.test.ts
T
2026-07-08 16:15:37 +02:00

49 lines
2.1 KiB
TypeScript

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"');
});
});