// The board as data (board.mjs): its groups, the moves the keys and drag // make, the words compare, and the export in the house format. import { test } from "node:test"; import assert from "node:assert/strict"; import { coverageLine, exportMarkdown, findingOf, groupsOf, holdsWords, moveQuote, moveSection, placeQuote, wordsOf } from "./board.mjs"; const q = (id, section, extra = {}) => ({ id, section, text: `words of ${id}`, cite: { kind: "video", source: "remote:https://a.example", channel: "harbor-radio", video: `v-${id}`, title: `Episode ${id}`, date: "20240520", t: 10, end: 13.8, clock: "0:10", url: `https://a.example/?v=harbor-radio%2Fv-${id}&t=10` }, claim: "", note: "", speakerChecked: false, pinnedAt: "", ...extra, }); const doc = (quotes, sections = [{ id: "s1", title: "First" }, { id: "s2", title: "Second" }]) => ({ id: "board", title: "Employee count", scope: { source: "remote:https://a.example", query: "how many employees" }, search: null, sections, quotes, notes: "", }); const ids = (a) => a.order.map((o) => `${o.id}:${o.section ?? "-"}`).join(" "); test("groups: Unsorted first only when it holds anything (or there are no sections), then each section", () => { assert.deepEqual(groupsOf(doc([q("q1", "s2"), q("q2", "s1")])).map((g) => [g.id, g.quotes.map((x) => x.id)]), [["s1", ["q2"]], ["s2", ["q1"]]]); assert.deepEqual(groupsOf(doc([q("q1", null), q("q2", "s1")])).map((g) => g.id), [null, "s1", "s2"]); assert.deepEqual(groupsOf(doc([], [])).map((g) => g.title), ["Unsorted"]); }); test("alt+j/k: a quote moves within its section, then across into the next or the previous", () => { const d = doc([q("q1", null), q("q2", "s1"), q("q3", "s1"), q("q4", "s2")]); assert.equal(ids(moveQuote(d, "q2", 1)), "q1:- q3:s1 q2:s1 q4:s2"); assert.equal(ids(moveQuote(d, "q3", 1)), "q1:- q2:s1 q3:s2 q4:s2", "past the end of s1 into the top of s2"); assert.equal(ids(moveQuote(d, "q2", -1)), "q1:- q2:- q3:s1 q4:s2", "past the top of s1 into Unsorted's end"); assert.equal(moveQuote(d, "q1", -1), null); assert.equal(moveQuote(d, "q4", 1), null); const noUnsorted = doc([q("q2", "s1")]); assert.equal(ids(moveQuote(noUnsorted, "q2", -1)), "q2:-", "Unsorted is above the first section even when empty"); }); test("drag: a quote placed in a section at an index; a section moved", () => { const d = doc([q("q1", null), q("q2", "s1"), q("q3", "s1")]); assert.equal(ids(placeQuote(d, "q1", "s1", 1)), "q2:s1 q1:s1 q3:s1"); assert.equal(ids(placeQuote(d, "q3", "s2", 0)), "q1:- q2:s1 q3:s2"); assert.deepEqual(moveSection(d, "s1", 1).sections.map((s) => s.id), ["s2", "s1"]); assert.equal(moveSection(d, "s1", -1), null); }); test("words: case, punctuation and spacing aside; whole words, in order", () => { assert.equal(wordsOf(" How many EMPLOYEES? You fired them all, "), "how many employees you fired them all"); assert.equal(holdsWords("okay so — How many employees? You fired them all, right", "how many employees you fired them all"), true); assert.equal(holdsWords("they voted the budget down eight to one", "they voted the budget down nine to one"), false); assert.equal(holdsWords("the budgets", "the budget"), false, "a word is whole"); assert.equal(holdsWords("it’s fine", "it's fine"), true); }); test("a finding: the claim (no quotation marks), the quote, its link; our notes after it", () => { const f = findingOf(q("q1", null, { claim: 'He said "no".', note: "Panel, not Jeremy", text: 'a "quoted" word' })); assert.equal( f, '- He said no: "a \'quoted\' word" — [Episode q1 @ 0:10](https://a.example/?v=harbor-radio%2Fv-q1&t=10)\n Note: Panel, not Jeremy. Speaker not checked.', ); assert.equal(findingOf(q("q2", null, { speakerChecked: true })), '- "words of q2" — [Episode q2 @ 0:10](https://a.example/?v=harbor-radio%2Fv-q2&t=10)'); const post = findingOf(q("q3", null, { cite: { kind: "post", channel: "x", video: "p1", author: "Ann", date: "20250101", url: "https://a.example/?v=x%2Fp1&vm=post" } })); assert.match(post, /^- "words of q3" — \[post by Ann, 2025-01-01\]\(https:\/\/a\.example\/\?v=x%2Fp1&vm=post\)$/); assert.match(findingOf(q("q4", null, { verify: { status: "drifted", at: "2026-10-14T00:00:00Z" } })), /Drifted: the transcript read differently at the last re-verify \(2026-10-14\)/); }); test("the export: title, summary, a heading per section (Findings when there are none), Coverage", () => { const md = exportMarkdown(doc([q("q1", "s2"), q("q2", null, { speakerChecked: true }), q("q3", "s2")]), { sourceLabel: "Jeralyzer", read: 2 }); const heads = md.split("\n").filter((l) => l.startsWith("#")); assert.deepEqual(heads, ["# Employee count", "## Unsorted", "## Second", "## Coverage"]); assert.match(md, /3 quotes from 3 sources, pinned on a research board from the search “how many employees”/); assert.ok(md.indexOf("words of q1") < md.indexOf("words of q3"), "board order"); const bare = exportMarkdown(doc([q("q1", null)], [])); assert.ok(bare.includes("\n## Findings\n")); assert.match(coverageLine({ ...doc([q("q1", null)]), search: { session: "FAKE-TEST-VALUE", query: "q", total: 27, complete: false, notReached: ["a"], at: "" } }, { read: 5 }), /27 recordings, PARTIAL \(not reached: a\)\. Read 5 of 27\. 1 pinned\. 1 with the speaker not checked\./); });