Loading cardinal-android/app/src/main/java/earth/maps/cardinal/ui/home/NearbyViewModel.kt +4 −0 Original line number Diff line number Diff line Loading @@ -110,6 +110,10 @@ class NearbyViewModel @Inject constructor( } } fun getSelectedCategoriesSet(): Set<String> { return selectedCategories.toSet() } suspend fun fetchNearby(latitude: Double, longitude: Double) { _isLoading.value = true _error.value = null Loading cardinal-android/app/src/test/java/earth/maps/cardinal/ui/home/NearbyViewModelTest.kt +59 −0 Original line number Diff line number Diff line Loading @@ -244,4 +244,63 @@ class NearbyViewModelTest { ) } } @Test fun `setCategorySelection should add and remove categories correctly`() = runTest { val category1 = "food" val category2 = "health" // Initially no categories should be selected assertTrue(viewModel.getSelectedCategoriesSet().isEmpty()) // Add categories viewModel.setCategorySelection(category1, true) viewModel.setCategorySelection(category2, true) // Verify categories were added assertEquals(setOf(category1, category2), viewModel.getSelectedCategoriesSet()) // Remove one category viewModel.setCategorySelection(category1, false) // Verify remaining category assertEquals(setOf(category2), viewModel.getSelectedCategoriesSet()) } @Test fun `setCategorySelection should refresh data with selected categories`() = runTest { val testLocation = android.location.Location("test").apply { latitude = 37.7749 longitude = -122.4194 } val locationFlow = MutableStateFlow(testLocation) // Set up the location repository to return a location coEvery { mockLocationRepository.locationFlow } returns locationFlow // Mock the geocoding service coEvery { mockGeocodingService.nearby(any(), any(), any()) } returns emptyList() viewModel.startLocationObservation() advanceUntilIdle() // Clear previous verification calls io.mockk.clearMocks(mockGeocodingService) // Add categories viewModel.setCategorySelection("food", true) viewModel.setCategorySelection("health", true) // Allow coroutines to complete advanceUntilIdle() // Verify that fetchNearby was called with both selected categories coVerify { mockGeocodingService.nearby( testLocation.latitude, testLocation.longitude, listOf("food", "health") ) } } } Loading
cardinal-android/app/src/main/java/earth/maps/cardinal/ui/home/NearbyViewModel.kt +4 −0 Original line number Diff line number Diff line Loading @@ -110,6 +110,10 @@ class NearbyViewModel @Inject constructor( } } fun getSelectedCategoriesSet(): Set<String> { return selectedCategories.toSet() } suspend fun fetchNearby(latitude: Double, longitude: Double) { _isLoading.value = true _error.value = null Loading
cardinal-android/app/src/test/java/earth/maps/cardinal/ui/home/NearbyViewModelTest.kt +59 −0 Original line number Diff line number Diff line Loading @@ -244,4 +244,63 @@ class NearbyViewModelTest { ) } } @Test fun `setCategorySelection should add and remove categories correctly`() = runTest { val category1 = "food" val category2 = "health" // Initially no categories should be selected assertTrue(viewModel.getSelectedCategoriesSet().isEmpty()) // Add categories viewModel.setCategorySelection(category1, true) viewModel.setCategorySelection(category2, true) // Verify categories were added assertEquals(setOf(category1, category2), viewModel.getSelectedCategoriesSet()) // Remove one category viewModel.setCategorySelection(category1, false) // Verify remaining category assertEquals(setOf(category2), viewModel.getSelectedCategoriesSet()) } @Test fun `setCategorySelection should refresh data with selected categories`() = runTest { val testLocation = android.location.Location("test").apply { latitude = 37.7749 longitude = -122.4194 } val locationFlow = MutableStateFlow(testLocation) // Set up the location repository to return a location coEvery { mockLocationRepository.locationFlow } returns locationFlow // Mock the geocoding service coEvery { mockGeocodingService.nearby(any(), any(), any()) } returns emptyList() viewModel.startLocationObservation() advanceUntilIdle() // Clear previous verification calls io.mockk.clearMocks(mockGeocodingService) // Add categories viewModel.setCategorySelection("food", true) viewModel.setCategorySelection("health", true) // Allow coroutines to complete advanceUntilIdle() // Verify that fetchNearby was called with both selected categories coVerify { mockGeocodingService.nearby( testLocation.latitude, testLocation.longitude, listOf("food", "health") ) } } }