Skip to content

Commit 261e320

Browse files
committed
Adapt tests to flat list uiState
1 parent 18edefd commit 261e320

File tree

5 files changed

+215
-181
lines changed

5 files changed

+215
-181
lines changed

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

+14-11
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,20 +81,22 @@ class CustomListLocationsScreenTest {
8081
CustomListLocationsScreen(
8182
state =
8283
CustomListLocationsUiState.Content.Data(
83-
availableLocations = DUMMY_RELAY_COUNTRIES,
84-
selectedLocations = emptySet(),
84+
locations =
85+
listOf(
86+
RelayLocationListItem(DUMMY_RELAY_COUNTRIES[0], checked = true),
87+
RelayLocationListItem(
88+
DUMMY_RELAY_COUNTRIES[1],
89+
checked = false
90+
),
91+
),
8592
searchTerm = ""
8693
),
8794
)
8895
}
8996

9097
// Assert
9198
onNodeWithText("Relay Country 1").assertExists()
92-
onNodeWithText("Relay City 1").assertDoesNotExist()
93-
onNodeWithText("Relay host 1").assertDoesNotExist()
9499
onNodeWithText("Relay Country 2").assertExists()
95-
onNodeWithText("Relay City 2").assertDoesNotExist()
96-
onNodeWithText("Relay host 2").assertDoesNotExist()
97100
}
98101

