-
Notifications
You must be signed in to change notification settings - Fork 2
[Summit prep] Add a search feature #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -20,8 +20,28 @@ class CountryListViewModel( | |||||||||
| val error: CountryListError? = null, | ||||||||||
| val serverStatus: ServerStatus? = null, | ||||||||||
| val navigationTarget: Country? = null, | ||||||||||
| var searchQuery: String = "", | ||||||||||
|
||||||||||
| var searchQuery: String = "", | |
| val searchQuery: String = "", |
Outdated
Copilot
AI
Jul 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using !! on _state.value can throw a NullPointerException if value is ever null; consider using a safe call (value?.copy(...)) or ensuring the subject always has a non-null value before updating.
| _state.onNext(_state.value!!.copy(searchQuery = query)) | |
| _state.value?.let { currentState -> | |
| _state.onNext(currentState.copy(searchQuery = query)) | |
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,4 +80,44 @@ class CountryListViewModelTests: KoinTest { | |
| } | ||
| } | ||
| } | ||
|
|
||
| @Nested | ||
| @DisplayName("filteredContinents") | ||
| inner class FilteredContinents { | ||
| @Test | ||
| fun `returns only continents with matching countries`() { | ||
| // Arrange: set up continents with countries | ||
| val continents = listOf( | ||
| com.example.domainmodels.Continent( | ||
| name = "Europe", | ||
| countries = listOf( | ||
| com.example.domainmodels.Country(regionCode = "FR"), | ||
| com.example.domainmodels.Country(regionCode = "DE") | ||
| ) | ||
| ), | ||
| com.example.domainmodels.Continent( | ||
| name = "Asia", | ||
| countries = listOf( | ||
| com.example.domainmodels.Country(regionCode = "JP"), | ||
| com.example.domainmodels.Country(regionCode = "CN") | ||
| ) | ||
| ) | ||
| ) | ||
| // Set continents in state | ||
| val stateField = CountryListViewModel::class.java.getDeclaredField("_state") | ||
|
||
| stateField.isAccessible = true | ||
| val subject = stateField.get(viewModel) as io.reactivex.rxjava3.subjects.BehaviorSubject<CountryListViewModel.UiState> | ||
| subject.onNext(CountryListViewModel.UiState(continents = continents)) | ||
|
|
||
| // Act: update search query | ||
| viewModel.updateSearchQuery("fr") | ||
|
|
||
| // Assert: only Europe with France should match | ||
| val filtered = viewModel.filteredContinents | ||
| filtered.size.shouldBeEqualTo(1) | ||
| filtered[0].name.shouldBeEqualTo("Europe") | ||
| filtered[0].countries.size.shouldBeEqualTo(1) | ||
| filtered[0].countries[0].regionCode.shouldBeEqualTo("FR") | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The label string is hardcoded; for localization support, consider moving it into
strings.xmland referring to it via a resource ID.