Skip to content

Commit

Permalink
fix(Android): make flakiest tests more robust (#637)
Browse files Browse the repository at this point in the history
  • Loading branch information
boringcactus authored Jan 9, 2025
1 parent ca565ac commit 5108bc6
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class MoreViewModelTests {
composeTestRule.awaitIdle()
vm!!.toggleSetting(Settings.HideMaps)
composeTestRule.awaitIdle()
composeTestRule.waitUntil { toggledHideMaps }

assertTrue { toggledHideMaps }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mbta.tid.mbta_app.android.pages

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
Expand Down Expand Up @@ -56,10 +57,12 @@ class MorePageTests : KoinTest {
composeTestRule.onNodeWithText("Hide Maps").performClick()

composeTestRule.awaitIdle()
composeTestRule.waitUntil { hideMapToggleCalled }

assertTrue { hideMapToggleCalled }
}

@OptIn(ExperimentalTestApi::class)
@Test
fun testLinksExist() {
val koinApplication = koinApplication {
Expand All @@ -73,11 +76,15 @@ class MorePageTests : KoinTest {
KoinContext(koinApplication.koin) { MorePage(bottomBar = {}) }
}

composeTestRule.waitUntilExactlyOneExists(hasText("Send app feedback"))
composeTestRule.onNodeWithText("Send app feedback").assertIsDisplayed()
composeTestRule.onNodeWithText("Trip Planner").assertIsDisplayed()
composeTestRule.onNodeWithText("Fare Information").assertIsDisplayed()
composeTestRule.onNodeWithText("Commuter Rail and Ferry tickets").performScrollTo()
composeTestRule.onNodeWithText("Commuter Rail and Ferry tickets").assertIsDisplayed()
composeTestRule.onNodeWithText("Terms of Use").performScrollTo()
composeTestRule.onNodeWithText("Terms of Use").assertIsDisplayed()
composeTestRule.onNodeWithText("Privacy Policy").performScrollTo()
composeTestRule.onNodeWithText("Privacy Policy").assertIsDisplayed()
composeTestRule.onNode(hasText("View source on GitHub")).performScrollTo()
composeTestRule.onNodeWithText("View source on GitHub").assertIsDisplayed()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class GetGlobalDataTest {

requestSync.send(Unit)
composeTestRule.awaitIdle()
composeTestRule.waitUntil { globalData == actualData }
assertEquals(globalData, actualData)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class GetRailRouteShapesTest {
}

composeTestRule.awaitIdle()
composeTestRule.waitUntil { mapFriendlyRouteResponse == actualRailRouteShapes }
assertEquals(mapFriendlyRouteResponse, actualRailRouteShapes)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class GetStopMapDataTest {
}

composeTestRule.awaitIdle()
composeTestRule.waitUntil { stopMapResponse == actualStopMapResponse }
assertEquals(stopMapResponse, actualStopMapResponse)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class SubscribeToAlertsTest {
var actualData: AlertsStreamDataResponse? = null
composeRule.setContent { actualData = subscribeToAlerts(alertsRepo) }
composeRule.waitUntil { connectCount == 1 }
composeRule.waitUntil { alertsStreamDataResponse == actualData }
assertEquals(alertsStreamDataResponse, actualData)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class SubscribeToVehiclesTest {
runOnIdle { lifecycleOwner.handleLifecycleEvent(Lifecycle.Event.ON_RESUME) }

waitUntil { disconnectCount == 3 }
waitUntil { connectCount == 2 }
assertEquals(2, connectCount)
}
}

0 comments on commit 5108bc6

Please sign in to comment.