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
+40
@@ -0,0 +1,40 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildSelectTenantVM, toTenantCard } from "./select-tenant.vm.js";
|
||||
|
||||
describe("toTenantCard initials edge cases (select-tenant.ts:79)", () => {
|
||||
it("falls back to '?' when the name is blank/whitespace only", () => {
|
||||
expect(toTenantCard({ id: "t1", name: " ", slug: "blank" }).avatarInitials).toBe("?");
|
||||
});
|
||||
|
||||
it("takes the first two letters of a single-word name", () => {
|
||||
expect(toTenantCard({ id: "t1", name: "Acme", slug: "acme" }).avatarInitials).toBe("AC");
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildSelectTenantVM current-tenant sort branches (select-tenant.ts:111)", () => {
|
||||
it("pulls the current tenant to the front when it sits last in the input", () => {
|
||||
const vm = buildSelectTenantVM({
|
||||
tenants: [
|
||||
{ id: "t1", name: "Alpha", slug: "alpha" },
|
||||
{ id: "t2", name: "Beta", slug: "beta" },
|
||||
{ id: "t3", name: "Gamma", slug: "gamma" },
|
||||
],
|
||||
currentTenantId: "t3",
|
||||
});
|
||||
if (vm.status !== "ready") throw new Error("expected ready");
|
||||
expect(vm.data.tenants[0].id).toBe("t3");
|
||||
expect(vm.data.tenants.slice(1).map((c) => c.name)).toEqual(["Alpha", "Beta"]);
|
||||
});
|
||||
|
||||
it("keeps the current tenant first when it already leads the input", () => {
|
||||
const vm = buildSelectTenantVM({
|
||||
tenants: [
|
||||
{ id: "t1", name: "Alpha", slug: "alpha" },
|
||||
{ id: "t2", name: "Beta", slug: "beta" },
|
||||
],
|
||||
currentTenantId: "t1",
|
||||
});
|
||||
if (vm.status !== "ready") throw new Error("expected ready");
|
||||
expect(vm.data.tenants.map((c) => c.id)).toEqual(["t1", "t2"]);
|
||||
});
|
||||
});
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { toSelectTenantModel, type SelectTenantData } from "./select-tenant.vm.js";
|
||||
|
||||
function data(overrides: Partial<SelectTenantData> = {}): SelectTenantData {
|
||||
return {
|
||||
tenants: [
|
||||
{
|
||||
id: "t-current",
|
||||
name: "Acme GmbH",
|
||||
slug: "acme",
|
||||
avatarInitials: "AG",
|
||||
avatarColor: "blue",
|
||||
role: "owner",
|
||||
roleLabelKey: "account.selectTenant.role.owner",
|
||||
roleTone: "red-subtle",
|
||||
isCurrent: true,
|
||||
},
|
||||
{
|
||||
id: "t-other",
|
||||
name: "Globex AG",
|
||||
slug: "globex",
|
||||
avatarInitials: "GA",
|
||||
avatarColor: "green",
|
||||
isCurrent: false,
|
||||
},
|
||||
],
|
||||
totalCount: 2,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
describe("toSelectTenantModel (M015 hot-swap mapper)", () => {
|
||||
it("maps the domain data to the normalized model with i18n keys", () => {
|
||||
const model = toSelectTenantModel(data());
|
||||
expect(model.titleKey).toBe("account.selectTenant.title");
|
||||
expect(model.emptyHeadlineKey).toBe("account.selectTenant.empty");
|
||||
expect(model.rowCount).toBe(2);
|
||||
expect(model.totalCount).toBe(2);
|
||||
expect(model.rows.map((row) => row.id)).toEqual(["t-current", "t-other"]);
|
||||
});
|
||||
|
||||
it("carries the role label as an i18n key + tone, or null when the role is absent", () => {
|
||||
const model = toSelectTenantModel(data());
|
||||
expect(model.rows[0]?.roleLabelKey).toBe("account.selectTenant.role.owner");
|
||||
expect(model.rows[0]?.roleTone).toBe("red-subtle");
|
||||
expect(model.rows[1]?.roleLabelKey).toBeNull();
|
||||
expect(model.rows[1]?.roleTone).toBeNull();
|
||||
});
|
||||
|
||||
it("keeps tenant name/slug/initials as data", () => {
|
||||
const model = toSelectTenantModel(data());
|
||||
expect(model.rows[0]?.name).toBe("Acme GmbH");
|
||||
expect(model.rows[0]?.slug).toBe("acme");
|
||||
expect(model.rows[0]?.avatarInitials).toBe("AG");
|
||||
expect(model.rows[0]?.isCurrent).toBe(true);
|
||||
});
|
||||
|
||||
it("maps an empty tenant list to a zero-row model", () => {
|
||||
const model = toSelectTenantModel(data({ tenants: [], totalCount: 0 }));
|
||||
expect(model.rowCount).toBe(0);
|
||||
expect(model.rows).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
+50
@@ -116,3 +116,53 @@ export function buildSelectTenantVM(input: BuildSelectTenantInput): VMState<Sele
|
||||
data: { tenants: sorted, totalCount: sorted.length },
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalized prop-model the UI implementation renders (M015 Subframe-adapter
|
||||
* contract). The ui-app `selectTenant` adapter maps {@link SelectTenantData} ->
|
||||
* this model once, then the ui-subframe / ui-mock renderers stay dumb (hot-swap
|
||||
* drill, M017). Role label travels as an i18n key + tone literal (data), so the
|
||||
* renderer resolves no copy itself (DoD i18n).
|
||||
*/
|
||||
export interface SelectTenantModelRow {
|
||||
readonly id: string;
|
||||
readonly name: string;
|
||||
readonly slug: string;
|
||||
readonly avatarImage: string | null;
|
||||
readonly avatarInitials: string;
|
||||
readonly avatarColor: AvatarColor;
|
||||
readonly roleLabelKey: string | null;
|
||||
readonly roleTone: RoleTone | null;
|
||||
readonly isCurrent: boolean;
|
||||
readonly subtitle: string | null;
|
||||
}
|
||||
|
||||
export interface SelectTenantModel {
|
||||
readonly titleKey: string;
|
||||
readonly emptyHeadlineKey: string;
|
||||
readonly totalCount: number;
|
||||
readonly rows: readonly SelectTenantModelRow[];
|
||||
readonly rowCount: number;
|
||||
}
|
||||
|
||||
/** Map the domain data to the normalized hot-swap model (used by the ui-app adapter). */
|
||||
export function toSelectTenantModel(data: SelectTenantData): SelectTenantModel {
|
||||
return {
|
||||
titleKey: "account.selectTenant.title",
|
||||
emptyHeadlineKey: "account.selectTenant.empty",
|
||||
totalCount: data.totalCount,
|
||||
rows: data.tenants.map((tenant) => ({
|
||||
id: tenant.id,
|
||||
name: tenant.name,
|
||||
slug: tenant.slug,
|
||||
avatarImage: tenant.avatarImage ?? null,
|
||||
avatarInitials: tenant.avatarInitials,
|
||||
avatarColor: tenant.avatarColor,
|
||||
roleLabelKey: tenant.roleLabelKey ?? null,
|
||||
roleTone: tenant.roleTone ?? null,
|
||||
isCurrent: tenant.isCurrent,
|
||||
subtitle: tenant.subtitle ?? null,
|
||||
})),
|
||||
rowCount: data.tenants.length,
|
||||
};
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildSessionListVM } from "./session-list.vm.js";
|
||||
|
||||
const NOW = Date.UTC(2026, 5, 18, 12, 0, 0);
|
||||
|
||||
describe("toMs string-vs-Date handling (session-list.ts:61)", () => {
|
||||
it("accepts an ISO string for lastSeenAt and normalizes it to ISO", () => {
|
||||
const iso = new Date(NOW - 5 * 60 * 1000).toISOString();
|
||||
const vm = buildSessionListVM({
|
||||
sessions: [{ id: "s1", lastSeenAt: iso }],
|
||||
currentSessionId: "s1",
|
||||
nowMs: NOW,
|
||||
});
|
||||
if (vm.status !== "ready") throw new Error("expected ready");
|
||||
expect(vm.data.devices[0].lastSeenIso).toBe(iso);
|
||||
expect(vm.data.devices[0].lastSeenBucket).toBe("minutes");
|
||||
expect(vm.data.devices[0].lastSeenCount).toBe(5);
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildSessionListVM ordering branches (session-list.ts:104)", () => {
|
||||
it("keeps insertion order when no session is the current one (equal branch)", () => {
|
||||
const vm = buildSessionListVM({
|
||||
sessions: [
|
||||
{ id: "s1", lastSeenAt: new Date(NOW) },
|
||||
{ id: "s2", lastSeenAt: new Date(NOW) },
|
||||
],
|
||||
currentSessionId: null,
|
||||
nowMs: NOW,
|
||||
});
|
||||
if (vm.status !== "ready") throw new Error("expected ready");
|
||||
expect(vm.data.devices.map((d) => d.id)).toEqual(["s1", "s2"]);
|
||||
expect(vm.data.otherActiveCount).toBe(2);
|
||||
});
|
||||
|
||||
it("keeps the current device first when it already leads the input", () => {
|
||||
const vm = buildSessionListVM({
|
||||
sessions: [
|
||||
{ id: "s1", lastSeenAt: new Date(NOW) },
|
||||
{ id: "s2", lastSeenAt: new Date(NOW) },
|
||||
],
|
||||
currentSessionId: "s1",
|
||||
nowMs: NOW,
|
||||
});
|
||||
if (vm.status !== "ready") throw new Error("expected ready");
|
||||
expect(vm.data.devices[0].id).toBe("s1");
|
||||
});
|
||||
});
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { toSessionListModel, type SessionListData } from "./session-list.vm.js";
|
||||
|
||||
const I18N_KEY = /^[a-z][a-z0-9]*(?:[.-][a-z0-9]+)*$/;
|
||||
|
||||
function data(overrides: Partial<SessionListData> = {}): SessionListData {
|
||||
return {
|
||||
devices: [
|
||||
{
|
||||
id: "s-current",
|
||||
isCurrent: true,
|
||||
trusted: true,
|
||||
deviceLabel: "Chrome",
|
||||
approxLocation: "Berlin, DE",
|
||||
lastSeenIso: "2026-07-06T09:00:00.000Z",
|
||||
lastSeenBucket: "justNow",
|
||||
canRevoke: false,
|
||||
},
|
||||
{
|
||||
id: "s-other",
|
||||
isCurrent: false,
|
||||
trusted: false,
|
||||
deviceLabelFallbackKey: "settings.security.sessions.unknownDevice",
|
||||
lastSeenIso: "2026-07-06T07:00:00.000Z",
|
||||
lastSeenBucket: "hours",
|
||||
lastSeenCount: 2,
|
||||
canRevoke: true,
|
||||
},
|
||||
],
|
||||
currentDeviceId: "s-current",
|
||||
otherActiveCount: 1,
|
||||
canRevokeOthers: true,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
describe("toSessionListModel (M015 hot-swap mapper)", () => {
|
||||
it("maps the domain data to the normalized model with i18n keys", () => {
|
||||
const model = toSessionListModel(data());
|
||||
expect(model.titleKey).toMatch(I18N_KEY);
|
||||
expect(model.emptyHeadlineKey).toMatch(I18N_KEY);
|
||||
expect(model.rowCount).toBe(2);
|
||||
expect(model.currentDeviceId).toBe("s-current");
|
||||
expect(model.otherActiveCount).toBe(1);
|
||||
expect(model.canRevokeOthers).toBe(true);
|
||||
});
|
||||
|
||||
it("carries the raw device label as data and the fallback key when missing", () => {
|
||||
const model = toSessionListModel(data());
|
||||
expect(model.rows[0]?.deviceLabel).toBe("Chrome");
|
||||
expect(model.rows[0]?.deviceLabelFallbackKey).toBeNull();
|
||||
expect(model.rows[1]?.deviceLabel).toBeNull();
|
||||
expect(model.rows[1]?.deviceLabelFallbackKey).toBe("settings.security.sessions.unknownDevice");
|
||||
});
|
||||
|
||||
it("passes the bucketed last-seen through without pre-formatting", () => {
|
||||
const model = toSessionListModel(data());
|
||||
expect(model.rows[0]?.lastSeenBucket).toBe("justNow");
|
||||
expect(model.rows[0]?.lastSeenCount).toBeNull();
|
||||
expect(model.rows[1]?.lastSeenBucket).toBe("hours");
|
||||
expect(model.rows[1]?.lastSeenCount).toBe(2);
|
||||
});
|
||||
|
||||
it("maps an empty device list to a zero-row model", () => {
|
||||
const model = toSessionListModel(data({ devices: [], otherActiveCount: 0, canRevokeOthers: false }));
|
||||
expect(model.rowCount).toBe(0);
|
||||
expect(model.rows).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
+55
@@ -113,3 +113,58 @@ export function buildSessionListVM(input: BuildSessionListVMInput): SessionListV
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalized prop-model the UI implementation renders (M015 Subframe-adapter
|
||||
* contract). The ui-app `sessionList` adapter maps {@link SessionListData} -> this
|
||||
* model once, then the ui-subframe / ui-mock renderers stay dumb (hot-swap drill,
|
||||
* M017). Bucketed last-seen + the i18n device-fallback key travel as data, so the
|
||||
* renderer resolves no copy itself (DoD i18n).
|
||||
*/
|
||||
export interface SessionListModelRow {
|
||||
readonly id: string;
|
||||
/** Raw device label as DATA, or null when only the i18n fallback applies. */
|
||||
readonly deviceLabel: string | null;
|
||||
readonly deviceLabelFallbackKey: string | null;
|
||||
readonly approxLocation: string | null;
|
||||
readonly lastSeenIso: string;
|
||||
readonly lastSeenBucket: LastSeenBucket;
|
||||
readonly lastSeenCount: number | null;
|
||||
readonly isCurrent: boolean;
|
||||
readonly trusted: boolean;
|
||||
readonly canRevoke: boolean;
|
||||
}
|
||||
|
||||
export interface SessionListModel {
|
||||
readonly titleKey: string;
|
||||
readonly emptyHeadlineKey: string;
|
||||
readonly currentDeviceId: string | null;
|
||||
readonly otherActiveCount: number;
|
||||
readonly canRevokeOthers: boolean;
|
||||
readonly rows: readonly SessionListModelRow[];
|
||||
readonly rowCount: number;
|
||||
}
|
||||
|
||||
/** Map the domain data to the normalized hot-swap model (used by the ui-app adapter). */
|
||||
export function toSessionListModel(data: SessionListData): SessionListModel {
|
||||
return {
|
||||
titleKey: "settings.security.sessions.heading",
|
||||
emptyHeadlineKey: "settings.security.sessions.empty",
|
||||
currentDeviceId: data.currentDeviceId,
|
||||
otherActiveCount: data.otherActiveCount,
|
||||
canRevokeOthers: data.canRevokeOthers,
|
||||
rows: data.devices.map((device) => ({
|
||||
id: device.id,
|
||||
deviceLabel: device.deviceLabel ?? null,
|
||||
deviceLabelFallbackKey: device.deviceLabelFallbackKey ?? null,
|
||||
approxLocation: device.approxLocation ?? null,
|
||||
lastSeenIso: device.lastSeenIso,
|
||||
lastSeenBucket: device.lastSeenBucket,
|
||||
lastSeenCount: device.lastSeenCount ?? null,
|
||||
isCurrent: device.isCurrent,
|
||||
trusted: device.trusted,
|
||||
canRevoke: device.canRevoke,
|
||||
})),
|
||||
rowCount: data.devices.length,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user