Skip to content

Commit 2efa4c2

Browse files
committed
Fix more tests
1 parent fea0ea1 commit 2efa4c2

File tree

5 files changed

+42
-26
lines changed

5 files changed

+42
-26
lines changed

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

+11-6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import net.mullvad.mullvadvpn.compose.createEdgeToEdgeComposeExtension
1212
import net.mullvad.mullvadvpn.compose.data.DUMMY_RELAY_COUNTRIES
1313
import net.mullvad.mullvadvpn.compose.setContentWithTheme
1414
import net.mullvad.mullvadvpn.compose.state.CustomListLocationsUiState
15+
import net.mullvad.mullvadvpn.compose.state.RelayLocationListItem
1516
import net.mullvad.mullvadvpn.compose.test.CIRCULAR_PROGRESS_INDICATOR
1617
import net.mullvad.mullvadvpn.compose.test.SAVE_BUTTON_TEST_TAG
1718
import net.mullvad.mullvadvpn.lib.model.RelayItem
@@ -80,19 +81,22 @@ class CustomListLocationsScreenTest {
8081
CustomListLocationsScreen(
8182
state =
8283
CustomListLocationsUiState.Content.Data(
83-
locations = emptyList(),
84+
locations =
85+
listOf(
86+
RelayLocationListItem(DUMMY_RELAY_COUNTRIES[0], checked = true),
87+
RelayLocationListItem(
88+
DUMMY_RELAY_COUNTRIES[1],
89+
checked = false
90+
),
91+
),
8492
searchTerm = ""
8593
),
8694
)
8795
}
8896

8997
// Assert
9098
onNodeWithText("Relay Country 1").assertExists()
91-
onNodeWithText("Relay City 1").assertDoesNotExist()
92-
onNodeWithText("Relay host 1").assertDoesNotExist()
9399
onNodeWithText("Relay Country 2").assertExists()
94-
onNodeWithText("Relay City 2").assertDoesNotExist()
95-
onNodeWithText("Relay host 2").assertDoesNotExist()
96100
}
97101

98102
@Test
@@ -106,7 +110,8 @@ class CustomListLocationsScreenTest {
106110
state =
107111
CustomListLocationsUiState.Content.Data(
108112
newList = false,
109-
locations = emptyList()
113+
locations =
114+
listOf(RelayLocationListItem(selectedCountry, checked = true))
110115
),
111116
onRelaySelectionClick = mockedOnRelaySelectionClicked
112117
)

android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/CustomListLocationsUiState.kt

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ sealed interface CustomListLocationsUiState {
2222

2323
data class Data(
2424
override val newList: Boolean = false,
25-
val locations: List<RelayLocationItem>,
25+
val locations: List<RelayLocationListItem>,
2626
override val searchTerm: String = "",
2727
override val saveEnabled: Boolean = false,
2828
override val hasUnsavedChanges: Boolean = false
2929
) : Content
3030
}
3131
}
3232

