Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/bundler/cyclonedx-cocoapods-1.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
KaylaBrady authored Dec 18, 2024
2 parents a9b94ee + f80ff4c commit 3a308e4
Show file tree
Hide file tree
Showing 43 changed files with 1,590 additions and 475 deletions.
22 changes: 11 additions & 11 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ GEM
artifactory (3.0.17)
atomos (0.1.3)
aws-eventstream (1.3.0)
aws-partitions (1.1012.0)
aws-sdk-core (3.213.0)
aws-partitions (1.1023.0)
aws-sdk-core (3.214.0)
aws-eventstream (~> 1, >= 1.3.0)
aws-partitions (~> 1, >= 1.992.0)
aws-sigv4 (~> 1.9)
jmespath (~> 1, >= 1.6.1)
aws-sdk-kms (1.96.0)
aws-sdk-core (~> 3, >= 3.210.0)
aws-sigv4 (~> 1.5)
aws-sdk-s3 (1.173.0)
aws-sdk-s3 (1.176.1)
aws-sdk-core (~> 3, >= 3.210.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.5)
Expand Down Expand Up @@ -131,7 +131,7 @@ GEM
faraday_middleware (1.2.1)
faraday (~> 1.0)
fastimage (2.3.1)
fastlane (2.225.0)
fastlane (2.226.0)
CFPropertyList (>= 2.3, < 4.0.0)
addressable (>= 2.8, < 3.0.0)
artifactory (~> 3.0)
Expand Down Expand Up @@ -171,7 +171,7 @@ GEM
tty-spinner (>= 0.8.0, < 1.0.0)
word_wrap (~> 1.0.0)
xcodeproj (>= 1.13.0, < 2.0.0)
xcpretty (~> 0.3.0)
xcpretty (~> 0.4.0)
xcpretty-travis-formatter (>= 0.0.3, < 2.0.0)
fastlane-sirp (1.0.0)
sysrandom (~> 1.0)
Expand Down Expand Up @@ -218,13 +218,13 @@ GEM
os (>= 0.9, < 2.0)
signet (>= 0.16, < 2.a)
highline (2.0.3)
http-cookie (1.0.7)
http-cookie (1.0.8)
domain_name (~> 0.5)
httpclient (2.8.3)
i18n (1.14.6)
concurrent-ruby (~> 1.0)
jmespath (1.6.2)
json (2.8.2)
json (2.9.0)
jwt (2.9.3)
base64
logger (1.6.1)
Expand Down Expand Up @@ -258,8 +258,8 @@ GEM
trailblazer-option (>= 0.1.1, < 0.2.0)
uber (< 0.2.0)
retriable (3.1.2)
rexml (3.3.9)
rouge (2.0.7)
rexml (3.4.0)
rouge (3.28.0)
ruby-macho (2.5.1)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
Expand Down Expand Up @@ -296,8 +296,8 @@ GEM
colored2 (~> 3.1)
nanaimo (~> 0.4.0)
rexml (>= 3.3.6, < 4.0)
xcpretty (0.3.0)
rouge (~> 2.0.7)
xcpretty (0.4.0)
rouge (~> 3.28.0)
xcpretty-travis-formatter (1.0.1)
xcpretty (~> 0.2, >= 0.0.7)

