// Every layout New slide offers is a batch the ops module and the write // gate both accept, makes the template it names and the empty blocks it // lists, and lands where it was asked to. import test from 'node:test' import assert from 'node:assert/strict' import * as Y from 'yjs' import { applyOps, view } from './ops.mjs' import { checkDoc } from './check.mjs' import { LAYOUTS, LAYOUT_NAMES, layoutOps, layoutAfter } from './slide-layouts.mjs' let n = 0 const mint = () => 'blk' + String(++n).padStart(9, '0') test('each layout makes its template and its empty blocks, and passes the gate', () => { for (const name of LAYOUT_NAMES) { const doc = new Y.Doc() applyOps(doc, [{ op: 'set_meta', title: 'T', theme: 'paper' }]) applyOps(doc, layoutOps('slide' + name.replace(/-/g, '').slice(0, 7).padEnd(7, 'x'), name, undefined, mint)) const s = view(doc).slides[0] assert.equal(s.template, LAYOUTS[name].template, name) assert.deepEqual(s.blocks.map(b => b.type), LAYOUTS[name].blocks.map(b => b.type), name) for (const b of s.blocks) { for (const p of b.text ?? []) for (const r of p) assert.equal(r.t, '', `${name}: ${b.type} starts empty`) } assert.equal(checkDoc(doc), null, name) } }) test('a layout goes after the slide it is asked to follow', () => { const doc = new Y.Doc() applyOps(doc, [ { op: 'add_slide', id: 'first', layout: 'flow', template: 'title' }, { op: 'add_slide', id: 'last', layout: 'flow', template: 'title' } ]) applyOps(doc, layoutOps('middle', 'quote', 'first', mint)) assert.deepEqual(view(doc).slides.map(s => s.id), ['first', 'middle', 'last']) }) test('an unknown layout still makes a slide, and plain New slide follows the one before', () => { assert.equal(layoutOps('s', 'no-such-layout', undefined, mint)[0].template, 'title-body') assert.equal(layoutAfter('title'), 'title-text') assert.equal(layoutAfter('two-column'), 'two-column') assert.equal(layoutAfter('image-full'), 'picture') assert.equal(layoutAfter(undefined), 'title-text') })