Skip to content

Commit

Permalink
happy path tests for the primary untested views. (#385)
Browse files Browse the repository at this point in the history
* happy path tests for the primary untested views.
  • Loading branch information
JackVCurtis authored Sep 6, 2024
1 parent 71dbd52 commit 0ac66d5
Show file tree
Hide file tree
Showing 15 changed files with 1,337 additions and 45 deletions.
2 changes: 2 additions & 0 deletions androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ dependencies {
debugImplementation(libs.compose.ui.test.manifest)
debugImplementation(libs.compose.ui.tooling)
testImplementation(libs.junit)
testImplementation(libs.koin.test)
implementation(libs.koin.junit4)
androidTestImplementation(platform(libs.compose.bom))
androidTestImplementation(libs.compose.ui.test.junit4)
androidTestImplementation(libs.ktor.client.mock)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class BoldedTripStatusTest {

composeTestRule.setContent { BoldedTripStatus(text = text) }

composeTestRule.onNodeWithText("Hello").assertIsDisplayed()
composeTestRule.onNodeWithText("World").assertIsDisplayed()
composeTestRule.onNodeWithText("Hello World").assertIsDisplayed()
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.mbta.tid.mbta_app.android.component

import androidx.compose.ui.semantics.ProgressBarRangeInfo
import androidx.compose.ui.test.assertCountEquals
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.hasProgressBarRangeInfo
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onAllNodesWithText
import androidx.compose.ui.test.onNodeWithText
import com.mbta.tid.mbta_app.android.MyApplicationTheme
import com.mbta.tid.mbta_app.model.Alert
Expand Down Expand Up @@ -44,9 +42,8 @@ class HeadsignRowViewTest {
)

composeTestRule.onNodeWithText("Headsign").assertIsDisplayed()
composeTestRule.onNodeWithText("2").assertIsDisplayed()
composeTestRule.onNodeWithText("10").assertIsDisplayed()
composeTestRule.onAllNodesWithText("min").assertCountEquals(2)
composeTestRule.onNodeWithText("2 min").assertIsDisplayed()
composeTestRule.onNodeWithText("10 min").assertIsDisplayed()
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class StopDeparturesSummaryListTest {
}

composeTestRule.onNodeWithText("Alewife").assertExists()
composeTestRule.onNodeWithText("5").assertExists()
composeTestRule.onNodeWithText("min").assertExists()
composeTestRule.onNodeWithText("5 min").assertExists()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class UpcomingTripViewTest {
composeTestRule.setContent {
UpcomingTripView(UpcomingTripViewState.Some(TripInstantDisplay.Approaching))
}
composeTestRule.onNodeWithText("1").assertIsDisplayed()
composeTestRule.onNodeWithText("1 min").assertIsDisplayed()
}

@Test
Expand Down Expand Up @@ -85,7 +85,6 @@ class UpcomingTripViewTest {
composeTestRule.setContent {
UpcomingTripView(UpcomingTripViewState.Some(TripInstantDisplay.Minutes(5)))
}
composeTestRule.onNodeWithText("5").assertIsDisplayed()
composeTestRule.onNodeWithText("min").assertIsDisplayed()
composeTestRule.onNodeWithText("5 min").assertIsDisplayed()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package com.mbta.tid.mbta_app.android.nearbyTransit

import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithText
import com.mbta.tid.mbta_app.model.ObjectCollectionBuilder
import com.mbta.tid.mbta_app.model.PatternsByStop
import com.mbta.tid.mbta_app.model.Prediction
import com.mbta.tid.mbta_app.model.RealtimePatterns
import com.mbta.tid.mbta_app.model.RouteType
import com.mbta.tid.mbta_app.model.StopsAssociated
import com.mbta.tid.mbta_app.model.UpcomingTrip
import kotlin.time.Duration.Companion.minutes
import kotlinx.datetime.Instant
import org.junit.Rule
import org.junit.Test

class NearbyLineViewTest {
val builder = ObjectCollectionBuilder()
val now = Instant.fromEpochMilliseconds(System.currentTimeMillis())
val route =
builder.route {
id = "route_1"
type = RouteType.BUS
directionNames = listOf("North", "South")
directionDestinations = listOf("Downtown", "Uptown")
longName = "Sample Route Long Name"
shortName = "Sample Route"
lineId = "line_1"
routePatternIds = mutableListOf("pattern_1", "pattern_2")
}
val line =
builder.line {
id = "line_1"
color = "FF0000"
longName = "Sample Line Long Name"
shortName = "Sample Line"
textColor = "000000"
}
val routePattern =
builder.routePattern(route) {
id = "pattern_1"
directionId = 0
name = "Sample Route Pattern"
routeId = "route_1"
representativeTripId = "trip_1"
}
val stop =
builder.stop {
id = "stop_1"
name = "Sample Stop"
}
val trip =
builder.trip(routePattern) {
id = "trip_1"
headsign = "Sample Headsign"
}

val patternsByStop =
listOf(
PatternsByStop(
route,
stop,
listOf(
RealtimePatterns.ByHeadsign(
route,
"Sample Headsign",
line,
listOf(routePattern),
listOf(
UpcomingTrip(
trip,
Prediction(
"prediction_1",
now,
now.plus(1.minutes),
0,
false,
Prediction.ScheduleRelationship.Scheduled,
null,
1,
route.id,
stop.id,
trip.id,
null
)
)
)
)
)
)
)

@get:Rule val composeTestRule = createComposeRule()

@Test
fun testNearbyLineViewDisplaysCorrectly() {
composeTestRule.setContent {
NearbyLineView(
nearbyLine = StopsAssociated.WithLine(line, listOf(route), patternsByStop),
pinned = false,
onPin = {},
now = now,
onOpenStopDetails = { _, _ -> }
)
}
composeTestRule.onNodeWithText("Sample Line Long Name").assertIsDisplayed()
composeTestRule.onNodeWithText("Sample Stop").assertIsDisplayed()
composeTestRule.onNodeWithText("Sample Headsign").assertIsDisplayed()
composeTestRule.onNodeWithText("ARR").assertIsDisplayed()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package com.mbta.tid.mbta_app.android.nearbyTransit

import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithText
import com.mbta.tid.mbta_app.model.ObjectCollectionBuilder
import com.mbta.tid.mbta_app.model.PatternsByStop
import com.mbta.tid.mbta_app.model.Prediction
import com.mbta.tid.mbta_app.model.RealtimePatterns
import com.mbta.tid.mbta_app.model.RouteType
import com.mbta.tid.mbta_app.model.UpcomingTrip
import kotlin.time.Duration.Companion.minutes
import kotlinx.datetime.Instant
import org.junit.Rule
import org.junit.Test

class NearbyStopViewTest {
val builder = ObjectCollectionBuilder()
val now = Instant.fromEpochMilliseconds(System.currentTimeMillis())
val route =
builder.route {
id = "route_1"
type = RouteType.BUS
directionNames = listOf("North", "South")
directionDestinations = listOf("Downtown", "Uptown")
longName = "Sample Route Long Name"
shortName = "Sample Route"
lineId = "line_1"
routePatternIds = mutableListOf("pattern_1", "pattern_2")
}
val line =
builder.line {
id = "line_1"
longName = "Sample Line Long Name"
shortName = "Sample Line"
}
val routePattern =
builder.routePattern(route) {
id = "pattern_1"
directionId = 0
name = "Sample Route Pattern"
routeId = "route_1"
representativeTripId = "trip_1"
}
val stop =
builder.stop {
id = "stop_1"
name = "Sample Stop"
}
val trip =
builder.trip(routePattern) {
id = "trip_1"
headsign = "Sample Headsign"
}

val patternsByStop =
PatternsByStop(
route,
stop,
listOf(
RealtimePatterns.ByHeadsign(
route,
"Sample Headsign",
line,
listOf(routePattern),
listOf(
UpcomingTrip(
trip,
Prediction(
"prediction_1",
now,
now.plus(1.minutes),
0,
false,
Prediction.ScheduleRelationship.Scheduled,
null,
1,
route.id,
stop.id,
trip.id,
null
)
)
)
)
)
)

@get:Rule val composeTestRule = createComposeRule()

@Test
fun testNearbyStopViewDisplaysCorrectly() {
composeTestRule.setContent {
NearbyStopView(
patternsAtStop = patternsByStop,
condenseHeadsignPredictions = false,
now = now,
onOpenStopDetails = { _, _ -> }
)
}

composeTestRule.onNodeWithText("Sample Stop").assertIsDisplayed()
composeTestRule.onNodeWithText("Sample Headsign").assertIsDisplayed()
composeTestRule.onNodeWithText("ARR").assertIsDisplayed()
}
}
Loading

0 comments on commit 0ac66d5

Please sign in to comment.