diff --git a/app/src/androidTest/java/com/android/polybazaar/map/ListingsMapTest.kt b/app/src/androidTest/java/com/android/polybazaar/map/ListingsMapTest.kt
new file mode 100644
index 00000000..d6d4238d
--- /dev/null
+++ b/app/src/androidTest/java/com/android/polybazaar/map/ListingsMapTest.kt
@@ -0,0 +1,72 @@
+// Co-authored-by: Claude Code (Claude Opus 5.5)
+package com.android.polybazaar.map
+
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.setValue
+import androidx.compose.ui.test.junit4.v2.createComposeRule
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.android.polybazaar.listing.model.ListingType
+import com.android.polybazaar.map.model.Campus
+import com.android.polybazaar.map.model.Coordinates
+import com.android.polybazaar.map.ui.ListingsMap
+import com.android.polybazaar.map.viewmodel.MapCentre
+import com.android.polybazaar.map.viewmodel.MapMarker
+import org.junit.Assert.assertTrue
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+
+/**
+ * Runs the Google map on a real device (the CI emulator has Google Play services), which unit tests
+ * can't: an item and a skill marker, with the renter's circle and then a campus marker. It waits
+ * for the map to be created (onMapReady) rather than loaded: tiles need a key that accepts this
+ * build, which debug builds don't have, so onMapLoaded might never fire.
+ */
+@RunWith(AndroidJUnit4::class)
+class ListingsMapTest {
+
+ @get:Rule val composeTestRule = createComposeRule()
+
+ private val markers =
+ listOf(
+ MapMarker(
+ "drill",
+ "Bosch drill set",
+ ListingType.ITEM,
+ Coordinates(46.519, 6.567),
+ "CHF 8",
+ ),
+ MapMarker(
+ "maths",
+ "Analysis tutoring",
+ ListingType.SERVICE,
+ Coordinates(46.522, 6.579),
+ "CHF 25",
+ ),
+ )
+
+ @Test
+ fun mapWithMarkers_isCreated_aroundTheRenter_onACampus_andWhileChoosing() {
+ var centre: MapCentre by mutableStateOf(MapCentre.Located(Coordinates(46.52, 6.57)))
+ var ready = false
+ composeTestRule.setContent {
+ ListingsMap(centre = centre, markers = markers, onMapReady = { ready = true })
+ }
+
+ // The map exists, with its markers and the renter's circle: no crash so far.
+ composeTestRule.waitUntil(MAP_READY_MILLIS) { ready }
+
+ // Moving to a campus marker, then to the overview, recomposes without crashing.
+ composeTestRule.runOnIdle { centre = MapCentre.OnCampus(Campus.EPFL) }
+ composeTestRule.waitForIdle()
+ composeTestRule.runOnIdle { centre = MapCentre.NeedsChoice() }
+ composeTestRule.waitForIdle()
+ assertTrue(ready)
+ }
+
+ private companion object {
+ /** Generous for a cold emulator; the map is usually created within a second or two. */
+ const val MAP_READY_MILLIS = 20_000L
+ }
+}
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index fae0ddb6..842d2724 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -55,6 +55,13 @@
+
+
\ No newline at end of file
diff --git a/app/src/main/java/com/android/polybazaar/map/ui/ListingsMap.kt b/app/src/main/java/com/android/polybazaar/map/ui/ListingsMap.kt
new file mode 100644
index 00000000..8c888b69
--- /dev/null
+++ b/app/src/main/java/com/android/polybazaar/map/ui/ListingsMap.kt
@@ -0,0 +1,99 @@
+// Co-authored-by: Claude Code (Claude Opus 5.5)
+package com.android.polybazaar.map.ui
+
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.runtime.key
+import androidx.compose.ui.Modifier
+import com.android.polybazaar.R
+import com.android.polybazaar.auth.ui.AuthColors
+import com.android.polybazaar.map.model.Coordinates
+import com.android.polybazaar.map.viewmodel.MapCentre
+import com.android.polybazaar.map.viewmodel.MapMarker
+import com.google.android.gms.maps.model.CameraPosition
+import com.google.android.gms.maps.model.LatLng
+import com.google.maps.android.compose.Circle
+import com.google.maps.android.compose.GoogleMap
+import com.google.maps.android.compose.MapEffect
+import com.google.maps.android.compose.MapUiSettings
+import com.google.maps.android.compose.MapsComposeExperimentalApi
+import com.google.maps.android.compose.MarkerComposable
+import com.google.maps.android.compose.rememberCameraPositionState
+import com.google.maps.android.compose.rememberUpdatedMarkerState
+
+/** Radius of the "approximate location" circle (Figma "Map — Centred on you"), in metres. */
+private const val APPROXIMATE_RADIUS_METRES = 150.0
+
+private fun Coordinates.toLatLng() = LatLng(latitude, longitude)
+
+/**
+ * The Google map itself: camera from [cameraFor], one marker per listing with its item or skill
+ * icon, and the renter's approximate circle or their campus marker. [onMapReady] is called once the
+ * map is created (tests wait for it). Kept to drawing only, since Google Maps can't run in unit
+ * tests: every decision is in the tested functions of MapScreen.kt.
+ */
+@OptIn(MapsComposeExperimentalApi::class)
+@Composable
+internal fun ListingsMap(
+ centre: MapCentre,
+ markers: List,
+ onMapReady: () -> Unit = {},
+) {
+ val camera = cameraFor(centre)
+ val cameraState = rememberCameraPositionState {
+ position = CameraPosition.fromLatLngZoom(camera.target.toLatLng(), camera.zoom)
+ }
+ // Moves when the centre changes, for example once the location is read or a campus is picked.
+ // Setting the position rather than animating: CameraUpdateFactory needs the map to be
+ // initialised first, which isn't guaranteed this early on a slow device.
+ LaunchedEffect(camera) {
+ cameraState.position = CameraPosition.fromLatLngZoom(camera.target.toLatLng(), camera.zoom)
+ }
+ GoogleMap(
+ modifier = Modifier.fillMaxSize(),
+ cameraPositionState = cameraState,
+ // The location layer and the bottom bar already cover the edges: keep the map's own
+ // controls out of their way.
+ uiSettings = MapUiSettings(zoomControlsEnabled = false, mapToolbarEnabled = false),
+ ) {
+ // Once the map exists, whether or not its tiles can load: lets the instrumented test wait for
+ // the map instead of sleeping.
+ MapEffect(Unit) { onMapReady() }
+ markers.forEach { marker ->
+ // Keyed by listing, not by its place in the list: after a reload that drops or reorders
+ // listings, each marker keeps its own state instead of taking its neighbour's, and a listing
+ // its owner moved follows its new position (rememberUpdatedMarkerState).
+ key(marker.id) {
+ MarkerComposable(
+ keys = arrayOf(marker.id, marker.type),
+ state = rememberUpdatedMarkerState(position = marker.coordinates.toLatLng()),
+ title = markerLabel(marker),
+ ) {
+ MarkerPin(icon = markerIcon(marker.type))
+ }
+ }
+ }
+ when (centre) {
+ is MapCentre.Located ->
+ Circle(
+ center = centre.coordinates.toLatLng(),
+ radius = APPROXIMATE_RADIUS_METRES,
+ fillColor = AuthColors.Accent.copy(alpha = 0.15f),
+ strokeColor = AuthColors.Accent.copy(alpha = 0.4f),
+ strokeWidth = 2f,
+ )
+ is MapCentre.OnCampus ->
+ key(centre.campus) {
+ MarkerComposable(
+ keys = arrayOf(centre.campus),
+ state = rememberUpdatedMarkerState(position = centre.campus.centre.toLatLng()),
+ title = centre.campus.name,
+ ) {
+ MarkerPin(icon = R.drawable.ic_campus)
+ }
+ }
+ else -> Unit
+ }
+ }
+}
diff --git a/app/src/main/java/com/android/polybazaar/map/ui/MapScreen.kt b/app/src/main/java/com/android/polybazaar/map/ui/MapScreen.kt
new file mode 100644
index 00000000..97ed7106
--- /dev/null
+++ b/app/src/main/java/com/android/polybazaar/map/ui/MapScreen.kt
@@ -0,0 +1,240 @@
+// Co-authored-by: Claude Code (Claude Opus 5.5)
+package com.android.polybazaar.map.ui
+
+import androidx.annotation.DrawableRes
+import androidx.annotation.StringRes
+import androidx.compose.foundation.background
+import androidx.compose.foundation.border
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.BoxScope
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.RowScope
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.heightIn
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.size
+import androidx.compose.foundation.shape.CircleShape
+import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.material3.CircularProgressIndicator
+import androidx.compose.material3.Icon
+import androidx.compose.material3.Text
+import androidx.compose.material3.TextButton
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.collectAsState
+import androidx.compose.runtime.getValue
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.draw.shadow
+import androidx.compose.ui.platform.testTag
+import androidx.compose.ui.res.painterResource
+import androidx.compose.ui.res.stringResource
+import androidx.compose.ui.text.font.FontWeight
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.unit.sp
+import com.android.polybazaar.R
+import com.android.polybazaar.auth.ui.AuthColors
+import com.android.polybazaar.error.ui.message
+import com.android.polybazaar.listing.model.ListingType
+import com.android.polybazaar.map.model.Campus
+import com.android.polybazaar.map.model.Coordinates
+import com.android.polybazaar.map.viewmodel.MapCentre
+import com.android.polybazaar.map.viewmodel.MapMarker
+import com.android.polybazaar.map.viewmodel.MapUiState
+import com.android.polybazaar.map.viewmodel.MapViewModel
+
+object MapScreenTags {
+ const val SCREEN = "map_screen"
+ const val LOADING = "map_loading_listings"
+ const val ERROR = "map_listings_error"
+ const val RETRY_BUTTON = "map_retry_button"
+ const val EMPTY = "map_no_listings"
+}
+
+/** Where the map's camera points and how close. */
+internal data class MapCamera(val target: Coordinates, val zoom: Float)
+
+/** Street level: a few hundred metres around the renter or the campus. */
+private const val CLOSE_ZOOM = 15f
+
+/** Both campuses at once, before the renter's centre is known. */
+private const val OVERVIEW_ZOOM = 14f
+
+/**
+ * The camera for [centre]: close on the renter or their campus, and an overview of EPFL and UNIL
+ * while the centre isn't known yet (asking, locating, choosing).
+ */
+internal fun cameraFor(centre: MapCentre): MapCamera =
+ when (centre) {
+ is MapCentre.Located -> MapCamera(centre.coordinates, CLOSE_ZOOM)
+ is MapCentre.OnCampus -> MapCamera(centre.campus.centre, CLOSE_ZOOM)
+ MapCentre.Undecided,
+ MapCentre.Locating,
+ is MapCentre.NeedsChoice -> MapCamera(campusesMidpoint(), OVERVIEW_ZOOM)
+ }
+
+/** Halfway between the campuses, so the overview shows both. */
+private fun campusesMidpoint(): Coordinates =
+ Coordinates(
+ latitude = Campus.entries.map { it.centre.latitude }.average(),
+ longitude = Campus.entries.map { it.centre.longitude }.average(),
+ )
+
+/** The marker icon of a listing: items and skills differ by icon, not only colour (#353). */
+@DrawableRes
+internal fun markerIcon(type: ListingType): Int =
+ when (type) {
+ ListingType.ITEM -> R.drawable.ic_marker_item
+ ListingType.SERVICE -> R.drawable.ic_marker_service
+ }
+
+/** What TalkBack reads for a marker: its title, whether it's an item or a skill, and its price. */
+@StringRes
+internal fun markerDescription(type: ListingType): Int =
+ when (type) {
+ ListingType.ITEM -> R.string.map_marker_item
+ ListingType.SERVICE -> R.string.map_marker_service
+ }
+
+/**
+ * The Map tab (#341): the listings around the renter or their campus on a map, item and skill
+ * markers drawn differently, with the location layer (#340) over it.
+ *
+ * @param map draws the map for the state; the Google map by default, a stand-in in tests.
+ */
+@Composable
+fun MapScreen(
+ viewModel: MapViewModel,
+ modifier: Modifier = Modifier,
+ map: @Composable (MapUiState) -> Unit = { ListingsMap(it.centre, it.markers) },
+) {
+ val uiState by viewModel.uiState.collectAsState()
+ MapContent(
+ uiState = uiState,
+ onRetry = viewModel::loadListings,
+ map = { map(uiState) },
+ locationLayer = { MapLocationLayer(viewModel) },
+ modifier = modifier,
+ )
+}
+
+/**
+ * The map tab without its ViewModel: [map] draws the map (the Google map in the app, a stand-in in
+ * tests, where Google Maps can't run), then what the listings' state needs over it, then
+ * [locationLayer] on top.
+ *
+ * @param onRetry reloads the listings after a failure.
+ */
+@Composable
+fun MapContent(
+ uiState: MapUiState,
+ onRetry: () -> Unit,
+ map: @Composable () -> Unit,
+ locationLayer: @Composable () -> Unit,
+ modifier: Modifier = Modifier,
+) {
+ Box(modifier = modifier.fillMaxSize().testTag(MapScreenTags.SCREEN)) {
+ map()
+ ListingsStatus(uiState, onRetry)
+ // Last, so its cards and their dim cover the status too.
+ locationLayer()
+ }
+}
+
+/**
+ * Why there are no markers, or a load in progress, at the bottom of the map. A reload while markers
+ * are shown (the tab coming back) shows nothing, so the map doesn't flicker.
+ */
+@Composable
+private fun BoxScope.ListingsStatus(uiState: MapUiState, onRetry: () -> Unit) {
+ val error = uiState.error
+ when {
+ error != null ->
+ BottomPill(MapScreenTags.ERROR) {
+ Text(
+ text = error.message(),
+ color = AuthColors.Danger,
+ fontSize = 12.sp,
+ modifier = Modifier.weight(1f, fill = false),
+ )
+ TextButton(
+ onClick = onRetry,
+ modifier = Modifier.heightIn(min = 48.dp).testTag(MapScreenTags.RETRY_BUTTON),
+ ) {
+ Text(
+ text = stringResource(R.string.map_retry),
+ color = AuthColors.Accent,
+ fontSize = 12.sp,
+ fontWeight = FontWeight.SemiBold,
+ )
+ }
+ }
+ uiState.isLoading && uiState.markers.isEmpty() ->
+ BottomPill(MapScreenTags.LOADING) {
+ CircularProgressIndicator(
+ color = AuthColors.Accent,
+ strokeWidth = 2.dp,
+ modifier = Modifier.size(16.dp),
+ )
+ Text(
+ text = stringResource(R.string.map_loading_listings),
+ color = AuthColors.TextSecondary,
+ fontSize = 12.sp,
+ modifier = Modifier.padding(vertical = 12.dp),
+ )
+ }
+ !uiState.isLoading && uiState.markers.isEmpty() ->
+ BottomPill(MapScreenTags.EMPTY) {
+ Text(
+ text = stringResource(R.string.map_no_listings),
+ color = AuthColors.TextSecondary,
+ fontSize = 12.sp,
+ modifier = Modifier.padding(vertical = 12.dp),
+ )
+ }
+ }
+}
+
+/** A pill at the bottom of the map, styled like the location pills at the top. */
+@Composable
+private fun BoxScope.BottomPill(tag: String, content: @Composable RowScope.() -> Unit) {
+ Row(
+ modifier =
+ Modifier.align(Alignment.BottomCenter)
+ .padding(start = 18.dp, end = 18.dp, bottom = 16.dp)
+ .shadow(2.dp, RoundedCornerShape(24.dp))
+ .background(AuthColors.CardBackground, RoundedCornerShape(24.dp))
+ .border(1.dp, AuthColors.Outline, RoundedCornerShape(24.dp))
+ .padding(horizontal = 14.dp)
+ .testTag(tag),
+ verticalAlignment = Alignment.CenterVertically,
+ horizontalArrangement = Arrangement.spacedBy(8.dp),
+ ) {
+ content()
+ }
+}
+
+/** The round accent pin with a white icon, drawn for listing and campus markers. */
+@Composable
+internal fun MarkerPin(@DrawableRes icon: Int, modifier: Modifier = Modifier) {
+ Box(
+ modifier =
+ modifier
+ .size(32.dp)
+ .background(AuthColors.Accent, CircleShape)
+ .border(2.dp, AuthColors.CardBackground, CircleShape),
+ contentAlignment = Alignment.Center,
+ ) {
+ Icon(
+ painter = painterResource(icon),
+ contentDescription = null,
+ tint = AuthColors.CardBackground,
+ modifier = Modifier.size(16.dp),
+ )
+ }
+}
+
+/** What TalkBack reads for [marker], for example "Bosch drill set, item, CHF 8 per day". */
+@Composable
+internal fun markerLabel(marker: MapMarker): String =
+ stringResource(markerDescription(marker.type), marker.title, marker.price)
diff --git a/app/src/main/res/drawable/ic_marker_item.xml b/app/src/main/res/drawable/ic_marker_item.xml
new file mode 100644
index 00000000..40491161
--- /dev/null
+++ b/app/src/main/res/drawable/ic_marker_item.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
diff --git a/app/src/main/res/drawable/ic_marker_service.xml b/app/src/main/res/drawable/ic_marker_service.xml
new file mode 100644
index 00000000..2ca72dd6
--- /dev/null
+++ b/app/src/main/res/drawable/ic_marker_service.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index dc7784f8..42172a6c 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -127,6 +127,11 @@
Showing %1$s
Change
Change campus
+ Loading listings…
+ No listings with a location nearby yet
+ Retry
+ %1$s, item, %2$s per day
+ %1$s, skill, %2$s per day
Your bio was saved, but the photo couldn’t be removed. Tap Save to try again.
diff --git a/app/src/test/java/com/android/polybazaar/map/ui/MapScreenTest.kt b/app/src/test/java/com/android/polybazaar/map/ui/MapScreenTest.kt
new file mode 100644
index 00000000..582a0cb5
--- /dev/null
+++ b/app/src/test/java/com/android/polybazaar/map/ui/MapScreenTest.kt
@@ -0,0 +1,220 @@
+// Co-authored-by: Claude Code (Claude Opus 5.5)
+package com.android.polybazaar.map.ui
+
+import android.content.Context
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.platform.testTag
+import androidx.compose.ui.test.assertHeightIsAtLeast
+import androidx.compose.ui.test.assertIsDisplayed
+import androidx.compose.ui.test.junit4.v2.createComposeRule
+import androidx.compose.ui.test.onNodeWithTag
+import androidx.compose.ui.test.onNodeWithText
+import androidx.compose.ui.test.performClick
+import androidx.compose.ui.unit.dp
+import androidx.lifecycle.SavedStateHandle
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.ext.junit.runners.AndroidJUnit4
+import com.android.polybazaar.R
+import com.android.polybazaar.error.model.AppError
+import com.android.polybazaar.listing.model.FakeListingRepository
+import com.android.polybazaar.listing.model.ItemListing
+import com.android.polybazaar.listing.model.ListingCategory
+import com.android.polybazaar.listing.model.ListingLocation
+import com.android.polybazaar.listing.model.ListingType
+import com.android.polybazaar.map.model.Campus
+import com.android.polybazaar.map.model.Coordinates
+import com.android.polybazaar.map.model.FakeLocationRepository
+import com.android.polybazaar.map.viewmodel.MapCentre
+import com.android.polybazaar.map.viewmodel.MapMarker
+import com.android.polybazaar.map.viewmodel.MapUiState
+import com.android.polybazaar.map.viewmodel.MapViewModel
+import java.net.UnknownHostException
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertNotEquals
+import org.junit.Assert.assertTrue
+import org.junit.Rule
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@RunWith(AndroidJUnit4::class)
+class MapScreenTest {
+
+ @get:Rule val composeTestRule = createComposeRule()
+
+ private val context: Context = ApplicationProvider.getApplicationContext()
+
+ private val drill =
+ MapMarker("drill", "Bosch drill set", ListingType.ITEM, Coordinates(46.519, 6.567), "CHF 8")
+
+ private fun node(tag: String) = composeTestRule.onNodeWithTag(tag, useUnmergedTree = true)
+
+ /** The map tab with a stand-in map, since Google Maps can't run in unit tests. */
+ private fun setContent(uiState: MapUiState, onRetry: () -> Unit = {}) {
+ composeTestRule.setContent {
+ MapContent(
+ uiState = uiState,
+ onRetry = onRetry,
+ map = { Box(Modifier.fillMaxSize().testTag("map")) },
+ locationLayer = { Box(Modifier.fillMaxSize().testTag("location_layer")) },
+ )
+ }
+ }
+
+ // ---- Camera ----
+
+ @Test
+ fun camera_isCloseOnTheRenter() {
+ val renter = Coordinates(46.52, 6.57)
+
+ assertEquals(MapCamera(renter, 15f), cameraFor(MapCentre.Located(renter)))
+ }
+
+ @Test
+ fun camera_isCloseOnTheCampus() {
+ assertEquals(MapCamera(Campus.UNIL.centre, 15f), cameraFor(MapCentre.OnCampus(Campus.UNIL)))
+ }
+
+ @Test
+ fun camera_beforeTheCentreIsKnown_showsBothCampuses() {
+ listOf(MapCentre.Undecided, MapCentre.Locating, MapCentre.NeedsChoice()).forEach { centre ->
+ val camera = cameraFor(centre)
+ assertEquals(14f, camera.zoom)
+ // Between the campuses, on both axes.
+ val latitudes = Campus.entries.map { it.centre.latitude }
+ val longitudes = Campus.entries.map { it.centre.longitude }
+ assertTrue(camera.target.latitude in latitudes.min()..latitudes.max())
+ assertTrue(camera.target.longitude in longitudes.min()..longitudes.max())
+ }
+ }
+
+ // ---- Markers ----
+
+ @Test
+ fun itemsAndSkills_haveDifferentIconsAndDescriptions() {
+ assertNotEquals(markerIcon(ListingType.ITEM), markerIcon(ListingType.SERVICE))
+ assertNotEquals(markerDescription(ListingType.ITEM), markerDescription(ListingType.SERVICE))
+ }
+
+ @Test
+ fun markerLabel_readsTitleTypeAndPrice() {
+ var label = ""
+ composeTestRule.setContent { label = markerLabel(drill) }
+ composeTestRule.waitForIdle()
+
+ assertEquals(context.getString(R.string.map_marker_item, "Bosch drill set", "CHF 8"), label)
+ }
+
+ @Test
+ fun markerPin_drawsItsIcon() {
+ composeTestRule.setContent {
+ MarkerPin(icon = markerIcon(ListingType.SERVICE), modifier = Modifier.testTag("pin"))
+ }
+
+ node("pin").assertIsDisplayed()
+ }
+
+ // ---- Listings state over the map ----
+
+ @Test
+ fun mapAndLocationLayer_areBothDrawn() {
+ setContent(MapUiState(markers = listOf(drill)))
+
+ node("map").assertIsDisplayed()
+ node("location_layer").assertIsDisplayed()
+ }
+
+ @Test
+ fun firstLoad_showsLoading() {
+ setContent(MapUiState(isLoading = true))
+
+ node(MapScreenTags.LOADING).assertIsDisplayed()
+ composeTestRule
+ .onNodeWithText(context.getString(R.string.map_loading_listings))
+ .assertIsDisplayed()
+ }
+
+ @Test
+ fun reloadWithMarkersShown_showsNothing_soTheMapDoesNotFlicker() {
+ setContent(MapUiState(markers = listOf(drill), isLoading = true))
+
+ node(MapScreenTags.LOADING).assertDoesNotExist()
+ node(MapScreenTags.EMPTY).assertDoesNotExist()
+ }
+
+ @Test
+ fun noListingWithALocation_saysSo() {
+ setContent(MapUiState())
+
+ node(MapScreenTags.EMPTY).assertIsDisplayed()
+ composeTestRule.onNodeWithText(context.getString(R.string.map_no_listings)).assertIsDisplayed()
+ }
+
+ @Test
+ fun markersShown_showNoStatus() {
+ setContent(MapUiState(markers = listOf(drill)))
+
+ node(MapScreenTags.LOADING).assertDoesNotExist()
+ node(MapScreenTags.EMPTY).assertDoesNotExist()
+ node(MapScreenTags.ERROR).assertDoesNotExist()
+ }
+
+ @Test
+ fun failedLoad_saysWhy_andRetryReloads() {
+ var retries = 0
+ setContent(MapUiState(error = AppError.NETWORK), onRetry = { retries++ })
+
+ node(MapScreenTags.ERROR).assertIsDisplayed()
+ composeTestRule.onNodeWithText(context.getString(R.string.error_network)).assertIsDisplayed()
+ node(MapScreenTags.RETRY_BUTTON).assertHeightIsAtLeast(48.dp).performClick()
+
+ assertEquals(1, retries)
+ }
+
+ @Test
+ fun failedReloadWithMarkersShown_stillOffersRetry() {
+ setContent(MapUiState(markers = listOf(drill), error = AppError.NETWORK))
+
+ node(MapScreenTags.RETRY_BUTTON).assertIsDisplayed()
+ }
+
+ // ---- With the real ViewModel ----
+
+ @Test
+ fun screen_showsTheViewModelsMarkers_andRetryReloads() {
+ val listings =
+ FakeListingRepository(
+ allListings =
+ listOf(
+ ItemListing(
+ category = ListingCategory.ITEM_TOOLS,
+ price = 8.0,
+ title = "Bosch drill set",
+ description = "With bits",
+ listingId = "drill",
+ ownerUid = "lender",
+ location = ListingLocation(46.519, 6.567, "Rolex Learning Center"),
+ )
+ )
+ )
+ // The first load fails, as offline without a cache.
+ listings.failure = UnknownHostException("firestore.googleapis.com")
+ val viewModel = MapViewModel(FakeLocationRepository(), listings, "renter", SavedStateHandle())
+ // A campus already picked, so the location card doesn't cover the bottom of the map.
+ viewModel.chooseCampus(Campus.EPFL)
+ var shown = emptyList()
+
+ composeTestRule.setContent { MapScreen(viewModel, map = { shown = it.markers }) }
+ composeTestRule.waitForIdle()
+ assertEquals(emptyList(), shown.map { it.id })
+ node(MapLocationTags.CAMPUS_PILL).assertIsDisplayed()
+
+ listings.failure = null
+ node(MapScreenTags.RETRY_BUTTON).performClick()
+ composeTestRule.waitForIdle()
+
+ assertEquals(listOf("drill"), shown.map { it.id })
+ node(MapScreenTags.ERROR).assertDoesNotExist()
+ }
+}