Files
story/web/test/home-model.test.mjs
T
Codex Local bf1233d5df
ci / verify (push) Canceled after 0s
feat: expand companion platform, device controls, and memoir workflows
Add customer and operator login, BLE provisioning, device fleet controls, call memory, memoir generation, and refreshed family and maintenance portals. Include API contracts, migrations, firmware sources, tests, assets, and deployment documentation.
2026-10-08 10:06:44 +08:00

42 lines
2.9 KiB
JavaScript

import test from "node:test";
import assert from "node:assert/strict";
import { homeWeek, homeDeviceStatus } from "../src/components/home/home-model.ts";
const now = new Date("2026-09-20T12:00:00+08:00");
const call = (id, created_at, extras = {}) => ({ id, subject_id: "elder-a", status: "COMPLETED", duration_ms: 60000, created_at, ...extras });
test("empty days never become steady mood observations", () => {
const week = homeWeek([], "elder-a", {}, now);
assert.equal(week.count, 0); assert.equal(week.minutes, 0); assert.equal(week.days.length, 7);
assert.equal(week.range, "9月14日—9月20日");
assert(week.days.every(day => day.moodLabel === undefined));
});
test("counts conversations, not days with activity", () => {
const week = homeWeek([call("one", "2026-09-19T10:00:00+08:00"), call("two", "2026-09-19T11:00:00+08:00", { duration_ms: 120000 })], "elder-a", {}, now);
assert.equal(week.count, 2); assert.equal(week.minutes, 3); assert.equal(week.days[5].count, 2);
});
test("scopes to selected elder and completed calls within week; excludes future records", () => {
const week = homeWeek([
call("other", "2026-09-19T10:00:00+08:00", { subject_id: "elder-b" }),
call("failed", "2026-09-19T10:00:00+08:00", { status: "FAILED" }),
call("previous", "2026-09-13T23:59:59+08:00"), call("future", "2026-09-20T13:00:00+08:00"),
call("current", "2026-09-14T00:00:00+08:00")
], "elder-a", {}, now);
assert.equal(week.count, 1); assert.equal(week.latest.id, "current");
});
test("uses Beijing at UTC date boundaries even with a historical profile timezone", () => {
assert.equal(homeWeek([call("boundary", "2026-09-13T16:05:00Z")], "elder-a", {}, now, "Asia/Shanghai").days[0].count, 1);
assert.equal(homeWeek([call("boundary", "2026-09-13T16:05:00Z")], "elder-a", {}, now, "America/Los_Angeles").days[0].count, 1);
assert.equal(homeWeek([], "elder-a", {}, new Date("2026-10-04T16:00:00Z"), "America/Los_Angeles").range, "10月5日—10月11日");
});
test("mood needs both a record and supporting evidence", () => {
const conversations = [call("one", "2026-09-19T11:00:00+08:00")];
assert.equal(homeWeek(conversations, "elder-a", { one: { moodLabel: "平稳" } }, now).days[5].moodLabel, undefined);
assert.equal(homeWeek(conversations, "elder-a", { one: { moodLabel: "愉快", evidence: "聊天摘要中的原始表达" } }, now).days[5].moodLabel, "愉快");
});
test("missing presence is unknown; any online device counts as connected", () => {
const devices = [{ id: "one", subject_id: "elder-a" }, { id: "two", subject_id: "elder-a" }];
assert.equal(homeDeviceStatus(devices, {}, "elder-a"), "unknown");
assert.equal(homeDeviceStatus(devices, { one: { online: false }, two: { online: false } }, "elder-a"), "offline");
assert.equal(homeDeviceStatus(devices, { one: { online: true } }, "elder-a"), "online");
assert.equal(homeDeviceStatus(devices, {}, "elder-b"), "unbound");
});