47 lines
1.9 KiB
TypeScript
47 lines
1.9 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { uuidToWiki, wikiToUuid, wikiToName } from "../src/links.js";
|
|
import { JournalDb } from "../src/db.js";
|
|
import { ensureJournalFixture } from "./helpers.js";
|
|
|
|
describe("link resolution", () => {
|
|
let db: JournalDb;
|
|
const setup = async () => { if (!db) { db = await JournalDb.open(ensureJournalFixture()); } };
|
|
it("resolves @UUID -> [[Name|Display]] when display differs", async () => {
|
|
await setup();
|
|
// Foundry had @UUID[JournalEntry.8ByDE0fih9WaKgcX]{Aldric}; name is Aldric Raventhorne.
|
|
const out = uuidToWiki("Where @UUID[JournalEntry.8ByDE0fih9WaKgcX]{Aldric} is graceful", db);
|
|
expect(out).toBe("Where [[Aldric Raventhorne|Aldric]] is graceful");
|
|
});
|
|
|
|
it("resolves @UUID -> [[Name]] when display equals name", async () => {
|
|
await setup();
|
|
const out = uuidToWiki("@UUID[JournalEntry.ssuVELIoFKniPZLn]{House Raventhorne}", db);
|
|
expect(out).toBe("[[House Raventhorne]]");
|
|
});
|
|
|
|
it("falls back to display text for an unmatched UUID", async () => {
|
|
await setup();
|
|
const out = uuidToWiki("@UUID[JournalEntry.unknownID]{Mystery}", db);
|
|
expect(out).toBe("Mystery");
|
|
});
|
|
|
|
it("round-trips [[Name|Display]] -> @UUID -> [[Name|Display]]", async () => {
|
|
await setup();
|
|
const wiki = "[[Aldric Raventhorne|Aldric]]";
|
|
const uuid = wikiToUuid(wiki, db);
|
|
expect(uuid).toBe("@UUID[JournalEntry.8ByDE0fih9WaKgcX]{Aldric}");
|
|
expect(uuidToWiki(uuid, db)).toBe(wiki);
|
|
});
|
|
|
|
it("leaves unmatched wiki links intact when converting to @UUID", async () => {
|
|
await setup();
|
|
const out = wikiToUuid("[[Nobody Knows This]]", db);
|
|
expect(out).toBe("[[Nobody Knows This]]");
|
|
});
|
|
|
|
it("wikiToName collapses display aliases", () => {
|
|
expect(wikiToName("[[Aldric Raventhorne|Aldric]] and [[House Raventhorne]]")).toBe(
|
|
"[[Aldric Raventhorne]] and [[House Raventhorne]]",
|
|
);
|
|
});
|
|
}); |