Skip to content

Commit 2052561

Browse files
MaryamShaghaghiBoki91
authored andcommitted
Add test for split tunneling view model and update the other tests
Co-Authored-By: Boban Sijuk <49131853+Boki91@users.noreply.github.com>
1 parent 53c198e commit 2052561

File tree

2 files changed

+55
-5
lines changed

2 files changed

+55
-5
lines changed

android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/SplitTunnelingScreenTest.kt

+8-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ class SplitTunnelingScreenTest {
3434
fun testLoadingState() =
3535
composeExtension.use {
3636
// Arrange
37-
setContentWithTheme { SplitTunnelingScreen(uiState = SplitTunnelingUiState.Loading) }
37+
setContentWithTheme {
38+
SplitTunnelingScreen(uiState = SplitTunnelingUiState.Loading(enabled = true))
39+
}
3840

3941
// Assert
4042
onNodeWithText(TITLE).assertExists()
@@ -64,6 +66,7 @@ class SplitTunnelingScreenTest {
6466
SplitTunnelingScreen(
6567
uiState =
6668
SplitTunnelingUiState.ShowAppList(
69+
enabled = true,
6770
excludedApps = listOf(excludedApp),
6871
includedApps = listOf(includedApp),
6972
showSystemApps = false
@@ -95,6 +98,7 @@ class SplitTunnelingScreenTest {
9598
SplitTunnelingScreen(
9699
uiState =
97100
SplitTunnelingUiState.ShowAppList(
101+
enabled = true,
98102
excludedApps = emptyList(),
99103
includedApps = listOf(includedApp),
100104
showSystemApps = false
@@ -133,6 +137,7 @@ class SplitTunnelingScreenTest {
133137
SplitTunnelingScreen(
134138
uiState =
135139
SplitTunnelingUiState.ShowAppList(
140+
enabled = true,
136141
excludedApps = listOf(excludedApp),
137142
includedApps = listOf(includedApp),
138143
showSystemApps = false
@@ -169,6 +174,7 @@ class SplitTunnelingScreenTest {
169174
SplitTunnelingScreen(
170175
uiState =
171176
SplitTunnelingUiState.ShowAppList(
177+
enabled = true,
172178
excludedApps = listOf(excludedApp),
173179
includedApps = listOf(includedApp),
174180
showSystemApps = false
@@ -205,6 +211,7 @@ class SplitTunnelingScreenTest {
205211
SplitTunnelingScreen(
206212
uiState =
207213
SplitTunnelingUiState.ShowAppList(
214+
enabled = true,
208215
excludedApps = listOf(excludedApp),
209216
includedApps = listOf(includedApp),
210217
showSystemApps = false

android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/SplitTunnelingViewModelTest.kt

+47-4
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class SplitTunnelingViewModelTest {
5757
initTestSubject(emptyList())
5858
val actualState: SplitTunnelingUiState = testSubject.uiState.value
5959

60-
val initialExpectedState = SplitTunnelingUiState.Loading
60+
val initialExpectedState = SplitTunnelingUiState.Loading(enabled = false)
6161

6262
assertEquals(initialExpectedState, actualState)
6363

@@ -70,9 +70,14 @@ class SplitTunnelingViewModelTest {
7070
{
7171
lambda<(Set<String>) -> Unit>().invoke(emptySet())
7272
}
73+
every { mockedSplitTunneling.enabledChange = captureLambda() } answers
74+
{
75+
lambda<(Boolean) -> Unit>().invoke(true)
76+
}
7377
initTestSubject(emptyList())
7478
val expectedState =
7579
SplitTunnelingUiState.ShowAppList(
80+
enabled = true,
7681
excludedApps = emptyList(),
7782
includedApps = emptyList(),
7883
showSystemApps = false
@@ -88,11 +93,16 @@ class SplitTunnelingViewModelTest {
8893
{
8994
lambda<(Set<String>) -> Unit>().invoke(setOf(appExcluded.packageName))
9095
}
96+
every { mockedSplitTunneling.enabledChange = captureLambda() } answers
97+
{
98+
lambda<(Boolean) -> Unit>().invoke(true)
99+
}
91100

92101
initTestSubject(listOf(appExcluded, appNotExcluded))
93102

94103
val expectedState =
95104
SplitTunnelingUiState.ShowAppList(
105+
enabled = true,
96106
excludedApps = listOf(appExcluded),
97107
includedApps = listOf(appNotExcluded),
98108
showSystemApps = false
@@ -102,7 +112,7 @@ class SplitTunnelingViewModelTest {
102112
val actualState = awaitItem()
103113
assertEquals(expectedState, actualState)
104114
verifyAll {
105-
mockedSplitTunneling.enabled
115+
mockedSplitTunneling.enabledChange = any()
106116
mockedSplitTunneling.excludedAppsChange = any()
107117
}
108118
}
@@ -118,17 +128,23 @@ class SplitTunnelingViewModelTest {
118128
excludedAppsCallback = lambda()
119129
excludedAppsCallback.invoke(setOf(app.packageName))
120130
}
131+
every { mockedSplitTunneling.enabledChange = captureLambda() } answers
132+
{
133+
lambda<(Boolean) -> Unit>().invoke(true)
134+
}
121135

122136
initTestSubject(listOf(app))
123137

124138
val expectedStateBeforeAction =
125139
SplitTunnelingUiState.ShowAppList(
140+
enabled = true,
126141
excludedApps = listOf(app),
127142
includedApps = emptyList(),
128143
showSystemApps = false
129144
)
130145
val expectedStateAfterAction =
131146
SplitTunnelingUiState.ShowAppList(
147+
enabled = true,
132148
excludedApps = emptyList(),
133149
includedApps = listOf(app),
134150
showSystemApps = false
@@ -141,7 +157,7 @@ class SplitTunnelingViewModelTest {
141157
assertEquals(expectedStateAfterAction, awaitItem())
142158

143159
verifyAll {
144-
mockedSplitTunneling.enabled
160+
mockedSplitTunneling.enabledChange = any()
145161
mockedSplitTunneling.excludedAppsChange = any()
146162
mockedSplitTunneling.includeApp(app.packageName)
147163
}
@@ -158,18 +174,24 @@ class SplitTunnelingViewModelTest {
158174
excludedAppsCallback = lambda()
159175
excludedAppsCallback.invoke(emptySet())
160176
}
177+
every { mockedSplitTunneling.enabledChange = captureLambda() } answers
178+
{
179+
lambda<(Boolean) -> Unit>().invoke(true)
180+
}
161181

162182
initTestSubject(listOf(app))
163183

164184
val expectedStateBeforeAction =
165185
SplitTunnelingUiState.ShowAppList(
186+
enabled = true,
166187
excludedApps = emptyList(),
167188
includedApps = listOf(app),
168189
showSystemApps = false
169190
)
170191

171192
val expectedStateAfterAction =
172193
SplitTunnelingUiState.ShowAppList(
194+
enabled = true,
173195
excludedApps = listOf(app),
174196
includedApps = emptyList(),
175197
showSystemApps = false
@@ -182,13 +204,34 @@ class SplitTunnelingViewModelTest {
182204
assertEquals(expectedStateAfterAction, awaitItem())
183205

184206
verifyAll {
185-
mockedSplitTunneling.enabled
207+
mockedSplitTunneling.enabledChange = any()
186208
mockedSplitTunneling.excludedAppsChange = any()
187209
mockedSplitTunneling.excludeApp(app.packageName)
188210
}
189211
}
190212
}
191213

214+
@Test
215+
fun test_disabled_state() = runTest {
216+
every { mockedSplitTunneling.excludedAppsChange = captureLambda() } answers
217+
{
218+
lambda<(Set<String>) -> Unit>().invoke(emptySet())
219+
}
220+
every { mockedSplitTunneling.enabledChange = captureLambda() } answers
221+
{
222+
lambda<(Boolean) -> Unit>().invoke(false)
223+
}
224+
225+
initTestSubject(emptyList())
226+
227+
val expectedState = SplitTunnelingUiState.ShowAppList(enabled = false)
228+
229+
testSubject.uiState.test {
230+
val actualState = awaitItem()
231+
assertEquals(expectedState, actualState)
232+
}
233+
}
234+
192235
private fun initTestSubject(appList: List<AppData>) {
193236
every { mockedApplicationsProvider.getAppsList() } returns appList
194237
every { mockedServiceConnectionManager.connectionState } returns

0 commit comments

Comments
 (0)