// view.mjs over documents no op can produce — the twin of the tests in // core/src/view.rs. The server reads the view through typed structs, so // a malformed leaf passed through untyped fails the parse of the whole // deck; each fixed-shape leaf is rebuilt from the fields that have the // right type and omitted otherwise. Both sides must agree, because the // vectors compare them. import test from 'node:test' import assert from 'node:assert/strict' import * as Y from 'yjs' import { view } from './view.mjs' import { poisonDoc, poisonUpdates, shapes } from './poison.mjs' test('malformed fonts are null', () => { assert.equal(view(poisonDoc('fonts')).meta.fonts, null) }) test('a malformed background is the theme default', () => { assert.deepEqual(view(poisonDoc('background')).slides[0].background, { kind: 'theme', value: '' }) }) test('a malformed box is null', () => { assert.equal(view(poisonDoc('box')).slides[0].blocks[0].box, null) }) test('the phone layer keeps only its typed fields, order as a whole number', () => { const doc = new Y.Doc({ guid: 'phone' }) doc.clientID = 1 const slide = new Y.Map() doc.getArray('slides').push([slide]) const blocks = new Y.Array() slide.set('blocks', blocks) const block = new Y.Map() blocks.push([block]) const phone = new Y.Map() block.set('phone', phone) phone.set('hidden', 'yes') phone.set('order', 2.7) phone.set('size', 7) phone.set('box', { x: 0, y: 0, w: 1, h: 0.5 }) assert.deepEqual(view(doc).slides[0].blocks[0].phone, { order: 2, box: { x: 0, y: 0, w: 1, h: 0.5 } }) }) test('assets are typed or skipped', () => { assert.deepEqual(view(poisonDoc('assets')).assets, { poisonbadnm: { ref: 'poisonref', name: '', width: 0, height: 9, alt: '' } }) }) test('every poison update is deterministic bytes that apply to any deck', () => { const first = poisonUpdates() const second = poisonUpdates() for (const name of Object.keys(shapes)) { assert.deepEqual(Buffer.from(first[name]), Buffer.from(second[name]), name) const doc = new Y.Doc({ guid: 'anydeck' }) Y.applyUpdate(doc, first[name]) view(doc) // must not throw } })