Expand Down
1 change: 1 addition & 0 deletions androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ dependencies {
implementation(libs.mapbox.turf)
implementation(libs.okhttp)
implementation(libs.playServices.location)
implementation(libs.androidx.lifecycle.runtime.testing)
debugImplementation(platform(libs.compose.bom))
debugImplementation(libs.compose.ui.test.manifest)
debugImplementation(libs.compose.ui.tooling)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.compose.LocalLifecycleOwner
import androidx.lifecycle.testing.TestLifecycleOwner
import androidx.test.rule.GrantPermissionRule
import com.mbta.tid.mbta_app.android.location.MockFusedLocationProviderClient
import com.mbta.tid.mbta_app.android.util.LocalActivity
Expand All @@ -31,7 +34,8 @@ class ContentViewTests : KoinTest {
val koinApplication = koinApplication {
modules(
repositoriesModule(MockRepositories.buildWithDefaults()),
module { single<PhoenixSocket> { MockPhoenixSocket() } }
MainApplication.koinViewModelModule,
module { single<PhoenixSocket> { MockPhoenixSocket() } },
)
}

Expand All @@ -54,4 +58,45 @@ class ContentViewTests : KoinTest {
composeTestRule.onNodeWithText("Nearby").performClick()
composeTestRule.onNodeWithText("Nearby Transit").assertIsDisplayed()
}

@Test
fun testSocketClosedOnPause() {
val lifecycleOwner = TestLifecycleOwner(Lifecycle.State.RESUMED)
var onAttachCount = 0
var onDetatchCount = 0

val koinApplication = koinApplication {
modules(
repositoriesModule(MockRepositories.buildWithDefaults()),
MainApplication.koinViewModelModule,
module {
single<PhoenixSocket> {
MockPhoenixSocket({ onAttachCount += 1 }, { onDetatchCount += 1 })
}
}
)
}

composeTestRule.setContent {
KoinContext(koinApplication.koin) {
CompositionLocalProvider(
LocalActivity provides (LocalContext.current as Activity),
LocalLocationClient provides MockFusedLocationProviderClient(),
LocalLifecycleOwner provides lifecycleOwner
) {
ContentView()
}
}
}

composeTestRule.waitUntil { onAttachCount == 1 && onDetatchCount == 0 }

composeTestRule.runOnIdle { lifecycleOwner.handleLifecycleEvent(Lifecycle.Event.ON_PAUSE) }

composeTestRule.waitUntil { onAttachCount == 1 && onDetatchCount == 1 }

composeTestRule.runOnIdle { lifecycleOwner.handleLifecycleEvent(Lifecycle.Event.ON_RESUME) }

composeTestRule.waitUntil { onAttachCount == 2 && onDetatchCount == 1 }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.test.rule.GrantPermissionRule
import com.mapbox.geojson.FeatureCollection
import com.mapbox.maps.MapboxExperimental
import com.mapbox.maps.extension.compose.animation.viewport.rememberMapViewportState
import com.mbta.tid.mbta_app.android.location.MockFusedLocationProviderClient
Expand All @@ -25,14 +26,18 @@ import com.mbta.tid.mbta_app.android.pages.NearbyTransit
import com.mbta.tid.mbta_app.android.pages.NearbyTransitPage
import com.mbta.tid.mbta_app.android.util.LocalActivity
import com.mbta.tid.mbta_app.android.util.LocalLocationClient
import com.mbta.tid.mbta_app.map.RouteLineData
import com.mbta.tid.mbta_app.model.Coordinate
import com.mbta.tid.mbta_app.model.GlobalMapData
import com.mbta.tid.mbta_app.model.LocationType
import com.mbta.tid.mbta_app.model.NearbyStaticData
import com.mbta.tid.mbta_app.model.ObjectCollectionBuilder
import com.mbta.tid.mbta_app.model.RouteType
import com.mbta.tid.mbta_app.model.Stop
import com.mbta.tid.mbta_app.model.response.AlertsStreamDataResponse
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.MapFriendlyRouteResponse
import com.mbta.tid.mbta_app.model.response.NearbyResponse
import com.mbta.tid.mbta_app.model.response.PredictionsByStopJoinResponse
import com.mbta.tid.mbta_app.model.response.PredictionsByStopMessageResponse
Expand All @@ -42,9 +47,11 @@ import com.mbta.tid.mbta_app.repositories.IPinnedRoutesRepository
import com.mbta.tid.mbta_app.repositories.IPredictionsRepository
import com.mbta.tid.mbta_app.repositories.IRailRouteShapeRepository
import com.mbta.tid.mbta_app.repositories.ISchedulesRepository
import com.mbta.tid.mbta_app.repositories.ISearchResultRepository
import com.mbta.tid.mbta_app.repositories.IVehiclesRepository
import com.mbta.tid.mbta_app.repositories.MockRailRouteShapeRepository
import com.mbta.tid.mbta_app.repositories.MockScheduleRepository
import com.mbta.tid.mbta_app.repositories.MockSearchResultRepository
import com.mbta.tid.mbta_app.repositories.MockVehiclesRepository
import com.mbta.tid.mbta_app.usecases.TogglePinnedRouteUsecase
import io.github.dellisd.spatialk.geojson.Position
Expand Down Expand Up @@ -244,6 +251,7 @@ class NearbyTransitPageTest : KoinTest {
single<IRailRouteShapeRepository> { MockRailRouteShapeRepository() }
single<TogglePinnedRouteUsecase> { TogglePinnedRouteUsecase(get()) }
single<IVehiclesRepository> { MockVehiclesRepository() }
single<ISearchResultRepository> { MockSearchResultRepository() }
}
)
}
Expand Down Expand Up @@ -306,12 +314,30 @@ class NearbyTransitPageTest : KoinTest {
open class MockMapVM : IMapViewModel {
var mutableLastErrorTimestamp = MutableStateFlow<Instant?>(null)
override var lastMapboxErrorTimestamp: Flow<Instant?> = mutableLastErrorTimestamp
override var railRouteLineData: Flow<List<RouteLineData>?> =
MutableStateFlow(value = null)
override var stopSourceData: Flow<FeatureCollection?> = MutableStateFlow(value = null)
override var globalResponse: Flow<GlobalResponse?> = MutableStateFlow(value = null)
override var railRouteShapes: Flow<MapFriendlyRouteResponse?> =
MutableStateFlow(value = null)

var loadConfigCalledCount = 0

override suspend fun loadConfig() {
loadConfigCalledCount += 1
}

override fun globalMapData(now: Instant): GlobalMapData? {
return null
}

override suspend fun refreshRouteLineData(now: Instant) {}

override suspend fun refreshStopFeatures(now: Instant, selectedStop: Stop?) {}

override suspend fun setAlertsData(alertsData: AlertsStreamDataResponse?) {}

override suspend fun setGlobalResponse(globalResponse: GlobalResponse?) {}
}

val mockMapVM = MockMapVM()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.mbta.tid.mbta_app.android.nearbyTransit

import com.mbta.tid.mbta_app.model.ObjectCollectionBuilder
import com.mbta.tid.mbta_app.model.PatternsByStop
import com.mbta.tid.mbta_app.model.StopDetailsDepartures
import com.mbta.tid.mbta_app.model.StopDetailsFilter
import kotlin.test.assertEquals
import kotlin.test.assertNull
import org.junit.Test

class NearbyTransitTabViewModelTest {

@Test
fun testSetStopDetailsFilter() {
val vm = NearbyTransitTabViewModel()
val newFilter = StopDetailsFilter("route_1", 1)

assertNull(vm.stopDetailsFilter.value)

vm.setStopDetailsFilter(newFilter)
assertEquals(newFilter, vm.stopDetailsFilter.value)
}

@Test
fun testSetStopDetailsDepartures() {
val vm = NearbyTransitTabViewModel()
val objectCollectionBuilder = ObjectCollectionBuilder()
val route = objectCollectionBuilder.route {}
val stop = objectCollectionBuilder.stop {}

val departures = StopDetailsDepartures(listOf(PatternsByStop(route, stop, emptyList())))

assertNull(vm.stopDetailsDepartures.value)

vm.setStopDetailsDepartures(departures)
assertEquals(departures, vm.stopDetailsDepartures.value)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package com.mbta.tid.mbta_app.android.onboarding

import android.location.Location
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.test.rule.GrantPermissionRule
import com.mbta.tid.mbta_app.android.location.MockLocationDataManager
import com.mbta.tid.mbta_app.model.OnboardingScreen
import com.mbta.tid.mbta_app.repositories.MockSettingsRepository
import com.mbta.tid.mbta_app.repositories.Settings
import kotlin.test.assertEquals
import kotlin.test.assertTrue
import org.junit.Rule
import org.junit.Test

class OnboardingScreenViewTest {
@get:Rule val composeTestRule = createComposeRule()

// We can't easily mock the permission request, so we grant the permission eagerly.
@get:Rule
val runtimePermissionRule =
GrantPermissionRule.grant(android.Manifest.permission.ACCESS_FINE_LOCATION)

@Test
fun testLocationFlow() {
var advanced = false
val locationDataManager = MockLocationDataManager(Location("mock"))
composeTestRule.setContent {
OnboardingScreenView(
screen = OnboardingScreen.Location,
advance = { advanced = true },
locationDataManager = locationDataManager,
)
}

composeTestRule
.onNodeWithText(
"We use your location to show you nearby transit options.",
substring = true
)
.assertIsDisplayed()
composeTestRule.onNodeWithText("Continue").performClick()

composeTestRule.waitForIdle()
assertTrue(advanced)
}

@Test
fun testHideMapsFlow() {
var savedSetting = false
val settingsRepo =
MockSettingsRepository(
settings = mapOf(Settings.HideMaps to false),
onSaveSettings = {
assertEquals(mapOf(Settings.HideMaps to true), it)
savedSetting = true
}
)
var advanced = false
composeTestRule.setContent {
OnboardingScreenView(
screen = OnboardingScreen.HideMaps,
advance = { advanced = true },
locationDataManager = MockLocationDataManager(Location("mock")),
settingsRepository = settingsRepo
)
}
composeTestRule
.onNodeWithText(
"When using TalkBack, we can skip reading out maps to keep you focused on transit information."
)
.assertIsDisplayed()
composeTestRule.onNodeWithText("Show maps").assertIsDisplayed()
composeTestRule.onNodeWithText("Hide maps").performClick()

composeTestRule.waitForIdle()
assertTrue(savedSetting)
assertTrue(advanced)
}

@Test
fun testFeedbackFlow() {
var advanced = false
composeTestRule.setContent {
OnboardingScreenView(
screen = OnboardingScreen.Feedback,
advance = { advanced = true },
locationDataManager = MockLocationDataManager(Location("mock")),
)
}
composeTestRule
.onNodeWithText(
"MBTA Go is in the early stages! We want your feedback" +
" as we continue making improvements and adding new features."
)
.assertIsDisplayed()
composeTestRule.onNodeWithText("Get started").performClick()

composeTestRule.waitForIdle()
assertTrue(advanced)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.mbta.tid.mbta_app.repositories.ISettingsRepository
import com.mbta.tid.mbta_app.repositories.MockSettingsRepository
import com.mbta.tid.mbta_app.repositories.Settings
import kotlin.test.assertTrue
import kotlinx.coroutines.test.runTest
import org.junit.Rule
import org.junit.Test
import org.koin.compose.KoinContext
Expand All @@ -29,8 +30,7 @@ class MorePageTests : KoinTest {
}

@Test
fun testSettings() {

fun testSettings() = runTest {
var hideMapToggleCalled = false

val koinApplication = koinApplication {
Expand All @@ -55,6 +55,8 @@ class MorePageTests : KoinTest {
composeTestRule.onNodeWithText("Settings").assertIsDisplayed()
composeTestRule.onNodeWithText("Hide Maps").performClick()

composeTestRule.awaitIdle()

assertTrue { hideMapToggleCalled }
}

Expand Down
Loading

0 comments on commit 3a308e4

Please sign in to comment.