// Rôle : teste les parseurs d'import texte utilisés par les outils toolbox. import { test } from "node:test"; import assert from "node:assert/strict"; import { parseColonImportLines } from "../website/src/features/toolboxes/modules/textImport.js"; import { getTimePatternRecurrenceMs, getTimePatternTargetMs } from "../website/src/features/toolboxes/modules/timerUtils.js"; import { compactModuleDataForStorage, createToolboxExportPayload, normalizeNotepadData, normalizeTaskPlannerData } from "../website/src/features/toolboxes/storage/toolboxStorage.js"; test("colon text import keeps urls intact after the first separator", () => { assert.deepEqual(parseColonImportLines("Build:https://example.com/build?class=rogue\nPotion:10"), [ { label: "Build", value: "https://example.com/build?class=rogue" }, { label: "Potion", value: "10" } ]); }); test("colon text import accepts labels without value", () => { assert.deepEqual(parseColonImportLines("Simple item"), [ { label: "Simple item", value: "" } ]); }); test("time pattern recurrence uses configured frequency instead of next remaining delay", () => { const now = new Date(2026, 0, 1, 13, 23, 45, 0).getTime(); const target = getTimePatternTargetMs("X:24:X", now); assert.equal(new Date(target).getHours(), 13); assert.equal(new Date(target).getMinutes(), 24); assert.equal(new Date(target).getSeconds(), 0); assert.equal(getTimePatternRecurrenceMs("X:24:X"), 60 * 60 * 1000); assert.equal(getTimePatternRecurrenceMs("X:X:30"), 60 * 1000); }); test("notepad data migrates text, sanitizes html and compacts drawings", () => { const migrated = normalizeNotepadData({ text: "Boss\nPhase 2" }); assert.equal(migrated.text, "Boss\nPhase 2"); assert.match(migrated.html, /
Boss<\/p>
Phase 2<\/p>/); const normalized = normalizeNotepadData({ html: '
Note
", text: "Note", drawingMode: "temporary", drawings: { strokes: normalized.drawings.strokes } }); assert.equal(compactTemporary.drawings, undefined); assert.equal(compactTemporary.drawingMode, undefined); const compactPermanent = compactModuleDataForStorage("notepad", { html: "Note
", text: "Note", updatedAt: "not a date", drawingMode: "permanent", drawings: normalized.drawings }); assert.equal(compactPermanent.updatedAt, undefined); assert.equal(compactPermanent.drawingMode, "permanent"); assert.equal(compactPermanent.drawings.strokes.length, 1); }); test("image annotation storage keeps drawing strokes as percent coordinates", () => { const compact = compactModuleDataForStorage("imageAnnotation", { image: "data:image/png;base64,aaa", markers: [{ id: "marker1", x: 120, y: 50, label: "Boss" }], drawings: { strokes: [ { id: "stroke1", color: "#22d3ee", width: 4, points: [{ x: 10.123, y: 20.456 }, { x: 140, y: -4 }] } ] } }); assert.equal(compact.markers[0].x, 100); assert.deepEqual(compact.drawings.strokes[0].points, [{ x: 10.12, y: 20.46 }, { x: 100, y: 0 }]); const exported = createToolboxExportPayload( { id: "toolbox1", name: "Map", modules: [{ id: "module1", type: "imageAnnotation" }], updatedAt: "2026-01-01T00:00:00.000Z" }, { "toolbox1:module1": compact } ); assert.equal(exported.modules.m1.markers[0].id, "k1"); assert.equal(exported.modules.m1.drawings.strokes[0].id, "d1"); }); test("task planner data normalizes invalid settings and relations", () => { const normalized = normalizeTaskPlannerData({ weeklyResetDay: 9, resetTime: "27:80", hideCompleted: true, categoryOrder: ["Raid", "Missing", "Farm", "Raid"], collapsedCategories: ["Raid", "", "Raid"], tasks: [ { id: "task1", title: "Daily", type: "daily", checked: true, checkedAt: 1000, category: "Farm" }, { id: "task2", title: "Weekly", type: "weekly", weeklyResetDay: 4, category: "Raid" }, { id: "task3", title: "Invalid type", type: "later", category: "Farm" } ], relations: [ { id: "link1", fromTaskId: "task1", toTaskId: "task2" }, { id: "dep1", fromTaskId: "task3", toTaskId: "task2", prerequisite: true }, { id: "bad", fromTaskId: "task1", toTaskId: "missing" }, { id: "self", fromTaskId: "task2", toTaskId: "task2" } ] }); assert.equal(normalized.weeklyResetDay, 1); assert.equal(normalized.resetTime, "00:00"); assert.equal(normalized.hideCompleted, true); assert.deepEqual(normalized.categoryOrder, ["Raid"]); assert.deepEqual(normalized.collapsedCategories, ["Raid"]); assert.equal(normalized.tasks[0].category, undefined); assert.equal(normalized.tasks[1].weeklyResetDay, 4); assert.equal(normalized.tasks[1].category, "Raid"); assert.equal(normalized.tasks[2].type, "unique"); assert.deepEqual(normalized.relations.map((relation) => relation.id), ["link1", "dep1"]); assert.equal(normalized.relations[0].prerequisite, false); assert.equal(normalized.relations[1].prerequisite, true); }); test("task planner storage compacts defaults and export remaps task relations", () => { const compact = compactModuleDataForStorage("taskPlanner", { weeklyResetDay: 1, resetTime: "00:00", hideCompleted: true, collapsedCategories: ["Raid"], tasks: [ { id: "task1", title: "Daily", description: "", type: "daily", checked: false }, { id: "task2", title: "Weekly", description: "Run", type: "weekly", checked: true, checkedAt: 2000, weeklyResetDay: 5, category: "Raid" } ], categoryOrder: ["Raid"], relations: [ { id: "dep1", fromTaskId: "task1", toTaskId: "task2", prerequisite: true } ] }); assert.equal(compact.weeklyResetDay, undefined); assert.equal(compact.resetTime, undefined); assert.equal(compact.hideCompleted, true); assert.deepEqual(compact.collapsedCategories, ["Raid"]); assert.deepEqual(compact.categoryOrder, ["Raid"]); assert.deepEqual(compact.tasks[0], { id: "task1", title: "Daily", type: "daily" }); assert.equal(compact.tasks[1].category, "Raid"); assert.equal(compact.tasks[1].weeklyResetDay, 5); const exported = createToolboxExportPayload( { id: "toolbox1", name: "Planner", modules: [{ id: "module1", type: "taskPlanner" }], updatedAt: "2026-01-01T00:00:00.000Z" }, { "toolbox1:module1": compact } ); const exportedPlanner = exported.modules.m1; assert.deepEqual(exportedPlanner.tasks.map((task) => task.id), ["a1", "a2"]); assert.equal(exportedPlanner.relations[0].fromTaskId, "a1"); assert.equal(exportedPlanner.relations[0].toTaskId, "a2"); assert.equal(exportedPlanner.relations[0].prerequisite, true); });