jkdsjkdsj
All checks were successful
Test / test (push) Successful in 2s
Build and Deploy Nuxt / build (push) Successful in 50s

This commit is contained in:
2026-10-16 17:53:15 +02:00
parent 3f2ac16394
commit 013c3512fe
3 changed files with 28 additions and 11 deletions

View File

@@ -255,7 +255,7 @@ function makeWorld({ markdown = true } = {}) {
const page = {
id: `page-${state.nextId++}`,
documentName: "JournalEntryPage",
title: data.title,
name: data.name,
text: { content: data.text?.content ?? "" },
flags: data.flags ?? {},
writes: 0,
@@ -285,6 +285,8 @@ function makeWorld({ markdown = true } = {}) {
async update(update) { return writeFoundryPaths(this, update); },
async createEmbeddedDocuments(documentName, docs) {
assert.equal(documentName, "JournalEntryPage", "the notes' pages are journal pages");
// Foundry's own page validation refuses a page without a name.
for (const doc of docs) assert.ok(doc.name, "a journal page needs a non-empty name");
const created = docs.map((doc) => makePage(this, doc));
pages.push(...created);
return created;
@@ -428,7 +430,7 @@ test("the campaign's notes become pages of one Dragonroll journal", async () =>
assert.equal(world.journals().length, 1, "one journal carries the campaign's notes");
const journal = world.journals()[0];
assert.equal(journal.name, "Dragonroll");
assert.deepEqual(journal.pages.contents.map((page) => [page.title.text, page.text.content]), [
assert.deepEqual(journal.pages.contents.map((page) => [page.name, page.text.content]), [
["Session 1", "<marked>**The start**</marked>"],
["Tavern Brawl", "<marked>A rope, a chandelier.</marked>"],
], "each note is a page, its markdown rendered by Foundry's own renderer");
@@ -440,6 +442,19 @@ test("the campaign's notes become pages of one Dragonroll journal", async () =>
], "and the campaign remembers each note's page");
});
test("reconciling again does not double the journal or its pages", async () => {
const world = await makeWorld().linkedSetup();
world.remoteNotes = [sessionNote(), tavernNote()];
await world.runIntervals();
await world.runIntervals();
await world.runIntervals();
assert.equal(world.journals().length, 1, "the journal is made once, not per reconcile");
assert.equal(world.journals()[0].pages.contents.length, 2, "and each note stands as the one page it was given");
assert.equal(world.mapNoteRequests().length, 2, "an already-mapped note is not mapped again");
});
test("an existing journal named Dragonroll is used, not doubled", async () => {
const world = await makeWorld().linkedSetup();
const gmsOwn = world.addJournal("Dragonroll");
@@ -448,7 +463,7 @@ test("an existing journal named Dragonroll is used, not doubled", async () => {
await world.runIntervals();
assert.equal(world.journals().length, 1, "the journal the world already had is the notes' one");
assert.deepEqual(gmsOwn.pages.contents.map((page) => page.title.text), ["Session 1"]);
assert.deepEqual(gmsOwn.pages.contents.map((page) => page.name), ["Session 1"]);
assert.equal(gmsOwn.getFlag(MODULE_ID, "notesJournal"), true, "and it is marked, so renaming it keeps the notes' home findable");
});
@@ -463,7 +478,7 @@ test("a note edited in Dragonroll rewrites its page", async () => {
const journal = world.journals()[0];
assert.equal(journal.pages.contents.length, 1, "the note still stands as the same single page");
assert.deepEqual(journal.pages.contents[0].title.text, "Session 1 — revisited");
assert.deepEqual(journal.pages.contents[0].name, "Session 1 — revisited");
assert.equal(journal.pages.contents[0].text.content, "<marked>**A different start**</marked>");
assert.equal(world.mapNoteRequests().length, 1, "the pairing the world reads back needs no remapping");
});
@@ -474,11 +489,11 @@ test("a note deleted in Dragonroll takes its page with it", async () => {
await world.runIntervals();
const journal = world.journals()[0];
const gmsPage = world.addPage(journal, { title: { text: "My own notes" }, text: { content: "not from Dragonroll" } });
const gmsPage = world.addPage(journal, { name: "My own notes", text: { content: "not from Dragonroll" } });
world.remoteNotes = world.remoteNotes.filter((note) => note._id !== "note-2");
await world.runIntervals();
assert.deepEqual(journal.pages.contents.map((page) => page.title.text), ["Session 1", "My own notes"],
assert.deepEqual(journal.pages.contents.map((page) => page.name), ["Session 1", "My own notes"],
"the deleted note's page goes; the GM's own page stays");
assert.ok(journal.pages.contents.includes(gmsPage));
});
@@ -497,13 +512,13 @@ test("pages already in step with the campaign are not rewritten", async () => {
test("the campaign's page mapping claims a page whose flag was lost", async () => {
const world = await makeWorld().linkedSetup();
const journal = world.addJournal("Dragonroll");
const orphan = world.addPage(journal, { title: { text: "Old name" }, text: { content: "old" } });
const orphan = world.addPage(journal, { name: "Old name", text: { content: "old" } });
world.remoteNotes = [{ _id: "note-1", title: "Session 1", content: "**The start**", foundryPageId: orphan.id }];
await world.runIntervals();
assert.equal(journal.pages.contents.length, 1, "no second page under the same title");
assert.equal(orphan.title.text, "Session 1");
assert.equal(orphan.name, "Session 1");
assert.equal(orphan.getFlag(MODULE_ID, "noteId"), "note-1", "and the page is marked again");
});