Something went wrong. Try again.
small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230// Pure tree edits: preserve scrolling widths through persistent layout changes.import assert from 'node:assert/strict';import test from 'node:test';import { check, fc } from './property.mjs';import { close, column, leaf, makeRow, stack, widths, tree,} from './tiles-fixture.mjs';
const layouts = fc .record({ weights: fc .array(fc.integer({ min: 1, max: 30 }), { minLength: 2, maxLength: 7 }) .filter((values) => values.some((value) => value !== values[0])), moved: fc.nat(), away: fc.nat(), side: fc.constantFrom('left', 'right'), viewport: fc.integer({ min: 360, max: 2400 }), span: fc.option( fc.integer({ min: 40, max: 400 }).map((value) => value / 100), { nil: undefined }, ), whole: fc.boolean(), reorder: fc.boolean(), }) .map(({ weights, moved, away, ...rest }) => { const moving = moved % weights.length; return { ...rest, weights, moved: moving, target: (moving + 1 + (away % (weights.length - 1))) % weights.length, }; });
test('moving a direct column reorders its original pixel width', () => { check( fc.property( layouts, ({ weights, moved, target, side, viewport, span, whole, reorder }) => { const before = makeRow(weights, span, (at) => whole ? { ...column(at), name: `section-${at}` } : leaf(`pane-${at}`), ); const oldWidths = widths(before, viewport); const original = before.children[moved]; const originalKey = original.kind === 'leaf' ? original.window : original.id; const add = original.kind === 'leaf' && !reorder ? { ...original, id: `carried-${original.window}` } : original; const rest = original.kind === 'leaf' ? tree.remove(before, original.window) : tree.update(before, original.id, () => null); const targetTile = before.children[target]; const extent = reorder ? 'reorder' : { width: oldWidths.get(originalKey), viewport }; const next = tree.extendBeside( before, rest, targetTile.id, add, side, extent, ); const expected = before.children.filter((_, at) => at !== moved); const targetAt = expected.indexOf(targetTile); expected.splice(targetAt + (side === 'right' ? 1 : 0), 0, add);
assert.deepEqual(next.children, expected); assert.equal(next.span, before.span); const nextWidths = widths(next, viewport); for (const [id, width] of oldWidths) close(nextWidths.get(id), width); assert.ok(tree.valid(next)); }, ), );});
test('inserting a new column preserves existing pixel widths and adds one gutter', () => { check( fc.property( layouts, fc.integer({ min: 120, max: 1200 }), ({ weights, target, side, viewport, span }, addedWidth) => { const root = makeRow(weights, span, column); const oldWidths = widths(root, viewport); const add = leaf('added'); const next = tree.extendBeside( root, root, root.children[target].id, add, side, { width: addedWidth, viewport }, ); const nextWidths = widths(next, viewport);
close(nextWidths.get('added'), addedWidth); for (const [id, width] of oldWidths) close(nextWidths.get(id), width); close( next.span * viewport, (root.span ?? 1) * viewport + addedWidth + tree.GUTTER, ); assert.ok(tree.valid(next)); }, ), );});
test('tearing a nested tab out keeps its old pixel width', () => { check( fc.property( fc.record({ weights: fc.tuple( fc.integer({ min: 1, max: 20 }), fc.integer({ min: 1, max: 20 }), fc.integer({ min: 1, max: 20 }), ), viewport: fc.integer({ min: 480, max: 2400 }), span: fc.option( fc.integer({ min: 40, max: 350 }).map((value) => value / 100), { nil: undefined }, ), side: fc.constantFrom('left', 'right'), }), ({ weights, viewport, span, side }) => { const moving = leaf('moving'); const group = { id: 'tabs', kind: 'tabs', children: [moving, leaf('staying')], active: moving.id, }; const before = makeRow(weights, span, (at) => at === 0 ? group : column(at), ); const oldWidths = widths(before, viewport); const rest = tree.remove(before, moving.window); const next = tree.extendBeside( before, rest, before.children[1].id, moving, side, { width: oldWidths.get(group.id), viewport }, ); const nextWidths = widths(next, viewport);
close(nextWidths.get(moving.window), oldWidths.get(group.id)); for (const [id, width] of oldWidths) close(nextWidths.get(id === group.id ? 'staying' : id), width); assert.ok(tree.valid(next)); }, ), );});
test('a new row preserves a whole existing viewport', () => { check( fc.property( fc.integer({ min: 320, max: 2400 }), fc.integer({ min: 120, max: 1200 }), fc.constantFrom('left', 'right'), (viewport, addedWidth, side) => { const rest = column('rest'); const add = leaf('added'); const next = tree.extendBeside(rest, rest, rest.id, add, side, { width: addedWidth, viewport, }); const nextWidths = widths(next, viewport); close(nextWidths.get(rest.id), viewport); close(nextWidths.get(add.window), addedWidth); assert.ok(tree.valid(next)); }, ), );});
// A scrolling span is only meaningful on the board's root row.test('wrapping a scrolling row makes its span ordinary', () => { const root = makeRow([1, 2], 1.5, column); const wrapped = tree.normalize({ id: 'wrapper', kind: 'split', axis: 'column', children: [root, leaf('below')], sizes: [0.5, 0.5], }); assert.equal(wrapped.children[0].span, undefined); assert.ok(tree.valid(wrapped));});
test('closing a named column shrinks a narrow row without losing it before docking', () => { check( fc.property( fc.integer({ min: 30, max: 90 }), fc.boolean(), (percent, asTab) => { // A named branch that empties should shrink the row just like a leaf. const closing = stack('closing', [leaf('closing')], [400]); closing.name = 'close this section'; const root = makeRow([1, 2], percent / 100, (at) => at === 0 ? closing : leaf('remaining'), ); const rest = tree.remove(root, 'closing'); assert.equal(rest.id, root.id); close(rest.span, (root.span * 2) / 3); assert.strictEqual(tree.normalize(rest), rest); assert.ok(tree.valid(rest)); const added = leaf('docked'); const dock = asTab ? tree.addTab(rest, rest.id, added) : tree.splitBeside(rest, rest.id, added, 'top'); assert.equal(dock.span, rest.span); assert.ok(tree.valid(dock)); assert.deepEqual(tree.windows(dock).sort(), ['docked', 'remaining']); }, ), );});