From 604070ce4bd0b5013e38acf2d0c7f7dcdb16d18b Mon Sep 17 00:00:00 2001 From: shahondin1624 Date: Fri, 13 Mar 2026 13:21:06 +0100 Subject: [PATCH] test: navigation routing test for drawer and page routing (Closes #34) (#53) --- .../shahondin1624/NavigationRoutingTest.kt | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 sharedUI/src/commonTest/kotlin/org/shahondin1624/NavigationRoutingTest.kt diff --git a/sharedUI/src/commonTest/kotlin/org/shahondin1624/NavigationRoutingTest.kt b/sharedUI/src/commonTest/kotlin/org/shahondin1624/NavigationRoutingTest.kt new file mode 100644 index 0000000..565a90c --- /dev/null +++ b/sharedUI/src/commonTest/kotlin/org/shahondin1624/NavigationRoutingTest.kt @@ -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() + } +}