-
Notifications
You must be signed in to change notification settings - Fork 339
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
177 additions
and
0 deletions.
There are no files selected for viewing
177 changes: 177 additions & 0 deletions
177
...oid/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/WelcomeScreenTest.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,177 @@ | ||
package net.mullvad.mullvadvpn.compose.screen | ||
|
||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.test.onNodeWithText | ||
import androidx.compose.ui.test.performClick | ||
import io.mockk.MockKAnnotations | ||
import io.mockk.mockk | ||
import io.mockk.verify | ||
import kotlinx.coroutines.flow.MutableSharedFlow | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import net.mullvad.mullvadvpn.compose.state.WelcomeUiState | ||
import net.mullvad.mullvadvpn.viewmodel.WelcomeViewModel | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class WelcomeScreenTest { | ||
@get:Rule val composeTestRule = createComposeRule() | ||
|
||
@Before | ||
fun setup() { | ||
MockKAnnotations.init(this) | ||
} | ||
|
||
@Test | ||
fun testDefaultState() { | ||
// Arrange | ||
composeTestRule.setContent { | ||
WelcomeScreen( | ||
showSitePayment = true, | ||
uiState = WelcomeUiState(), | ||
viewActions = MutableSharedFlow(), | ||
onSitePaymentClick = {}, | ||
onRedeemVoucherClick = {}, | ||
onSettingsClick = {}, | ||
openConnectScreen = {} | ||
) | ||
} | ||
|
||
// Assert | ||
composeTestRule.apply { | ||
onNodeWithText("Congrats!").assertExists() | ||
onNodeWithText("Here’s your account number. Save it!").assertExists() | ||
} | ||
} | ||
|
||
@Test | ||
fun testDisableSitePayment() { | ||
// Arrange | ||
composeTestRule.setContent { | ||
WelcomeScreen( | ||
showSitePayment = false, | ||
uiState = WelcomeUiState(), | ||
viewActions = MutableSharedFlow(), | ||
onSitePaymentClick = {}, | ||
onRedeemVoucherClick = {}, | ||
onSettingsClick = {}, | ||
openConnectScreen = {} | ||
) | ||
} | ||
|
||
// Assert | ||
composeTestRule.apply { | ||
onNodeWithText( | ||
"Either buy credit on our website or redeem a voucher.", | ||
substring = true | ||
) | ||
.assertDoesNotExist() | ||
onNodeWithText("Buy credit").assertDoesNotExist() | ||
} | ||
} | ||
|
||
@Test | ||
fun testShowAccountNumber() { | ||
// Arrange | ||
val mockAccountNumber = "1111 2222 3333 4444" | ||
composeTestRule.setContent { | ||
WelcomeScreen( | ||
showSitePayment = true, | ||
uiState = WelcomeUiState(accountNumber = mockAccountNumber), | ||
viewActions = MutableSharedFlow(), | ||
onSitePaymentClick = {}, | ||
onRedeemVoucherClick = {}, | ||
onSettingsClick = {}, | ||
openConnectScreen = {} | ||
) | ||
} | ||
|
||
// Assert | ||
composeTestRule.apply { onNodeWithText(mockAccountNumber).assertExists() } | ||
} | ||
|
||
@Test | ||
fun testOpenAccountView() { | ||
// Arrange | ||
composeTestRule.setContent { | ||
WelcomeScreen( | ||
showSitePayment = true, | ||
uiState = WelcomeUiState(), | ||
viewActions = MutableStateFlow(WelcomeViewModel.ViewAction.OpenAccountView("222")), | ||
onSitePaymentClick = {}, | ||
onRedeemVoucherClick = {}, | ||
onSettingsClick = {}, | ||
openConnectScreen = {} | ||
) | ||
} | ||
|
||
// Assert | ||
composeTestRule.apply { onNodeWithText("Congrats!").assertDoesNotExist() } | ||
} | ||
|
||
@Test | ||
fun testOpenConnectScreen() { | ||
// Arrange | ||
val mockClickListener: () -> Unit = mockk(relaxed = true) | ||
composeTestRule.setContent { | ||
WelcomeScreen( | ||
showSitePayment = true, | ||
uiState = WelcomeUiState(), | ||
viewActions = MutableStateFlow(WelcomeViewModel.ViewAction.OpenConnectScreen), | ||
onSitePaymentClick = {}, | ||
onRedeemVoucherClick = {}, | ||
onSettingsClick = {}, | ||
openConnectScreen = mockClickListener | ||
) | ||
} | ||
|
||
// Assert | ||
verify(exactly = 1) { mockClickListener.invoke() } | ||
} | ||
|
||
@Test | ||
fun testClickSitePaymentButton() { | ||
// Arrange | ||
val mockClickListener: () -> Unit = mockk(relaxed = true) | ||
composeTestRule.setContent { | ||
WelcomeScreen( | ||
showSitePayment = true, | ||
uiState = WelcomeUiState(), | ||
viewActions = MutableStateFlow(WelcomeViewModel.ViewAction.OpenConnectScreen), | ||
onSitePaymentClick = mockClickListener, | ||
onRedeemVoucherClick = {}, | ||
onSettingsClick = {}, | ||
openConnectScreen = {} | ||
) | ||
} | ||
|
||
// Act | ||
composeTestRule.apply { onNodeWithText("Buy credit").performClick() } | ||
|
||
// Assert | ||
verify(exactly = 1) { mockClickListener.invoke() } | ||
} | ||
|
||
@Test | ||
fun testClickRedeemVoucher() { | ||
// Arrange | ||
val mockClickListener: () -> Unit = mockk(relaxed = true) | ||
composeTestRule.setContent { | ||
WelcomeScreen( | ||
showSitePayment = true, | ||
uiState = WelcomeUiState(), | ||
viewActions = MutableStateFlow(WelcomeViewModel.ViewAction.OpenConnectScreen), | ||
onSitePaymentClick = {}, | ||
onRedeemVoucherClick = mockClickListener, | ||
onSettingsClick = {}, | ||
openConnectScreen = {} | ||
) | ||
} | ||
|
||
// Act | ||
composeTestRule.apply { onNodeWithText("Redeem voucher").performClick() } | ||
|
||
// Assert | ||
verify(exactly = 1) { mockClickListener.invoke() } | ||
} | ||
} |