Extract table module helpers
This commit is contained in:
parent
df0033739c
commit
d4fe3c796a
4 changed files with 353 additions and 299 deletions
|
|
@ -5,6 +5,7 @@ import assert from "node:assert/strict";
|
|||
import { SOCKET_SHAPES, formatValue, getSocketItemName, setItemCategory } from "../website/src/features/toolboxes/modules/equipmentPlannerOptions.js";
|
||||
import { applyDueResets, getTaskParentMap, getTaskTreeIds, moveTask } from "../website/src/features/toolboxes/modules/taskPlannerUtils.js";
|
||||
import { createInput, getInputLabel, normalizeCustomKey, parseHoldSeconds } from "../website/src/features/toolboxes/modules/combosUtils.js";
|
||||
import { getBoundsFromStartAndSize, getSelectionBounds, moveSelectionCells, parseTsvBlock, pasteCellBlock } from "../website/src/features/toolboxes/modules/tableUtils.js";
|
||||
|
||||
test("toolbox storage, cards and pages are wired", async () => {
|
||||
const source = await readFile("website/src/main.jsx", "utf8");
|
||||
|
|
@ -119,6 +120,8 @@ test("toolbox module registry and modules expose expected behavior", async () =>
|
|||
const combosUtils = await readFile("website/src/features/toolboxes/modules/combosUtils.js", "utf8");
|
||||
const calculatorModule = await readFile("website/src/features/toolboxes/modules/CalculatorModule.jsx", "utf8");
|
||||
const tableModule = await readFile("website/src/features/toolboxes/modules/TableModule.jsx", "utf8");
|
||||
const tableGridParts = await readFile("website/src/features/toolboxes/modules/TableGridParts.jsx", "utf8");
|
||||
const tableUtils = await readFile("website/src/features/toolboxes/modules/tableUtils.js", "utf8");
|
||||
const tableFormulaEngine = await readFile("website/src/features/toolboxes/modules/tableFormulaEngine.js", "utf8");
|
||||
const timerModule = await readFile("website/src/features/toolboxes/modules/TimerModule.jsx", "utf8");
|
||||
const taskPlannerModule = await readFile("website/src/features/toolboxes/modules/TaskPlannerModule.jsx", "utf8");
|
||||
|
|
@ -241,11 +244,11 @@ test("toolbox module registry and modules expose expected behavior", async () =>
|
|||
assert.match(tableModule, /draggingSelectionRef/);
|
||||
assert.match(tableModule, /movingSelectionRef/);
|
||||
assert.match(tableModule, /copiedSelectionRef/);
|
||||
assert.match(tableModule, /moveSelectionCells/);
|
||||
assert.match(tableModule, /pasteCellBlock/);
|
||||
assert.match(tableModule, /parseTsvBlock/);
|
||||
assert.match(tableModule, /is-move-target/);
|
||||
assert.match(tableModule, /isMultiCellSelection/);
|
||||
assert.match(tableUtils, /moveSelectionCells/);
|
||||
assert.match(tableUtils, /pasteCellBlock/);
|
||||
assert.match(tableUtils, /parseTsvBlock/);
|
||||
assert.match(tableGridParts, /is-move-target/);
|
||||
assert.match(tableUtils, /isMultiCellSelection/);
|
||||
assert.match(tableModule, /handleCellKeyDown/);
|
||||
assert.match(tableModule, /clearSelection/);
|
||||
assert.match(tableModule, /event\.key === "Delete"/);
|
||||
|
|
@ -253,10 +256,10 @@ test("toolbox module registry and modules expose expected behavior", async () =>
|
|||
assert.match(tableModule, /ArrowDown/);
|
||||
assert.match(tableModule, /ArrowLeft/);
|
||||
assert.match(tableModule, /ArrowRight/);
|
||||
assert.match(tableModule, /function HeaderLabelInput/);
|
||||
assert.match(tableModule, /useInlineEdit/);
|
||||
assert.match(tableGridParts, /export function HeaderLabelInput/);
|
||||
assert.match(tableGridParts, /useInlineEdit/);
|
||||
assert.match(tableModule, /TextExchangeActions/);
|
||||
assert.match(tableModule, /event\.target\.select/);
|
||||
assert.match(tableGridParts, /event\.target\.select/);
|
||||
assert.match(tableFormulaEngine, /export function evaluateTableCell/);
|
||||
assert.doesNotMatch(tableFormulaEngine, /Function\(/);
|
||||
assert.doesNotMatch(tableFormulaEngine, /\beval\(/);
|
||||
|
|
@ -424,3 +427,27 @@ test("combos helpers keep labels, hold parsing and custom keys stable", () => {
|
|||
assert.equal(parseHoldSeconds("abc"), 0);
|
||||
assert.equal(normalizeCustomKey(" Ctrl Alt Shift "), "Ctrl Alt Shift");
|
||||
});
|
||||
|
||||
test("table helpers keep selection, movement and TSV behavior stable", () => {
|
||||
const selection = {
|
||||
anchor: { rowIndex: 2, columnIndex: 3 },
|
||||
focus: { rowIndex: 1, columnIndex: 1 }
|
||||
};
|
||||
assert.deepEqual(getSelectionBounds(selection), {
|
||||
startRow: 1,
|
||||
endRow: 2,
|
||||
startColumn: 1,
|
||||
endColumn: 3
|
||||
});
|
||||
assert.deepEqual(parseTsvBlock("A\tB\nC\tD"), {
|
||||
height: 2,
|
||||
width: 2,
|
||||
values: [["A", "B"], ["C", "D"]]
|
||||
});
|
||||
|
||||
const moved = moveSelectionCells({ A1: "a", B1: "b", A2: "c" }, getBoundsFromStartAndSize(0, 0, 1, 2), getBoundsFromStartAndSize(1, 1, 1, 2));
|
||||
assert.deepEqual(moved, { A2: "c", B2: "a", C2: "b" });
|
||||
|
||||
const pasted = pasteCellBlock({}, parseTsvBlock("A\t\nC\tD"), 0, 0, 2, 2);
|
||||
assert.deepEqual(pasted.cells, { A1: "A", A2: "C", B2: "D" });
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue