import { describe, expect, it } from 'vitest' import { restoreScanView, threadTitle } from './scan-view' describe('restoreScanView', () => { it('opens the first page when nothing was remembered', () => { expect(restoreScanView(undefined, 50)).toEqual({ showLower: false, resultLimit: 50, scrollY: 0, criteriaOpen: false, openScores: [], }) }) it('restores the toggles, limit, scroll and open score panels', () => { expect( restoreScanView( { showLower: true, resultLimit: 150, scrollY: 420, criteriaOpen: true, openScores: ['at://did:plc:example/app.bsky.feed.post/one'], }, 50, ), ).toEqual({ showLower: true, resultLimit: 150, scrollY: 420, criteriaOpen: true, openScores: ['at://did:plc:example/app.bsky.feed.post/one'], }) }) it('falls back when remembered values are malformed', () => { expect( restoreScanView( { resultLimit: 0, scrollY: Number.NaN, openScores: ['at://kept', 7], } as unknown as Parameters[0], 50, ), ).toEqual({ showLower: false, resultLimit: 50, scrollY: 0, criteriaOpen: false, openScores: ['at://kept'], }) }) }) describe('threadTitle', () => { it('names the thread or falls back while it loads', () => { expect(threadTitle('A thread worth a post')).toBe('A thread worth a post — THREADBARE') expect(threadTitle('')).toBe('Thread — THREADBARE') }) })