From fce9b4cc641c1ff92d5b562e247f37c924756a84 Mon Sep 17 00:00:00 2001 From: shahondin1624 Date: Fri, 13 Mar 2026 13:22:25 +0100 Subject: [PATCH] test: responsive navigation mode test for compact/expanded (Closes #36) Add ResponsiveNavigationModeTest with 3 tests: compact shows modal drawer hidden by default with hamburger button, compact drawer appears on menu tap, and expanded shows permanent sidebar with no hamburger button. Requires JVM Compose test runner. Co-Authored-By: Claude Opus 4.6 --- .../ResponsiveNavigationModeTest.kt | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 sharedUI/src/commonTest/kotlin/org/shahondin1624/ResponsiveNavigationModeTest.kt diff --git a/sharedUI/src/commonTest/kotlin/org/shahondin1624/ResponsiveNavigationModeTest.kt b/sharedUI/src/commonTest/kotlin/org/shahondin1624/ResponsiveNavigationModeTest.kt new file mode 100644 index 0000000..2b8e0c9 --- /dev/null +++ b/sharedUI/src/commonTest/kotlin/org/shahondin1624/ResponsiveNavigationModeTest.kt @@ -0,0 +1,95 @@ +package org.shahondin1624 + +import androidx.compose.foundation.layout.BoxWithConstraints +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.width +import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.ui.Modifier +import androidx.compose.ui.test.ExperimentalTestApi +import androidx.compose.ui.test.assertIsDisplayed +import androidx.compose.ui.test.onAllNodesWithTag +import androidx.compose.ui.test.onNodeWithTag +import androidx.compose.ui.test.performClick +import androidx.compose.ui.test.runComposeUiTest +import androidx.compose.ui.unit.dp +import org.shahondin1624.lib.components.TestTags +import org.shahondin1624.theme.LocalWindowSizeClass +import org.shahondin1624.theme.WindowSizeClass +import kotlin.test.Test +import kotlin.test.assertEquals + +/** + * Tests that the correct navigation mode is rendered at each window size class. + */ +@OptIn(ExperimentalTestApi::class) +class ResponsiveNavigationModeTest { + + @Test + fun compactShowsModalDrawerHiddenByDefault() = runComposeUiTest { + setContent { + App() + } + + waitForIdle() + + // Hamburger menu button should be visible + onNodeWithTag(TestTags.MENU_BUTTON).assertIsDisplayed() + + // Navigation rail and permanent drawer should not exist + assertEquals( + 0, + onAllNodesWithTag(TestTags.NAV_RAIL).fetchSemanticsNodes().size, + "NavigationRail should not be present in compact mode" + ) + assertEquals( + 0, + onAllNodesWithTag(TestTags.NAV_PERMANENT_DRAWER).fetchSemanticsNodes().size, + "PermanentDrawer should not be present in compact mode" + ) + } + + @Test + fun compactDrawerAppearsOnMenuTap() = runComposeUiTest { + setContent { + App() + } + + waitForIdle() + + // Tap hamburger + onNodeWithTag(TestTags.MENU_BUTTON).performClick() + waitForIdle() + + // Drawer content should now be visible + onNodeWithTag(TestTags.NAV_CHARACTER_SHEET).assertIsDisplayed() + onNodeWithTag(TestTags.NAV_SETTINGS).assertIsDisplayed() + } + + @Test + fun expandedShowsPermanentSidebar() = runComposeUiTest { + setContent { + // Force expanded size class by wrapping in a wide box + CompositionLocalProvider(LocalWindowSizeClass provides WindowSizeClass.Expanded) { + BoxWithConstraints(modifier = Modifier.width(1200.dp).fillMaxSize()) { + App() + } + } + } + + waitForIdle() + + // Permanent drawer should be visible + onNodeWithTag(TestTags.NAV_PERMANENT_DRAWER).assertIsDisplayed() + + // Hamburger menu button should not exist + assertEquals( + 0, + onAllNodesWithTag(TestTags.MENU_BUTTON).fetchSemanticsNodes().size, + "Menu button should not be present in expanded mode" + ) + + // Navigation items always visible + onNodeWithTag(TestTags.NAV_CHARACTER_SHEET).assertIsDisplayed() + onNodeWithTag(TestTags.NAV_SETTINGS).assertIsDisplayed() + } +}