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

This commit was merged in pull request #53.
This commit is contained in:
2026-03-13 13:21:06 +01:00
parent 86e6be8146
commit 604070ce4b

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()
}
}