Skip to content

Commit

Permalink
Fix remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawa committed Nov 21, 2023
1 parent b7dd1b8 commit e2d5d94
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class OutOfTimeScreenTest {
// Arrange
composeTestRule.setContentWithTheme {
OutOfTimeScreen(
showSitePayment = false,
uiState = OutOfTimeUiState(deviceName = ""),
onSitePaymentClick = {},
onRedeemVoucherClick = {},
Expand All @@ -60,8 +59,7 @@ class OutOfTimeScreenTest {
// Arrange
composeTestRule.setContentWithTheme {
OutOfTimeScreen(
showSitePayment = true,
uiState = OutOfTimeUiState(deviceName = ""),
uiState = OutOfTimeUiState(deviceName = "", showSitePayment = true),
onSitePaymentClick = {},
onRedeemVoucherClick = {},
onSettingsClick = {},
Expand All @@ -80,8 +78,7 @@ class OutOfTimeScreenTest {
val mockClickListener: () -> Unit = mockk(relaxed = true)
composeTestRule.setContentWithTheme {
OutOfTimeScreen(
showSitePayment = true,
uiState = OutOfTimeUiState(deviceName = ""),
uiState = OutOfTimeUiState(deviceName = "", showSitePayment = true),
onSitePaymentClick = mockClickListener,
onRedeemVoucherClick = {},
onSettingsClick = {},
Expand All @@ -103,8 +100,7 @@ class OutOfTimeScreenTest {
val mockClickListener: () -> Unit = mockk(relaxed = true)
composeTestRule.setContentWithTheme {
OutOfTimeScreen(
showSitePayment = true,
uiState = OutOfTimeUiState(deviceName = ""),
uiState = OutOfTimeUiState(deviceName = "", showSitePayment = true),
onSitePaymentClick = {},
onRedeemVoucherClick = mockClickListener,
onSettingsClick = {},
Expand All @@ -126,11 +122,11 @@ class OutOfTimeScreenTest {
val mockClickListener: () -> Unit = mockk(relaxed = true)
composeTestRule.setContentWithTheme {
OutOfTimeScreen(
showSitePayment = true,
uiState =
OutOfTimeUiState(
tunnelState = TunnelState.Connecting(null, null),
deviceName = ""
deviceName = "",
showSitePayment = true
),
onSitePaymentClick = {},
onRedeemVoucherClick = {},
Expand All @@ -152,8 +148,11 @@ class OutOfTimeScreenTest {
// Arrange
composeTestRule.setContentWithTheme {
OutOfTimeScreen(
showSitePayment = true,
uiState = OutOfTimeUiState().copy(billingPaymentState = PaymentState.Error.Billing),
uiState =
OutOfTimeUiState(
showSitePayment = true,
billingPaymentState = PaymentState.Error.Billing
),
onSitePaymentClick = {},
onRedeemVoucherClick = {},
onSettingsClick = {},
Expand All @@ -174,9 +173,9 @@ class OutOfTimeScreenTest {
every { mockPaymentProduct.status } returns null
composeTestRule.setContentWithTheme {
OutOfTimeScreen(
showSitePayment = true,
uiState =
OutOfTimeUiState(
showSitePayment = true,
billingPaymentState =
PaymentState.PaymentAvailable(listOf(mockPaymentProduct))
),
Expand All @@ -200,13 +199,12 @@ class OutOfTimeScreenTest {
every { mockPaymentProduct.status } returns PaymentStatus.PENDING
composeTestRule.setContentWithTheme {
OutOfTimeScreen(
showSitePayment = true,
uiState =
OutOfTimeUiState()
.copy(
billingPaymentState =
PaymentState.PaymentAvailable(listOf(mockPaymentProduct))
),
OutOfTimeUiState(
showSitePayment = true,
billingPaymentState =
PaymentState.PaymentAvailable(listOf(mockPaymentProduct))
),
)
}

Expand All @@ -223,13 +221,12 @@ class OutOfTimeScreenTest {
val mockNavigateToVerificationPending: () -> Unit = mockk(relaxed = true)
composeTestRule.setContentWithTheme {
OutOfTimeScreen(
showSitePayment = true,
uiState =
OutOfTimeUiState()
.copy(
billingPaymentState =
PaymentState.PaymentAvailable(listOf(mockPaymentProduct))
),
OutOfTimeUiState(
showSitePayment = true,
billingPaymentState =
PaymentState.PaymentAvailable(listOf(mockPaymentProduct))
),
navigateToVerificationPendingDialog = mockNavigateToVerificationPending
)
}
Expand All @@ -249,13 +246,12 @@ class OutOfTimeScreenTest {
every { mockPaymentProduct.status } returns PaymentStatus.VERIFICATION_IN_PROGRESS
composeTestRule.setContentWithTheme {
OutOfTimeScreen(
showSitePayment = true,
uiState =
OutOfTimeUiState()
.copy(
billingPaymentState =
PaymentState.PaymentAvailable(listOf(mockPaymentProduct))
),
OutOfTimeUiState(
billingPaymentState =
PaymentState.PaymentAvailable(listOf(mockPaymentProduct)),
showSitePayment = true,
)
)
}

Expand All @@ -273,11 +269,11 @@ class OutOfTimeScreenTest {
every { mockPaymentProduct.status } returns null
composeTestRule.setContentWithTheme {
OutOfTimeScreen(
showSitePayment = true,
uiState =
OutOfTimeUiState(
billingPaymentState =
PaymentState.PaymentAvailable(listOf(mockPaymentProduct))
PaymentState.PaymentAvailable(listOf(mockPaymentProduct)),
showSitePayment = true,
),
onSitePaymentClick = {},
onRedeemVoucherClick = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import io.mockk.MockKAnnotations
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asSharedFlow
import net.mullvad.mullvadvpn.compose.setContentWithTheme
import net.mullvad.mullvadvpn.compose.state.PaymentState
import net.mullvad.mullvadvpn.compose.state.WelcomeUiState
Expand All @@ -19,7 +16,6 @@ import net.mullvad.mullvadvpn.lib.payment.model.PaymentProduct
import net.mullvad.mullvadvpn.lib.payment.model.PaymentStatus
import net.mullvad.mullvadvpn.lib.payment.model.ProductId
import net.mullvad.mullvadvpn.lib.payment.model.ProductPrice
import net.mullvad.mullvadvpn.viewmodel.WelcomeViewModel
import org.junit.Before
import org.junit.Rule
import org.junit.Test
Expand All @@ -38,12 +34,10 @@ class WelcomeScreenTest {
composeTestRule.setContentWithTheme {
WelcomeScreen(
uiState = WelcomeUiState(),
uiSideEffect = MutableSharedFlow(),
onSitePaymentClick = {},
onRedeemVoucherClick = {},
onSettingsClick = {},
onAccountClick = {},
openConnectScreen = {},
navigateToDeviceInfoDialog = {},
onPurchaseBillingProductClick = { _ -> },
navigateToVerificationPendingDialog = {}
Expand All @@ -63,12 +57,10 @@ class WelcomeScreenTest {
composeTestRule.setContentWithTheme {
WelcomeScreen(
uiState = WelcomeUiState(),
uiSideEffect = MutableSharedFlow(),
onSitePaymentClick = {},
onRedeemVoucherClick = {},
onSettingsClick = {},
onAccountClick = {},
openConnectScreen = {},
navigateToDeviceInfoDialog = {},
onPurchaseBillingProductClick = { _ -> },
navigateToVerificationPendingDialog = {}
Expand All @@ -94,12 +86,10 @@ class WelcomeScreenTest {
composeTestRule.setContentWithTheme {
WelcomeScreen(
uiState = WelcomeUiState(accountNumber = rawAccountNumber),
uiSideEffect = MutableSharedFlow(),
onSitePaymentClick = {},
onRedeemVoucherClick = {},
onSettingsClick = {},
onAccountClick = {},
openConnectScreen = {},
onPurchaseBillingProductClick = { _ -> },
navigateToDeviceInfoDialog = {},
navigateToVerificationPendingDialog = {}
Expand All @@ -110,65 +100,17 @@ class WelcomeScreenTest {
composeTestRule.apply { onNodeWithText(expectedAccountNumber).assertExists() }
}

@Test
fun testOpenAccountView() {
// Arrange
composeTestRule.setContentWithTheme {
WelcomeScreen(
uiState = WelcomeUiState(),
uiSideEffect =
MutableStateFlow(WelcomeViewModel.UiSideEffect.OpenAccountView("222")),
onSitePaymentClick = {},
onRedeemVoucherClick = {},
onSettingsClick = {},
onAccountClick = {},
openConnectScreen = {},
onPurchaseBillingProductClick = { _ -> },
navigateToDeviceInfoDialog = {},
navigateToVerificationPendingDialog = {}
)
}

// Assert
composeTestRule.apply { onNodeWithText("Congrats!").assertDoesNotExist() }
}

@Test
fun testOpenConnectScreen() {
// Arrange
val mockClickListener: () -> Unit = mockk(relaxed = true)
composeTestRule.setContentWithTheme {
WelcomeScreen(
uiState = WelcomeUiState(),
uiSideEffect = MutableStateFlow(WelcomeViewModel.UiSideEffect.OpenConnectScreen),
onSitePaymentClick = {},
onRedeemVoucherClick = {},
onSettingsClick = {},
onAccountClick = {},
openConnectScreen = mockClickListener,
onPurchaseBillingProductClick = { _ -> },
navigateToVerificationPendingDialog = {},
navigateToDeviceInfoDialog = {}
)
}

// Assert
verify(exactly = 1) { mockClickListener.invoke() }
}

@Test
fun testClickSitePaymentButton() {
// Arrange
val mockClickListener: () -> Unit = mockk(relaxed = true)
composeTestRule.setContentWithTheme {
WelcomeScreen(
uiState = WelcomeUiState(showSitePayment = true),
uiSideEffect = MutableStateFlow(WelcomeViewModel.UiSideEffect.OpenConnectScreen),
onSitePaymentClick = mockClickListener,
onRedeemVoucherClick = {},
onSettingsClick = {},
onAccountClick = {},
openConnectScreen = {},
onPurchaseBillingProductClick = { _ -> },
navigateToVerificationPendingDialog = {},
navigateToDeviceInfoDialog = {}
Expand All @@ -189,12 +131,10 @@ class WelcomeScreenTest {
composeTestRule.setContentWithTheme {
WelcomeScreen(
uiState = WelcomeUiState(),
uiSideEffect = MutableStateFlow(WelcomeViewModel.UiSideEffect.OpenConnectScreen),
onSitePaymentClick = {},
onRedeemVoucherClick = mockClickListener,
onSettingsClick = {},
onAccountClick = {},
openConnectScreen = {},
onPurchaseBillingProductClick = { _ -> },
navigateToVerificationPendingDialog = {},
navigateToDeviceInfoDialog = {}
Expand All @@ -214,12 +154,10 @@ class WelcomeScreenTest {
composeTestRule.setContentWithTheme {
WelcomeScreen(
uiState = WelcomeUiState().copy(billingPaymentState = PaymentState.Error.Billing),
uiSideEffect = MutableSharedFlow<WelcomeViewModel.UiSideEffect>().asSharedFlow(),
onSitePaymentClick = {},
onRedeemVoucherClick = {},
onSettingsClick = {},
onAccountClick = {},
openConnectScreen = {},
onPurchaseBillingProductClick = { _ -> },
navigateToVerificationPendingDialog = {},
navigateToDeviceInfoDialog = {}
Expand All @@ -243,12 +181,10 @@ class WelcomeScreenTest {
billingPaymentState =
PaymentState.PaymentAvailable(listOf(mockPaymentProduct))
),
uiSideEffect = MutableStateFlow(WelcomeViewModel.UiSideEffect.OpenConnectScreen),
onSitePaymentClick = {},
onRedeemVoucherClick = {},
onSettingsClick = {},
onAccountClick = {},
openConnectScreen = {},
onPurchaseBillingProductClick = { _ -> },
navigateToVerificationPendingDialog = {},
navigateToDeviceInfoDialog = {}
Expand All @@ -273,12 +209,10 @@ class WelcomeScreenTest {
billingPaymentState =
PaymentState.PaymentAvailable(listOf(mockPaymentProduct))
),
uiSideEffect = MutableSharedFlow<WelcomeViewModel.UiSideEffect>().asSharedFlow(),
onSitePaymentClick = {},
onRedeemVoucherClick = {},
onSettingsClick = {},
onAccountClick = {},
openConnectScreen = {},
onPurchaseBillingProductClick = { _ -> },
navigateToVerificationPendingDialog = {},
navigateToDeviceInfoDialog = {}
Expand All @@ -304,12 +238,10 @@ class WelcomeScreenTest {
billingPaymentState =
PaymentState.PaymentAvailable(listOf(mockPaymentProduct))
),
uiSideEffect = MutableSharedFlow<WelcomeViewModel.UiSideEffect>().asSharedFlow(),
onSitePaymentClick = {},
onRedeemVoucherClick = {},
onSettingsClick = {},
onAccountClick = {},
openConnectScreen = {},
onPurchaseBillingProductClick = { _ -> },
navigateToVerificationPendingDialog = mockShowPendingInfo,
navigateToDeviceInfoDialog = {}
Expand Down Expand Up @@ -337,12 +269,10 @@ class WelcomeScreenTest {
billingPaymentState =
PaymentState.PaymentAvailable(listOf(mockPaymentProduct))
),
uiSideEffect = MutableSharedFlow<WelcomeViewModel.UiSideEffect>().asSharedFlow(),
onSitePaymentClick = {},
onRedeemVoucherClick = {},
onSettingsClick = {},
onAccountClick = {},
openConnectScreen = {},
onPurchaseBillingProductClick = { _ -> },
navigateToVerificationPendingDialog = {},
navigateToDeviceInfoDialog = {}
Expand All @@ -368,12 +298,10 @@ class WelcomeScreenTest {
billingPaymentState =
PaymentState.PaymentAvailable(listOf(mockPaymentProduct))
),
uiSideEffect = MutableStateFlow(WelcomeViewModel.UiSideEffect.OpenConnectScreen),
onSitePaymentClick = {},
onRedeemVoucherClick = {},
onSettingsClick = {},
onAccountClick = {},
openConnectScreen = {},
onPurchaseBillingProductClick = clickHandler,
navigateToVerificationPendingDialog = {},
navigateToDeviceInfoDialog = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import net.mullvad.mullvadvpn.compose.destinations.VerificationPendingDialogDest
import net.mullvad.mullvadvpn.compose.extensions.createOpenAccountPageHook
import net.mullvad.mullvadvpn.compose.state.OutOfTimeUiState
import net.mullvad.mullvadvpn.compose.transitions.NoTransition
import net.mullvad.mullvadvpn.constant.IS_PLAY_BUILD
import net.mullvad.mullvadvpn.lib.payment.model.ProductId
import net.mullvad.mullvadvpn.lib.theme.AppTheme
import net.mullvad.mullvadvpn.lib.theme.Dimens
Expand Down
Loading

0 comments on commit e2d5d94

Please sign in to comment.