diff --git a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/ComposeRuleExtensions.kt b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/ComposeRuleExtensions.kt new file mode 100644 index 000000000000..69cd530b19f1 --- /dev/null +++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/ComposeRuleExtensions.kt @@ -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() } } +} diff --git a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/AccountScreenTest.kt b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/AccountScreenTest.kt index 41bf44936926..aec6c85595d4 100644 --- a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/AccountScreenTest.kt +++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/AccountScreenTest.kt @@ -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 @@ -27,7 +28,7 @@ class AccountScreenTest { @Test fun testDefaultState() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { AccountScreen( uiState = AccountUiState( @@ -52,7 +53,7 @@ class AccountScreenTest { fun testManageAccountClick() { // Arrange val mockedClickHandler: () -> Unit = mockk(relaxed = true) - composeTestRule.setContent { + composeTestRule.setContentWithTheme { AccountScreen( uiState = AccountUiState( @@ -78,7 +79,7 @@ class AccountScreenTest { fun testRedeemVoucherClick() { // Arrange val mockedClickHandler: () -> Unit = mockk(relaxed = true) - composeTestRule.setContent { + composeTestRule.setContentWithTheme { AccountScreen( uiState = AccountUiState( @@ -104,7 +105,7 @@ class AccountScreenTest { fun testLogoutClick() { // Arrange val mockedClickHandler: () -> Unit = mockk(relaxed = true) - composeTestRule.setContent { + composeTestRule.setContentWithTheme { AccountScreen( uiState = AccountUiState( diff --git a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/ChangelogDialogTest.kt b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/ChangelogDialogTest.kt index 778799c5899f..ab8f2b15123e 100644 --- a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/ChangelogDialogTest.kt +++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/ChangelogDialogTest.kt @@ -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 @@ -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 diff --git a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/ConnectScreenTest.kt b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/ConnectScreenTest.kt index 68cfa2b92c06..d6ef5d3311b1 100644 --- a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/ConnectScreenTest.kt +++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/ConnectScreenTest.kt @@ -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 @@ -53,7 +54,7 @@ class ConnectScreenTest { @Test fun testDefaultState() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { ConnectScreen( uiState = ConnectUiState.INITIAL, uiSideEffect = MutableSharedFlow().asSharedFlow() @@ -71,7 +72,7 @@ class ConnectScreenTest { @Test fun testConnectingState() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { ConnectScreen( uiState = ConnectUiState( @@ -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( @@ -143,7 +144,7 @@ class ConnectScreenTest { fun testConnectedState() { // Arrange val mockTunnelEndpoint: TunnelEndpoint = mockk(relaxed = true) - composeTestRule.setContent { + composeTestRule.setContentWithTheme { ConnectScreen( uiState = ConnectUiState( @@ -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( @@ -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( @@ -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( @@ -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( @@ -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( @@ -356,7 +357,7 @@ class ConnectScreenTest { @Test fun testReconnectingState() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { ConnectScreen( uiState = ConnectUiState( @@ -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( @@ -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( @@ -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( @@ -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( @@ -529,7 +530,7 @@ class ConnectScreenTest { fun testOnConnectClick() { // Arrange val mockedClickHandler: () -> Unit = mockk(relaxed = true) - composeTestRule.setContent { + composeTestRule.setContentWithTheme { ConnectScreen( uiState = ConnectUiState( @@ -561,7 +562,7 @@ class ConnectScreenTest { fun testOnCancelClick() { // Arrange val mockedClickHandler: () -> Unit = mockk(relaxed = true) - composeTestRule.setContent { + composeTestRule.setContentWithTheme { ConnectScreen( uiState = ConnectUiState( @@ -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( @@ -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( @@ -673,7 +674,7 @@ class ConnectScreenTest { isOutdated = true, isSupported = true ) - composeTestRule.setContent { + composeTestRule.setContentWithTheme { ConnectScreen( uiState = ConnectUiState( @@ -711,7 +712,7 @@ class ConnectScreenTest { isOutdated = true, isSupported = false ) - composeTestRule.setContent { + composeTestRule.setContentWithTheme { ConnectScreen( uiState = ConnectUiState( @@ -746,7 +747,7 @@ class ConnectScreenTest { fun testAccountExpiredNotification() { // Arrange val expiryDate = DateTime(2020, 11, 11, 10, 10) - composeTestRule.setContent { + composeTestRule.setContentWithTheme { ConnectScreen( uiState = ConnectUiState( @@ -785,7 +786,7 @@ class ConnectScreenTest { isOutdated = true, isSupported = false ) - composeTestRule.setContent { + composeTestRule.setContentWithTheme { ConnectScreen( onUpdateVersionClick = mockedClickHandler, uiState = @@ -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 = @@ -851,7 +852,7 @@ class ConnectScreenTest { @Test fun testOpenAccountView() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { ConnectScreen( uiState = ConnectUiState.INITIAL, uiSideEffect = @@ -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), diff --git a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/DeviceRevokedScreenTest.kt b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/DeviceRevokedScreenTest.kt index f7d40399fea0..56e24b9a08b8 100644 --- a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/DeviceRevokedScreenTest.kt +++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/DeviceRevokedScreenTest.kt @@ -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 @@ -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() @@ -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() @@ -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 diff --git a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/OutOfTimeScreenTest.kt b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/OutOfTimeScreenTest.kt index 95b44f82864a..b0198316e393 100644 --- a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/OutOfTimeScreenTest.kt +++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/OutOfTimeScreenTest.kt @@ -8,6 +8,7 @@ import io.mockk.mockk import io.mockk.verify import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow +import net.mullvad.mullvadvpn.compose.setContentWithTheme import net.mullvad.mullvadvpn.compose.state.OutOfTimeUiState import net.mullvad.mullvadvpn.model.TunnelState import net.mullvad.mullvadvpn.viewmodel.OutOfTimeViewModel @@ -26,7 +27,7 @@ class OutOfTimeScreenTest { @Test fun testDisableSitePayment() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { OutOfTimeScreen( showSitePayment = false, uiState = OutOfTimeUiState(deviceName = ""), @@ -54,7 +55,7 @@ class OutOfTimeScreenTest { @Test fun testOpenAccountView() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { OutOfTimeScreen( showSitePayment = true, uiState = OutOfTimeUiState(deviceName = ""), @@ -77,7 +78,7 @@ class OutOfTimeScreenTest { fun testOpenConnectScreen() { // Arrange val mockClickListener: () -> Unit = mockk(relaxed = true) - composeTestRule.setContent { + composeTestRule.setContentWithTheme { OutOfTimeScreen( showSitePayment = true, uiState = OutOfTimeUiState(deviceName = ""), @@ -99,7 +100,7 @@ class OutOfTimeScreenTest { fun testClickSitePaymentButton() { // Arrange val mockClickListener: () -> Unit = mockk(relaxed = true) - composeTestRule.setContent { + composeTestRule.setContentWithTheme { OutOfTimeScreen( showSitePayment = true, uiState = OutOfTimeUiState(deviceName = ""), @@ -124,7 +125,7 @@ class OutOfTimeScreenTest { fun testClickRedeemVoucher() { // Arrange val mockClickListener: () -> Unit = mockk(relaxed = true) - composeTestRule.setContent { + composeTestRule.setContentWithTheme { OutOfTimeScreen( showSitePayment = true, uiState = OutOfTimeUiState(deviceName = ""), @@ -149,7 +150,7 @@ class OutOfTimeScreenTest { fun testClickDisconnect() { // Arrange val mockClickListener: () -> Unit = mockk(relaxed = true) - composeTestRule.setContent { + composeTestRule.setContentWithTheme { OutOfTimeScreen( showSitePayment = true, uiState = diff --git a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/SelectLocationScreenTest.kt b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/SelectLocationScreenTest.kt index dd767b0c7a40..411d540f65e1 100644 --- a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/SelectLocationScreenTest.kt +++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/SelectLocationScreenTest.kt @@ -9,9 +9,9 @@ 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.compose.state.SelectLocationUiState import net.mullvad.mullvadvpn.compose.test.CIRCULAR_PROGRESS_INDICATOR -import net.mullvad.mullvadvpn.lib.theme.AppTheme import net.mullvad.mullvadvpn.model.PortRange import net.mullvad.mullvadvpn.model.RelayEndpointData import net.mullvad.mullvadvpn.model.RelayList @@ -35,7 +35,7 @@ class SelectLocationScreenTest { @Test fun testDefaultState() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { SelectLocationScreen( uiState = SelectLocationUiState.Loading, uiCloseAction = MutableSharedFlow(), @@ -50,7 +50,7 @@ class SelectLocationScreenTest { @Test fun testShowRelayListState() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { SelectLocationScreen( uiState = SelectLocationUiState.ShowData( @@ -87,18 +87,16 @@ class SelectLocationScreenTest { } // Arrange - composeTestRule.setContent { - AppTheme { - SelectLocationScreen( - uiState = - SelectLocationUiState.ShowData( - countries = updatedDummyList, - selectedRelay = updatedDummyList[0].cities[0].relays[0] - ), - uiCloseAction = MutableSharedFlow(), - enterTransitionEndAction = MutableSharedFlow().asSharedFlow() - ) - } + composeTestRule.setContentWithTheme { + SelectLocationScreen( + uiState = + SelectLocationUiState.ShowData( + countries = updatedDummyList, + selectedRelay = updatedDummyList[0].cities[0].relays[0] + ), + uiCloseAction = MutableSharedFlow(), + enterTransitionEndAction = MutableSharedFlow().asSharedFlow() + ) } // Assert @@ -116,19 +114,14 @@ class SelectLocationScreenTest { fun testSearchInput() { // Arrange val mockedSearchTermInput: (String) -> Unit = mockk(relaxed = true) - composeTestRule.setContent { - AppTheme { - SelectLocationScreen( - uiState = - SelectLocationUiState.ShowData( - countries = emptyList(), - selectedRelay = null - ), - uiCloseAction = MutableSharedFlow(), - enterTransitionEndAction = MutableSharedFlow().asSharedFlow(), - onSearchTermInput = mockedSearchTermInput - ) - } + composeTestRule.setContentWithTheme { + SelectLocationScreen( + uiState = + SelectLocationUiState.ShowData(countries = emptyList(), selectedRelay = null), + uiCloseAction = MutableSharedFlow(), + enterTransitionEndAction = MutableSharedFlow().asSharedFlow(), + onSearchTermInput = mockedSearchTermInput + ) } val mockSearchString = "SEARCH" @@ -144,16 +137,13 @@ class SelectLocationScreenTest { // Arrange val mockedSearchTermInput: (String) -> Unit = mockk(relaxed = true) val mockSearchString = "SEARCH" - composeTestRule.setContent { - AppTheme { - SelectLocationScreen( - uiState = - SelectLocationUiState.NoSearchResultFound(searchTerm = mockSearchString), - uiCloseAction = MutableSharedFlow(), - enterTransitionEndAction = MutableSharedFlow().asSharedFlow(), - onSearchTermInput = mockedSearchTermInput - ) - } + composeTestRule.setContentWithTheme { + SelectLocationScreen( + uiState = SelectLocationUiState.NoSearchResultFound(searchTerm = mockSearchString), + uiCloseAction = MutableSharedFlow(), + enterTransitionEndAction = MutableSharedFlow().asSharedFlow(), + onSearchTermInput = mockedSearchTermInput + ) } // Assert diff --git a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/SettingsScreenTest.kt b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/SettingsScreenTest.kt index 6a163dbbb0b2..576660551e6a 100644 --- a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/SettingsScreenTest.kt +++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/SettingsScreenTest.kt @@ -6,6 +6,7 @@ import androidx.compose.ui.test.onNodeWithText import io.mockk.MockKAnnotations import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.asSharedFlow +import net.mullvad.mullvadvpn.compose.setContentWithTheme import net.mullvad.mullvadvpn.compose.state.SettingsUiState import org.junit.Before import org.junit.Rule @@ -23,7 +24,7 @@ class SettingsScreenTest { @OptIn(ExperimentalMaterial3Api::class) fun testLoggedInState() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { SettingsScreen( uiState = SettingsUiState(appVersion = "", isLoggedIn = true, isUpdateAvailable = true), @@ -42,7 +43,7 @@ class SettingsScreenTest { @OptIn(ExperimentalMaterial3Api::class) fun testLoggedOutState() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { SettingsScreen( uiState = SettingsUiState(appVersion = "", isLoggedIn = false, isUpdateAvailable = true), diff --git a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/SplitTunnelingScreenTest.kt b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/SplitTunnelingScreenTest.kt index 8b2f2394c0aa..05709d089bd3 100644 --- a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/SplitTunnelingScreenTest.kt +++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/SplitTunnelingScreenTest.kt @@ -11,6 +11,7 @@ import io.mockk.unmockkAll import io.mockk.verify import net.mullvad.mullvadvpn.applist.AppData import net.mullvad.mullvadvpn.applist.ApplicationsIconManager +import net.mullvad.mullvadvpn.compose.setContentWithTheme import net.mullvad.mullvadvpn.compose.state.SplitTunnelingUiState import org.junit.After import org.junit.Before @@ -47,7 +48,9 @@ class SplitTunnelingScreenTest { @Test fun testLoadingState() { // Arrange - composeTestRule.setContent { SplitTunnelingScreen(uiState = SplitTunnelingUiState.Loading) } + composeTestRule.setContentWithTheme { + SplitTunnelingScreen(uiState = SplitTunnelingUiState.Loading) + } // Assert composeTestRule.apply { @@ -66,7 +69,7 @@ class SplitTunnelingScreenTest { AppData(packageName = EXCLUDED_APP_PACKAGE_NAME, iconRes = 0, name = EXCLUDED_APP_NAME) val includedApp = AppData(packageName = INCLUDED_APP_PACKAGE_NAME, iconRes = 0, name = INCLUDED_APP_NAME) - composeTestRule.setContent { + composeTestRule.setContentWithTheme { SplitTunnelingScreen( uiState = SplitTunnelingUiState.ShowAppList( @@ -94,7 +97,7 @@ class SplitTunnelingScreenTest { // Arrange val includedApp = AppData(packageName = INCLUDED_APP_PACKAGE_NAME, iconRes = 0, name = INCLUDED_APP_NAME) - composeTestRule.setContent { + composeTestRule.setContentWithTheme { SplitTunnelingScreen( uiState = SplitTunnelingUiState.ShowAppList( @@ -125,7 +128,7 @@ class SplitTunnelingScreenTest { val includedApp = AppData(packageName = INCLUDED_APP_PACKAGE_NAME, iconRes = 0, name = INCLUDED_APP_NAME) val mockedClickHandler: (String) -> Unit = mockk(relaxed = true) - composeTestRule.setContent { + composeTestRule.setContentWithTheme { SplitTunnelingScreen( uiState = SplitTunnelingUiState.ShowAppList( @@ -152,7 +155,7 @@ class SplitTunnelingScreenTest { val includedApp = AppData(packageName = INCLUDED_APP_PACKAGE_NAME, iconRes = 0, name = INCLUDED_APP_NAME) val mockedClickHandler: (String) -> Unit = mockk(relaxed = true) - composeTestRule.setContent { + composeTestRule.setContentWithTheme { SplitTunnelingScreen( uiState = SplitTunnelingUiState.ShowAppList( @@ -179,7 +182,7 @@ class SplitTunnelingScreenTest { val includedApp = AppData(packageName = INCLUDED_APP_PACKAGE_NAME, iconRes = 0, name = INCLUDED_APP_NAME) val mockedClickHandler: (Boolean) -> Unit = mockk(relaxed = true) - composeTestRule.setContent { + composeTestRule.setContentWithTheme { SplitTunnelingScreen( uiState = SplitTunnelingUiState.ShowAppList( diff --git a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/VpnSettingsScreenTest.kt b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/VpnSettingsScreenTest.kt index a9af28e08a8b..e5b7ebedb06f 100644 --- a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/VpnSettingsScreenTest.kt +++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/VpnSettingsScreenTest.kt @@ -15,6 +15,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.compose.state.VpnSettingsUiState import net.mullvad.mullvadvpn.compose.test.CUSTOM_PORT_DIALOG_INPUT_TEST_TAG import net.mullvad.mullvadvpn.compose.test.LAZY_LIST_LAST_ITEM_TEST_TAG @@ -46,7 +47,7 @@ class VpnSettingsScreenTest { @Test fun testDefaultState() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { VpnSettingsScreen( uiState = VpnSettingsUiState.DefaultUiState(), toastMessagesSharedFlow = MutableSharedFlow().asSharedFlow() @@ -72,7 +73,7 @@ class VpnSettingsScreenTest { @Test fun testMtuCustomValue() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { VpnSettingsScreen( uiState = VpnSettingsUiState.DefaultUiState(mtu = VALID_DUMMY_MTU_VALUE), toastMessagesSharedFlow = MutableSharedFlow().asSharedFlow() @@ -87,7 +88,7 @@ class VpnSettingsScreenTest { fun testMtuClick() { // Arrange val mockedClickHandler: () -> Unit = mockk(relaxed = true) - composeTestRule.setContent { + composeTestRule.setContentWithTheme { VpnSettingsScreen( uiState = VpnSettingsUiState.DefaultUiState(), onMtuCellClick = mockedClickHandler, @@ -105,7 +106,7 @@ class VpnSettingsScreenTest { @Test fun testMtuDialogWithDefaultValue() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { VpnSettingsScreen( uiState = VpnSettingsUiState.MtuDialogUiState(mtuEditValue = EMPTY_STRING), toastMessagesSharedFlow = MutableSharedFlow().asSharedFlow() @@ -119,7 +120,7 @@ class VpnSettingsScreenTest { @Test fun testMtuDialogWithEditValue() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { VpnSettingsScreen( uiState = VpnSettingsUiState.MtuDialogUiState(mtuEditValue = VALID_DUMMY_MTU_VALUE), toastMessagesSharedFlow = MutableSharedFlow().asSharedFlow() @@ -133,7 +134,7 @@ class VpnSettingsScreenTest { @Test fun testMtuDialogTextInput() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { VpnSettingsScreen( uiState = VpnSettingsUiState.MtuDialogUiState(mtuEditValue = EMPTY_STRING), toastMessagesSharedFlow = MutableSharedFlow().asSharedFlow() @@ -151,7 +152,7 @@ class VpnSettingsScreenTest { fun testMtuDialogSubmitOfValidValue() { // Arrange val mockedSubmitHandler: (Int) -> Unit = mockk(relaxed = true) - composeTestRule.setContent { + composeTestRule.setContentWithTheme { VpnSettingsScreen( uiState = VpnSettingsUiState.MtuDialogUiState(mtuEditValue = VALID_DUMMY_MTU_VALUE), onSaveMtuClick = mockedSubmitHandler, @@ -169,7 +170,7 @@ class VpnSettingsScreenTest { @Test fun testMtuDialogSubmitButtonDisabledWhenInvalidInput() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { VpnSettingsScreen( uiState = VpnSettingsUiState.MtuDialogUiState(mtuEditValue = INVALID_DUMMY_MTU_VALUE), @@ -185,7 +186,7 @@ class VpnSettingsScreenTest { fun testMtuDialogResetClick() { // Arrange val mockedClickHandler: () -> Unit = mockk(relaxed = true) - composeTestRule.setContent { + composeTestRule.setContentWithTheme { VpnSettingsScreen( uiState = VpnSettingsUiState.MtuDialogUiState(mtuEditValue = EMPTY_STRING), onRestoreMtuClick = mockedClickHandler, @@ -204,7 +205,7 @@ class VpnSettingsScreenTest { fun testMtuDialogCancelClick() { // Arrange val mockedClickHandler: () -> Unit = mockk(relaxed = true) - composeTestRule.setContent { + composeTestRule.setContentWithTheme { VpnSettingsScreen( uiState = VpnSettingsUiState.MtuDialogUiState(mtuEditValue = EMPTY_STRING), onCancelMtuDialogClick = mockedClickHandler, @@ -222,7 +223,7 @@ class VpnSettingsScreenTest { @Test fun testCustomDnsAddressesAndAddButtonVisibleWhenCustomDnsEnabled() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { VpnSettingsScreen( uiState = VpnSettingsUiState.DefaultUiState( @@ -253,7 +254,7 @@ class VpnSettingsScreenTest { @Test fun testCustomDnsAddressesAndAddButtonNotVisibleWhenCustomDnsDisabled() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { VpnSettingsScreen( uiState = VpnSettingsUiState.DefaultUiState( @@ -274,7 +275,7 @@ class VpnSettingsScreenTest { @Test fun testLanWarningNotShownWhenLanTrafficEnabledAndLocalAddressIsUsed() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { VpnSettingsScreen( uiState = VpnSettingsUiState.DefaultUiState( @@ -294,7 +295,7 @@ class VpnSettingsScreenTest { @Test fun testLanWarningNotShowedWhenLanTrafficDisabledAndLocalAddressIsNotUsed() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { VpnSettingsScreen( uiState = VpnSettingsUiState.DefaultUiState( @@ -314,7 +315,7 @@ class VpnSettingsScreenTest { @Test fun testLanWarningNotShowedWhenLanTrafficEnabledAndLocalAddressIsNotUsed() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { VpnSettingsScreen( uiState = VpnSettingsUiState.DefaultUiState( @@ -334,7 +335,7 @@ class VpnSettingsScreenTest { @Test fun testLanWarningShowedWhenAllowLanEnabledAndLocalDnsAddressIsUsed() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { VpnSettingsScreen( uiState = VpnSettingsUiState.DefaultUiState( @@ -360,7 +361,7 @@ class VpnSettingsScreenTest { fun testClickAddDns() { // Arrange val mockedClickHandler: (Int?) -> Unit = mockk(relaxed = true) - composeTestRule.setContent { + composeTestRule.setContentWithTheme { VpnSettingsScreen( uiState = VpnSettingsUiState.DefaultUiState(isCustomDnsEnabled = true), onDnsClick = mockedClickHandler, @@ -381,7 +382,7 @@ class VpnSettingsScreenTest { @Test fun testShowDnsDialogForNewDnsServer() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { VpnSettingsScreen( uiState = VpnSettingsUiState.DnsDialogUiState( @@ -401,7 +402,7 @@ class VpnSettingsScreenTest { @Test fun testShowDnsDialogForUpdatingDnsServer() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { VpnSettingsScreen( uiState = VpnSettingsUiState.DnsDialogUiState( @@ -422,7 +423,7 @@ class VpnSettingsScreenTest { @Test fun testDnsDialogLanWarningShownWhenLanTrafficDisabledAndLocalAddressUsed() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { VpnSettingsScreen( uiState = VpnSettingsUiState.DnsDialogUiState( @@ -444,7 +445,7 @@ class VpnSettingsScreenTest { @Test fun testDnsDialogLanWarningNotShownWhenLanTrafficEnabledAndLocalAddressUsed() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { VpnSettingsScreen( uiState = VpnSettingsUiState.DnsDialogUiState( @@ -466,7 +467,7 @@ class VpnSettingsScreenTest { @Test fun testDnsDialogLanWarningNotShownWhenLanTrafficEnabledAndNonLocalAddressUsed() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { VpnSettingsScreen( uiState = VpnSettingsUiState.DnsDialogUiState( @@ -488,7 +489,7 @@ class VpnSettingsScreenTest { @Test fun testDnsDialogLanWarningNotShownWhenLanTrafficDisabledAndNonLocalAddressUsed() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { VpnSettingsScreen( uiState = VpnSettingsUiState.DnsDialogUiState( @@ -510,7 +511,7 @@ class VpnSettingsScreenTest { @Test fun testDnsDialogSubmitButtonDisabledOnInvalidDnsAddress() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { VpnSettingsScreen( uiState = VpnSettingsUiState.DnsDialogUiState( @@ -531,7 +532,7 @@ class VpnSettingsScreenTest { @Test fun testDnsDialogSubmitButtonDisabledOnDuplicateDnsAddress() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { VpnSettingsScreen( uiState = VpnSettingsUiState.DnsDialogUiState( @@ -552,7 +553,7 @@ class VpnSettingsScreenTest { @Test fun testShowSelectedTunnelQuantumOption() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { VpnSettingsScreen( uiState = VpnSettingsUiState.DefaultUiState(quantumResistant = QuantumResistantState.On), @@ -574,7 +575,7 @@ class VpnSettingsScreenTest { // Arrange val mockSelectQuantumResistantSettingListener: (QuantumResistantState) -> Unit = mockk(relaxed = true) - composeTestRule.setContent { + composeTestRule.setContentWithTheme { VpnSettingsScreen( uiState = VpnSettingsUiState.DefaultUiState( @@ -600,7 +601,7 @@ class VpnSettingsScreenTest { @Test fun testShowTunnelQuantumInfo() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { VpnSettingsScreen( uiState = VpnSettingsUiState.QuantumResistanceInfoDialogUiState(), toastMessagesSharedFlow = MutableSharedFlow().asSharedFlow() @@ -614,7 +615,7 @@ class VpnSettingsScreenTest { @Test fun testShowWireguardPortOptions() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { VpnSettingsScreen( uiState = VpnSettingsUiState.DefaultUiState( @@ -645,7 +646,7 @@ class VpnSettingsScreenTest { // Arrange val mockSelectWireguardPortSelectionListener: (Constraint) -> Unit = mockk(relaxed = true) - composeTestRule.setContent { + composeTestRule.setContentWithTheme { VpnSettingsScreen( uiState = VpnSettingsUiState.DefaultUiState( @@ -678,7 +679,7 @@ class VpnSettingsScreenTest { @Test fun testShowWireguardPortInfo() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { VpnSettingsScreen( uiState = VpnSettingsUiState.WireguardPortInfoDialogUiState( @@ -699,7 +700,7 @@ class VpnSettingsScreenTest { @Test fun testShowWireguardCustomPortDialog() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { VpnSettingsScreen( uiState = VpnSettingsUiState.CustomPortDialogUiState( @@ -716,7 +717,7 @@ class VpnSettingsScreenTest { @Test fun testShowWireguardCustomPort() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { VpnSettingsScreen( uiState = VpnSettingsUiState.DefaultUiState( @@ -739,7 +740,7 @@ class VpnSettingsScreenTest { fun testClickWireguardCustomPortMainCell() { // Arrange val mockOnShowCustomPortDialog: () -> Unit = mockk(relaxed = true) - composeTestRule.setContent { + composeTestRule.setContentWithTheme { VpnSettingsScreen( uiState = VpnSettingsUiState.DefaultUiState(), onShowCustomPortDialog = mockOnShowCustomPortDialog, @@ -761,7 +762,7 @@ class VpnSettingsScreenTest { fun testClickWireguardCustomPortNumberCell() { // Arrange val mockOnShowCustomPortDialog: () -> Unit = mockk(relaxed = true) - composeTestRule.setContent { + composeTestRule.setContentWithTheme { VpnSettingsScreen( uiState = VpnSettingsUiState.DefaultUiState( @@ -788,7 +789,7 @@ class VpnSettingsScreenTest { fun testSelectWireguardCustomPort() { // Arrange val onWireguardPortSelected: (Constraint) -> Unit = mockk(relaxed = true) - composeTestRule.setContent { + composeTestRule.setContentWithTheme { VpnSettingsScreen( uiState = VpnSettingsUiState.DefaultUiState( @@ -817,7 +818,7 @@ class VpnSettingsScreenTest { // the app // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { VpnSettingsScreen( uiState = VpnSettingsUiState.CustomPortDialogUiState( diff --git a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/WelcomeScreenTest.kt b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/WelcomeScreenTest.kt index 4efa98225b3b..8331794cab0f 100644 --- a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/WelcomeScreenTest.kt +++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/WelcomeScreenTest.kt @@ -8,6 +8,7 @@ import io.mockk.mockk import io.mockk.verify import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow +import net.mullvad.mullvadvpn.compose.setContentWithTheme import net.mullvad.mullvadvpn.compose.state.WelcomeUiState import net.mullvad.mullvadvpn.viewmodel.WelcomeViewModel import org.junit.Before @@ -25,7 +26,7 @@ class WelcomeScreenTest { @Test fun testDefaultState() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { WelcomeScreen( showSitePayment = true, uiState = WelcomeUiState(), @@ -48,7 +49,7 @@ class WelcomeScreenTest { @Test fun testDisableSitePayment() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { WelcomeScreen( showSitePayment = false, uiState = WelcomeUiState(), @@ -77,7 +78,7 @@ class WelcomeScreenTest { // Arrange val rawAccountNumber = "1111222233334444" val expectedAccountNumber = "1111 2222 3333 4444" - composeTestRule.setContent { + composeTestRule.setContentWithTheme { WelcomeScreen( showSitePayment = true, uiState = WelcomeUiState(accountNumber = rawAccountNumber), @@ -97,7 +98,7 @@ class WelcomeScreenTest { @Test fun testOpenAccountView() { // Arrange - composeTestRule.setContent { + composeTestRule.setContentWithTheme { WelcomeScreen( showSitePayment = true, uiState = WelcomeUiState(), @@ -119,7 +120,7 @@ class WelcomeScreenTest { fun testOpenConnectScreen() { // Arrange val mockClickListener: () -> Unit = mockk(relaxed = true) - composeTestRule.setContent { + composeTestRule.setContentWithTheme { WelcomeScreen( showSitePayment = true, uiState = WelcomeUiState(), @@ -140,7 +141,7 @@ class WelcomeScreenTest { fun testClickSitePaymentButton() { // Arrange val mockClickListener: () -> Unit = mockk(relaxed = true) - composeTestRule.setContent { + composeTestRule.setContentWithTheme { WelcomeScreen( showSitePayment = true, uiState = WelcomeUiState(), @@ -164,7 +165,7 @@ class WelcomeScreenTest { fun testClickRedeemVoucher() { // Arrange val mockClickListener: () -> Unit = mockk(relaxed = true) - composeTestRule.setContent { + composeTestRule.setContentWithTheme { WelcomeScreen( showSitePayment = true, uiState = WelcomeUiState(), diff --git a/android/scripts/run-instrumented-tests-locally.sh b/android/scripts/run-instrumented-tests-locally.sh new file mode 100755 index 000000000000..359c648d30d9 --- /dev/null +++ b/android/scripts/run-instrumented-tests-locally.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +set -eu + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +cd $SCRIPT_DIR/.. +./gradlew assembleOssProdAndroidTest +./gradlew app:assembleOssProdDebug +$SCRIPT_DIR/run-instrumented-tests.sh app