package com.github.nullptroma.wallenc.ui.screens.main.screens.storage.secrets

import androidx.compose.material3.MaterialTheme
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import com.github.nullptroma.wallenc.domain.datatypes.TextSecretEntryRecord
import com.github.nullptroma.wallenc.domain.datatypes.TextSecretRecord
import com.github.nullptroma.wallenc.ui.R
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class TextSecretsScreenContentTest {

    @get:Rule
    val composeRule = createComposeRule()

    private val context get() = InstrumentationRegistry.getInstrumentation().targetContext

    @Test
    fun showsEmptyStateWhenNoSecrets() {
        composeRule.setContent {
            MaterialTheme {
                TextSecretsScreenContent(
                    uiState = TextSecretsScreenState(
                        isLoading = false,
                        isAvailable = true,
                        items = emptyList(),
                    ),
                )
            }
        }
        composeRule.onNodeWithText(context.getString(R.string.text_secret_empty_state)).assertIsDisplayed()
    }

    @Test
    fun showsSecretTitle() {
        val secret = TextSecretRecord(
            id = "s1",
            title = "Production DB",
            items = listOf(TextSecretEntryRecord(label = "user", value = "admin")),
        )
        composeRule.setContent {
            MaterialTheme {
                TextSecretsScreenContent(
                    uiState = TextSecretsScreenState(
                        isLoading = false,
                        isAvailable = true,
                        items = listOf(secret),
                    ),
                ) {
                    TextSecretListCard(
                        secret = secret,
                        onClick = {},
                        enabled = true,
                    )
                }
            }
        }
        composeRule.onNodeWithText("Production DB").assertIsDisplayed()
    }
}
