package com.tt.honeyDue.ui.animation

import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertNull
import kotlin.test.assertTrue

/**
 * P5 Stream R — unit tests for [AnimationTestingScreenState].
 *
 * Pure state-machine tests (no Compose runtime). Mirrors the behavior of
 * the iOS `AnimationTestingView` — a dev-only screen that lists each
 * registered animation and lets the user pick/play one.
 */
class AnimationTestingScreenStateTest {

    @Test
    fun initial_noAnimationSelected_playCountZero() {
        val state = AnimationTestingScreenState()
        assertNull(state.selected, "no animation selected on launch")
        assertEquals(0, state.playCount)
    }

    @Test
    fun availableAnimations_matchesRegistry() {
        val state = AnimationTestingScreenState()
        // Screen must list every animation that TaskAnimations registers.
        assertEquals(TaskAnimations.all.size, state.available.size)
        assertTrue(state.available.any { it.name == "completionCheckmark" })
        assertTrue(state.available.any { it.name == "cardEnter" })
        assertTrue(state.available.any { it.name == "cardDismiss" })
        assertTrue(state.available.any { it.name == "priorityPulse" })
        assertTrue(state.available.any { it.name == "honeycombLoop" })
    }

    @Test
    fun onRowTap_setsSelected() {
        val state = AnimationTestingScreenState()
        state.onRowTap(TaskAnimations.cardEnter)
        assertNotNull(state.selected)
        assertEquals("cardEnter", state.selected?.name)
    }

    @Test
    fun onRowTap_swappingSelection_replaces() {
        val state = AnimationTestingScreenState()
        state.onRowTap(TaskAnimations.cardEnter)
        state.onRowTap(TaskAnimations.cardDismiss)
        assertEquals("cardDismiss", state.selected?.name)
    }

    @Test
    fun onPlay_withoutSelection_isNoop() {
        val state = AnimationTestingScreenState()
        state.onPlay()
        assertEquals(0, state.playCount, "play is a no-op when nothing is selected")
    }

    @Test
    fun onPlay_incrementsCounterOnlyWhenSelected() {
        val state = AnimationTestingScreenState()
        state.onRowTap(TaskAnimations.priorityPulse)
        state.onPlay()
        state.onPlay()
        state.onPlay()
        assertEquals(3, state.playCount, "play count increments for each trigger")
    }

    @Test
    fun onReset_clearsSelectionAndCounter() {
        val state = AnimationTestingScreenState()
        state.onRowTap(TaskAnimations.honeycombLoop)
        state.onPlay()
        state.onReset()
        assertNull(state.selected)
        assertEquals(0, state.playCount)
    }
}
