package com.ponzischeme89.memby.ui.whatsnew

import org.junit.Assert.assertEquals
import org.junit.Test

class WhatsNewTest {

    private fun decide(
        installed: String = "0.2.24",
        seen: String? = "0.2.23",
        signedIn: Boolean = true,
    ) = whatsNewDecision(installed, seen, signedIn)

    @Test
    fun `an updated television is notified of the build it is running`() {
        assertEquals(WhatsNewDecision.Notify("0.2.24"), decide())
    }

    @Test
    fun `the same build is only announced once`() {
        assertEquals(WhatsNewDecision.Nothing, decide(seen = "0.2.24"))
    }

    @Test
    fun `a fresh install records the version instead of announcing it`() {
        assertEquals(
            WhatsNewDecision.MarkSeen("0.2.24"),
            decide(seen = null, signedIn = false),
        )
    }

    @Test
    fun `an install that predates the record is announced once it is signed in`() {
        assertEquals(WhatsNewDecision.Notify("0.2.24"), decide(seen = null, signedIn = true))
    }

    @Test
    fun `a signed-out television with a record waits rather than consuming the notice`() {
        assertEquals(WhatsNewDecision.Nothing, decide(seen = "0.2.23", signedIn = false))
    }

    @Test
    fun `an updated build does not depend on a changelog entry`() {
        assertEquals(WhatsNewDecision.Notify("0.9.0"), decide(installed = "0.9.0"))
    }

    @Test
    fun `an unreadable version does nothing at all`() {
        assertEquals(WhatsNewDecision.Nothing, decide(installed = "  "))
    }

}
