oficina / slides Public

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

Plain git — no account needed to clone.

Download

Download this file

1// moves.test.mjs — the browser's moves against the server's, through the
2// shared vectors (vectors/moves.json, which
3// internal/slides/deck/talk_test.go reads too). Two ops there are not
4// moves: "start" is start(view) and "settle" is settle(view, from), or
5// settleNear(view, from, near) when the case has a near.
6import { test } from 'node:test'
7import assert from 'node:assert/strict'
8import { readFileSync } from 'node:fs'
9import { talkOrder, start, advance, settle, settleNear } from './moves.mjs'
10
11const vectors = JSON.parse(readFileSync(new URL('./vectors/moves.json', import.meta.url)))
12
13test('moves vectors', async t => {
14 assert.ok(vectors.length >= 20)
15 for (const c of vectors) {
16 await t.test(c.name, () => {
17 let got
18 if (c.move.op === 'start') got = start(c.deck)
19 else if (c.move.op !== 'settle') got = advance(c.deck, c.from, c.move)
20 else got = 'near' in c ? settleNear(c.deck, c.from, c.near) : settle(c.deck, c.from)
21 assert.deepEqual(got, c.to)
22 })
23 }
24})
25
26test('talkOrder leaves out parked slides, and full-only ones in core', () => {
27 const view = { slides: [{ id: 'a' }, { id: 'b', talk: 'full' }, { id: 'c', talk: 'parked' }, { id: 'd' }] }
28 assert.deepEqual(talkOrder(view, 'core'), [0, 3])
29 assert.deepEqual(talkOrder(view, 'full'), [0, 1, 3])
30})
31