-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add api access method details ui tests
- Loading branch information
Showing
6 changed files
with
304 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
258 changes: 258 additions & 0 deletions
258
...roidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/ApiAccessMethodDetailsScreenTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,258 @@ | ||
package net.mullvad.mullvadvpn.compose.screen | ||
|
||
import androidx.compose.ui.test.ExperimentalTestApi | ||
import androidx.compose.ui.test.assertIsNotEnabled | ||
import androidx.compose.ui.test.onNodeWithTag | ||
import androidx.compose.ui.test.onNodeWithText | ||
import androidx.compose.ui.test.performClick | ||
import io.mockk.mockk | ||
import io.mockk.verify | ||
import net.mullvad.mullvadvpn.compose.createEdgeToEdgeComposeExtension | ||
import net.mullvad.mullvadvpn.compose.data.CUSTOM_ACCESS_METHOD | ||
import net.mullvad.mullvadvpn.compose.data.DIRECT_ACCESS_METHOD | ||
import net.mullvad.mullvadvpn.compose.setContentWithTheme | ||
import net.mullvad.mullvadvpn.compose.state.ApiAccessMethodDetailsUiState | ||
import net.mullvad.mullvadvpn.compose.test.API_ACCESS_DETAILS_EDIT_BUTTON | ||
import net.mullvad.mullvadvpn.compose.test.API_ACCESS_DETAILS_TOP_BAR_DROPDOWN_BUTTON_TEST_TAG | ||
import net.mullvad.mullvadvpn.compose.test.API_ACCESS_TEST_METHOD_BUTTON | ||
import net.mullvad.mullvadvpn.compose.test.API_ACCESS_USE_METHOD_BUTTON | ||
import net.mullvad.mullvadvpn.lib.model.ApiAccessMethodId | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.RegisterExtension | ||
|
||
@OptIn(ExperimentalTestApi::class) | ||
class ApiAccessMethodDetailsScreenTest { | ||
@JvmField @RegisterExtension val composeExtension = createEdgeToEdgeComposeExtension() | ||
|
||
@Test | ||
fun whenApiAccessMethodIsNotEditableShouldNotShowDeleteAndEdit() = | ||
composeExtension.use { | ||
// Arrange | ||
val apiAccessMethod = DIRECT_ACCESS_METHOD | ||
setContentWithTheme { | ||
ApiAccessMethodDetailsScreen( | ||
state = | ||
ApiAccessMethodDetailsUiState.Content( | ||
apiAccessMethodId = apiAccessMethod.id, | ||
name = apiAccessMethod.name, | ||
enabled = apiAccessMethod.enabled, | ||
isEditable = false, | ||
isDisableable = true, | ||
isCurrentMethod = true, | ||
testApiAccessMethodState = null | ||
) | ||
) | ||
} | ||
|
||
// Assert | ||
onNodeWithTag(API_ACCESS_DETAILS_TOP_BAR_DROPDOWN_BUTTON_TEST_TAG).assertDoesNotExist() | ||
onNodeWithTag(API_ACCESS_DETAILS_EDIT_BUTTON).assertDoesNotExist() | ||
} | ||
|
||
@Test | ||
fun whenApiAccessMethodIsNotDisableableShouldNotBeAbleDisable() = | ||
composeExtension.use { | ||
// Arrange | ||
val onEnableClicked: (Boolean) -> Unit = mockk(relaxed = true) | ||
val apiAccessMethod = DIRECT_ACCESS_METHOD | ||
setContentWithTheme { | ||
ApiAccessMethodDetailsScreen( | ||
state = | ||
ApiAccessMethodDetailsUiState.Content( | ||
apiAccessMethodId = apiAccessMethod.id, | ||
name = apiAccessMethod.name, | ||
enabled = apiAccessMethod.enabled, | ||
isEditable = false, | ||
isDisableable = false, | ||
isCurrentMethod = true, | ||
testApiAccessMethodState = null | ||
), | ||
onEnableClicked = onEnableClicked | ||
) | ||
} | ||
|
||
// Act | ||
onNodeWithText("Enable method").performClick() | ||
|
||
// Assert | ||
onNodeWithText("At least one method needs to be enabled") | ||
verify(exactly = 0) { onEnableClicked(any()) } | ||
} | ||
|
||
@Test | ||
fun whenApiAccessMethodIsCurrentMethodShouldNotBeAbleToSetCurrent() = | ||
composeExtension.use { | ||
// Arrange | ||
val onUseMethodClicked: () -> Unit = mockk(relaxed = true) | ||
val apiAccessMethod = DIRECT_ACCESS_METHOD | ||
setContentWithTheme { | ||
ApiAccessMethodDetailsScreen( | ||
state = | ||
ApiAccessMethodDetailsUiState.Content( | ||
apiAccessMethodId = apiAccessMethod.id, | ||
name = apiAccessMethod.name, | ||
enabled = apiAccessMethod.enabled, | ||
isEditable = false, | ||
isDisableable = false, | ||
isCurrentMethod = true, | ||
testApiAccessMethodState = null | ||
), | ||
onUseMethodClicked = onUseMethodClicked | ||
) | ||
} | ||
|
||
// Act | ||
onNodeWithTag(API_ACCESS_USE_METHOD_BUTTON).performClick() | ||
|
||
// Assert | ||
onNodeWithTag(API_ACCESS_USE_METHOD_BUTTON).assertIsNotEnabled() | ||
onNodeWithText("This is already set as current") | ||
verify(exactly = 0) { onUseMethodClicked() } | ||
} | ||
|
||
@Test | ||
fun whenClickingOnDeleteMethodShouldCallOnDeleteApiAccessMethodClicked() = | ||
composeExtension.use { | ||
// Arrange | ||
val onDeleteApiAccessMethodClicked: (ApiAccessMethodId) -> Unit = mockk(relaxed = true) | ||
val apiAccessMethod = CUSTOM_ACCESS_METHOD | ||
setContentWithTheme { | ||
ApiAccessMethodDetailsScreen( | ||
state = | ||
ApiAccessMethodDetailsUiState.Content( | ||
apiAccessMethodId = apiAccessMethod.id, | ||
name = apiAccessMethod.name, | ||
enabled = apiAccessMethod.enabled, | ||
isEditable = true, | ||
isDisableable = false, | ||
isCurrentMethod = true, | ||
testApiAccessMethodState = null | ||
), | ||
onDeleteApiAccessMethodClicked = onDeleteApiAccessMethodClicked | ||
) | ||
} | ||
|
||
// Act | ||
onNodeWithTag(API_ACCESS_DETAILS_TOP_BAR_DROPDOWN_BUTTON_TEST_TAG).performClick() | ||
onNodeWithText("Delete method").performClick() | ||
|
||
// Assert | ||
verify(exactly = 1) { onDeleteApiAccessMethodClicked(apiAccessMethod.id) } | ||
} | ||
|
||
@Test | ||
fun whenClickingOnEditMethodShouldCallOnEditMethodClicked() = | ||
composeExtension.use { | ||
// Arrange | ||
val onEditMethodClicked: () -> Unit = mockk(relaxed = true) | ||
val apiAccessMethod = CUSTOM_ACCESS_METHOD | ||
setContentWithTheme { | ||
ApiAccessMethodDetailsScreen( | ||
state = | ||
ApiAccessMethodDetailsUiState.Content( | ||
apiAccessMethodId = apiAccessMethod.id, | ||
name = apiAccessMethod.name, | ||
enabled = apiAccessMethod.enabled, | ||
isEditable = true, | ||
isDisableable = false, | ||
isCurrentMethod = true, | ||
testApiAccessMethodState = null | ||
), | ||
onEditMethodClicked = onEditMethodClicked | ||
) | ||
} | ||
|
||
// Act | ||
onNodeWithTag(API_ACCESS_DETAILS_EDIT_BUTTON).performClick() | ||
|
||
// Assert | ||
verify(exactly = 1) { onEditMethodClicked() } | ||
} | ||
|
||
@Test | ||
fun whenClickingOnEnableMethodShouldCallOnEnableClicked() = | ||
composeExtension.use { | ||
// Arrange | ||
val onEnableClicked: (Boolean) -> Unit = mockk(relaxed = true) | ||
val apiAccessMethod = DIRECT_ACCESS_METHOD | ||
setContentWithTheme { | ||
ApiAccessMethodDetailsScreen( | ||
state = | ||
ApiAccessMethodDetailsUiState.Content( | ||
apiAccessMethodId = apiAccessMethod.id, | ||
name = apiAccessMethod.name, | ||
enabled = apiAccessMethod.enabled, | ||
isEditable = false, | ||
isDisableable = true, | ||
isCurrentMethod = true, | ||
testApiAccessMethodState = null | ||
), | ||
onEnableClicked = onEnableClicked | ||
) | ||
} | ||
|
||
// Act | ||
onNodeWithText("Enable method").performClick() | ||
|
||
// Assert | ||
verify(exactly = 1) { onEnableClicked(false) } | ||
} | ||
|
||
@Test | ||
fun whenClickingOnTestMethodShouldCallOnTestMethodClicked() = | ||
composeExtension.use { | ||
// Arrange | ||
val onTestMethodClicked: () -> Unit = mockk(relaxed = true) | ||
val apiAccessMethod = DIRECT_ACCESS_METHOD | ||
setContentWithTheme { | ||
ApiAccessMethodDetailsScreen( | ||
state = | ||
ApiAccessMethodDetailsUiState.Content( | ||
apiAccessMethodId = apiAccessMethod.id, | ||
name = apiAccessMethod.name, | ||
enabled = apiAccessMethod.enabled, | ||
isEditable = false, | ||
isDisableable = true, | ||
isCurrentMethod = true, | ||
testApiAccessMethodState = null | ||
), | ||
onTestMethodClicked = onTestMethodClicked | ||
) | ||
} | ||
|
||
// Act | ||
onNodeWithTag(API_ACCESS_TEST_METHOD_BUTTON).performClick() | ||
|
||
// Assert | ||
verify(exactly = 1) { onTestMethodClicked() } | ||
} | ||
|
||
@Test | ||
fun whenClickingOnUseMethodShouldCallOnUseMethodClicked() = | ||
composeExtension.use { | ||
// Arrange | ||
val onUseMethodClicked: () -> Unit = mockk(relaxed = true) | ||
val apiAccessMethod = DIRECT_ACCESS_METHOD | ||
setContentWithTheme { | ||
ApiAccessMethodDetailsScreen( | ||
state = | ||
ApiAccessMethodDetailsUiState.Content( | ||
apiAccessMethodId = apiAccessMethod.id, | ||
name = apiAccessMethod.name, | ||
enabled = apiAccessMethod.enabled, | ||
isEditable = false, | ||
isDisableable = true, | ||
isCurrentMethod = false, | ||
testApiAccessMethodState = null | ||
), | ||
onUseMethodClicked = onUseMethodClicked | ||
) | ||
} | ||
|
||
// Act | ||
onNodeWithTag(API_ACCESS_USE_METHOD_BUTTON).performClick() | ||
|
||
// Assert | ||
verify(exactly = 1) { onUseMethodClicked() } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters