package net.hivetechnology.o20010_06

import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test

class PortalNavigationTest {
    @Test
    fun companionDestinationUsesAndroidFlow() {
        assertEquals(
            "https://portal.hivetechnology.net/mobile-vpn?platform=android",
            mobileVpnPortalDestination(null),
        )
    }

    @Test
    fun returnUrlAcceptsOnlyTheMobileVpnPortalRoute() {
        val trusted = "https://portal.hivetechnology.net/mobile-vpn?platform=android"
        assertEquals(trusted, validatedMobileVpnPortalUrl(trusted))
        assertNull(validatedMobileVpnPortalUrl("http://portal.hivetechnology.net/mobile-vpn"))
        assertNull(validatedMobileVpnPortalUrl("https://example.com/mobile-vpn"))
        assertNull(validatedMobileVpnPortalUrl("https://portal.hivetechnology.net/devices"))
        assertNull(validatedMobileVpnPortalUrl("https://portal.hivetechnology.net/mobile-vpn/../devices"))
    }

    @Test
    fun portalActionIsVisibleOnlyForTerminalStates() {
        listOf("idle", "stopped", "failed", "cancelled").forEach {
            assertTrue(it, shouldShowPortalAction(it))
        }
        listOf("privacy-consent", "redeeming", "awaiting-permission", "waiting-runtime", "connecting", "reconnecting", "connected", "stopping").forEach {
            assertFalse(it, shouldShowPortalAction(it))
        }
    }
}
