Files
timelog/tests/title.test.ts
T

34 lines
1.3 KiB
TypeScript
Raw Normal View History

import { describe, expect, test } from "bun:test";
import { countdown, pageTitle } from "../src/client/title.ts";
const start = +new Date(2026, 10, 5, 9, 0, 0);
const session = { startMs: start, targetSeconds: 25 * 60, tag: "Study" };
describe("browser tab title", () => {
test("is the app name when no session runs", () => {
expect(pageTitle(null, start)).toBe("Timelog");
});
test("shows the remaining time and tag while a session runs", () => {
expect(pageTitle(session, start)).toBe("25:00 · Study — Timelog");
expect(pageTitle(session, start + 61_500)).toBe("23:59 · Study — Timelog");
});
test("stops at 00:00 when the session is due", () => {
expect(pageTitle(session, start + 26 * 60_000)).toBe("00:00 · Study — Timelog");
});
test("countdown rounds partial seconds up", () => {
expect(countdown(1)).toBe("00:01");
expect(countdown(120 * 60_000)).toBe("120:00");
expect(countdown(-5)).toBe("00:00");
});
});
test("redundant UI text is gone", async () => {
const source = (await Bun.file("src/client/main.ts").text()).toLowerCase();
for (const text of [
"a quiet record of time", "local first", "forest csv / v1",
"one session at a time", "make time count", "actual logged time",
]) expect(source).not.toContain(text);
});