package com.ponzischeme89.memby.data

import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test

/**
 * The rule the infinite scroll stops on. Both halves of it exist because either one alone
 * leaves a real case broken: a shelf that stops half way through a genre, or a grid that
 * asks forever for pages that will never come.
 */
class GenreBrowseTest {

    @Test
    fun `keeps paging while the genre has more`() {
        assertTrue(hasMoreGenreItems(loaded = 48, total = 412, lastPageSize = 48, pageSize = 48))
    }

    @Test
    fun `stops once everything has been loaded`() {
        assertFalse(hasMoreGenreItems(loaded = 412, total = 412, lastPageSize = 44, pageSize = 48))
    }

    @Test
    fun `a short page is the end, whatever the total claims`() {
        // A backend that would not count sends a total this side cannot trust. The page
        // itself is the evidence, and one short of what was asked for is the last one.
        assertFalse(hasMoreGenreItems(loaded = 61, total = 9_999, lastPageSize = 13, pageSize = 48))
    }

    @Test
    fun `an empty genre does not page`() {
        assertFalse(hasMoreGenreItems(loaded = 0, total = 0, lastPageSize = 0, pageSize = 48))
        // Nor does one whose backend reported nothing at all about how much there is.
        assertFalse(hasMoreGenreItems(loaded = 48, total = 0, lastPageSize = 48, pageSize = 48))
    }
}
