import { test, expect } from 'vitest'; import { seriesProgress, stageOf } from './seriesProgress.js'; const chunk = (id, x = {}) => ({ id, startVerse: 1, endVerse: 2, ...x }); const project = (chunks, outline = []) => ({ title: 'Romans', outline, chapters: [{ book: 'Romans', bookAbbrev: 'ROM', chapter: '8', verses: [], chunks }] }); test('a session moves from not started to taught as things get written', () => { const p = project([chunk('a')]); expect(stageOf(p, chunk('a'))).toBe(0); expect(stageOf(p, chunk('a', { observation: 'Notes' }))).toBe(1); expect(stageOf(p, chunk('a', { observation: 'Notes', discussionQuestions: 'Why?' }))).toBe(2); expect(stageOf(p, chunk('a', { observation: 'Notes', groupNotes: 'They liked it' }))).toBe(3); expect(stageOf(p, chunk('a', { attendees: ' ' }))).toBe(0); }); test('an outline point linked to the session counts as ready to teach', () => { const p = project([chunk('a', { application: 'x' })], [{ id: 'o', text: 'Point', chunkId: 'a', children: [] }]); expect(stageOf(p, p.chapters[0].chunks[0])).toBe(2); }); test('the series summary counts stages, open follow-ups and comments, and names the next session to teach', () => { const p = project([ chunk('a', { groupNotes: 'Done', followUps: [{ id: 'f1', text: 'x', done: false }, { id: 'f2', text: 'y', done: true }] }), chunk('b', { observation: 'Started', comments: [{ id: 'c1', done: false }, { id: 'c2', done: true }] }), chunk('c'), ]); const s = seriesProgress(p); expect(s.counts).toEqual([1, 1, 0, 1]); expect(s.taught).toBe(1); expect(s.total).toBe(3); expect(s.rows[0].openFollowUps).toBe(1); expect(s.rows[1].openComments).toBe(1); expect(s.next.id).toBe('b'); }); test('a finished series has no next session', () => { expect(seriesProgress(project([chunk('a', { teachBack: 'x' })])).next).toBeNull(); });