package pl.firmatpp.kierowca.ui

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

class OtpAutoSubmitPolicyTest {
    @Test
    fun submitsWhenSixthDigitIsEntered() {
        val policy = OtpAutoSubmitPolicy()

        assertFalse(policy.shouldSubmit("12345", loading = false))
        assertTrue(policy.shouldSubmit("123456", loading = false))
    }

    @Test
    fun submitsSmsRetrieverCodeOnlyOnceWhileItStaysTheSame() {
        val policy = OtpAutoSubmitPolicy()

        assertTrue(policy.shouldSubmit("987654", loading = false))
        assertFalse(policy.shouldSubmit("987654", loading = false))
    }

    @Test
    fun allowsRetryAfterCodeIsEditedBelowSixDigits() {
        val policy = OtpAutoSubmitPolicy()

        assertTrue(policy.shouldSubmit("111111", loading = false))
        assertFalse(policy.shouldSubmit("111111", loading = false))
        assertFalse(policy.shouldSubmit("11111", loading = false))
        assertTrue(policy.shouldSubmit("111111", loading = false))
    }

    @Test
    fun doesNotSubmitWhileLoadingOrForLongerCodes() {
        val policy = OtpAutoSubmitPolicy()

        assertFalse(policy.shouldSubmit("123456", loading = true))
        assertFalse(policy.shouldSubmit("1234567", loading = false))
    }
}
