package wang.yaojia.webterm.nav

import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

/**
 * A26 · the single adaptive-layout decision + the pointer-menu gate, both pure (plan §5 A26, R13).
 *
 * Mirrors iOS `LayoutPolicyTests`: compact → stack, medium/expanded → list-detail; and the
 * pointer-context-menu gate (list-detail AND `smallestScreenWidthDp >= 600`). Plain enum / Int inputs —
 * no Compose, no device.
 */
class LayoutPolicyTest {

    // ── LayoutPolicy.mode: one decision per width class ──────────────────────────────────────────────

    @Test
    fun `compact width falls back to the single-pane stack`() {
        assertEquals(LayoutMode.STACK, LayoutPolicy.mode(WindowWidth.COMPACT))
    }

    @Test
    fun `medium width opens the sidebar plus detail split`() {
        assertEquals(LayoutMode.LIST_DETAIL, LayoutPolicy.mode(WindowWidth.MEDIUM))
    }

    @Test
    fun `expanded width opens the sidebar plus detail split`() {
        assertEquals(LayoutMode.LIST_DETAIL, LayoutPolicy.mode(WindowWidth.EXPANDED))
    }

    // ── PointerMenuPolicy.enabled: list-detail AND a real tablet width ───────────────────────────────

    @Test
    fun `pointer menu is enabled in list-detail on a tablet at exactly the breakpoint`() {
        assertTrue(PointerMenuPolicy.enabled(LayoutMode.LIST_DETAIL, smallestScreenWidthDp = 600))
    }

    @Test
    fun `pointer menu is enabled in list-detail on a wide tablet`() {
        assertTrue(PointerMenuPolicy.enabled(LayoutMode.LIST_DETAIL, smallestScreenWidthDp = 840))
    }

    @Test
    fun `pointer menu is disabled just below the tablet breakpoint`() {
        assertFalse(PointerMenuPolicy.enabled(LayoutMode.LIST_DETAIL, smallestScreenWidthDp = 599))
    }

    @Test
    fun `pointer menu is disabled in the compact stack even on a wide screen`() {
        assertFalse(PointerMenuPolicy.enabled(LayoutMode.STACK, smallestScreenWidthDp = 600))
        assertFalse(PointerMenuPolicy.enabled(LayoutMode.STACK, smallestScreenWidthDp = 1000))
    }

    @Test
    fun `the tablet breakpoint is the Material 600dp smallest-width`() {
        assertEquals(600, PointerMenuPolicy.TABLET_MIN_WIDTH_DP)
    }
}
