-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add missing tests and fix some found issues
- Loading branch information
1 parent
db8b1fa
commit 1eb0111
Showing
11 changed files
with
230 additions
and
22 deletions.
There are no files selected for viewing
3 changes: 1 addition & 2 deletions
3
...bta_app/android/util/GetGlobalDataTest.kt → ...ta_app/android/state/GetGlobalDataTest.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
71 changes: 71 additions & 0 deletions
71
androidApp/src/androidTest/java/com/mbta/tid/mbta_app/android/state/GetNearbyTest.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,71 @@ | ||
package com.mbta.tid.mbta_app.android.state | ||
|
||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import com.mbta.tid.mbta_app.model.Coordinate | ||
import com.mbta.tid.mbta_app.model.NearbyStaticData | ||
import com.mbta.tid.mbta_app.model.ObjectCollectionBuilder | ||
import com.mbta.tid.mbta_app.model.response.ApiResult | ||
import com.mbta.tid.mbta_app.model.response.GlobalResponse | ||
import com.mbta.tid.mbta_app.model.response.NearbyResponse | ||
import com.mbta.tid.mbta_app.repositories.INearbyRepository | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class GetNearbyTest { | ||
@get:Rule val composeTestRule = createComposeRule() | ||
|
||
@Test | ||
fun testNearby() = runTest { | ||
val builder1 = ObjectCollectionBuilder() | ||
|
||
val globalResponse = GlobalResponse(builder1) | ||
|
||
val builder2 = ObjectCollectionBuilder() | ||
|
||
val coordinate1 = Coordinate(0.0, 0.0) | ||
val coordinate2 = Coordinate(1.0, 1.0) | ||
|
||
val nearbyRepository = | ||
object : INearbyRepository { | ||
override suspend fun getNearby( | ||
globalResponse: GlobalResponse, | ||
location: Coordinate | ||
): ApiResult<NearbyStaticData> { | ||
if (location == coordinate1) { | ||
return ApiResult.Ok( | ||
NearbyStaticData(globalResponse, NearbyResponse(builder1)) | ||
) | ||
} else { | ||
return ApiResult.Ok( | ||
NearbyStaticData(globalResponse, NearbyResponse(builder2)) | ||
) | ||
} | ||
} | ||
} | ||
|
||
var coordinate by mutableStateOf(coordinate1) | ||
var actualNearby: NearbyStaticData? = null | ||
|
||
composeTestRule.setContent { | ||
actualNearby = | ||
getNearby( | ||
globalResponse = globalResponse, | ||
location = coordinate1, | ||
setLastLocation = { /* null-op */}, | ||
nearbyRepository = nearbyRepository | ||
) | ||
} | ||
|
||
composeTestRule.awaitIdle() | ||
assertEquals(NearbyStaticData(globalResponse, NearbyResponse(builder1)), actualNearby) | ||
|
||
coordinate = coordinate2 | ||
composeTestRule.awaitIdle() | ||
assertEquals(NearbyStaticData(globalResponse, NearbyResponse(builder2)), actualNearby) | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...oidApp/src/androidTest/java/com/mbta/tid/mbta_app/android/state/GetRailRouteShapesTest.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,62 @@ | ||
package com.mbta.tid.mbta_app.android.state | ||
|
||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import com.mbta.tid.mbta_app.model.ObjectCollectionBuilder | ||
import com.mbta.tid.mbta_app.model.SegmentedRouteShape | ||
import com.mbta.tid.mbta_app.model.response.ApiResult | ||
import com.mbta.tid.mbta_app.model.response.MapFriendlyRouteResponse | ||
import com.mbta.tid.mbta_app.repositories.IRailRouteShapeRepository | ||
import kotlin.test.assertEquals | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class GetRailRouteShapesTest { | ||
@get:Rule val composeTestRule = createComposeRule() | ||
|
||
@Test | ||
fun testRailRouteShapes() = runTest { | ||
val builder = ObjectCollectionBuilder() | ||
val route = builder.route() | ||
val routePattern = builder.routePattern(route) | ||
val mapFriendlyRouteResponse = | ||
MapFriendlyRouteResponse( | ||
listOf( | ||
MapFriendlyRouteResponse.RouteWithSegmentedShapes( | ||
route.id, | ||
listOf( | ||
SegmentedRouteShape( | ||
routePattern.id, | ||
route.id, | ||
1, | ||
listOf(), | ||
builder.shape() | ||
) | ||
) | ||
) | ||
) | ||
) | ||
val railRouteShapeRepository = | ||
object : IRailRouteShapeRepository { | ||
override val state: StateFlow<MapFriendlyRouteResponse?> | ||
get() { | ||
/* null-op */ | ||
return MutableStateFlow<MapFriendlyRouteResponse?>(null) | ||
} | ||
|
||
override suspend fun getRailRouteShapes(): ApiResult<MapFriendlyRouteResponse> { | ||
return ApiResult.Ok(mapFriendlyRouteResponse) | ||
} | ||
} | ||
|
||
var actualRailRouteShapes: MapFriendlyRouteResponse? = null | ||
composeTestRule.setContent { | ||
actualRailRouteShapes = getRailRouteShapes(railRouteShapeRepository) | ||
} | ||
|
||
composeTestRule.awaitIdle() | ||
assertEquals(mapFriendlyRouteResponse, actualRailRouteShapes) | ||
} | ||
} |
3 changes: 1 addition & 2 deletions
3
.../mbta_app/android/util/GetScheduleTest.kt → ...mbta_app/android/state/GetScheduleTest.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
37 changes: 37 additions & 0 deletions
37
androidApp/src/androidTest/java/com/mbta/tid/mbta_app/android/state/GetStopMapDataTest.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,37 @@ | ||
package com.mbta.tid.mbta_app.android.state | ||
|
||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import com.mbta.tid.mbta_app.model.ObjectCollectionBuilder | ||
import com.mbta.tid.mbta_app.model.response.ApiResult | ||
import com.mbta.tid.mbta_app.model.response.StopMapResponse | ||
import com.mbta.tid.mbta_app.repositories.IStopRepository | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class GetStopMapDataTest { | ||
@get:Rule val composeTestRule = createComposeRule() | ||
|
||
@Test | ||
fun testStopMapData() = runTest { | ||
val builder = ObjectCollectionBuilder() | ||
val stop = builder.stop() | ||
val stopMapResponse = StopMapResponse(listOf(), mapOf(stop.id to stop)) | ||
|
||
val stopRepository = | ||
object : IStopRepository { | ||
override suspend fun getStopMapData(stopId: String): ApiResult<StopMapResponse> { | ||
return ApiResult.Ok(stopMapResponse) | ||
} | ||
} | ||
|
||
var actualStopMapResponse: StopMapResponse? = null | ||
composeTestRule.setContent { | ||
actualStopMapResponse = getStopMapData(stop.id, stopRepository) | ||
} | ||
|
||
composeTestRule.awaitIdle() | ||
assertEquals(stopMapResponse, actualStopMapResponse) | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
androidApp/src/androidTest/java/com/mbta/tid/mbta_app/android/state/SubscribeToAlertsTest.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,44 @@ | ||
package com.mbta.tid.mbta_app.android.state | ||
|
||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import com.mbta.tid.mbta_app.model.ObjectCollectionBuilder | ||
import com.mbta.tid.mbta_app.model.response.AlertsStreamDataResponse | ||
import com.mbta.tid.mbta_app.model.response.ApiResult | ||
import com.mbta.tid.mbta_app.repositories.IAlertsRepository | ||
import kotlin.test.assertEquals | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class SubscribeToAlertsTest { | ||
@get:Rule val composeRule = createComposeRule() | ||
|
||
@Test | ||
fun testAlerts() = runTest { | ||
val builder = ObjectCollectionBuilder() | ||
builder.alert { | ||
id = "1" | ||
header = "Alert 1" | ||
description = "Description 1" | ||
} | ||
val alertsStreamDataResponse = AlertsStreamDataResponse(builder) | ||
|
||
val alertsRepo = | ||
object : IAlertsRepository { | ||
override fun connect(onReceive: (ApiResult<AlertsStreamDataResponse>) -> Unit) { | ||
launch { onReceive(ApiResult.Ok(alertsStreamDataResponse)) } | ||
} | ||
|
||
override fun disconnect() { | ||
{ /* null-op */} | ||
} | ||
} | ||
|
||
var actualData: AlertsStreamDataResponse? = null | ||
composeRule.setContent { actualData = subscribeToAlerts(alertsRepo) } | ||
|
||
composeRule.awaitIdle() | ||
assertEquals(alertsStreamDataResponse, actualData) | ||
} | ||
} |
3 changes: 1 addition & 2 deletions
3
...ndroid/util/SubscribeToPredictionsTest.kt → ...droid/state/SubscribeToPredictionsTest.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
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
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