oficina / slides Public

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

Plain git — no account needed to clone.

Download

Download this file

1// What the card shows (spec §4.1) follows this person's selection: a
2// box's options, the notes' marks, or the slide's and the deck's.
3import test from 'node:test'
4import assert from 'node:assert/strict'
5import { mountInspect } from './inspect.mjs'
6
7function mount () {
8 const root = { dataset: { inspect: 'slide' } }
9 const heard = []
10 const inspect = mountInspect({ root, onChange: kind => heard.push(kind) })
11 return { root, heard, inspect }
12}
13
14test('it starts on the slide, as the server rendered it', () => {
15 const { root, inspect, heard } = mount()
16 assert.equal(inspect.current(), 'slide')
17 assert.equal(root.dataset.inspect, 'slide')
18 assert.deepEqual(heard, [])
19})
20
21test('a box selected shows the box', () => {
22 const { root, inspect, heard } = mount()
23 inspect.selection(['a'])
24 assert.equal(inspect.current(), 'box')
25 assert.equal(root.dataset.inspect, 'box')
26 assert.deepEqual(heard, ['box'])
27})
28
29test('nothing selected shows the slide', () => {
30 const { inspect } = mount()
31 inspect.selection([])
32 assert.equal(inspect.current(), 'slide')
33})
34
35test('the selected box gone (deleted, or its creation undone) shows the slide, never an empty box', () => {
36 const { root, inspect, heard } = mount()
37 inspect.selection(['a'])
38 inspect.selection([])
39 assert.equal(inspect.current(), 'slide')
40 assert.equal(root.dataset.inspect, 'slide')
41 assert.deepEqual(heard, ['box', 'slide'])
42})
43
44test('the caret in the notes shows the notes', () => {
45 const { root, inspect } = mount()
46 inspect.caret('notes')
47 assert.equal(inspect.current(), 'notes')
48 assert.equal(root.dataset.inspect, 'notes')
49})
50
51test('with the caret in the notes, nothing selected stays on the notes; a box selected shows the box', () => {
52 const { inspect, heard } = mount()
53 inspect.caret('notes')
54 inspect.selection([])
55 assert.equal(inspect.current(), 'notes')
56 inspect.selection(['a'])
57 assert.equal(inspect.current(), 'box')
58 assert.deepEqual(heard, ['notes', 'box'])
59})
60
61test('the caret back on the stage leaves the kind to the selection', () => {
62 const { inspect } = mount()
63 inspect.caret('stage')
64 assert.equal(inspect.current(), 'slide', 'nothing selected')
65 inspect.selection(['a'])
66 inspect.caret('stage')
67 assert.equal(inspect.current(), 'box', 'a box selected')
68 inspect.caret('notes')
69 inspect.caret('stage')
70 assert.equal(inspect.current(), 'box', 'from the notes back to the selected box')
71 inspect.selection([])
72 inspect.caret('notes')
73 inspect.caret('stage')
74 assert.equal(inspect.current(), 'slide', 'from the notes back to nothing selected')
75})
76
77test('reset shows the slide, from anything', () => {
78 for (const before of [i => i.selection(['a']), i => i.caret('notes'), () => {}]) {
79 const { inspect } = mount()
80 before(inspect)
81 inspect.reset()
82 assert.equal(inspect.current(), 'slide')
83 inspect.caret('stage')
84 assert.equal(inspect.current(), 'slide', 'and nothing is selected after it')
85 }
86})
87
88test('onChange hears a change of kind only, never a repeat', () => {
89 const { inspect, heard } = mount()
90 inspect.selection(['a'])
91 inspect.selection(['a'])
92 inspect.selection(['b'])
93 inspect.caret('stage')
94 inspect.caret('notes')
95 inspect.caret('notes')
96 inspect.reset()
97 inspect.reset()
98 inspect.selection([])
99 assert.deepEqual(heard, ['box', 'notes', 'slide'])
100})
101
102test('a box, the notes, then the same box again shows the box', () => {
103 const { inspect } = mount()
104 inspect.selection(['a'])
105 inspect.caret('notes')
106 inspect.selection(['a'])
107 assert.equal(inspect.current(), 'box')
108})
109
110test('no slide left (a colleague removed the last one) shows the deck, from the notes or a box', () => {
111 for (const before of [i => i.caret('notes'), i => i.selection(['a']), () => {}]) {
112 const { root, inspect } = mount()
113 before(inspect)
114 inspect.slideShown('')
115 assert.equal(inspect.current(), 'slide', 'the slide kind, which with no slide is the deck alone')
116 assert.equal(root.dataset.inspect, 'slide')
117 inspect.caret('stage')
118 assert.equal(inspect.current(), 'slide', 'and nothing is selected after it')
119 }
120})
121
122test('a slide shown keeps the card as it was: the notes stay the notes', () => {
123 const { inspect } = mount()
124 inspect.caret('notes')
125 inspect.slideShown('s1')
126 assert.equal(inspect.current(), 'notes')
127})
128