add new table tool
All checks were successful
Deploy Sokko G / deploy (push) Successful in 6s

This commit is contained in:
Shinuwa 2026-07-30 11:32:33 +02:00
parent 896ae23ff2
commit 025cd4bf22
19 changed files with 1336 additions and 1 deletions

View file

@ -1,9 +1,10 @@
// 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 { evaluateTableCell } from "../website/src/features/toolboxes/modules/tableFormulaEngine.js";
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";
import { compactModuleDataForStorage, createToolboxExportPayload, normalizeNotepadData, normalizeTableData, 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"), [
@ -28,6 +29,72 @@ test("time pattern recurrence uses configured frequency instead of next remainin
assert.equal(getTimePatternRecurrenceMs("X:X:30"), 60 * 1000);
});
test("table formulas evaluate arithmetic, parentheses and cell references", () => {
const cells = {
A1: "100",
A2: "20",
B1: "=A1+A2*2",
B2: "=(A1+A2)/2",
C1: "=B1-B2/3"
};
const dimensions = { rows: 10, columns: 6 };
assert.equal(evaluateTableCell("B1", cells, dimensions).display, "140");
assert.equal(evaluateTableCell("B2", cells, dimensions).display, "60");
assert.equal(evaluateTableCell("C1", cells, dimensions).display, "120");
});
test("table formulas report invalid references, division by zero and circular references", () => {
const dimensions = { rows: 10, columns: 6 };
assert.equal(evaluateTableCell("A1", { A1: "=Z99+1" }, dimensions).error, "reference");
assert.equal(evaluateTableCell("A1", { A1: "=10/0" }, dimensions).error, "division");
assert.equal(evaluateTableCell("A1", { A1: "=B1", B1: "=A1" }, dimensions).error, "cycle");
assert.deepEqual(evaluateTableCell("A1", { A1: "texte", B1: "=A1+1" }, dimensions), { value: null, display: "texte", error: "" });
assert.equal(evaluateTableCell("B1", { A1: "texte", B1: "=A1+1" }, dimensions).error, "reference");
});
test("table storage clamps dimensions and compacts non-empty cells", () => {
const normalized = normalizeTableData({
rows: 200,
columns: 40,
cells: {
A1: "Boss",
T50: "=A1+1",
U51: "Ignored",
B1: " "
},
rowLabels: {
0: "Boss final ",
1: "2",
50: "Ignored"
},
columnLabels: {
0: "Item final ",
1: "B",
20: "Ignored"
}
});
assert.equal(normalized.rows, 50);
assert.equal(normalized.columns, 20);
assert.deepEqual(normalized.cells, { A1: "Boss", T50: "=A1+1" });
assert.deepEqual(normalized.rowLabels, { 0: "Boss final " });
assert.deepEqual(normalized.columnLabels, { 0: "Item final " });
const compact = compactModuleDataForStorage("table", normalized);
assert.equal(compact.rows, 50);
assert.equal(compact.columns, 20);
assert.deepEqual(compact.cells, { A1: "Boss", T50: "=A1+1" });
assert.deepEqual(compact.rowLabels, { 0: "Boss final " });
assert.deepEqual(compact.columnLabels, { 0: "Item final " });
assert.deepEqual(compactModuleDataForStorage("table", { rows: 10, columns: 6, cells: {}, columnLabels: { 0: "Item " } }), {
cells: {},
columnLabels: { 0: "Item " }
});
assert.equal(compactModuleDataForStorage("table", { rows: 10, columns: 6, cells: {} }), null);
});
test("notepad data migrates text, sanitizes html and compacts drawings", () => {
const migrated = normalizeNotepadData({ text: "Boss\nPhase 2" });
assert.equal(migrated.text, "Boss\nPhase 2");