import assert from 'node:assert/strict' import { describe, it } from 'node:test' import { applyColumnWidthDelta, applyRowHeightDelta, clampColumnWidthsToMax, isInsideEdgeBand } from './tinymce-table-edge-resize.ts' describe('applyColumnWidthDelta', () => { it('takes width from the next column and keeps the table width', () => { const start = [100, 80, 60] const { widths, tableWidth } = applyColumnWidthDelta(start, 1, 20) assert.deepEqual(widths, [100, 100, 40]) assert.equal(tableWidth, 240) assert.deepEqual(start, [100, 80, 60]) }) it('does not shrink a column below 28px or grow the table from the last column', () => { const shrunk = applyColumnWidthDelta([100, 36, 46], 1, -100) assert.deepEqual(shrunk.widths, [100, 28, 54]) assert.equal(shrunk.tableWidth, 182) const last = applyColumnWidthDelta([100, 80, 60], 2, 40) assert.deepEqual(last.widths, [100, 80, 60]) assert.equal(last.tableWidth, 240) }) }) describe('clampColumnWidthsToMax', () => { it('scales columns down to the page content width', () => { const { widths, tableWidth } = clampColumnWidthsToMax([200, 200, 200], 300) assert.equal(tableWidth, 300) assert.equal(widths.reduce((sum, width) => sum + width, 0), 300) assert.ok(widths.every((width) => width >= 28)) }) }) describe('isInsideEdgeBand', () => { it('stays false until the pointer is inside the edge band', () => { assert.equal(isInsideEdgeBand(9, true, 8), false) assert.equal(isInsideEdgeBand(8, false, 8), false) assert.equal(isInsideEdgeBand(8, true, 8), true) }) }) describe('applyRowHeightDelta', () => { it('keeps row height at or above 20px', () => { assert.equal(applyRowHeightDelta(30, 10), 40) assert.equal(applyRowHeightDelta(30, -40), 20) }) })