/*
 * Copyright (C) 2026 SHX VPN
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 */

package org.strongswan.android.ui.compose

import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.onAllNodesWithText
import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Rule
import org.junit.Test
import org.strongswan.android.R
import org.strongswan.android.ui.compose.theme.ShxTheme

class SettingsScreenTest
{
	@get:Rule
	val composeRule = createComposeRule()

	private fun string(id: Int): String =
		InstrumentationRegistry.getInstrumentation().targetContext.getString(id)

	private fun setContent()
	{
		composeRule.setContent {
			ShxTheme {
				SettingsScreen(profiles = emptyList())
			}
		}
		composeRule.waitForIdle()
	}

	@Test
	fun showsSectionHeaders()
	{
		setContent()
		composeRule.onNodeWithText(
			string(R.string.settings_section_automation)
		).assertIsDisplayed()
		composeRule.onNodeWithText(
			string(R.string.settings_section_security)
		).assertIsDisplayed()
		composeRule.onNodeWithText(
			string(R.string.settings_section_support)
		).assertIsDisplayed()
	}

	@Test
	fun showsTrustedNetworksEntry()
	{
		setContent()
		composeRule.onNodeWithText(
			string(R.string.auto_connect_title)
		).assertIsDisplayed()
	}

	@Test
	fun showsKillSwitchEntry()
	{
		setContent()
		composeRule.onNodeWithText(
			string(R.string.kill_switch_title)
		).assertIsDisplayed()
		composeRule.onAllNodesWithText(
			string(R.string.kill_switch_summary_off)
		).fetchSemanticsNodes().isNotEmpty()
	}
}
