import { test, expect } from 'vitest'; import { audienceState, audienceUrl, isAudienceWindow, publicStep } from './presentSync.js'; const step = { id: 'a', label: 'I.', depth: 0, text: 'Welcome', ref: 'Rom 1:16', note: 'SECRET speaker note', minutes: 7, plannedEnd: 7, kind: 'quote', scripture: { text: 'For I am not ashamed', ref: 'Romans 1:16', translation: 'BSB' }, attachments: [{ id: 'x', type: 'word', label: 'pistis', detail: 'PRIVATE detail' }] }; test('what the audience gets of a point never includes the private note, minutes or details', () => { const pub = publicStep(step); expect(pub).toEqual({ label: 'I.', kind: 'quote', text: 'Welcome', ref: 'Rom 1:16', scripture: { text: 'For I am not ashamed', ref: 'Romans 1:16' }, attachments: [{ type: 'word', label: 'pistis' }] }); const message = JSON.stringify(audienceState({ title: 'Romans', mode: 'outline', step, index: 0, total: 3 })); expect(message).not.toMatch(/SECRET|PRIVATE|minutes|plannedEnd/); expect(message).toContain('Welcome'); }); test('in script mode the audience gets the title only, and blank blacks the screen out', () => { const state = audienceState({ title: 'Romans 8', subtitle: 'Session 1', mode: 'script', step, blank: true }); expect(state.step).toBeNull(); expect(state.blank).toBe(true); expect(JSON.stringify(state)).not.toMatch(/SECRET|Welcome/); expect(publicStep(null)).toBeNull(); }); test('the audience window is recognised by its address', () => { expect(audienceUrl({ origin: 'https://study.test', pathname: '/' })).toBe('https://study.test/?audience=1'); expect(isAudienceWindow('?audience=1')).toBe(true); expect(isAudienceWindow('?share=abc')).toBe(false); expect(isAudienceWindow('')).toBe(false); });