33-
data class RelayLocationItem(
33+
data class RelayLocationListItem(
3434
val item: RelayItem.Location,
35-
val depth: Int,
36-
val checked: Boolean,
37-
val expanded: Boolean
35+
val depth: Int = 0,
36+
val checked: Boolean = false,
37+
val expanded: Boolean = false
3838
)

android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModel.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import kotlinx.coroutines.launch
1818
import net.mullvad.mullvadvpn.compose.communication.CustomListAction
1919
import net.mullvad.mullvadvpn.compose.communication.LocationsChanged
2020
import net.mullvad.mullvadvpn.compose.state.CustomListLocationsUiState
21-
import net.mullvad.mullvadvpn.compose.state.RelayLocationItem
21+
import net.mullvad.mullvadvpn.compose.state.RelayLocationListItem
2222
import net.mullvad.mullvadvpn.lib.model.RelayItem
2323
import net.mullvad.mullvadvpn.lib.model.RelayItemId
2424
import net.mullvad.mullvadvpn.relaylist.MIN_SEARCH_LENGTH
@@ -239,11 +239,11 @@ class CustomListLocationsViewModel(
239239
isSelected: (RelayItem) -> Boolean,
240240
isExpanded: (RelayItemId) -> Boolean,
241241
depth: Int = 0,
242-
): List<RelayLocationItem> = flatMap { relayItem ->
243-
buildList<RelayLocationItem> {
242+
): List<RelayLocationListItem> = flatMap { relayItem ->
243+
buildList<RelayLocationListItem> {
244244
val expanded = isExpanded(relayItem.id)
245245
add(
246-
RelayLocationItem(
246+
RelayLocationListItem(
247247
item = relayItem,
248248
depth = depth,
249249
checked = isSelected(relayItem),

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import net.mullvad.mullvadvpn.compose.communication.CustomListAction
1313
import net.mullvad.mullvadvpn.compose.communication.LocationsChanged
1414
import net.mullvad.mullvadvpn.compose.screen.CustomListLocationsNavArgs
1515
import net.mullvad.mullvadvpn.compose.state.CustomListLocationsUiState
16-
import net.mullvad.mullvadvpn.compose.state.RelayLocationItem
16+
import net.mullvad.mullvadvpn.compose.state.RelayLocationListItem
1717
import net.mullvad.mullvadvpn.lib.common.test.TestCoroutineRule
1818
import net.mullvad.mullvadvpn.lib.common.test.assertLists
1919
import net.mullvad.mullvadvpn.lib.model.CustomList
@@ -71,7 +71,7 @@ class CustomListLocationsViewModelTest {
7171
// Arrange
7272
val expectedList =
7373
DUMMY_COUNTRIES.map {
74-
RelayLocationItem(
74+
RelayLocationListItem(
7575
item = it,
7676
depth = it.toDepth(),
7777
checked = false,

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

+20-9
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,14 @@ class SelectLocationViewModelTest {
119119
assertIs<SelectLocationUiState.Content>(actualState)
120120
assertLists(
121121
testCountries.map { it.id },
122-
actualState.relayListItems.mapNotNull { it.relayItemId() })
122+
actualState.relayListItems.mapNotNull { it.relayItemId() }
123+
)
123124
assertTrue(
124125
actualState.relayListItems
125126
.filterIsInstance<RelayListItem.SelectableItem>()
126127
.first { it.relayItemId() == selectedId }
127-
.isSelected)
128+
.isSelected
129+
)
128130
}
129131
}
130132

@@ -140,11 +142,13 @@ class SelectLocationViewModelTest {
140142
assertIs<SelectLocationUiState.Content>(actualState)
141143
assertLists(
142144
testCountries.map { it.id },
143-
actualState.relayListItems.mapNotNull { it.relayItemId() })
145+
actualState.relayListItems.mapNotNull { it.relayItemId() }
146+
)
144147
assertTrue(
145148
actualState.relayListItems.filterIsInstance<RelayListItem.SelectableItem>().all {
146149
!it.isSelected
147-
})
150+
}
151+
)
148152
}
149153
}
150154

@@ -191,7 +195,8 @@ class SelectLocationViewModelTest {
191195
assertTrue(
192196
actualState.relayListItems.filterIsInstance<RelayListItem.GeoLocationItem>().any {
193197
it.item is RelayItem.Location.City && it.item.name == "Gothenburg"
194-
})
198+
}
199+
)
195200
}
196201
}
197202

@@ -218,7 +223,8 @@ class SelectLocationViewModelTest {
218223
assertIs<SelectLocationUiState.Content>(actualState)
219224
assertEquals(
220225
listOf(RelayListItem.LocationsEmptyText(mockSearchString)),
221-
actualState.relayListItems)
226+
actualState.relayListItems
227+
)
222228
}
223229
}
224230

@@ -278,7 +284,8 @@ class SelectLocationViewModelTest {
278284
CustomList(
279285
id = CustomListId("1"),
280286
name = CustomListName.fromString("custom"),
281-
locations = emptyList()),
287+
locations = emptyList()
288+
),
282289
locations = emptyList(),
283290
)
284291
coEvery { mockCustomListActionUseCase(any<CustomListAction.UpdateLocations>()) } returns
@@ -321,7 +328,11 @@ class SelectLocationViewModelTest {
321328
RelayItem.Location.City(
322329
id = GeoLocationId.City(GeoLocationId.Country("se"), "got"),
323330
"Gothenburg",
324-
emptyList()))),
325-
RelayItem.Location.Country(id = GeoLocationId.Country("no"), "Norway", emptyList()))
331+
emptyList()
332+
)
333+
)
334+
),
335+
RelayItem.Location.Country(id = GeoLocationId.Country("no"), "Norway", emptyList())
336+
)
326337
}
327338
}

0 commit comments

Comments
 (0)