aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-android/app/src/test/kotlin/org/meshbay/client/LocalNetworkTest.kt
blob: cc5d3bac4bfbcce2f8d9458a1a01f0b4adc1def6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package org.meshbay.client

import org.junit.Assert.assertEquals
import org.junit.Test
import org.meshbay.client.shell.LocalNetwork

class LocalNetworkTest {
    private fun state(sdk: Int = 37, granted: Boolean = false, asked: Boolean = false, rationale: Boolean = false) =
        LocalNetwork.stateOf(sdk, granted, asked, rationale)

    @Test fun `before Android 17 the local network comes with the internet`() {
        assertEquals("granted", state(sdk = 36))
        assertEquals("granted", state(sdk = 26, asked = true))
    }

    @Test fun `a permission given is granted`() {
        assertEquals("granted", state(granted = true))
    }

    @Test fun `never asked, or refused once, Android still asks`() {
        assertEquals("prompt", state())
        assertEquals("prompt", state(asked = true, rationale = true))
    }

    @Test fun `refused for good, only the settings can change it`() {
        assertEquals("denied", state(asked = true, rationale = false))
    }
}