feat: add adaptive authenticated navigation
This commit is contained in:
+91
@@ -0,0 +1,91 @@
|
||||
package com.flagship.abox.manager.ui.navigation
|
||||
|
||||
import com.flagship.abox.manager.domain.DeviceName
|
||||
import com.flagship.abox.manager.domain.DeviceType
|
||||
import com.flagship.abox.manager.domain.ProviderProfileId
|
||||
import com.flagship.abox.manager.ui.shell.ABoxWindowSizeClass
|
||||
import com.flagship.abox.manager.ui.shell.DetailPresentation
|
||||
import com.flagship.abox.manager.ui.shell.MainNavigationPresentation
|
||||
import com.flagship.abox.manager.ui.shell.MainTab
|
||||
import com.flagship.abox.manager.ui.shell.DeviceSelection
|
||||
import com.flagship.abox.manager.ui.shell.detailPresentation
|
||||
import com.flagship.abox.manager.ui.shell.navigationPresentation
|
||||
import com.flagship.abox.manager.ui.shell.widthClass
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Test
|
||||
|
||||
class AuthenticatedNavigationTest {
|
||||
|
||||
@Test
|
||||
fun `profile key change recreates authenticated graph`() {
|
||||
val firstProfile = ProviderProfileId("first")
|
||||
val secondProfile = ProviderProfileId("second")
|
||||
val firstGraph = AuthenticatedGraphState(firstProfile)
|
||||
.selectTab(MainTab.SCENES)
|
||||
.selectDevice(DeviceName("socket"), DeviceType.SOCKET)
|
||||
|
||||
val recreated = firstGraph.recreateForProfile(secondProfile)
|
||||
|
||||
assertEquals(secondProfile, recreated.profileId)
|
||||
assertEquals(MainTab.DEVICES, recreated.currentTab)
|
||||
assertNull(recreated.selectedDevice)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `reselecting main tab pops to its root`() {
|
||||
val state = AuthenticatedGraphState(ProviderProfileId("profile"))
|
||||
.selectTab(MainTab.SCENES)
|
||||
.pushChild("scene/editor/manual")
|
||||
|
||||
val reselected = state.selectTab(MainTab.SCENES)
|
||||
|
||||
assertEquals(MainTab.SCENES, reselected.currentTab)
|
||||
assertEquals(listOf(MainTab.SCENES.route), reselected.tabBackStack(MainTab.SCENES))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `compact uses bottom navigation`() {
|
||||
assertEquals(MainNavigationPresentation.BOTTOM_NAVIGATION, navigationPresentation(widthClass(599)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `medium and expanded use rail`() {
|
||||
assertEquals(MainNavigationPresentation.NAVIGATION_RAIL, navigationPresentation(widthClass(600)))
|
||||
assertEquals(MainNavigationPresentation.NAVIGATION_RAIL, navigationPresentation(widthClass(840)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `profile replacement clears previously selected device`() {
|
||||
val state = AuthenticatedGraphState(ProviderProfileId("first"))
|
||||
.selectDevice(DeviceName("sensor"), DeviceType.TEMPERATURE_HUMIDITY)
|
||||
|
||||
val replaced = state.recreateForProfile(ProviderProfileId("second"))
|
||||
|
||||
assertNull(replaced.selectedDevice)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `selected device uses pane on expanded layouts and full screen otherwise`() {
|
||||
val selection = DeviceSelection(
|
||||
profileId = ProviderProfileId("profile"),
|
||||
deviceName = DeviceName("sensor"),
|
||||
type = DeviceType.TEMPERATURE_HUMIDITY,
|
||||
)
|
||||
|
||||
assertEquals(DetailPresentation.FULL_SCREEN, detailPresentation(widthClass(599), selection))
|
||||
assertEquals(DetailPresentation.PANE, detailPresentation(widthClass(840), selection))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `back closes child route before leaving its main tab`() {
|
||||
val state = AuthenticatedGraphState(ProviderProfileId("profile"))
|
||||
.selectTab(MainTab.SCENES)
|
||||
.pushChild("scene/editor/manual")
|
||||
|
||||
val afterBack = state.handleBack()
|
||||
|
||||
assertEquals(MainTab.SCENES, afterBack.currentTab)
|
||||
assertEquals(listOf(MainTab.SCENES.route), afterBack.tabBackStack(MainTab.SCENES))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user