Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Pururun committed Jun 13, 2024
1 parent 8ad4d33 commit 4742869
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,5 @@ sealed interface TestApiAccessMethodState {
data object Successful : Result

data object Failure : Result

fun isSuccessful() = this is Successful
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -89,7 +87,6 @@ class SaveApiAccessMethodViewModelTest {

// Act, Assert
saveApiAccessMethodViewModel.uiState.test {
// After successful test
assertEquals(
SaveApiAccessMethodUiState(
testingState = TestApiAccessMethodState.Result.Failure,
Expand Down

0 comments on commit 4742869

Please sign in to comment.