77 lines
2.6 KiB
TypeScript
77 lines
2.6 KiB
TypeScript
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"');
|
|
});
|
|
});
|