test: navigation routing test for drawer and page routing (Closes #34)

Add NavigationRoutingTest with 3 tests: menu button opens drawer with
nav items visible, clicking Settings navigates to settings page, and
navigating back restores the character sheet. Requires JVM Compose
test runner.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
shahondin1624
2026-03-13 13:20:50 +01:00
parent 86e6be8146
commit db9cef8582

View File

@@ -0,0 +1,78 @@
package org.shahondin1624
import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.runComposeUiTest
import org.shahondin1624.lib.components.TestTags
import kotlin.test.Test
/**
* Tests for navigation routing: drawer opens, items visible, and routing works.
* These tests render the full App composable in compact mode (default).
*/
@OptIn(ExperimentalTestApi::class)
class NavigationRoutingTest {
@Test
fun menuButtonOpensDrawerWithNavItems() = runComposeUiTest {
setContent {
App()
}
waitForIdle()
// Click the menu button to open the drawer
onNodeWithTag(TestTags.MENU_BUTTON).performClick()
waitForIdle()
// Assert both navigation items are visible
onNodeWithText("Character Sheet").assertIsDisplayed()
onNodeWithText("Settings").assertIsDisplayed()
}
@Test
fun clickSettingsNavigatesToSettingsPage() = runComposeUiTest {
setContent {
App()
}
waitForIdle()
// Open drawer and click Settings
onNodeWithTag(TestTags.MENU_BUTTON).performClick()
waitForIdle()
onNodeWithTag(TestTags.NAV_SETTINGS).performClick()
waitForIdle()
// Assert Settings page content appears
onNodeWithTag("settings_page").assertIsDisplayed()
}
@Test
fun navigateBackToCharacterSheet() = runComposeUiTest {
setContent {
App()
}
waitForIdle()
// Navigate to Settings
onNodeWithTag(TestTags.MENU_BUTTON).performClick()
waitForIdle()
onNodeWithTag(TestTags.NAV_SETTINGS).performClick()
waitForIdle()
// Navigate back to Character Sheet
onNodeWithTag(TestTags.MENU_BUTTON).performClick()
waitForIdle()
onNodeWithTag(TestTags.NAV_CHARACTER_SHEET).performClick()
waitForIdle()
// Assert character sheet content reappears (attribute cards)
onNodeWithTag(TestTags.attributeCard("Body")).assertIsDisplayed()
}
}