iterate.com / dash

git clone https://git.iterate.com/repos/dash

dash / tests / page.test.mjsmain at da05cae

// tests/page.test.mjs — what the Dash's page does before its modules have loaded (../index.html,
// ../public/app.js), read from the files' text.
// Run from the repo's root: node --test "tests/*.test.mjs"
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { test } from "node:test";

const page = readFileSync(new URL("../index.html", import.meta.url), "utf8");
const script = readFileSync(new URL("../public/app.js", import.meta.url), "utf8");

test("the page asks for its session in its head, while its modules load, and app.js takes that answer", () => {
  const asked = page.indexOf('window.__session = fetch("/.auth/session.json")');
  assert.ok(asked > 0);
  // before the first stylesheet, which a script after it waits for, and before the app's module
  assert.ok(asked < page.indexOf('rel="stylesheet"'));
  assert.ok(script.includes("window.__session"));
});

test("the Dash asks the zone's website for the profile, and draws with the zone until it answers", () => {
  assert.ok(script.includes("fetch(`https://${zone}/.well-known/iterate-profile`)"));
  assert.ok(script.includes("name: name || zone"));
});

test("the sidebar shows Repos and Contexts as rows of their own", () => {
  for (const id of ["repos", "contexts"]) {
    const block = new RegExp(`id:\\s*"${id}"[\\s\\S]*?component:`).exec(script)?.[0];
    assert.ok(block, `the page "${id}"`);
    assert.doesNotMatch(block, /\brow\s*:\s*false\b/);
  }
});