49 lines
1.7 KiB
TypeScript
49 lines
1.7 KiB
TypeScript
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");
|
|
});
|
|
});
|