99102
@Test
@@ -107,8 +110,8 @@ class CustomListLocationsScreenTest {
107110
state =
108111
CustomListLocationsUiState.Content.Data(
109112
newList = false,
110-
availableLocations = DUMMY_RELAY_COUNTRIES,
111-
selectedLocations = setOf(selectedCountry)
113+
locations =
114+
listOf(RelayLocationListItem(selectedCountry, checked = true))
112115
),
113116
onRelaySelectionClick = mockedOnRelaySelectionClicked
114117
)
@@ -131,7 +134,7 @@ class CustomListLocationsScreenTest {
131134
state =
132135
CustomListLocationsUiState.Content.Data(
133136
newList = false,
134-
availableLocations = DUMMY_RELAY_COUNTRIES,
137+
locations = emptyList(),
135138
),
136139
onSearchTermInput = mockedSearchTermInput
137140
)
@@ -197,7 +200,7 @@ class CustomListLocationsScreenTest {
197200
state =
198201
CustomListLocationsUiState.Content.Data(
199202
newList = false,
200-
availableLocations = DUMMY_RELAY_COUNTRIES,
203+
locations = emptyList(),
201204
saveEnabled = true,
202205
),
203206
onSaveClick = mockOnSaveClick
@@ -221,7 +224,7 @@ class CustomListLocationsScreenTest {
221224
state =
222225
CustomListLocationsUiState.Content.Data(
223226
newList = false,
224-
availableLocations = DUMMY_RELAY_COUNTRIES,
227+
locations = emptyList(),
225228
saveEnabled = false,
226229
),
227230
onSaveClick = mockOnSaveClick

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

+34-91
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.data.DUMMY_RELAY_ITEM_CUSTOM_LISTS
1414
import net.mullvad.mullvadvpn.compose.setContentWithTheme
15+
import net.mullvad.mullvadvpn.compose.state.RelayListItem
1516
import net.mullvad.mullvadvpn.compose.state.SelectLocationUiState
1617
import net.mullvad.mullvadvpn.compose.test.CIRCULAR_PROGRESS_INDICATOR
1718
import net.mullvad.mullvadvpn.compose.test.SELECT_LOCATION_CUSTOM_LIST_BOTTOM_SHEET_TEST_TAG
@@ -54,13 +55,13 @@ class SelectLocationScreenTest {
5455
SelectLocationScreen(
5556
state =
5657
SelectLocationUiState.Content(
58+
searchTerm = "",
59+
filterChips = emptyList(),
60+
relayListItems =
61+
DUMMY_RELAY_COUNTRIES.map {
62+
RelayListItem.GeoLocationItem(item = it)
63+
},
5764
customLists = emptyList(),
58-
filteredCustomLists = emptyList(),
59-
countries = DUMMY_RELAY_COUNTRIES,
60-
selectedItem = null,
61-
selectedOwnership = null,
62-
selectedProvidersCount = 0,
63-
searchTerm = ""
6465
),
6566
)
6667
}
@@ -74,45 +75,6 @@ class SelectLocationScreenTest {
7475
onNodeWithText("Relay host 2").assertDoesNotExist()
7576
}
7677

77-
@Test
78-
fun testShowRelayListStateSelected() =
79-
composeExtension.use {
80-
val updatedDummyList =
81-
DUMMY_RELAY_COUNTRIES.let {
82-
val cities = it[0].cities.toMutableList()
83-
val city = cities.removeAt(0)
84-
cities.add(0, city.copy(expanded = true))
85-
86-
val mutableRelayList = it.toMutableList()
87-
mutableRelayList[0] = it[0].copy(expanded = true, cities = cities.toList())
88-
mutableRelayList
89-
}
90-
91-
// Arrange
92-
setContentWithTheme {
93-
SelectLocationScreen(
94-
state =
95-
SelectLocationUiState.Content(
96-
customLists = emptyList(),
97-
filteredCustomLists = emptyList(),
98-
countries = updatedDummyList,
99-
selectedItem = updatedDummyList[0].cities[0].relays[0].id,
100-
selectedOwnership = null,
101-
selectedProvidersCount = 0,
102-
searchTerm = ""
103-
),
104-
)
105-
}
106-
107-
// Assert
108-
onNodeWithText("Relay Country 1").assertExists()
109-
onNodeWithText("Relay City 1").assertExists()
110-
onNodeWithText("Relay host 1").assertExists()
111-
onNodeWithText("Relay Country 2").assertExists()
112-
onNodeWithText("Relay City 2").assertDoesNotExist()
113-
onNodeWithText("Relay host 2").assertDoesNotExist()
114-
}
115-
11678
@Test
11779
fun testSearchInput() =
11880
composeExtension.use {
@@ -122,13 +84,10 @@ class SelectLocationScreenTest {
12284
SelectLocationScreen(
12385
state =
12486
SelectLocationUiState.Content(
125-
customLists = emptyList(),
126-
filteredCustomLists = emptyList(),
127-
countries = emptyList(),
128-
selectedItem = null,
129-
selectedOwnership = null,
130-
selectedProvidersCount = 0,
131-
searchTerm = ""
87+
searchTerm = "",
88+
filterChips = emptyList(),
89+
relayListItems = emptyList(),
90+
customLists = emptyList()
13291
),
13392
onSearchTermInput = mockedSearchTermInput
13493
)
@@ -152,13 +111,11 @@ class SelectLocationScreenTest {
152111
SelectLocationScreen(
153112
state =
154113
SelectLocationUiState.Content(
114+
searchTerm = mockSearchString,
115+
filterChips = emptyList(),
116+
relayListItems =
117+
listOf(RelayListItem.LocationsEmptyText(mockSearchString)),
155118
customLists = emptyList(),
156-
filteredCustomLists = emptyList(),
157-
countries = emptyList(),
158-
selectedItem = null,
159-
selectedOwnership = null,
160-
selectedProvidersCount = 0,
161-
searchTerm = mockSearchString
162119
),
163120
onSearchTermInput = mockedSearchTermInput
164121
)
@@ -170,21 +127,18 @@ class SelectLocationScreenTest {
170127
}
171128

172129
@Test
173-
fun givenNoCustomListsAndSearchIsTermIsEmptyShouldShowCustomListsEmptyText() =
130+
fun customListFooterShouldShowEmptyTextWhenNoCustomList() =
174131
composeExtension.use {
175132
// Arrange
176133
val mockSearchString = ""
177134
setContentWithTheme {
178135
SelectLocationScreen(
179136
state =
180137
SelectLocationUiState.Content(
138+
searchTerm = mockSearchString,
139+
filterChips = emptyList(),
140+
relayListItems = listOf(RelayListItem.CustomListFooter(false)),
181141
customLists = emptyList(),
182-
filteredCustomLists = emptyList(),
183-
countries = emptyList(),
184-
selectedItem = null,
185-
selectedOwnership = null,
186-
selectedProvidersCount = 0,
187-
searchTerm = mockSearchString
188142
),
189143
)
190144
}
@@ -202,13 +156,10 @@ class SelectLocationScreenTest {
202156
SelectLocationScreen(
203157
state =
204158
SelectLocationUiState.Content(
159+
searchTerm = mockSearchString,
160+
filterChips = emptyList(),
161+
relayListItems = emptyList(),
205162
customLists = DUMMY_RELAY_ITEM_CUSTOM_LISTS,
206-
filteredCustomLists = emptyList(),
207-
countries = emptyList(),
208-
selectedItem = null,
209-
selectedOwnership = null,
210-
selectedProvidersCount = 0,
211-
searchTerm = mockSearchString
212163
),
213164
)
214165
}
@@ -228,13 +179,10 @@ class SelectLocationScreenTest {
228179
SelectLocationScreen(
229180
state =
230181
SelectLocationUiState.Content(
231-
customLists = DUMMY_RELAY_ITEM_CUSTOM_LISTS,
232-
filteredCustomLists = DUMMY_RELAY_ITEM_CUSTOM_LISTS,
233-
countries = emptyList(),
234-
selectedItem = null,
235-
selectedOwnership = null,
236-
selectedProvidersCount = 0,
237-
searchTerm = ""
182+
searchTerm = "",
183+
filterChips = emptyList(),
184+
relayListItems = listOf(RelayListItem.CustomListItem(customList)),
185+
customLists = DUMMY_RELAY_ITEM_CUSTOM_LISTS
238186
),
239187
onSelectRelay = mockedOnSelectRelay
240188
)
@@ -257,13 +205,11 @@ class SelectLocationScreenTest {
257205
SelectLocationScreen(
258206
state =
259207
SelectLocationUiState.Content(
260-
customLists = DUMMY_RELAY_ITEM_CUSTOM_LISTS,
261-
filteredCustomLists = DUMMY_RELAY_ITEM_CUSTOM_LISTS,
262-
countries = emptyList(),
263-
selectedItem = null,
264-
selectedOwnership = null,
265-
selectedProvidersCount = 0,
266-
searchTerm = ""
208+
searchTerm = "",
209+
filterChips = emptyList(),
210+
relayListItems =
211+
listOf(RelayListItem.CustomListItem(item = customList)),
212+
customLists = DUMMY_RELAY_ITEM_CUSTOM_LISTS
267213
),
268214
onSelectRelay = mockedOnSelectRelay
269215
)
@@ -286,13 +232,10 @@ class SelectLocationScreenTest {
286232
SelectLocationScreen(
287233
state =
288234
SelectLocationUiState.Content(
235+
searchTerm = "",
236+
filterChips = emptyList(),
237+
relayListItems = listOf(RelayListItem.GeoLocationItem(relayItem)),
289238
customLists = emptyList(),
290-
filteredCustomLists = emptyList(),
291-
countries = DUMMY_RELAY_COUNTRIES,
292-
selectedItem = null,
293-
selectedOwnership = null,
294-
selectedProvidersCount = 0,
295-
searchTerm = ""
296239
),
297240
onSelectRelay = mockedOnSelectRelay
298241
)

android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/CustomListActionUseCaseTest.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ class CustomListActionUseCaseTest {
7171
RelayItem.Location.Country(
7272
id = locationId,
7373
name = locationName,
74-
expanded = false,
7574
cities = emptyList()
7675
)
7776
)
@@ -151,7 +150,7 @@ class CustomListActionUseCaseTest {
151150
val action = CustomListAction.Delete(id = customListId)
152151
val expectedResult =
153152
Deleted(undo = action.not(name = name, locations = listOf(location))).right()
154-
every { mockLocation.countryCode } returns location.countryCode
153+
every { mockLocation.code } returns location.code
155154
coEvery { mockCustomListsRepository.deleteCustomList(id = customListId) } returns
156155
Unit.right()
157156
coEvery { mockCustomListsRepository.getCustomListById(customListId) } returns

0 commit comments

Comments
 (0)