home / client / test / lb.test.mjs
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// The leaderboards: rank numbering, the top-10 slice, the empty/loading states,
// the game picker and week/all tabs, and `row.name || row.pub.slice(0,8)` — a
// JS-truthiness site an unnamed player exercises.
//
// fetch-weekly is the only stubbed seam (the drops carry co-signed receipts we
// cannot forge); the rows come out of social-kit's real aggregate(). The clock
// is pinned to the fixture's `now` — ReceiptSet ages receipts out otherwise.
import test from "node:test";
import assert from "node:assert/strict";
import { boot, flush, serialize, vectors } from "./harness.mjs";

const v = vectors("lb");
const { env, lib } = await boot();

test("bootLb replays every recorded state", async () => {
  // social-kit is compiled INTO the testlib now (it is a ClojureScript library
  // on this build's classpath, not an npm dist), so there is no module boundary
  // left for a resolve hook to intercept: the seam is the var itself, swapped
  // through home.testlib/set-fetch-weekly!. `kit` below is still the installed
  // package — the same aggregate() the browser runs, from the other side of the
  // sha pin, which is what makes the deep-equal an interop check.
  const kit = await import("ardegazu-social-kit");
  const section = env.document.getElementById("lb");
  const realNow = Date.now;
  Date.now = () => v.script.now;
  // the network seam: serve the recorded drop for the first game only
  lib.setFetchWeekly(async (g) => (g === v.script.games[0].g ? v.script.weekly : []));
  env.localStorage.clear();
  try {
    // the real aggregator must still fold the recorded receipts the same way
    assert.deepEqual(JSON.parse(JSON.stringify(kit.aggregate(v.script.weekly))), v.rows);

    const out = [];
    const snap = async (label) => { await flush(40); out.push({ label, html: serialize(section) }); };

    lib.providePubsub(null);
    await lib.bootLb(v.script.games);
    await snap(v.out[0].label);

    env.document.getElementById("view-boards").classList.add("on");
    env.window.dispatchEvent(new globalThis.CustomEvent("viewchange", { detail: { view: "boards" } }));
    await snap(v.out[1].label);

    const pickers = section.querySelectorAll(".soc-picker");
    pickers[1].children[1].dispatch("click");
    await snap(v.out[2].label);
    pickers[0].children[1].dispatch("click");
    await snap(v.out[3].label);
    section.querySelectorAll(".soc-picker")[0].children[0].dispatch("click");
    await snap(v.out[4].label);

    for (const [i, l] of [["ro", 5], ["hu", 6], ["en", 7]].map(([a, b]) => [b, a])) {
      lib.setLang(l);
      await snap(v.out[i].label);
    }
    lib.setLang("en");

    assert.deepEqual(out, v.out);
  } finally {
    Date.now = realNow;
    lib.setFetchWeekly(async () => []);
  }
});

static mirror of HEAD · about · clone: git clone https://git.ardegazu.ro/home.git