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 <noreply@anthropic.com>
This commit is contained in:
@@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user