Skip to content

Commit

Permalink
Wrap all tests in AppTheme
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawa authored and Pururun committed Oct 18, 2023
1 parent b6308af commit 926c049
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 141 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.mullvad.mullvadvpn.compose

import androidx.compose.runtime.Composable
import androidx.compose.ui.test.junit4.ComposeContentTestRule
import net.mullvad.mullvadvpn.lib.theme.AppTheme

fun ComposeContentTestRule.setContentWithTheme(content: @Composable () -> Unit) {
setContent { AppTheme { content() } }
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import io.mockk.mockk
import io.mockk.verify
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.asSharedFlow
import net.mullvad.mullvadvpn.compose.setContentWithTheme
import net.mullvad.mullvadvpn.viewmodel.AccountUiState
import net.mullvad.mullvadvpn.viewmodel.AccountViewModel
import org.junit.Before
Expand All @@ -27,7 +28,7 @@ class AccountScreenTest {
@Test
fun testDefaultState() {
// Arrange
composeTestRule.setContent {
composeTestRule.setContentWithTheme {
AccountScreen(
uiState =
AccountUiState(
Expand All @@ -52,7 +53,7 @@ class AccountScreenTest {
fun testManageAccountClick() {
// Arrange
val mockedClickHandler: () -> Unit = mockk(relaxed = true)
composeTestRule.setContent {
composeTestRule.setContentWithTheme {
AccountScreen(
uiState =
AccountUiState(
Expand All @@ -78,7 +79,7 @@ class AccountScreenTest {
fun testRedeemVoucherClick() {
// Arrange
val mockedClickHandler: () -> Unit = mockk(relaxed = true)
composeTestRule.setContent {
composeTestRule.setContentWithTheme {
AccountScreen(
uiState =
AccountUiState(
Expand All @@ -104,7 +105,7 @@ class AccountScreenTest {
fun testLogoutClick() {
// Arrange
val mockedClickHandler: () -> Unit = mockk(relaxed = true)
composeTestRule.setContent {
composeTestRule.setContentWithTheme {
AccountScreen(
uiState =
AccountUiState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import io.mockk.just
import io.mockk.verify
import kotlinx.coroutines.flow.MutableStateFlow
import net.mullvad.mullvadvpn.compose.dialog.ChangelogDialog
import net.mullvad.mullvadvpn.lib.theme.AppTheme
import net.mullvad.mullvadvpn.compose.setContentWithTheme
import net.mullvad.mullvadvpn.viewmodel.ChangelogDialogUiState
import net.mullvad.mullvadvpn.viewmodel.ChangelogViewModel
import org.junit.Before
Expand All @@ -35,14 +35,12 @@ class ChangelogDialogTest {
MutableStateFlow(ChangelogDialogUiState.Show(listOf(CHANGELOG_ITEM)))
every { mockedViewModel.dismissChangelogDialog() } just Runs

composeTestRule.setContent {
AppTheme {
ChangelogDialog(
changesList = listOf(CHANGELOG_ITEM),
version = CHANGELOG_VERSION,
onDismiss = { mockedViewModel.dismissChangelogDialog() }
)
}
composeTestRule.setContentWithTheme {
ChangelogDialog(
changesList = listOf(CHANGELOG_ITEM),
version = CHANGELOG_VERSION,
onDismiss = { mockedViewModel.dismissChangelogDialog() }
)
}

// Check changelog content showed within dialog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ 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.ConnectNotificationState
import net.mullvad.mullvadvpn.compose.state.ConnectUiState
import net.mullvad.mullvadvpn.compose.test.CIRCULAR_PROGRESS_INDICATOR
Expand Down Expand Up @@ -53,7 +54,7 @@ class ConnectScreenTest {
@Test
fun testDefaultState() {
// Arrange
composeTestRule.setContent {
composeTestRule.setContentWithTheme {
ConnectScreen(
uiState = ConnectUiState.INITIAL,
uiSideEffect = MutableSharedFlow<ConnectViewModel.UiSideEffect>().asSharedFlow()
Expand All @@ -71,7 +72,7 @@ class ConnectScreenTest {
@Test
fun testConnectingState() {
// Arrange
composeTestRule.setContent {
composeTestRule.setContentWithTheme {
ConnectScreen(
uiState =
ConnectUiState(
Expand Down Expand Up @@ -107,7 +108,7 @@ class ConnectScreenTest {
// Arrange
val mockTunnelEndpoint: TunnelEndpoint = mockk(relaxed = true)
every { mockTunnelEndpoint.quantumResistant } returns true
composeTestRule.setContent {
composeTestRule.setContentWithTheme {
ConnectScreen(
uiState =
ConnectUiState(
Expand Down Expand Up @@ -143,7 +144,7 @@ class ConnectScreenTest {
fun testConnectedState() {
// Arrange
val mockTunnelEndpoint: TunnelEndpoint = mockk(relaxed = true)
composeTestRule.setContent {
composeTestRule.setContentWithTheme {
ConnectScreen(
uiState =
ConnectUiState(
Expand Down Expand Up @@ -176,7 +177,7 @@ class ConnectScreenTest {
// Arrange
val mockTunnelEndpoint: TunnelEndpoint = mockk(relaxed = true)
every { mockTunnelEndpoint.quantumResistant } returns true
composeTestRule.setContent {
composeTestRule.setContentWithTheme {
ConnectScreen(
uiState =
ConnectUiState(
Expand Down Expand Up @@ -210,7 +211,7 @@ class ConnectScreenTest {
val mockRelayLocation: RelayItem = mockk(relaxed = true)
val mockLocationName = "Home"
every { mockRelayLocation.locationName } returns mockLocationName
composeTestRule.setContent {
composeTestRule.setContentWithTheme {
ConnectScreen(
uiState =
ConnectUiState(
Expand Down Expand Up @@ -244,7 +245,7 @@ class ConnectScreenTest {
val mockRelayLocation: RelayItem = mockk(relaxed = true)
val mockLocationName = "Home"
every { mockRelayLocation.locationName } returns mockLocationName
composeTestRule.setContent {
composeTestRule.setContentWithTheme {
ConnectScreen(
uiState =
ConnectUiState(
Expand Down Expand Up @@ -278,7 +279,7 @@ class ConnectScreenTest {
val mockRelayLocation: RelayItem = mockk(relaxed = true)
val mockLocationName = "Home"
every { mockRelayLocation.locationName } returns mockLocationName
composeTestRule.setContent {
composeTestRule.setContentWithTheme {
ConnectScreen(
uiState =
ConnectUiState(
Expand Down Expand Up @@ -318,7 +319,7 @@ class ConnectScreenTest {
val mockRelayLocation: RelayItem = mockk(relaxed = true)
val mockLocationName = "Home"
every { mockRelayLocation.locationName } returns mockLocationName
composeTestRule.setContent {
composeTestRule.setContentWithTheme {
ConnectScreen(
uiState =
ConnectUiState(
Expand Down Expand Up @@ -356,7 +357,7 @@ class ConnectScreenTest {
@Test
fun testReconnectingState() {
// Arrange
composeTestRule.setContent {
composeTestRule.setContentWithTheme {
ConnectScreen(
uiState =
ConnectUiState(
Expand Down Expand Up @@ -394,7 +395,7 @@ class ConnectScreenTest {
val mockRelayLocation: RelayItem = mockk(relaxed = true)
val mockLocationName = "Home"
every { mockRelayLocation.locationName } returns mockLocationName
composeTestRule.setContent {
composeTestRule.setContentWithTheme {
ConnectScreen(
uiState =
ConnectUiState(
Expand Down Expand Up @@ -431,7 +432,7 @@ class ConnectScreenTest {
val mockLocationName = "Home"
every { mockRelayLocation.locationName } returns mockLocationName
val mockedClickHandler: () -> Unit = mockk(relaxed = true)
composeTestRule.setContent {
composeTestRule.setContentWithTheme {
ConnectScreen(
uiState =
ConnectUiState(
Expand Down Expand Up @@ -464,7 +465,7 @@ class ConnectScreenTest {
// Arrange
val mockTunnelEndpoint: TunnelEndpoint = mockk(relaxed = true)
val mockedClickHandler: () -> Unit = mockk(relaxed = true)
composeTestRule.setContent {
composeTestRule.setContentWithTheme {
ConnectScreen(
uiState =
ConnectUiState(
Expand Down Expand Up @@ -497,7 +498,7 @@ class ConnectScreenTest {
// Arrange
val mockTunnelEndpoint: TunnelEndpoint = mockk(relaxed = true)
val mockedClickHandler: () -> Unit = mockk(relaxed = true)
composeTestRule.setContent {
composeTestRule.setContentWithTheme {
ConnectScreen(
uiState =
ConnectUiState(
Expand Down Expand Up @@ -529,7 +530,7 @@ class ConnectScreenTest {
fun testOnConnectClick() {
// Arrange
val mockedClickHandler: () -> Unit = mockk(relaxed = true)
composeTestRule.setContent {
composeTestRule.setContentWithTheme {
ConnectScreen(
uiState =
ConnectUiState(
Expand Down Expand Up @@ -561,7 +562,7 @@ class ConnectScreenTest {
fun testOnCancelClick() {
// Arrange
val mockedClickHandler: () -> Unit = mockk(relaxed = true)
composeTestRule.setContent {
composeTestRule.setContentWithTheme {
ConnectScreen(
uiState =
ConnectUiState(
Expand Down Expand Up @@ -594,7 +595,7 @@ class ConnectScreenTest {
// Arrange
val mockedClickHandler: () -> Unit = mockk(relaxed = true)
val dummyLocation = GeoIpLocation(null, null, "dummy country", null, "dummy hostname")
composeTestRule.setContent {
composeTestRule.setContentWithTheme {
ConnectScreen(
uiState =
ConnectUiState(
Expand Down Expand Up @@ -634,7 +635,7 @@ class ConnectScreenTest {
val mockInAddress = Triple(mockHost, mockPort, mockProtocol)
val mockOutAddress = "HostAddressV4 / HostAddressV4"
every { mockLocation.hostname } returns mockHostName
composeTestRule.setContent {
composeTestRule.setContentWithTheme {
ConnectScreen(
uiState =
ConnectUiState(
Expand Down Expand Up @@ -673,7 +674,7 @@ class ConnectScreenTest {
isOutdated = true,
isSupported = true
)
composeTestRule.setContent {
composeTestRule.setContentWithTheme {
ConnectScreen(
uiState =
ConnectUiState(
Expand Down Expand Up @@ -711,7 +712,7 @@ class ConnectScreenTest {
isOutdated = true,
isSupported = false
)
composeTestRule.setContent {
composeTestRule.setContentWithTheme {
ConnectScreen(
uiState =
ConnectUiState(
Expand Down Expand Up @@ -746,7 +747,7 @@ class ConnectScreenTest {
fun testAccountExpiredNotification() {
// Arrange
val expiryDate = DateTime(2020, 11, 11, 10, 10)
composeTestRule.setContent {
composeTestRule.setContentWithTheme {
ConnectScreen(
uiState =
ConnectUiState(
Expand Down Expand Up @@ -785,7 +786,7 @@ class ConnectScreenTest {
isOutdated = true,
isSupported = false
)
composeTestRule.setContent {
composeTestRule.setContentWithTheme {
ConnectScreen(
onUpdateVersionClick = mockedClickHandler,
uiState =
Expand Down Expand Up @@ -819,7 +820,7 @@ class ConnectScreenTest {
// Arrange
val mockedClickHandler: () -> Unit = mockk(relaxed = true)
val expiryDate = DateTime(2020, 11, 11, 10, 10)
composeTestRule.setContent {
composeTestRule.setContentWithTheme {
ConnectScreen(
onManageAccountClick = mockedClickHandler,
uiState =
Expand Down Expand Up @@ -851,7 +852,7 @@ class ConnectScreenTest {
@Test
fun testOpenAccountView() {
// Arrange
composeTestRule.setContent {
composeTestRule.setContentWithTheme {
ConnectScreen(
uiState = ConnectUiState.INITIAL,
uiSideEffect =
Expand All @@ -869,7 +870,7 @@ class ConnectScreenTest {
fun testOpenOutOfTimeScreen() {
// Arrange
val mockedOpenScreenHandler: () -> Unit = mockk(relaxed = true)
composeTestRule.setContent {
composeTestRule.setContentWithTheme {
ConnectScreen(
uiState = ConnectUiState.INITIAL,
uiSideEffect = MutableStateFlow(ConnectViewModel.UiSideEffect.OpenOutOfTimeView),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import androidx.compose.ui.test.performClick
import io.mockk.MockKAnnotations
import io.mockk.mockk
import io.mockk.verify
import net.mullvad.mullvadvpn.compose.setContentWithTheme
import net.mullvad.mullvadvpn.compose.state.DeviceRevokedUiState
import net.mullvad.mullvadvpn.lib.theme.AppTheme
import org.junit.Before
import org.junit.Rule
import org.junit.Test
Expand All @@ -26,7 +26,7 @@ class DeviceRevokedScreenTest {
val state = DeviceRevokedUiState.SECURED

// Act
composeTestRule.setContent { AppTheme { DeviceRevokedScreen(state) } }
composeTestRule.setContentWithTheme { DeviceRevokedScreen(state) }

// Assert
composeTestRule.onNodeWithText(UNBLOCK_WARNING).assertExists()
Expand All @@ -38,7 +38,7 @@ class DeviceRevokedScreenTest {
val state = DeviceRevokedUiState.UNSECURED

// Act
composeTestRule.setContent { AppTheme { DeviceRevokedScreen(state) } }
composeTestRule.setContentWithTheme { DeviceRevokedScreen(state) }

// Assert
composeTestRule.onNodeWithText(UNBLOCK_WARNING).assertDoesNotExist()
Expand All @@ -49,10 +49,8 @@ class DeviceRevokedScreenTest {
// Arrange
val state = DeviceRevokedUiState.UNSECURED
val mockOnGoToLoginClicked: () -> Unit = mockk(relaxed = true)
composeTestRule.setContent {
AppTheme {
DeviceRevokedScreen(state = state, onGoToLoginClicked = mockOnGoToLoginClicked)
}
composeTestRule.setContentWithTheme {
DeviceRevokedScreen(state = state, onGoToLoginClicked = mockOnGoToLoginClicked)
}

// Act
Expand Down
Loading

0 comments on commit 926c049

Please sign in to comment.