import { describe, expect, it } from 'vitest'; import { positionDisplay } from '../viewer/position'; // UI-02 §5.2 位置计数形态判定(纯数据层):三种真实回退 + 前瞻 total 形态。 // 组件侧当前传 total=null(公开端点游标分页无总数);lightbox.spec 覆盖 // loaded / index / preview 三种模式的端到端渲染。 describe('viewer position display fallbacks (UI-02 §5.2)', () => { it('shows i / total only when the API provides an accurate total', () => { expect(positionDisplay({ index: 11, loaded: 24, total: 248, atEnd: false, solo: false })).toEqual({ kind: 'total', current: 12, total: 248, }); }); it('shows the loaded count while more pages remain and no total exists', () => { expect(positionDisplay({ index: 2, loaded: 24, total: null, atEnd: false, solo: false })).toEqual({ kind: 'loaded', count: 24, }); }); it('shows i / n of the filtered sequence once all pages are loaded', () => { expect(positionDisplay({ index: 4, loaded: 30, total: null, atEnd: true, solo: false })).toEqual({ kind: 'index', current: 5, total: 30, }); }); it('never fabricates a position for unpositioned or solo deep-link entries', () => { // solo:即使有准确 total,也不知道目标在筛选序列中的自然位置。 expect(positionDisplay({ index: 24, loaded: 25, total: 248, atEnd: true, solo: true })).toEqual({ kind: 'preview', }); // 下标未知(-1,防御分支)。 expect(positionDisplay({ index: -1, loaded: 3, total: null, atEnd: true, solo: false })).toEqual({ kind: 'preview', }); }); });