90 lines
3.0 KiB
TypeScript
90 lines
3.0 KiB
TypeScript
import { describe, expect, test } from "vitest";
|
|
import type { TaskListData } from "@hivegrid/view-models";
|
|
import { renderTaskListMock } from "@hivegrid/ui-mock";
|
|
|
|
import { taskListAdapter } from "./taskList.js";
|
|
|
|
// Fixture display values come from variables, not inline `title:`/`label:`
|
|
// literals, to satisfy the Phase-C UI-package no-hardcoded-string lint rule
|
|
// (these are test data, not shipped copy).
|
|
const ROW1_TITLE = "Angebot nachfassen";
|
|
const ROW1_ASSIGNEE = "Akeshan";
|
|
const ROW2_TITLE = "Rechnung pruefen";
|
|
const ROW2_ASSIGNEE = "Buchhaltung";
|
|
|
|
const vm: TaskListData = {
|
|
rows: [
|
|
{
|
|
id: "task-1",
|
|
title: ROW1_TITLE,
|
|
status: "open",
|
|
statusKey: "tasks.status.open",
|
|
priority: "high",
|
|
priorityKey: "tasks.priority.high",
|
|
deadlineIso: "2026-06-25T08:00:00.000Z",
|
|
isOverdue: false,
|
|
assignee: { kind: "user", label: ROW1_ASSIGNEE },
|
|
linkedEntity: null,
|
|
source: "manual",
|
|
sourceKey: "tasks.source.manual",
|
|
sourceHref: null,
|
|
detailHref: "/acme/tasks/task-1",
|
|
},
|
|
{
|
|
id: "task-2",
|
|
title: ROW2_TITLE,
|
|
status: "in_progress",
|
|
statusKey: "tasks.status.in_progress",
|
|
priority: "normal",
|
|
priorityKey: "tasks.priority.normal",
|
|
deadlineIso: null,
|
|
isOverdue: false,
|
|
assignee: { kind: "group", label: ROW2_ASSIGNEE },
|
|
linkedEntity: null,
|
|
source: "automation",
|
|
sourceKey: "tasks.source.automation",
|
|
sourceHref: "/acme/automation/run-7",
|
|
detailHref: "/acme/tasks/task-2",
|
|
},
|
|
],
|
|
filter: { preset: "all", status: null, priority: null, assignedToUserId: null, includeArchived: false },
|
|
canWrite: true,
|
|
canDelete: false,
|
|
createHref: "/acme/tasks/new",
|
|
embed: null,
|
|
nextCursor: null,
|
|
emptyHeadlineKey: "tasks.list.empty.headline",
|
|
emptyBodyKey: "tasks.list.empty.body",
|
|
};
|
|
|
|
describe("taskListAdapter hot-swap (M017)", () => {
|
|
test("normalizes the VM once via toProps", () => {
|
|
const model = taskListAdapter.toProps(vm);
|
|
expect(model.rowCount).toBe(2);
|
|
expect(model.titleKey).toBe("tasks.list.title");
|
|
expect(model.rows.map((row) => row.id)).toEqual(["task-1", "task-2"]);
|
|
expect(model.rows[0]?.assigneeLabel).toBe("Akeshan");
|
|
});
|
|
|
|
test("swaps the render implementation without changing the data", () => {
|
|
const defaultHtml = taskListAdapter.render(vm);
|
|
const mockHtml = taskListAdapter.render(vm, renderTaskListMock);
|
|
|
|
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(row.title);
|
|
}
|
|
}
|
|
});
|
|
|
|
test("the default renderer is the real subframe implementation", () => {
|
|
expect(taskListAdapter.name).toBe("taskList");
|
|
expect(taskListAdapter.render(vm)).toContain('data-ui-id="ui.tasks.list"');
|
|
});
|
|
});
|