import { initHighlightsDatabase, addHighlight, getHighlight, getAllHighlights, deleteHighlight } from '@/lib/highlight-manager' import { BibleHighlight } from '@/types' describe('HighlightManager', () => { beforeEach(async () => { // Clear IndexedDB before each test const db = await initHighlightsDatabase() const tx = db.transaction('highlights', 'readwrite') tx.objectStore('highlights').clear() }) it('should initialize database with highlights store', async () => { const db = await initHighlightsDatabase() expect(db.objectStoreNames.contains('highlights')).toBe(true) }) it('should add a highlight and retrieve it', async () => { const highlight: BibleHighlight = { id: 'h-123', verseId: 'v-456', color: 'yellow', createdAt: Date.now(), updatedAt: Date.now(), syncStatus: 'pending' } await addHighlight(highlight) const retrieved = await getHighlight('h-123') expect(retrieved).toEqual(highlight) }) it('should get all highlights', async () => { const highlights: BibleHighlight[] = [ { id: 'h-1', verseId: 'v-1', color: 'yellow', createdAt: Date.now(), updatedAt: Date.now(), syncStatus: 'pending' }, { id: 'h-2', verseId: 'v-2', color: 'blue', createdAt: Date.now(), updatedAt: Date.now(), syncStatus: 'synced' } ] for (const h of highlights) { await addHighlight(h) } const all = await getAllHighlights() expect(all.length).toBe(2) }) it('should delete a highlight', async () => { const highlight: BibleHighlight = { id: 'h-123', verseId: 'v-456', color: 'yellow', createdAt: Date.now(), updatedAt: Date.now(), syncStatus: 'pending' } await addHighlight(highlight) await deleteHighlight('h-123') const retrieved = await getHighlight('h-123') expect(retrieved).toBeNull() }) })