CoolFace
Apppublic

vonargo/mosAIc

sourceHugging Facemitupdated 2mo agoView on Hugging Face
1likes
drag.test.js27 linesDownload Raw Back to test
1// test/drag.test.js — reorder is pure; and the trust rationale is LOCKED: a reordered2// okf-carrying tile keeps its okf through the apply boundary only when trusted.3import { test } from 'node:test';4import assert from 'node:assert/strict';5import { reorder } from '../js/drag.js';6import { composePatch } from '../js/overlay.js';7 8test('reorder moves from→to, pure, no-op on bad/equal indices', () => {9  const l = ['a', 'b', 'c', 'd'];10  assert.deepEqual(reorder(l, 0, 2), ['b', 'c', 'a', 'd']);11  assert.deepEqual(reorder(l, 3, 0), ['d', 'a', 'b', 'c']);12  assert.deepEqual(l, ['a', 'b', 'c', 'd']);            // source untouched13  assert.deepEqual(reorder(l, 1, 1), l);14  assert.deepEqual(reorder(l, -1, 2), l);15  assert.deepEqual(reorder(l, 0, 9), l);16  assert.deepEqual(reorder(null, 0, 1), []);17});18 19test('a dragged okf tile keeps its provenance ONLY through a trusted apply (why drag dispatches trusted)', () => {20  const okfTile = { type: 'markdown', title: 'Concept', body: 'x', okf: { sourced: true } };21  const patch = { views: [{ id: 'v', title: 'V', tesserae: [okfTile] }] };22  const trusted = composePatch({}, structuredClone(patch), { trusted: true });23  const stripped = composePatch({}, structuredClone(patch), { trusted: false });24  assert.ok(trusted.views[0].tesserae[0].okf, 'trusted keeps okf');25  assert.equal(stripped.views[0].tesserae[0].okf, undefined, 'untrusted strips okf');26});27