From 47428699361ef974beec2a889888fd90e6f0afa4 Mon Sep 17 00:00:00 2001 From: Jonatan Rhodin Date: Thu, 13 Jun 2024 10:27:55 +0200 Subject: [PATCH] Minor fixes --- .../compose/screen/ApiAccessListScreenTest.kt | 1 - .../dialog/SaveApiAccessMethodDialog.kt | 6 ++++-- .../state/SaveApiAccessMethodUiState.kt | 2 -- .../viewmodel/EditApiAccessMethodViewModel.kt | 18 ++++-------------- .../ApiAccessMethodDetailsViewModelTest.kt | 2 +- .../SaveApiAccessMethodViewModelTest.kt | 5 +---- 6 files changed, 10 insertions(+), 24 deletions(-) diff --git a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/ApiAccessListScreenTest.kt b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/ApiAccessListScreenTest.kt index 4efc09fe04ec..e80a2cb7d7eb 100644 --- a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/ApiAccessListScreenTest.kt +++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/ApiAccessListScreenTest.kt @@ -12,7 +12,6 @@ import net.mullvad.mullvadvpn.compose.setContentWithTheme import net.mullvad.mullvadvpn.compose.state.ApiAccessListUiState import net.mullvad.mullvadvpn.compose.test.API_ACCESS_LIST_INFO_TEST_TAG import net.mullvad.mullvadvpn.lib.model.ApiAccessMethod -import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.RegisterExtension diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/dialog/SaveApiAccessMethodDialog.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/dialog/SaveApiAccessMethodDialog.kt index e87188aadbbe..1630174e5b60 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/dialog/SaveApiAccessMethodDialog.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/dialog/SaveApiAccessMethodDialog.kt @@ -89,7 +89,9 @@ fun SaveApiAccessMethodDialog( painter = painterResource( id = - if (testingState.isSuccessful()) { + if ( + testingState is TestApiAccessMethodState.Result.Successful + ) { R.drawable.icon_success } else { R.drawable.icon_fail @@ -104,7 +106,7 @@ fun SaveApiAccessMethodDialog( } }, title = { Text(text = state.text(), style = MaterialTheme.typography.headlineSmall) }, - onDismissRequest = { /*Should not be able to dismiss*/}, + onDismissRequest = { /*Should not be able to dismiss*/ }, confirmButton = { PrimaryButton( onClick = onCancel, diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/SaveApiAccessMethodUiState.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/SaveApiAccessMethodUiState.kt index 0ee7b040267b..e38a4de569b6 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/SaveApiAccessMethodUiState.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/SaveApiAccessMethodUiState.kt @@ -12,7 +12,5 @@ sealed interface TestApiAccessMethodState { data object Successful : Result data object Failure : Result - - fun isSuccessful() = this is Successful } } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/EditApiAccessMethodViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/EditApiAccessMethodViewModel.kt index 235b99e16caa..6799c15ce67a 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/EditApiAccessMethodViewModel.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/EditApiAccessMethodViewModel.kt @@ -104,20 +104,10 @@ class EditApiAccessMethodViewModel( { errors -> formData.update { it.updateWithErrors(errors) } }, { customProxy -> isTestingApiAccessMethod.value = true - apiAccessRepository - .testCustomApiAccessMethod(customProxy) - .fold( - { - _uiSideEffect.send( - EditApiAccessSideEffect.TestApiAccessMethodResult(false) - ) - }, - { - _uiSideEffect.send( - EditApiAccessSideEffect.TestApiAccessMethodResult(true) - ) - }, - ) + val result = apiAccessRepository.testCustomApiAccessMethod(customProxy) + _uiSideEffect.send( + EditApiAccessSideEffect.TestApiAccessMethodResult(result.isRight()) + ) isTestingApiAccessMethod.value = false } ) diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/ApiAccessMethodDetailsViewModelTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/ApiAccessMethodDetailsViewModelTest.kt index ae978bb4e7a0..50cd30161cce 100644 --- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/ApiAccessMethodDetailsViewModelTest.kt +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/ApiAccessMethodDetailsViewModelTest.kt @@ -147,7 +147,7 @@ class ApiAccessMethodDetailsViewModelTest { } @Test - fun `when enable access method is not successful show error`() = runTest { + fun `when enable access method is not successful should show error`() = runTest { // Arrange coEvery { mockApiAccessRepository.setEnabledApiAccessMethod(apiAccessMethodId, true) diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/SaveApiAccessMethodViewModelTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/SaveApiAccessMethodViewModelTest.kt index fa6b936dc7d0..f1b02e001fec 100644 --- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/SaveApiAccessMethodViewModelTest.kt +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/SaveApiAccessMethodViewModelTest.kt @@ -18,7 +18,7 @@ import net.mullvad.mullvadvpn.lib.model.NewAccessMethod import net.mullvad.mullvadvpn.lib.model.TestApiAccessMethodError import net.mullvad.mullvadvpn.lib.model.UnknownApiAccessMethodError import net.mullvad.mullvadvpn.repository.ApiAccessRepository -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -29,8 +29,6 @@ class SaveApiAccessMethodViewModelTest { private lateinit var saveApiAccessMethodViewModel: SaveApiAccessMethodViewModel - @BeforeEach fun setUp() {} - @Test fun `when testing and updating an existing method successfully should do the correct steps`() = runTest { @@ -89,7 +87,6 @@ class SaveApiAccessMethodViewModelTest { // Act, Assert saveApiAccessMethodViewModel.uiState.test { - // After successful test assertEquals( SaveApiAccessMethodUiState( testingState = TestApiAccessMethodState.Result.Failure,