import { TestCase } from "./framework/test_case.js"; import { setupDom, teardownDom } from "./framework/dom.js"; import { formatCommitDate, renderDevlog } from "../client/js/devlog.js"; import { DEVLOG } from "../client/js/devlog_data.js"; const FIXTURE = [ { hash: "abc1234", date: "2026-09-21", subject: "Fixed the invisible country names", body: "A longer explanation of the fix.", }, { hash: "def5678", date: "2026-09-20", subject: "Added the devlog", body: "", }, ]; export class DevlogTest extends TestCase { test_dates_read_without_a_locale() { this.assertEqual(formatCommitDate("2026-09-21"), "21 Sep 2026"); this.assertEqual(formatCommitDate("2026-01-02"), "2 Jan 2026"); this.assertEqual(formatCommitDate("not a date"), "not a date"); this.assertEqual(formatCommitDate(""), ""); } async test_headers_show_the_date_and_subject_and_expand() { const env = await setupDom(); try { renderDevlog(env.$("#devlog-list"), FIXTURE); const headers = env.$("#devlog-list .devlog-header"); this.assertSize(headers, 2, "one header per commit"); this.assertTrue( headers.eq(0).find(".devlog-date").text().includes("21 Sep 2026"), "the newest commit shows its date" ); this.assertTrue( headers.eq(1).find(".devlog-subject").text().includes("Added the devlog"), "the subject is shown" ); const bodies = env.$("#devlog-list .devlog-body"); this.assertTrue(bodies.eq(0).hasClass("hidden"), "a message starts collapsed"); headers.eq(0).trigger("click"); this.assertFalse(bodies.eq(0).hasClass("hidden"), "clicking the header expands it"); this.assertTrue( bodies.eq(0).find(".devlog-message").text().includes("A longer explanation"), "the full message is shown" ); this.assertEqual(headers.eq(0).attr("aria-expanded"), "true", "the header reports it is open"); headers.eq(0).trigger("click"); this.assertTrue(bodies.eq(0).hasClass("hidden"), "clicking again collapses it"); } finally { teardownDom(env); } } test_the_generated_devlog_carries_ten_dated_commits() { this.assertTrue(Array.isArray(DEVLOG), "the devlog data is a list"); this.assertGreater(DEVLOG.length, 0, "there is at least one commit"); this.assertLess(DEVLOG.length, 11, "at most ten commits are shipped"); for (const commit of DEVLOG) { this.assertTrue(/^[0-9a-f]+$/.test(commit.hash), `a short hash: ${commit.hash}`); this.assertTrue(/^\d{4}-\d{2}-\d{2}$/.test(commit.date), `a date: ${commit.date}`); this.assertTrue(typeof commit.subject === "string" && commit.subject.length > 0, "a commit has a subject"); this.assertTrue(typeof commit.body === "string", "a commit has a body field"); } } }