package pl.firmatpp.kierowca.domain

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

class StartupSessionPolicyTest {
    @Test
    fun rotatesStartupMessagesAsWaitingTimeIncreases() {
        assertEquals("Sprawdzamy zapisaną sesję", StartupSessionPolicy.message(0).title)
        assertEquals("Potwierdzamy logowanie", StartupSessionPolicy.message(3).title)
        assertEquals("Pobieramy aktualne kursy", StartupSessionPolicy.message(6).title)
        assertEquals("To trwa dłużej niż zwykle", StartupSessionPolicy.message(9).title)
        assertEquals("Przygotowujemy tryb offline", StartupSessionPolicy.message(12).title)
    }

    @Test
    fun countsDownToOfflineFallbackWithoutGoingBelowZero() {
        assertEquals(15, StartupSessionPolicy.remainingSeconds(0))
        assertEquals(7, StartupSessionPolicy.remainingSeconds(8))
        assertEquals(0, StartupSessionPolicy.remainingSeconds(15))
        assertEquals(0, StartupSessionPolicy.remainingSeconds(30))
        assertEquals("Tryb offline najpóźniej za 5 s", StartupSessionPolicy.countdownLabel(10))
        assertEquals("Otwieramy zapisane dane offline", StartupSessionPolicy.countdownLabel(15))
    }

    @Test
    fun showsManualOfflineButtonAfterFourSecondsOnlyWhenCacheExists() {
        assertEquals(false, StartupSessionPolicy.shouldShowOfflineButton(3, offlineDataAvailable = true))
        assertEquals(true, StartupSessionPolicy.shouldShowOfflineButton(4, offlineDataAvailable = true))
        assertEquals(false, StartupSessionPolicy.shouldShowOfflineButton(10, offlineDataAvailable = false))
    }
}
