mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-18 00:57:02 +05:30
Revert "app: remove now uneeded navigation code"
This reverts commit 41c64f4b02
.
This commit is contained in:
parent
3d5ad28eb0
commit
72d51d5c52
4 changed files with 143 additions and 0 deletions
|
@ -0,0 +1,115 @@
|
|||
package dev.msfjarvis.lobsters
|
||||
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.test.assertContentDescriptionEquals
|
||||
import androidx.compose.ui.test.assertCountEquals
|
||||
import androidx.compose.ui.test.assertHasClickAction
|
||||
import androidx.compose.ui.test.assertIsDisplayed
|
||||
import androidx.compose.ui.test.assertIsNotSelected
|
||||
import androidx.compose.ui.test.assertIsSelected
|
||||
import androidx.compose.ui.test.assertTextEquals
|
||||
import androidx.compose.ui.test.junit4.createComposeRule
|
||||
import androidx.compose.ui.test.onChildAt
|
||||
import androidx.compose.ui.test.onChildren
|
||||
import androidx.compose.ui.test.onNodeWithTag
|
||||
import androidx.compose.ui.test.performClick
|
||||
import dev.msfjarvis.lobsters.ui.main.LobstersBottomNav
|
||||
import dev.msfjarvis.lobsters.ui.navigation.Destination
|
||||
import dev.msfjarvis.lobsters.ui.theme.LobstersTheme
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
|
||||
|
||||
class BottomNavigationLayoutTest {
|
||||
|
||||
@get:Rule
|
||||
val composeTestRule = createComposeRule()
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
composeTestRule.setContent {
|
||||
LobstersTheme {
|
||||
var mutableDestination by remember { mutableStateOf(Destination.startDestination) }
|
||||
|
||||
LobstersBottomNav(
|
||||
currentDestination = mutableDestination,
|
||||
navigateToDestination = { mutableDestination = it },
|
||||
jumpToIndex = {}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun bottomNavItemCountTest() {
|
||||
// Test to make sure total items are equal to enum objects present in Destination
|
||||
composeTestRule.onNodeWithTag("LobstersBottomNav")
|
||||
.assertExists()
|
||||
.assertIsDisplayed()
|
||||
.onChildren()
|
||||
.assertCountEquals(Destination.values().size)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun bottomNavItemTest() {
|
||||
// Check hottest BottomNavItem is rendered correctly
|
||||
composeTestRule.onNodeWithTag("LobstersBottomNav")
|
||||
.assertExists()
|
||||
.assertIsDisplayed()
|
||||
.onChildAt(0)
|
||||
.assertTextEquals("Hottest")
|
||||
.assertContentDescriptionEquals("Hottest")
|
||||
.assertHasClickAction()
|
||||
|
||||
// Check saved BottomNavItem is rendered correctly
|
||||
composeTestRule.onNodeWithTag("LobstersBottomNav")
|
||||
.assertExists()
|
||||
.assertIsDisplayed()
|
||||
.onChildAt(1)
|
||||
.assertTextEquals("Saved")
|
||||
.assertContentDescriptionEquals("Saved")
|
||||
.assertHasClickAction()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun bottomNavItemSelectedTest() {
|
||||
// Check hottest BottomNav item is selected
|
||||
composeTestRule.onNodeWithTag("LobstersBottomNav")
|
||||
.assertExists()
|
||||
.assertIsDisplayed()
|
||||
.onChildAt(0)
|
||||
.assertIsSelected()
|
||||
.assertTextEquals("Hottest")
|
||||
|
||||
// Check saved BottomNav item is not selected
|
||||
composeTestRule.onNodeWithTag("LobstersBottomNav")
|
||||
.assertExists()
|
||||
.assertIsDisplayed()
|
||||
.onChildAt(1)
|
||||
.assertIsNotSelected()
|
||||
|
||||
// Select the saved BottomNav item
|
||||
composeTestRule.onNodeWithTag("LobstersBottomNav")
|
||||
.onChildAt(1)
|
||||
.performClick()
|
||||
|
||||
// Check hottest BottomNav item is not selected
|
||||
composeTestRule.onNodeWithTag("LobstersBottomNav")
|
||||
.assertExists()
|
||||
.assertIsDisplayed()
|
||||
.onChildAt(0)
|
||||
.assertIsNotSelected()
|
||||
|
||||
// Check saved BottomNav item is selected
|
||||
composeTestRule.onNodeWithTag("LobstersBottomNav")
|
||||
.assertExists()
|
||||
.assertIsDisplayed()
|
||||
.onChildAt(1)
|
||||
.assertIsSelected()
|
||||
.assertTextEquals("Saved")
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package dev.msfjarvis.lobsters.ui.navigation
|
||||
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.annotation.StringRes
|
||||
import dev.msfjarvis.lobsters.R
|
||||
|
||||
/**
|
||||
* Destinations for navigation within the app.
|
||||
*/
|
||||
enum class Destination(
|
||||
val route: String,
|
||||
@StringRes val labelRes: Int,
|
||||
@DrawableRes val badgeRes: Int,
|
||||
) {
|
||||
Hottest("hottest", R.string.hottest_posts, R.drawable.ic_whatshot_24px),
|
||||
Saved("saved", R.string.saved_posts, R.drawable.ic_favorite_24px),
|
||||
;
|
||||
|
||||
companion object {
|
||||
val startDestination = Hottest
|
||||
|
||||
fun getDestinationFromRoute(route: String): Destination {
|
||||
return values().firstOrNull { it.route == route } ?: error("Incorrect route passed")
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue