Refactor calculator module helpers
All checks were successful
Deploy Sokko G / deploy (push) Successful in 15s
All checks were successful
Deploy Sokko G / deploy (push) Successful in 15s
This commit is contained in:
parent
e512eef232
commit
61176ba9b7
5 changed files with 211 additions and 170 deletions
|
|
@ -6,6 +6,7 @@ import { exportModuleText, importModuleText, parseColonImportLines } from "../we
|
|||
import { buildInsertedMixTagValue, normalizeMixTagSpacing, normalizeMixTagText, removeMixTagAtOffset, tokenizeMixTagValue } from "../website/src/utils/mixTagsInputUtils.js";
|
||||
import { getEffectiveGoalTreeProgressMode, getVisibleGoalTreeEdges } from "../website/src/features/toolboxes/modules/goalTreeDisplay.js";
|
||||
import { calculateGoalTreeFormula, evaluateGoalTreeNodes } from "../website/src/features/toolboxes/modules/goalTreeUtils.js";
|
||||
import { calculateExpression, createStoredFormula, evaluateCalculatorEntries, getEntriesInTreeOrder } from "../website/src/features/toolboxes/modules/calculatorUtils.js";
|
||||
import { createDefaultDraft, getDateSpanDays, getDraftSelection, normalizeDraftAlertOffsets, normalizeDraftMonthlyRepeatBy } from "../website/src/features/toolboxes/modules/calendarDraft.js";
|
||||
import { getMonthOccurrenceSegments, getWeekGridLayout, getWeekMinutePosition, layoutConcurrentOccurrences } from "../website/src/features/toolboxes/modules/calendarLayout.js";
|
||||
import { appendChecklistItems, moveChecklistItem, moveChecklistItemToCategory, renameChecklistSection } from "../website/src/features/toolboxes/modules/checklistUtils.js";
|
||||
|
|
@ -154,6 +155,21 @@ test("text exchange imports table TSV and calculator hierarchy", () => {
|
|||
assert.equal(calculatorImport.data.entries[1].formula, "base*5");
|
||||
});
|
||||
|
||||
test("calculator helpers evaluate formulas and preserve tree order", () => {
|
||||
const entries = evaluateCalculatorEntries([
|
||||
{ id: "root", label: "Root", value: 10, formula: "10" },
|
||||
{ id: "child", parentId: "root", label: "Child", value: 0, formula: "base*3" },
|
||||
{ id: "sibling", label: "Sibling", value: 2, formula: "1+1" }
|
||||
]);
|
||||
assert.equal(calculateExpression("2 + 3 * 4"), 14);
|
||||
assert.equal(calculateExpression("base / 2", 10), 5);
|
||||
assert.equal(calculateExpression("window.alert(1)"), null);
|
||||
assert.equal(createStoredFormula("+5", 10), "base+5");
|
||||
assert.equal(createStoredFormula("10*2", 10), "base*2");
|
||||
assert.deepEqual(entries.map((entry) => [entry.id, entry.value]), [["root", 10], ["child", 30], ["sibling", 2]]);
|
||||
assert.deepEqual(getEntriesInTreeOrder(entries).map((entry) => entry.id), ["root", "child", "sibling"]);
|
||||
});
|
||||
|
||||
test("calendar layout keeps week compaction and overlapping lanes deterministic", () => {
|
||||
const base = new Date(2026, 0, 5, 8, 0, 0, 0).getTime();
|
||||
const occurrences = [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue