-
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
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
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,52 @@ | ||
package com.android.periodpals.ui.navigation | ||
|
||
import androidx.compose.ui.test.assertIsDisplayed | ||
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 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() | ||
} | ||
} |