// What the card shows (spec ยง4.1) follows this person's selection: a // box's options, the notes' marks, or the slide's and the deck's. import test from 'node:test' import assert from 'node:assert/strict' import { mountInspect } from './inspect.mjs' function mount () { const root = { dataset: { inspect: 'slide' } } const heard = [] const inspect = mountInspect({ root, onChange: kind => heard.push(kind) }) return { root, heard, inspect } } test('it starts on the slide, as the server rendered it', () => { const { root, inspect, heard } = mount() assert.equal(inspect.current(), 'slide') assert.equal(root.dataset.inspect, 'slide') assert.deepEqual(heard, []) }) test('a box selected shows the box', () => { const { root, inspect, heard } = mount() inspect.selection(['a']) assert.equal(inspect.current(), 'box') assert.equal(root.dataset.inspect, 'box') assert.deepEqual(heard, ['box']) }) test('nothing selected shows the slide', () => { const { inspect } = mount() inspect.selection([]) assert.equal(inspect.current(), 'slide') }) test('the selected box gone (deleted, or its creation undone) shows the slide, never an empty box', () => { const { root, inspect, heard } = mount() inspect.selection(['a']) inspect.selection([]) assert.equal(inspect.current(), 'slide') assert.equal(root.dataset.inspect, 'slide') assert.deepEqual(heard, ['box', 'slide']) }) test('the caret in the notes shows the notes', () => { const { root, inspect } = mount() inspect.caret('notes') assert.equal(inspect.current(), 'notes') assert.equal(root.dataset.inspect, 'notes') }) test('with the caret in the notes, nothing selected stays on the notes; a box selected shows the box', () => { const { inspect, heard } = mount() inspect.caret('notes') inspect.selection([]) assert.equal(inspect.current(), 'notes') inspect.selection(['a']) assert.equal(inspect.current(), 'box') assert.deepEqual(heard, ['notes', 'box']) }) test('the caret back on the stage leaves the kind to the selection', () => { const { inspect } = mount() inspect.caret('stage') assert.equal(inspect.current(), 'slide', 'nothing selected') inspect.selection(['a']) inspect.caret('stage') assert.equal(inspect.current(), 'box', 'a box selected') inspect.caret('notes') inspect.caret('stage') assert.equal(inspect.current(), 'box', 'from the notes back to the selected box') inspect.selection([]) inspect.caret('notes') inspect.caret('stage') assert.equal(inspect.current(), 'slide', 'from the notes back to nothing selected') }) test('reset shows the slide, from anything', () => { for (const before of [i => i.selection(['a']), i => i.caret('notes'), () => {}]) { const { inspect } = mount() before(inspect) inspect.reset() assert.equal(inspect.current(), 'slide') inspect.caret('stage') assert.equal(inspect.current(), 'slide', 'and nothing is selected after it') } }) test('onChange hears a change of kind only, never a repeat', () => { const { inspect, heard } = mount() inspect.selection(['a']) inspect.selection(['a']) inspect.selection(['b']) inspect.caret('stage') inspect.caret('notes') inspect.caret('notes') inspect.reset() inspect.reset() inspect.selection([]) assert.deepEqual(heard, ['box', 'notes', 'slide']) }) test('a box, the notes, then the same box again shows the box', () => { const { inspect } = mount() inspect.selection(['a']) inspect.caret('notes') inspect.selection(['a']) assert.equal(inspect.current(), 'box') }) test('no slide left (a colleague removed the last one) shows the deck, from the notes or a box', () => { for (const before of [i => i.caret('notes'), i => i.selection(['a']), () => {}]) { const { root, inspect } = mount() before(inspect) inspect.slideShown('') assert.equal(inspect.current(), 'slide', 'the slide kind, which with no slide is the deck alone') assert.equal(root.dataset.inspect, 'slide') inspect.caret('stage') assert.equal(inspect.current(), 'slide', 'and nothing is selected after it') } }) test('a slide shown keeps the card as it was: the notes stay the notes', () => { const { inspect } = mount() inspect.caret('notes') inspect.slideShown('s1') assert.equal(inspect.current(), 'notes') })