56 lines
1.7 KiB
TypeScript
56 lines
1.7 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
buildDemoStringPreview,
|
|
formatDemoDurationFromMillis,
|
|
parseDemoTtlToSeconds,
|
|
persistDemoKeyTtl,
|
|
updateDemoKeyTtl,
|
|
updateDemoStringValue,
|
|
type DemoWorkspaceKey,
|
|
} from "./demo-workspace";
|
|
|
|
const demoKeys: DemoWorkspaceKey[] = [
|
|
{
|
|
id: "cache:homepage",
|
|
name: "cache:homepage",
|
|
type: "string",
|
|
ttl: "48s",
|
|
preview: "serialized landing payload",
|
|
editable: true,
|
|
value: "{\"hero\":\"Redis GUI\"}",
|
|
summary: "String keys are editable in V1.",
|
|
},
|
|
];
|
|
|
|
describe("demo workspace helpers", () => {
|
|
it("updates string values and refreshes the visible preview", () => {
|
|
expect(
|
|
updateDemoStringValue(demoKeys, "cache:homepage", "next value"),
|
|
).toEqual([
|
|
{
|
|
...demoKeys[0],
|
|
value: "next value",
|
|
preview: "next value",
|
|
},
|
|
]);
|
|
});
|
|
|
|
it("updates TTL state for session-local demo flows", () => {
|
|
expect(updateDemoKeyTtl(demoKeys, "cache:homepage", 90_000)[0]?.ttl).toBe("1m");
|
|
expect(persistDemoKeyTtl(demoKeys, "cache:homepage")[0]?.ttl).toBe("persistent");
|
|
});
|
|
|
|
it("formats preview text and durations consistently", () => {
|
|
expect(buildDemoStringPreview("alpha beta gamma delta epsilon zeta eta theta", 16)).toBe(
|
|
"alpha beta gamm…",
|
|
);
|
|
expect(formatDemoDurationFromMillis(750)).toBe("750ms");
|
|
expect(formatDemoDurationFromMillis(5_000)).toBe("5s");
|
|
expect(formatDemoDurationFromMillis(7_200_000)).toBe("2h");
|
|
expect(parseDemoTtlToSeconds("750ms")).toBe(0);
|
|
expect(parseDemoTtlToSeconds("5s")).toBe(5);
|
|
expect(parseDemoTtlToSeconds("2h")).toBe(7200);
|
|
expect(parseDemoTtlToSeconds("persistent")).toBe(-1);
|
|
});
|
|
});
|