-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
644 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 0 additions & 32 deletions
32
app/src/androidTest/java/com/android/periodpals/ExampleInstrumentedTest.kt
This file was deleted.
Oops, something went wrong.
96 changes: 96 additions & 0 deletions
96
app/src/androidTest/java/com/android/periodpals/ui/navigation/BottomNavigationMenuTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package com.android.periodpals.ui.navigation | ||
|
||
import android.annotation.SuppressLint | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.test.assertIsDisplayed | ||
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.performClick | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class BottomNavigationMenuTest { | ||
|
||
@get:Rule val composeTestRule = createComposeRule() | ||
|
||
@Test | ||
fun bottomNavigationMenu_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() | ||
} | ||
} | ||
|
||
@SuppressLint("UnrememberedMutableState") | ||
@Test | ||
fun bottomNavigationMenu_clickOnTab_changesSelection() { | ||
var selectedTab by mutableStateOf(Route.MAP) // Initially selected tab is "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() { | ||
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() | ||
} | ||
} | ||
|
||
@Test | ||
fun bottomNavigationMenu_initialSelectionIsCorrect() { | ||
composeTestRule.setContent { | ||
BottomNavigationMenu( | ||
onTabSelect = {}, tabList = LIST_TOP_LEVEL_DESTINATION, selectedItem = "Timer") | ||
} | ||
|
||
composeTestRule.onNodeWithTag("Timer").assertIsSelected() | ||
} | ||
|
||
@Test | ||
fun bottomNavigationMenu_selectingSameTabDoesNotCrash() { | ||
var selectedTab = Route.ALERT_LIST | ||
|
||
composeTestRule.setContent { | ||
BottomNavigationMenu( | ||
onTabSelect = { selectedTab = it.route }, | ||
tabList = LIST_TOP_LEVEL_DESTINATION, | ||
selectedItem = selectedTab) | ||
} | ||
|
||
composeTestRule.onNodeWithTag("Alert List").performClick() | ||
composeTestRule.onNodeWithTag("Alert List").assertIsSelected() | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
app/src/androidTest/java/com/android/periodpals/ui/navigation/TopAppBarTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package com.android.periodpals.ui.navigation | ||
|
||
import androidx.compose.ui.test.assertIsDisplayed | ||
import androidx.compose.ui.test.assertIsNotDisplayed | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.test.onNodeWithTag | ||
import androidx.compose.ui.test.performClick | ||
import org.junit.Assert.assertThrows | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class TopAppBarTest { | ||
|
||
@get:Rule val composeTestRule = createComposeRule() | ||
|
||
@Test | ||
fun topAppBar_displaysTitle() { | ||
composeTestRule.setContent { TopAppBar(title = "Tampon Timer") } | ||
|
||
composeTestRule.onNodeWithTag("topBar").assertIsDisplayed() | ||
composeTestRule.onNodeWithTag("screenTitle").assertIsDisplayed() | ||
} | ||
|
||
@Test | ||
fun topAppBar_displaysBackButton() { | ||
composeTestRule.setContent { TopAppBar(title = "Tampon Timer", backButton = true) } | ||
|
||
composeTestRule.onNodeWithTag("topBar").assertIsDisplayed() | ||
composeTestRule.onNodeWithTag("goBackButton").assertIsDisplayed() | ||
} | ||
|
||
@Test | ||
fun topAppBar_backButtonClick() { | ||
var backButtonClicked = false | ||
|
||
composeTestRule.setContent { | ||
TopAppBar( | ||
title = "Tampon Timer", | ||
backButton = true, | ||
onBackButtonClick = { backButtonClicked = true }) | ||
} | ||
|
||
composeTestRule.onNodeWithTag("goBackButton").performClick() | ||
assert(backButtonClicked) | ||
} | ||
|
||
@Test | ||
fun topAppBar_noBackButton() { | ||
composeTestRule.setContent { TopAppBar(title = "Tampon Timer", backButton = false) } | ||
|
||
composeTestRule.onNodeWithTag("topBar").assertIsDisplayed() | ||
composeTestRule.onNodeWithTag("goBackButton").assertDoesNotExist() | ||
} | ||
|
||
@Test | ||
fun topAppBar_backButtonTrue_onBackButtonClickNull_throwsException() { | ||
val exception = | ||
assertThrows(IllegalArgumentException::class.java) { | ||
composeTestRule.setContent { | ||
TopAppBar(title = "Test Title", backButton = true, onBackButtonClick = null) | ||
} | ||
} | ||
assert(exception.message == "onBackButtonClick must be provided when backButton is true") | ||
} | ||
|
||
@Test | ||
fun topAppBar_backButtonTrue_onBackButtonClickNotNull_doesNotThrowException() { | ||
composeTestRule.setContent { | ||
TopAppBar(title = "Test Title", backButton = true, onBackButtonClick = { /* Do nothing */}) | ||
} | ||
composeTestRule.onNodeWithTag("topBar").assertIsDisplayed() | ||
composeTestRule.onNodeWithTag("goBackButton").assertIsDisplayed() | ||
} | ||
|
||
@Test | ||
fun topAppBar_backButtonFalse_onBackButtonClickNull_doesNotThrowException() { | ||
composeTestRule.setContent { | ||
TopAppBar(title = "Test Title", backButton = false, onBackButtonClick = null) | ||
} | ||
composeTestRule.onNodeWithTag("topBar").assertIsDisplayed() | ||
composeTestRule.onNodeWithTag("goBackButton").assertIsNotDisplayed() | ||
} | ||
|
||
@Test | ||
fun topAppBar_backButtonFalse_onBackButtonClickNotNull_doesNotThrowException() { | ||
composeTestRule.setContent { | ||
TopAppBar(title = "Test Title", backButton = false, onBackButtonClick = { /* Do nothing */}) | ||
} | ||
composeTestRule.onNodeWithTag("topBar").assertIsDisplayed() | ||
composeTestRule.onNodeWithTag("goBackButton").assertIsNotDisplayed() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.