oficina / slides Public

Clone
git clone https://amadan.net/oficina/slides

Plain git — no account needed to clone.

Download

Download this file

1// view.mjs over documents no op can produce — the twin of the tests in
2// core/src/view.rs. The server reads the view through typed structs, so
3// a malformed leaf passed through untyped fails the parse of the whole
4// deck; each fixed-shape leaf is rebuilt from the fields that have the
5// right type and omitted otherwise. Both sides must agree, because the
6// vectors compare them.
7import test from 'node:test'
8import assert from 'node:assert/strict'
9import * as Y from 'yjs'
10import { view } from './view.mjs'
11import { poisonDoc, poisonUpdates, shapes } from './poison.mjs'
12
13test('malformed fonts are null', () => {
14 assert.equal(view(poisonDoc('fonts')).meta.fonts, null)
15})
16
17test('a malformed background is the theme default', () => {
18 assert.deepEqual(view(poisonDoc('background')).slides[0].background, { kind: 'theme', value: '' })
19})
20
21test('a malformed box is null', () => {
22 assert.equal(view(poisonDoc('box')).slides[0].blocks[0].box, null)
23})
24
25test('the phone layer keeps only its typed fields, order as a whole number', () => {
26 const doc = new Y.Doc({ guid: 'phone' })
27 doc.clientID = 1
28 const slide = new Y.Map()
29 doc.getArray('slides').push([slide])
30 const blocks = new Y.Array()
31 slide.set('blocks', blocks)
32 const block = new Y.Map()
33 blocks.push([block])
34 const phone = new Y.Map()
35 block.set('phone', phone)
36 phone.set('hidden', 'yes')
37 phone.set('order', 2.7)
38 phone.set('size', 7)
39 phone.set('box', { x: 0, y: 0, w: 1, h: 0.5 })
40 assert.deepEqual(view(doc).slides[0].blocks[0].phone, { order: 2, box: { x: 0, y: 0, w: 1, h: 0.5 } })
41})
42
43test('assets are typed or skipped', () => {
44 assert.deepEqual(view(poisonDoc('assets')).assets, {
45 poisonbadnm: { ref: 'poisonref', name: '', width: 0, height: 9, alt: '' }
46 })
47})
48
49test('every poison update is deterministic bytes that apply to any deck', () => {
50 const first = poisonUpdates()
51 const second = poisonUpdates()
52 for (const name of Object.keys(shapes)) {
53 assert.deepEqual(Buffer.from(first[name]), Buffer.from(second[name]), name)
54 const doc = new Y.Doc({ guid: 'anydeck' })
55 Y.applyUpdate(doc, first[name])
56 view(doc) // must not throw
57 }
58})
59