-
Notifications
You must be signed in to change notification settings - Fork 352
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
10 changed files
with
159 additions
and
98 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
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
85 changes: 85 additions & 0 deletions
85
...androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/ShadowsocksSettingsScreenTest.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,85 @@ | ||
package net.mullvad.mullvadvpn.compose.screen | ||
|
||
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.coVerify | ||
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.state.ShadowsocksSettingsState | ||
import net.mullvad.mullvadvpn.compose.test.SHADOWSOCKS_CUSTOM_PORT_TEXT_TEST_TAG | ||
import net.mullvad.mullvadvpn.compose.test.SHADOWSOCKS_PORT_ITEM_X_TEST_TAG | ||
import net.mullvad.mullvadvpn.lib.model.Constraint | ||
import net.mullvad.mullvadvpn.lib.model.Port | ||
import net.mullvad.mullvadvpn.onNodeWithTagAndText | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.RegisterExtension | ||
|
||
@OptIn(ExperimentalTestApi::class) | ||
class ShadowsocksSettingsScreenTest { | ||
@JvmField @RegisterExtension val composeExtension = createEdgeToEdgeComposeExtension() | ||
|
||
@Test | ||
fun testSelectTcpOverUdpPortOption() = | ||
composeExtension.use { | ||
// Arrange | ||
val onObfuscationPortSelected: (Constraint<Port>) -> Unit = mockk(relaxed = true) | ||
setContentWithTheme { | ||
ShadowsocksSettingsScreen( | ||
state = ShadowsocksSettingsState(port = Constraint.Any), | ||
onObfuscationPortSelected = onObfuscationPortSelected | ||
) | ||
} | ||
|
||
// Act | ||
onNodeWithTagAndText( | ||
testTag = String.format(SHADOWSOCKS_PORT_ITEM_X_TEST_TAG, 443), | ||
text = "443" | ||
) | ||
.assertExists() | ||
.performClick() | ||
|
||
// Assert | ||
coVerify(exactly = 1) { onObfuscationPortSelected.invoke(Constraint.Only(Port(443))) } | ||
} | ||
|
||
@Test | ||
fun testShowShadowsocksCustomPort() = | ||
composeExtension.use { | ||
// Arrange | ||
setContentWithTheme { | ||
ShadowsocksSettingsScreen( | ||
state = ShadowsocksSettingsState(customPort = Port(4000)), | ||
) | ||
} | ||
|
||
// Assert | ||
onNodeWithText("4000").assertExists() | ||
} | ||
|
||
@Test | ||
fun testSelectShadowsocksCustomPort() = | ||
composeExtension.use { | ||
// Arrange | ||
val onObfuscationPortSelected: (Constraint<Port>) -> Unit = mockk(relaxed = true) | ||
setContentWithTheme { | ||
ShadowsocksSettingsScreen( | ||
state = | ||
ShadowsocksSettingsState( | ||
port = Constraint.Only(Port(4000)), | ||
customPort = Port(4000) | ||
), | ||
onObfuscationPortSelected = onObfuscationPortSelected | ||
) | ||
} | ||
|
||
// Act | ||
onNodeWithTag(testTag = SHADOWSOCKS_CUSTOM_PORT_TEXT_TEST_TAG).performClick() | ||
|
||
// Assert | ||
verify { onObfuscationPortSelected.invoke(Constraint.Only(Port(4000))) } | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/Udp2TcpSettingsScreenTest.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,44 @@ | ||
package net.mullvad.mullvadvpn.compose.screen | ||
|
||
import androidx.compose.ui.test.ExperimentalTestApi | ||
import androidx.compose.ui.test.performClick | ||
import io.mockk.coVerify | ||
import io.mockk.mockk | ||
import net.mullvad.mullvadvpn.compose.createEdgeToEdgeComposeExtension | ||
import net.mullvad.mullvadvpn.compose.setContentWithTheme | ||
import net.mullvad.mullvadvpn.compose.state.Udp2TcpSettingsState | ||
import net.mullvad.mullvadvpn.compose.test.UDP_OVER_TCP_PORT_ITEM_X_TEST_TAG | ||
import net.mullvad.mullvadvpn.lib.model.Constraint | ||
import net.mullvad.mullvadvpn.lib.model.Port | ||
import net.mullvad.mullvadvpn.onNodeWithTagAndText | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.RegisterExtension | ||
|
||
@OptIn(ExperimentalTestApi::class) | ||
class Udp2TcpSettingsScreenTest { | ||
@JvmField @RegisterExtension val composeExtension = createEdgeToEdgeComposeExtension() | ||
|
||
@Test | ||
fun testSelectTcpOverUdpPortOption() = | ||
composeExtension.use { | ||
// Arrange | ||
val onObfuscationPortSelected: (Constraint<Port>) -> Unit = mockk(relaxed = true) | ||
setContentWithTheme { | ||
Udp2TcpSettingsScreen( | ||
state = Udp2TcpSettingsState(port = Constraint.Any), | ||
onObfuscationPortSelected = onObfuscationPortSelected | ||
) | ||
} | ||
|
||
// Act | ||
onNodeWithTagAndText( | ||
testTag = String.format(UDP_OVER_TCP_PORT_ITEM_X_TEST_TAG, 5001), | ||
text = "5001" | ||
) | ||
.assertExists() | ||
.performClick() | ||
|
||
// Assert | ||
coVerify(exactly = 1) { onObfuscationPortSelected.invoke(Constraint.Only(Port(5001))) } | ||
} | ||
} |
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
1 change: 0 additions & 1 deletion
1
android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/PortExtensions.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
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