Skip to content

fix/navigation/bottom-navigation-menu-ui-tests : Fix BottomNavigationMenu UI tests for M1 #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.compose.ui.test.assertIsNotSelected
import androidx.compose.ui.test.assertIsSelected
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import org.junit.Rule
import org.junit.Test
Expand All @@ -18,12 +19,12 @@ class BottomNavigationMenuTest {
@get:Rule val composeTestRule = createComposeRule()

@Test
fun bottomNavigationMenu_displaysAllTabs() {
fun displaysAllTabs() {

composeTestRule.setContent {
BottomNavigationMenu(
onTabSelect = {}, tabList = LIST_TOP_LEVEL_DESTINATION, selectedItem = "Map")
}

composeTestRule.onNodeWithTag("bottomNavigationMenu").assertIsDisplayed()
LIST_TOP_LEVEL_DESTINATION.forEach { tab ->
composeTestRule.onNodeWithTag(tab.textId).assertIsDisplayed()
Expand All @@ -32,55 +33,48 @@ class BottomNavigationMenuTest {

@SuppressLint("UnrememberedMutableState")
@Test
fun bottomNavigationMenu_clickOnTab_changesSelection() {
var selectedTab by mutableStateOf(Route.MAP) // Initially selected tab is "MAP"
fun clickOnTabChangesSelection() {

var selectedTab by mutableStateOf(Route.MAP)

// Set the composable content with an initial selected tab
composeTestRule.setContent {
BottomNavigationMenu(
onTabSelect = { selectedTab = it.route },
tabList = LIST_TOP_LEVEL_DESTINATION,
selectedItem = selectedTab)
}

// Initially, verify that "MAP" is selected
composeTestRule.onNodeWithTag("Map").assertIsSelected()

// Perform a click on the "Alert" tab
composeTestRule.onNodeWithTag("Alert").performClick()

// Now check that the "Alert" tab is selected
composeTestRule.onNodeWithTag("Alert").assertIsSelected()

// Optionally, check that the previously selected "Map" tab is no longer selected
composeTestRule.onNodeWithTag("Map").assertIsNotSelected()
}

@Test
fun bottomNavigationMenu_iconAndLabelAreDisplayedCorrectly() {
fun iconAndLabelAreCorrectlyDisplayed() {

composeTestRule.setContent {
BottomNavigationMenu(
onTabSelect = {}, tabList = LIST_TOP_LEVEL_DESTINATION, selectedItem = "Profile")
}

LIST_TOP_LEVEL_DESTINATION.forEach { tab ->
composeTestRule.onNodeWithTag(tab.textId).assertIsDisplayed()
composeTestRule.onNodeWithTag(tab.textId).assertIsDisplayed()
composeTestRule.onNodeWithText(tab.textId).assertIsDisplayed()
}
}

@Test
fun bottomNavigationMenu_initialSelectionIsCorrect() {
fun initialSelectionIsCorrect() {

composeTestRule.setContent {
BottomNavigationMenu(
onTabSelect = {}, tabList = LIST_TOP_LEVEL_DESTINATION, selectedItem = "Timer")
}

composeTestRule.onNodeWithTag("Timer").assertIsSelected()
}

@Test
fun bottomNavigationMenu_selectingSameTabDoesNotCrash() {
fun selectingSameTabDoesNotCrash() {

var selectedTab = Route.ALERT_LIST

composeTestRule.setContent {
Expand All @@ -89,7 +83,6 @@ class BottomNavigationMenuTest {
tabList = LIST_TOP_LEVEL_DESTINATION,
selectedItem = selectedTab)
}

composeTestRule.onNodeWithTag("Alert List").performClick()
composeTestRule.onNodeWithTag("Alert List").assertIsSelected()
}
Expand Down
Loading