-
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.
- Loading branch information
Showing
14 changed files
with
296 additions
and
120 deletions.
There are no files selected for viewing
157 changes: 157 additions & 0 deletions
157
...c/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/ServerIpOverridesScreenTest.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,157 @@ | ||
package net.mullvad.mullvadvpn.compose.screen | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.test.ExperimentalTestApi | ||
import androidx.compose.ui.test.onNodeWithTag | ||
import androidx.compose.ui.test.onNodeWithText | ||
import androidx.compose.ui.test.performClick | ||
import io.mockk.MockKAnnotations | ||
import io.mockk.mockk | ||
import io.mockk.verify | ||
import net.mullvad.mullvadvpn.compose.createEdgeToEdgeComposeExtension | ||
import net.mullvad.mullvadvpn.compose.setContentWithTheme | ||
import net.mullvad.mullvadvpn.compose.test.SERVER_IP_OVERRIDES_IMPORT_BY_FILE_TEST_TAG | ||
import net.mullvad.mullvadvpn.compose.test.SERVER_IP_OVERRIDES_IMPORT_BY_TEXT_TEST_TAG | ||
import net.mullvad.mullvadvpn.compose.test.SERVER_IP_OVERRIDE_IMPORT_TEST_TAG | ||
import net.mullvad.mullvadvpn.compose.test.SERVER_IP_OVERRIDE_INFO_TEST_TAG | ||
import net.mullvad.mullvadvpn.compose.test.SERVER_IP_OVERRIDE_MORE_VERT_TEST_TAG | ||
import net.mullvad.mullvadvpn.compose.test.SERVER_IP_OVERRIDE_RESET_OVERRIDES_TEST_TAG | ||
import net.mullvad.mullvadvpn.viewmodel.ServerIpOverridesViewState | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.RegisterExtension | ||
|
||
@ExperimentalTestApi | ||
class ServerIpOverridesScreenTest { | ||
@JvmField @RegisterExtension val composeExtension = createEdgeToEdgeComposeExtension() | ||
|
||
@BeforeEach | ||
fun setup() { | ||
MockKAnnotations.init(this) | ||
} | ||
|
||
@Composable | ||
private fun Screen( | ||
state: ServerIpOverridesViewState, | ||
onBackClick: () -> Unit = {}, | ||
onInfoClick: () -> Unit = {}, | ||
onResetOverridesClick: () -> Unit = {}, | ||
onImportByFile: () -> Unit = {}, | ||
onImportByText: () -> Unit = {}, | ||
) { | ||
ServerIpOverridesScreen( | ||
state = state, | ||
onBackClick = onBackClick, | ||
onInfoClick = onInfoClick, | ||
onResetOverridesClick = onResetOverridesClick, | ||
onImportByFile = onImportByFile, | ||
onImportByText = onImportByText | ||
) | ||
} | ||
|
||
@Test | ||
fun testOverridesInactive() = | ||
composeExtension.use { | ||
// Arrange | ||
setContentWithTheme { Screen(state = ServerIpOverridesViewState(false)) } | ||
|
||
// Assert | ||
onNodeWithText("Overrides inactive").assertExists() | ||
} | ||
|
||
@Test | ||
fun testOverridesActive() = | ||
composeExtension.use { | ||
// Arrange | ||
setContentWithTheme { Screen(state = ServerIpOverridesViewState(true)) } | ||
|
||
// Assert | ||
onNodeWithText("Overrides active").assertExists() | ||
} | ||
|
||
@Test | ||
fun testOverridesActiveShowsWarningOnImport() = | ||
composeExtension.use { | ||
// Arrange | ||
setContentWithTheme { Screen(state = ServerIpOverridesViewState(true)) } | ||
|
||
// Act | ||
onNodeWithTag(testTag = SERVER_IP_OVERRIDE_IMPORT_TEST_TAG).performClick() | ||
|
||
// Assert | ||
onNodeWithText( | ||
"Importing new overrides might replace some previously imported overrides." | ||
) | ||
.assertExists() | ||
} | ||
|
||
@Test | ||
fun testInfoClick() = | ||
composeExtension.use { | ||
// Arrange | ||
val clickHandler: () -> Unit = mockk(relaxed = true) | ||
setContentWithTheme { | ||
Screen(state = ServerIpOverridesViewState(false), onInfoClick = clickHandler) | ||
} | ||
|
||
// Act | ||
onNodeWithTag(SERVER_IP_OVERRIDE_INFO_TEST_TAG).performClick() | ||
|
||
// Assert | ||
verify { clickHandler() } | ||
} | ||
|
||
@Test | ||
fun testResetClick() = | ||
composeExtension.use { | ||
// Arrange | ||
val clickHandler: () -> Unit = mockk(relaxed = true) | ||
setContentWithTheme { | ||
Screen( | ||
state = ServerIpOverridesViewState(false), | ||
onResetOverridesClick = clickHandler | ||
) | ||
} | ||
|
||
// Act | ||
onNodeWithTag(SERVER_IP_OVERRIDE_MORE_VERT_TEST_TAG).performClick() | ||
onNodeWithTag(SERVER_IP_OVERRIDE_RESET_OVERRIDES_TEST_TAG).performClick() | ||
|
||
// Assert | ||
verify { clickHandler() } | ||
} | ||
|
||
@Test | ||
fun testImportByFile() = | ||
composeExtension.use { | ||
// Arrange | ||
val clickHandler: () -> Unit = mockk(relaxed = true) | ||
setContentWithTheme { | ||
Screen(state = ServerIpOverridesViewState(false), onImportByFile = clickHandler) | ||
} | ||
|
||
// Act | ||
onNodeWithTag(SERVER_IP_OVERRIDE_IMPORT_TEST_TAG).performClick() | ||
onNodeWithTag(SERVER_IP_OVERRIDES_IMPORT_BY_FILE_TEST_TAG).performClick() | ||
|
||
// Assert | ||
verify { clickHandler() } | ||
} | ||
|
||
@Test | ||
fun testImportByText() = | ||
composeExtension.use { | ||
// Arrange | ||
val clickHandler: () -> Unit = mockk(relaxed = true) | ||
setContentWithTheme { | ||
Screen(state = ServerIpOverridesViewState(false), onImportByText = clickHandler) | ||
} | ||
|
||
// Act | ||
onNodeWithTag(SERVER_IP_OVERRIDE_IMPORT_TEST_TAG).performClick() | ||
onNodeWithTag(SERVER_IP_OVERRIDES_IMPORT_BY_TEXT_TEST_TAG).performClick() | ||
|
||
// Assert | ||
verify { clickHandler() } | ||
} | ||
} |
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
Oops, something went wrong.