Add quantitative tasks with checklist controls to the planner
This commit is contained in:
parent
29fcb50fcd
commit
c08452d5a4
22 changed files with 434 additions and 33 deletions
|
|
@ -912,6 +912,10 @@ export function validateSiteContent(site) {
|
|||
"toolboxes.modules.taskPlanner.descriptionPlaceholder",
|
||||
"toolboxes.modules.taskPlanner.descriptionLabel",
|
||||
"toolboxes.modules.taskPlanner.typeLabel",
|
||||
"toolboxes.modules.taskPlanner.quantityLabel",
|
||||
"toolboxes.modules.taskPlanner.currentQuantityLabel",
|
||||
"toolboxes.modules.taskPlanner.incrementLabel",
|
||||
"toolboxes.modules.taskPlanner.decrementLabel",
|
||||
"toolboxes.modules.taskPlanner.uniqueType",
|
||||
"toolboxes.modules.taskPlanner.dailyType",
|
||||
"toolboxes.modules.taskPlanner.weeklyType",
|
||||
|
|
|
|||
83
tests/task-planner-quantities.test.mjs
Normal file
83
tests/task-planner-quantities.test.mjs
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
// Rôle : vérifie les quantités du planificateur, leurs resets et leurs échanges.
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { normalizeTaskPlannerData, compactTaskPlannerDataForStorage } from "../website/src/features/toolboxes/storage/modules/taskPlanner.js";
|
||||
import { applyDueResets, updateTaskQuantity, updateTaskQuantityTarget } from "../website/src/features/toolboxes/modules/taskPlannerUtils.js";
|
||||
import { exportModuleText, importModuleText } from "../website/src/features/toolboxes/modules/textImport.js";
|
||||
|
||||
const simple = { id: "task", title: "Collecter", type: "daily", checked: false, checkedAt: 0 };
|
||||
const context = { normalizeTaskPlannerData, uid: (() => { let id = 0; return () => `id-${++id}`; })() };
|
||||
|
||||
test("quantities clamp at the target, preserve checklist negatives and derive completion", () => {
|
||||
const task = updateTaskQuantityTarget(simple, 5, 100);
|
||||
assert.equal(updateTaskQuantity(task, 99, 200).qtyCurrent, 5);
|
||||
assert.equal(updateTaskQuantity(task, -2, 200).qtyCurrent, -2);
|
||||
assert.equal(updateTaskQuantity(task, "invalid", 200).qtyCurrent, 0);
|
||||
const complete = updateTaskQuantity(task, 5, 200);
|
||||
assert.equal(complete.checked, true);
|
||||
assert.equal(complete.checkedAt, 200);
|
||||
const partial = updateTaskQuantity(complete, 3, 300);
|
||||
assert.equal(partial.checked, false);
|
||||
assert.equal(partial.checkedAt, 0);
|
||||
assert.equal(partial.progressAt, 300);
|
||||
assert.equal(updateTaskQuantityTarget(partial, 2, 400).qtyCurrent, 2);
|
||||
assert.equal(updateTaskQuantityTarget(partial, 2, 400).checked, true);
|
||||
assert.equal(updateTaskQuantityTarget(complete, 10, 400).checked, false);
|
||||
assert.deepEqual(updateTaskQuantityTarget(partial, 1, 400), { ...simple, checked: true, checkedAt: 400 });
|
||||
assert.equal(updateTaskQuantityTarget({ ...simple, checked: true }, 5, 400).qtyCurrent, 1);
|
||||
});
|
||||
|
||||
test("compaction preserves quantitative progress without redundant completion and leaves simple tasks unchanged", () => {
|
||||
const compact = compactTaskPlannerDataForStorage({ tasks: [
|
||||
simple,
|
||||
{ ...simple, id: "partial", qtyTarget: 5, qtyCurrent: 3, progressAt: 100 },
|
||||
{ ...simple, id: "complete", qtyTarget: 5, qtyCurrent: 99, progressAt: 200 },
|
||||
{ ...simple, id: "zero", qtyTarget: 5, qtyCurrent: 0, progressAt: 300 }
|
||||
] });
|
||||
assert.deepEqual(compact.tasks[0], { id: "task", title: "Collecter", type: "daily" });
|
||||
assert.deepEqual(compact.tasks[1], { id: "partial", title: "Collecter", type: "daily", qtyTarget: 5, qtyCurrent: 3, progressAt: 100 });
|
||||
assert.equal(compact.tasks[2].qtyCurrent, 5);
|
||||
assert.equal(compact.tasks[2].checked, undefined);
|
||||
assert.equal(compact.tasks[2].checkedAt, undefined);
|
||||
assert.equal(compact.tasks[3].qtyCurrent, undefined);
|
||||
assert.equal(compact.tasks[3].progressAt, undefined);
|
||||
const restored = normalizeTaskPlannerData(compact);
|
||||
assert.equal(restored.tasks[2].checked, true);
|
||||
assert.equal(restored.tasks[2].checkedAt, 200);
|
||||
assert.deepEqual(compactTaskPlannerDataForStorage(restored), compact);
|
||||
});
|
||||
|
||||
test("daily and weekly resets clear partial progress at their own boundary, including after an offline gap", () => {
|
||||
const before = new Date(2030, 0, 7, 5, 59).getTime();
|
||||
const due = new Date(2030, 0, 7, 6, 0).getTime();
|
||||
const data = normalizeTaskPlannerData({ lastResetAt: before, resetTime: "06:00", tasks: [
|
||||
{ ...simple, id: "daily", qtyTarget: 5, qtyCurrent: 2, progressAt: before },
|
||||
{ ...simple, id: "weekly", type: "weekly", qtyTarget: 5, qtyCurrent: -2, progressAt: before },
|
||||
{ ...simple, id: "unique", type: "unique", qtyTarget: 5, qtyCurrent: 2, progressAt: before },
|
||||
{ ...simple, id: "later", dailyResetTime: "08:00", qtyTarget: 5, qtyCurrent: 2, progressAt: before },
|
||||
{ ...simple, id: "next-week", type: "weekly", weeklyResetDay: 2, qtyTarget: 5, qtyCurrent: 2, progressAt: before },
|
||||
{ ...simple, id: "fresh", qtyTarget: 5, qtyCurrent: 2, progressAt: due + 1 }
|
||||
] });
|
||||
assert.equal(applyDueResets(data, before), data);
|
||||
const reset = applyDueResets(data, due + 1);
|
||||
assert.deepEqual(reset.tasks.map((task) => task.qtyCurrent), [0, 0, 2, 2, 2, 2]);
|
||||
assert.equal(reset.tasks[0].progressAt, 0);
|
||||
assert.equal(applyDueResets(reset, due + 1), reset);
|
||||
const offline = applyDueResets(normalizeTaskPlannerData(compactTaskPlannerDataForStorage(reset)), due + 8 * 86400000);
|
||||
assert.deepEqual(offline.tasks.map((task) => task.qtyCurrent), [0, 0, 2, 0, 0, 0]);
|
||||
});
|
||||
|
||||
test("text exchange preserves targets and relations but starts progress at zero and rejects invalid targets", () => {
|
||||
const data = normalizeTaskPlannerData({ tasks: [
|
||||
{ ...simple, qtyTarget: 5, qtyCurrent: 5, progressAt: 100 },
|
||||
{ ...simple, id: "child", qtyTarget: 3, qtyCurrent: 1, progressAt: 100 }
|
||||
], relations: [{ id: "relation", fromTaskId: "child", toTaskId: "task", prerequisite: true }] });
|
||||
const result = importModuleText("taskPlanner", exportModuleText("taskPlanner", data), context);
|
||||
assert.equal(result.ok, true);
|
||||
assert.deepEqual(result.data.tasks.map((task) => [task.qtyTarget, task.qtyCurrent, task.progressAt, task.checked]), [[5, 0, 0, false], [3, 0, 0, false]]);
|
||||
assert.equal(result.data.relations[0].toTaskId, result.data.tasks[0].id);
|
||||
assert.equal(result.data.relations[0].prerequisite, true);
|
||||
for (const value of ["0", "-1", "1.5", "oops", "Infinity"]) {
|
||||
assert.equal(importModuleText("taskPlanner", `- daily Collecter\n @qtyTarget: ${value}`, context).ok, false);
|
||||
}
|
||||
});
|
||||
|
|
@ -40,7 +40,7 @@ function sourceModuleData() {
|
|||
"source:rngSimulator": { rates: [{ id: "rate", label: "Rare", rate: "5" }] },
|
||||
"source:combos": { combos: [{ id: "combo", name: "Attaque", inputs: [[{ kind: "button", value: "cross" }]] }] },
|
||||
"source:planner": {
|
||||
tasks: [{ id: "parent", title: "Parent", type: "unique" }, { id: "child", title: "Enfant", type: "daily" }],
|
||||
tasks: [{ id: "parent", title: "Parent", type: "unique", qtyTarget: 5, qtyCurrent: 5, progressAt: 1000 }, { id: "child", title: "Enfant", type: "daily", qtyTarget: 3, qtyCurrent: 1, progressAt: 2000 }],
|
||||
relations: [{ id: "relation", fromTaskId: "child", toTaskId: "parent" }]
|
||||
},
|
||||
"source:calculator": {
|
||||
|
|
@ -104,6 +104,24 @@ test("a v2 individual export round-trips all registered tool types and five spac
|
|||
const memos = roundTrip.toolbox.modules.find((module) => module.type === "memos");
|
||||
const planner = roundTrip.toolbox.modules.find((module) => module.type === "taskPlanner");
|
||||
assert.equal(roundTrip.modules[memos.id].plannerLink, planner.id);
|
||||
assert.deepEqual(roundTrip.modules[planner.id], payload.modules[planner.id]);
|
||||
});
|
||||
|
||||
test("v2 rejects noncanonical planner quantities before importing any toolbox", async () => {
|
||||
for (const patch of [{ qtyTarget: 1 }, { qtyTarget: 2.5 }, { qtyCurrent: 99 }, { qtyCurrent: "2" }, { checked: true }, { progressAt: -1 }]) {
|
||||
const payload = validIndividualPayload();
|
||||
const planner = payload.toolbox.modules.find((module) => module.type === "taskPlanner");
|
||||
Object.assign(payload.modules[planner.id].tasks[0], patch);
|
||||
let writes = 0;
|
||||
const actions = useToolboxActions({
|
||||
store: { ready: true, persistToolboxSnapshot: async () => { writes += 1; return true; } },
|
||||
notify() {},
|
||||
setConfirmModal() {}
|
||||
});
|
||||
assert.throws(() => validateToolboxImportPayload(payload, "single"));
|
||||
await actions.importToolbox({ text: async () => JSON.stringify(payload) });
|
||||
assert.equal(writes, 0);
|
||||
}
|
||||
});
|
||||
|
||||
test("compact empty individual and global v2 exports remain valid", () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue