import { describe, it, expect } from 'vitest';
import { isCaughtUp } from './continueReading';

const base = {
    chapter_number: 5 as number | null,
    chapter_page_count: 10 as number | null,
    page: 3,
    new_chapters_count: 0
};

describe('isCaughtUp', () => {
    it('is true on the last page of the latest chapter with nothing new', () => {
        expect(isCaughtUp({ ...base, page: 10 })).toBe(true);
    });

    it('is false mid-chapter (still something to continue)', () => {
        expect(isCaughtUp({ ...base, page: 3 })).toBe(false);
    });

    it('is false when newer chapters exist', () => {
        expect(isCaughtUp({ ...base, page: 10, new_chapters_count: 2 })).toBe(false);
    });

    it('is false when the last-read position is unknown', () => {
        expect(isCaughtUp({ ...base, page: 10, chapter_number: null })).toBe(false);
    });

    it('is false when the chapter page count is unknown or zero', () => {
        expect(isCaughtUp({ ...base, page: 10, chapter_page_count: null })).toBe(false);
        expect(isCaughtUp({ ...base, page: 1, chapter_page_count: 0 })).toBe(false);
    });
});
