package com.ponzischeme89.memby.ui.player

import android.content.Context
import android.view.LayoutInflater
import android.widget.FrameLayout
import android.widget.GridLayout
import android.widget.ImageView
import androidx.test.core.app.ApplicationProvider
import com.ponzischeme89.memby.R
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config

@RunWith(RobolectricTestRunner::class)
@Config(sdk = [34])
class PrerollLayoutTest {

    @Test
    fun `player preroll and its background inflate`() {
        val context = ApplicationProvider.getApplicationContext<Context>()

        assertNotNull(context.getDrawable(R.drawable.player_preroll_video_background))
        val preroll = LayoutInflater.from(context).inflate(
            R.layout.player_preroll,
            FrameLayout(context),
            false,
        )
        val videoHost = preroll.findViewById<FrameLayout>(R.id.player_preroll_video_host)
        assertNotNull(videoHost)
        assertEquals(
            (398 * context.resources.displayMetrics.density).toInt(),
            videoHost.layoutParams.width,
        )
        assertNotNull(preroll.findViewById<PrerollCountdownView>(R.id.player_preroll_countdown))
        assertNotNull(preroll.findViewById<ImageView>(R.id.player_preroll_brand))
        assertEquals(
            "Starting in 7 seconds…",
            context.getString(R.string.player_preroll_countdown_initial),
        )
        assertNotNull(context.getDrawable(R.drawable.player_preroll_video_frame))
        assertNotNull(preroll.findViewById<GridLayout>(R.id.player_preroll_calendar))
        assertEquals(6_500L, PlayerActivity.DEFAULT_PREROLL_DURATION_MS)
        assertNotNull(
            LayoutInflater.from(context).inflate(
                R.layout.player_cast_overlay,
                FrameLayout(context),
                false,
            ),
        )
    }
}
