import { expect, test } from 'vitest'; import { searchMarks, searchNotes, searchProjects } from './personalSearch.js'; const project = { id: 'p1', title: 'Romans study', chapters: [{ book: 'Romans', bookAbbrev: 'ROM', chapter: '8', verses: [{ number: 1, text: 'a' }, { number: 2, text: 'b' }], chunks: [ { id: 'c1', startVerse: 1, endVerse: 2, observation: 'No condemnation for those in Christ.', interpretation: '', application: '', generalNotes: '', finalScript: '' }, { id: 'c2', startVerse: 2, endVerse: 2, observation: '', interpretation: 'The Spirit of life sets us free', application: '', generalNotes: '', finalScript: '' }, ], }], }; test('finds notes, one hit per chunk, saying which field matched', () => { const hits = searchNotes([project], 'spirit'); expect(hits).toHaveLength(1); expect(hits[0]).toMatchObject({ projectId: 'p1', chunkId: 'c2', field: 'Interpretation' }); expect(hits[0].snippet).toContain('Spirit of life'); }); test('needs three letters before searching notes', () => { expect(searchNotes([project], 'sp')).toEqual([]); }); test('finds projects by title, passage or tag', () => { const index = [{ id: 'a', title: 'Romans study', chapterSummary: 'Romans 8', tags: ['grace'] }, { id: 'b', title: 'Psalms', chapterSummary: 'Psalms 23', tags: [] }]; expect(searchProjects(index, 'rom').map((e) => e.id)).toEqual(['a']); expect(searchProjects(index, 'grace').map((e) => e.id)).toEqual(['a']); expect(searchProjects(index, 'zzz')).toEqual([]); }); test('finds highlights by their words or colour name, and bookmarks by reference', () => { const marks = { bookmarks: { 'JHN-3-16': '#fef08a' }, highlights: [{ id: 'h1', book: 'ROM', chapter: 8, verse: 28, color: '#bbf7d0', text: 'all things work together', startOffset: 0, endOffset: 5 }], labels: { '#bbf7d0': 'Promise' }, }; expect(searchMarks(marks, 'together')[0]).toMatchObject({ kind: 'highlight', bookName: 'Romans', verse: 28 }); expect(searchMarks(marks, 'promise')[0]).toMatchObject({ kind: 'highlight' }); expect(searchMarks(marks, 'john 3')[0]).toMatchObject({ kind: 'bookmark', chapter: 3, verse: 16 }); });