import { test } from "node:test"; import assert from "node:assert/strict"; import { createSourcesOf } from "./createSources"; import type { SourceOption } from "../research/types"; const SOURCES: SourceOption[] = [ { handle: "local:/x/export/public", kind: "local", label: "Local corpus" }, { handle: "remote:https://stub.test", kind: "remote", label: "Stubalyzer", detail: "connected ยท stub.test" }, { handle: "hub:https://hub.test", kind: "hub", label: "Hub" }, ]; const ch = (slug: string, kind = "video") => ({ slug, name: slug, kind, platform: null, sites: [] }); test("Create offers the editor's corpus and each published archive, hubs aside", () => { const r = createSourcesOf(SOURCES, [ch("alpha")]); assert.deepEqual(r.sources.map((s) => s.handle), ["", "remote:https://stub.test"]); assert.equal(r.preselect, ""); }); test("with no local corpus the first archive is preselected; a remote-only channel is not a corpus", () => { assert.equal(createSourcesOf(SOURCES, []).preselect, "remote:https://stub.test"); assert.equal(createSourcesOf(SOURCES, [ch("stub-alpha", "remote-only")]).preselect, "remote:https://stub.test"); // The editor did not answer: nothing is assumed. assert.equal(createSourcesOf(SOURCES, null).preselect, ""); // No archive to offer: the local corpus, empty or not. assert.equal(createSourcesOf(SOURCES.slice(0, 1), []).preselect, ""); });