package pl.firmatpp.kierowca.ui

import androidx.compose.ui.text.AnnotatedString
import org.junit.Assert.assertEquals
import org.junit.Test

class PolishPhoneNumberVisualTransformationTest {
    @Test
    fun formatsPhoneDigitsWithoutChangingUnderlyingTextOffsets() {
        val transformed = PolishPhoneNumberVisualTransformation.filter(AnnotatedString("1234"))

        assertEquals("123 4", transformed.text.text)
        assertEquals(5, transformed.offsetMapping.originalToTransformed(4))
        assertEquals(4, transformed.offsetMapping.transformedToOriginal(5))
    }

    @Test
    fun mapsOffsetsAcrossBothInsertedSpaces() {
        val transformed = PolishPhoneNumberVisualTransformation.filter(AnnotatedString("123456789"))

        assertEquals("123 456 789", transformed.text.text)
        assertEquals(7, transformed.offsetMapping.originalToTransformed(6))
        assertEquals(11, transformed.offsetMapping.originalToTransformed(9))
        assertEquals(6, transformed.offsetMapping.transformedToOriginal(7))
        assertEquals(9, transformed.offsetMapping.transformedToOriginal(11))
    }
}
