import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.assertTextContains
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.runComposeUiTest
import ch.dissem.yaep.ui.common.EndOfGame
import ch.dissem.yaep.ui.common.IgnoreAndroidUnitTest
import ch.tutteli.atrium.api.fluent.en_GB.toEqual
import ch.tutteli.atrium.api.verbs.expect
import kotlin.test.Test

@IgnoreAndroidUnitTest
@OptIn(ExperimentalTestApi::class)
class EndOfGameTest {

    @Test
    fun ensure_end_of_game_works_correctly() = runComposeUiTest {
        var restart = false
        setContent {
            EndOfGame(
                isSolved = true,
                time = "42:42",
                onRestart = { restart = true }
            )
        }

        onNodeWithTag("EndOfGame.solved_time").assertTextContains(value = "42:42", substring = true)
        onNodeWithTag("EndOfGame.restart").performClick()

        expect(restart).toEqual(true)
    }

}