-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Android): update location with hide maps on (#803)
* fix(Android): update location with hide maps on * use helper function to cut down on boilerplate * stabilize locally flaky test * fix nonsensical linter error the ViewportProvider constructor does not, in fact, return Unit
- Loading branch information
1 parent
d528c24
commit 0d31007
Showing
8 changed files
with
172 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 14 additions & 2 deletions
16
...pp/src/androidTest/java/com/mbta/tid/mbta_app/android/location/MockLocationDataManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,20 @@ | ||
package com.mbta.tid.mbta_app.android.location | ||
|
||
import android.location.Location | ||
import io.github.dellisd.spatialk.geojson.Position | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
|
||
class MockLocationDataManager(location: Location?) : LocationDataManager() { | ||
override val currentLocation = MutableStateFlow(location) | ||
class MockLocationDataManager(position: Position? = Position(latitude = 0.0, longitude = 0.0)) : | ||
LocationDataManager() { | ||
override val currentLocation = MutableStateFlow(position?.let { MockLocation(it) }) | ||
|
||
fun moveTo(position: Position?) { | ||
currentLocation.value = position?.let { MockLocation(it) } | ||
} | ||
|
||
data class MockLocation(val coordinates: Position) : Location("mock") { | ||
override fun getLatitude() = coordinates.latitude | ||
|
||
override fun getLongitude() = coordinates.longitude | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
androidApp/src/androidTest/java/com/mbta/tid/mbta_app/android/pages/NearbyTransitPageTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package com.mbta.tid.mbta_app.android.pages | ||
|
||
import MockRepositories | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.test.ExperimentalTestApi | ||
import androidx.compose.ui.test.assertIsDisplayed | ||
import androidx.compose.ui.test.hasText | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.test.onNodeWithText | ||
import com.mapbox.maps.extension.compose.animation.viewport.MapViewportState | ||
import com.mbta.tid.mbta_app.analytics.Analytics | ||
import com.mbta.tid.mbta_app.analytics.MockAnalytics | ||
import com.mbta.tid.mbta_app.android.MainApplication | ||
import com.mbta.tid.mbta_app.android.component.sheet.rememberBottomSheetScaffoldState | ||
import com.mbta.tid.mbta_app.android.location.MockLocationDataManager | ||
import com.mbta.tid.mbta_app.android.location.ViewportProvider | ||
import com.mbta.tid.mbta_app.dependencyInjection.repositoriesModule | ||
import com.mbta.tid.mbta_app.model.ObjectCollectionBuilder | ||
import com.mbta.tid.mbta_app.model.RoutePattern | ||
import com.mbta.tid.mbta_app.model.RouteType | ||
import com.mbta.tid.mbta_app.model.response.AlertsStreamDataResponse | ||
import com.mbta.tid.mbta_app.model.response.GlobalResponse | ||
import com.mbta.tid.mbta_app.model.response.PredictionsByStopJoinResponse | ||
import com.mbta.tid.mbta_app.model.response.ScheduleResponse | ||
import com.mbta.tid.mbta_app.repositories.INearbyRepository | ||
import com.mbta.tid.mbta_app.repositories.IPredictionsRepository | ||
import com.mbta.tid.mbta_app.repositories.ISettingsRepository | ||
import com.mbta.tid.mbta_app.repositories.MockGlobalRepository | ||
import com.mbta.tid.mbta_app.repositories.MockPredictionsRepository | ||
import com.mbta.tid.mbta_app.repositories.MockScheduleRepository | ||
import com.mbta.tid.mbta_app.repositories.MockSettingsRepository | ||
import com.mbta.tid.mbta_app.repositories.NearbyRepository | ||
import com.mbta.tid.mbta_app.repositories.Settings | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.koin.androidx.compose.koinViewModel | ||
import org.koin.compose.KoinContext | ||
import org.koin.dsl.koinApplication | ||
import org.koin.dsl.module | ||
|
||
class NearbyTransitPageTest { | ||
@get:Rule val composeTestRule = createComposeRule() | ||
|
||
@OptIn(ExperimentalMaterial3Api::class, ExperimentalTestApi::class) | ||
@Test | ||
fun testHideMapsLocationUpdates() { | ||
val objects = ObjectCollectionBuilder() | ||
|
||
val stop1 = | ||
objects.stop { | ||
latitude = 1.0 | ||
longitude = 1.0 | ||
name = "Stop A" | ||
vehicleType = RouteType.BUS | ||
} | ||
val stop2 = | ||
objects.stop { | ||
latitude = 2.0 | ||
longitude = 2.0 | ||
name = "Stop B" | ||
vehicleType = RouteType.BUS | ||
} | ||
val route = objects.route { type = RouteType.BUS } | ||
objects.routePattern(route) { | ||
typicality = RoutePattern.Typicality.Typical | ||
representativeTrip { stopIds = listOf(stop1.id, stop2.id) } | ||
} | ||
|
||
val alertData = AlertsStreamDataResponse(objects) | ||
val globalResponse = GlobalResponse(objects) | ||
|
||
val koin = koinApplication { | ||
modules( | ||
repositoriesModule( | ||
MockRepositories.buildWithDefaults( | ||
global = MockGlobalRepository(globalResponse), | ||
schedules = MockScheduleRepository(ScheduleResponse(objects)) | ||
) | ||
), | ||
module { | ||
single<Analytics> { MockAnalytics() } | ||
single<INearbyRepository> { NearbyRepository() } | ||
single<IPredictionsRepository> { | ||
MockPredictionsRepository( | ||
connectV2Response = PredictionsByStopJoinResponse(objects) | ||
) | ||
} | ||
single<ISettingsRepository> { | ||
MockSettingsRepository(mapOf(Settings.HideMaps to true)) | ||
} | ||
}, | ||
MainApplication.koinViewModelModule | ||
) | ||
} | ||
|
||
val locationDataManager = MockLocationDataManager(stop1.position) | ||
val viewportProvider = ViewportProvider(MapViewportState()) | ||
|
||
composeTestRule.setContent { | ||
KoinContext(koin.koin) { | ||
NearbyTransitPage( | ||
nearbyTransit = | ||
NearbyTransit( | ||
alertData = alertData, | ||
globalResponse = globalResponse, | ||
hideMaps = true, | ||
lastNearbyTransitLocationState = remember { mutableStateOf(null) }, | ||
nearbyTransitSelectingLocationState = | ||
remember { mutableStateOf(false) }, | ||
scaffoldState = rememberBottomSheetScaffoldState(), | ||
locationDataManager = locationDataManager, | ||
viewportProvider = viewportProvider | ||
), | ||
navBarVisible = false, | ||
showNavBar = {}, | ||
hideNavBar = {}, | ||
bottomBar = {}, | ||
searchResultsViewModel = koinViewModel() | ||
) | ||
} | ||
} | ||
|
||
composeTestRule.waitUntilExactlyOneExists(hasText(stop1.name)) | ||
composeTestRule.onNodeWithText(stop1.name).assertIsDisplayed() | ||
|
||
locationDataManager.moveTo(stop2.position) | ||
|
||
composeTestRule.waitUntilExactlyOneExists(hasText(stop2.name)) | ||
composeTestRule.onNodeWithText(stop2.name).assertIsDisplayed() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters