package com.ponzischeme89.memby.ui

import kotlin.random.Random
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test

class WelcomeQuotesTest {
    @Test
    fun `unknown styles safely fall back to neutral`() {
        assertEquals(
            randomWelcomeQuote("neutral", Random(7)),
            randomWelcomeQuote("something-new", Random(7)),
        )
    }

    @Test
    fun `each style supplies a welcome line`() {
        WelcomeQuoteStyle.entries.forEach { style ->
            assertTrue(randomWelcomeQuote(style.value, Random(3)).isNotBlank())
        }
    }

    /**
     * The point of the pools is that a household does not read the same line every fifth
     * launch, and a pool that quietly shrank back — or gained a duplicate on a copy-paste —
     * would look identical to one that had not. Counted rather than eyeballed for that
     * reason; the floor is deliberately below what is written, so adding a tone does not
     * mean matching the longest list exactly.
     */
    @Test
    fun `every tone offers a deep pool of distinct lines`() {
        WelcomeQuoteStyle.entries.forEach { style ->
            val seen = (0 until 4_000)
                .map { randomWelcomeQuote(style.value, Random(it)) }
                .toSet()
            assertTrue(
                "${style.value} offers only ${seen.size} distinct lines",
                seen.size >= 20,
            )
        }
    }

    @Test
    fun `the loading headline varies and always says something`() {
        val seen = (0 until 1_000).map { randomLoadingHeadline(Random(it)) }.toSet()
        assertTrue("only ${seen.size} distinct headlines", seen.size >= 5)
        assertTrue(seen.none { it.isBlank() })
    }

    @Test
    fun `login greeting trims the authenticated username`() {
        assertTrue(
            loginWelcomeMessage("  Matt  ", "positive", Random(1))
                .startsWith("Welcome to Memby, Matt. "),
        )
    }
}
