Let a guide checklist update from its page filters without losing checks, and optionally limit the page to what the checklist contains
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
17e5cd5e63
commit
07a43ef848
17 changed files with 486 additions and 36 deletions
|
|
@ -1,10 +1,11 @@
|
|||
/**
|
||||
* @file Vérifie les correspondances des guides et la validité des associations persistantes.
|
||||
* @file Vérifie les correspondances des guides, la mise à jour d'une checklist depuis la page
|
||||
* et la validité des associations persistantes.
|
||||
*/
|
||||
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { aniimoChecklistEntries, matchGuideChecklist, normalizeGuideLabel, toggleGuideChecklistRows, validGuideAssociations } from "../website/src/features/games/guideChecklist.js";
|
||||
import { aniimoChecklistEntries, matchGuideChecklist, mergeGuideChecklistResults, normalizeGuideLabel, toGuideChecklistResults, toggleGuideChecklistRows, validGuideAssociations } from "../website/src/features/games/guideChecklist.js";
|
||||
|
||||
const variants = [{ key: "1:base", name: "emberpup", form: "base" }, { key: "1:mountain", name: "emberpup", form: "mountain" }];
|
||||
const entries = aniimoChecklistEntries(variants, { emberpup: "Loufeuteau", base: "Forme de base", mountain: "Montagnes" }, { emberpup: "Emberpup", base: "Basic form", mountain: "Mountain form" });
|
||||
|
|
@ -65,8 +66,60 @@ test("persistent associations require the current linked toolbox and an existing
|
|||
const toolbox = { id: "tb", modules: [{ id: "capture", type: "checklist" }, { id: "notes", type: "notepad" }] };
|
||||
const association = { toolboxId: "tb", moduleId: "capture", hideCompleted: true };
|
||||
const state = { "aniimo/aniimos": association, "mhwilds/monsters": { ...association, moduleId: "notes" }, unknown: association };
|
||||
assert.deepEqual(validGuideAssociations(state, [toolbox], { aniimo: "tb", mhwilds: "tb" }), { "aniimo/aniimos": association });
|
||||
assert.deepEqual(validGuideAssociations(state, [toolbox], { aniimo: "tb", mhwilds: "tb" }), { "aniimo/aniimos": { ...association, onlyListed: false } });
|
||||
assert.equal(validGuideAssociations({ "aniimo/aniimos": { ...association, onlyListed: true } }, [toolbox], { aniimo: "tb" })["aniimo/aniimos"].onlyListed, true);
|
||||
assert.deepEqual(validGuideAssociations(state, [toolbox], { aniimo: "other" }), {});
|
||||
assert.deepEqual(validGuideAssociations(state, [], { aniimo: "tb" }), {});
|
||||
assert.deepEqual(validGuideAssociations({ "aniimo/aniimos": null }, [toolbox], { aniimo: "tb" }), {});
|
||||
});
|
||||
|
||||
const sequence = () => {
|
||||
let next = 0;
|
||||
return (prefix) => `${prefix}-${++next}`;
|
||||
};
|
||||
const result = (label, ...aliases) => ({ key: label, label, labels: [label, ...aliases] });
|
||||
|
||||
test("page results keep progress of known rows and insert new ones in page order", () => {
|
||||
const data = { hideCompletedItems: true, items: [{ id: "flat" }], sections: [{ id: "s1", title: "", items: [
|
||||
{ id: "a", label: "Arkveld", qtyTarget: 2, qtyCurrent: 2 },
|
||||
{ id: "c", label: "Chatacabra", qtyCurrent: 0 },
|
||||
{ id: "z", label: "Note perso", qtyCurrent: 1 }
|
||||
] }] };
|
||||
const { data: merged, summary } = mergeGuideChecklistResults(data, [result("Ajarakan"), result("ARKVELD"), result("Balahara"), result("Chatacabra")], { uid: sequence() });
|
||||
assert.deepEqual(merged.sections[0].items.map((item) => item.label), ["Ajarakan", "Arkveld", "Balahara", "Chatacabra", "Note perso"]);
|
||||
assert.deepEqual(merged.sections[0].items.slice(0, 2), [{ id: "item-1", label: "Ajarakan", qtyTarget: 1, qtyCurrent: 0 }, data.sections[0].items[0]]);
|
||||
assert.equal(merged.hideCompletedItems, true);
|
||||
assert.equal("items" in merged, false);
|
||||
assert.deepEqual(summary, { added: 2, kept: 2, completed: 1, missing: 1, missingCompleted: 1, removed: 0 });
|
||||
assert.equal(data.sections[0].items.length, 3);
|
||||
});
|
||||
|
||||
test("missing rows are removed only on request and empty sections disappear", () => {
|
||||
const data = { sections: [
|
||||
{ id: "s1", title: "Monstres", items: [{ id: "a", label: "Arkveld", qtyCurrent: 1 }] },
|
||||
{ id: "s2", title: "Vieux", items: [{ id: "o", label: "Obsolète", qtyCurrent: 1 }] }
|
||||
] };
|
||||
const { data: merged, summary } = mergeGuideChecklistResults(data, [result("Arkveld"), result("Balahara")], { removeMissing: true, uid: sequence() });
|
||||
assert.deepEqual(merged.sections.map((section) => [section.title, section.items.map((item) => item.label)]), [["Monstres", ["Arkveld", "Balahara"]]]);
|
||||
assert.equal(summary.removed, 1);
|
||||
});
|
||||
|
||||
test("translated aliases match, duplicate results add one row, empty checklists get a section", () => {
|
||||
const aliases = mergeGuideChecklistResults({ sections: [{ id: "s", items: [{ id: "e", label: "Emberpup", qtyCurrent: 1 }] }] }, [result("Loufeuteau", "Emberpup")], { uid: sequence() });
|
||||
assert.deepEqual(aliases.summary, { added: 0, kept: 1, completed: 1, missing: 0, missingCompleted: 0, removed: 0 });
|
||||
const empty = mergeGuideChecklistResults(undefined, [result("Arkveld"), result("Arkveld")], { uid: sequence() });
|
||||
assert.deepEqual(empty.data.sections, [{ id: "section-2", title: "", items: [{ id: "item-1", label: "Arkveld", qtyTarget: 1, qtyCurrent: 0 }] }]);
|
||||
assert.equal(empty.summary.added, 1);
|
||||
});
|
||||
|
||||
test("Aniimo results follow the page grouping with French and English labels", () => {
|
||||
const aniimo = { translations: { emberpup: "loufeuteau", base: "forme de base", mountain: "montagnes" }, englishTranslations: { emberpup: "Emberpup", base: "Basic form" } };
|
||||
const items = variants.map((variant) => ({ ...variant, aniimoUid: "1" }));
|
||||
assert.deepEqual(toGuideChecklistResults("aniimo/aniimos", items, { aniimo, filters: { aniimo: { grouped: true } } }), [
|
||||
{ key: "1", label: "Loufeuteau", labels: ["Loufeuteau", "Emberpup"] }
|
||||
]);
|
||||
assert.deepEqual(toGuideChecklistResults("aniimo/aniimos", items, { aniimo, filters: { aniimo: { grouped: false } } }).map((entry) => entry.labels), [
|
||||
["Loufeuteau — Forme de base", "Emberpup — Basic form"],
|
||||
["Loufeuteau — Montagnes"]
|
||||
]);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue