/*
 * Copyright © All Contributors. See LICENSE and AUTHORS in the root directory for details.
 */

package at.bitfire.synctools.mapping.jtx.builder

import android.content.ContentValues
import android.content.Entity
import at.bitfire.synctools.icalendar.plusAssign
import at.bitfire.synctools.mapping.jtx.JtxProperty
import at.techbee.jtx.JtxContract
import net.fortuna.ical4j.model.component.VToDo
import net.fortuna.ical4j.model.property.XProperty
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner

@RunWith(RobolectricTestRunner::class)
class ExtendedStatusBuilderTest {

    private val builder = ExtendedStatusBuilder()

    @Test
    fun `No X-STATUS`() {
        val output = Entity(ContentValues())
        val task = VToDo()

        builder.build(from = task, main = task, to = output)

        assertTrue(output.entityValues.containsKey(JtxContract.JtxICalObject.EXTENDED_STATUS))
        assertNull(output.entityValues.get(JtxContract.JtxICalObject.EXTENDED_STATUS))
    }

    @Test
    fun `X-STATUS has text`() {
        val output = Entity(ContentValues())
        val task = VToDo().apply {
            this += XProperty(JtxProperty.X_XSTATUS, "Bla")
        }
        val main = VToDo()

        builder.build(from = task, main = main, to = output)

        assertEquals("Bla", output.entityValues.get(JtxContract.JtxICalObject.EXTENDED_STATUS))
    }
}
