jdkjskdj
Some checks failed
Build and Deploy Nuxt / build (push) Successful in 1m10s
Test / test (push) Failing after 2s

This commit is contained in:
2026-10-19 19:42:10 +02:00
parent 1c98af69b2
commit b83f64ff9e
14 changed files with 299 additions and 9 deletions

View File

@@ -40,8 +40,10 @@ function makeStubWorld({
const state = {
hooks: new Map(),
registered: new Map(),
menus: new Map(),
requests: [],
notifications: [],
copied: [],
};
const settingsStore = {
@@ -57,6 +59,10 @@ function makeStubWorld({
URL,
CONFIG: {},
window: { location: { origin: "http://vtt.test" } },
// The module registers a menu for its connection actions: the window needs
// ApplicationV2 to exist, not to render.
foundry: { applications: { api: { ApplicationV2: class { render() {} } } } },
navigator: { clipboard: { writeText: async (text) => state.copied.push(text) } },
ui: {
notifications: {
info: (text) => state.notifications.push(["info", text]),
@@ -110,6 +116,7 @@ function makeStubWorld({
state.registered.set(key, definition);
if (!(key in settingsStore)) settingsStore[key] = definition.default;
},
registerMenu(module, key, definition) { state.menus.set(key, definition); },
get(module, key) { return settingsStore[key]; },
async set(module, key, value) {
settingsStore[key] = value;
@@ -267,6 +274,43 @@ test("an expired link is replaced by one the GM can still open", async () => {
assert.match(world.status(), /link-code-2/, "and shows the new one");
});
test("the connection window copies the sign-up link", async () => {
const world = await makeStubWorld({
syncToken: "",
linkCode: "link-code-1",
linkUrl: SIGN_UP_LINK,
answers: { "link/pickup": { status: "ok", state: "pending" } },
}).start();
const menu = world.menus.get("pairingMenu");
assert.ok(menu, "the module settings open the connection window");
await menu.type.DEFAULT_OPTIONS.actions.copyLink.call(new menu.type());
assert.deepEqual(world.copied, [SIGN_UP_LINK], "the link waiting for its GM reaches the clipboard");
});
test("the connection window unlinks the campaign and asks for a fresh link", async () => {
const world = await makeStubWorld({
answers: {
"foundry/sync/status": { status: "ok", campaign: LINKED_CAMPAIGN, worldId: "world-1" },
"foundry/sync/unlink": { status: "ok" },
"link/start": { status: "ok", code: "link-code-2", linkUrl: SIGN_UP_LINK },
},
}).start();
assert.equal(world.status(), `Connected to the Dragonroll campaign "${LINKED_CAMPAIGN.name}".`);
const menu = world.menus.get("pairingMenu");
await menu.type.DEFAULT_OPTIONS.actions.unlink.call(new menu.type());
const unlink = world.requests.find((request) => request.href.includes("foundry/sync/unlink"));
assert.ok(unlink, "Dragonroll is told to forget this world");
assert.equal(unlink.body.worldId, "world-1");
assert.equal(unlink.authorization, "Bearer sync-token-1", "the world unlinks with the token it holds");
assert.equal(world.setting("syncToken"), "", "the token is dropped on this client too");
assert.equal(world.setting("linkCode"), "link-code-2", "a fresh link is kept ready to pair again");
assert.match(world.status(), /^Not connected yet/);
});
test("whatever is typed into the status is replaced by the real one", async () => {
const world = await makeStubWorld({
answers: { "foundry/sync/status": { status: "ok", campaign: LINKED_CAMPAIGN, worldId: "world-1" } },