Skip to content

Commit

Permalink
Merge branch 'main' into es-1.1.5-bump
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaSimon authored Jan 24, 2025
2 parents 5bcd787 + 5889894 commit a4650cc
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,43 +202,52 @@ struct StopDetailsFilteredDepartureDetails: View {
}
}

func getAlertDetailsHandler(_ alertId: String) -> () -> Void {
func getAlertDetailsHandler(_ alertId: String, spec: AlertCardSpec) -> () -> Void {
{
nearbyVM.pushNavEntry(.alertDetails(
alertId: alertId,
line: patternsByStop.line,
routes: patternsByStop.routes,
line: spec == .elevator ? nil : patternsByStop.line,
routes: spec == .elevator ? nil : patternsByStop.routes,
stop: patternsByStop.stop
))
analytics.tappedAlertDetails(
routeId: patternsByStop.routeIdentifier,
stopId: patternsByStop.stop.id,
alertId: alertId
alertId: alertId,
elevator: spec == .elevator
)
}
}

@ViewBuilder
func alertCard(_ alert: shared.Alert, _ spec: AlertCardSpec? = nil) -> some View {
let spec = spec ?? (alert.significance == .major ? .major : .secondary)
AlertCard(
alert: alert,
spec: spec ?? (alert.significance == .major ? .major : .secondary),
spec: spec,
color: routeColor,
textColor: routeTextColor,
onViewDetails: getAlertDetailsHandler(alert.id)
onViewDetails: getAlertDetailsHandler(alert.id, spec: spec)
)
}

@ViewBuilder
var alertCards: some View {
if !alerts.isEmpty || !downstreamAlerts.isEmpty {
if !alerts.isEmpty ||
!downstreamAlerts.isEmpty ||
(stopDetailsVM.showElevatorAccessibility && !patternsByStop.elevatorAlerts.isEmpty) {
VStack(spacing: 16) {
ForEach(alerts, id: \.id) { alert in
alertCard(alert)
}
ForEach(downstreamAlerts, id: \.id) { alert in
alertCard(alert, .downstream)
}
if stopDetailsVM.showElevatorAccessibility {
ForEach(patternsByStop.elevatorAlerts, id: \.id) { alert in
alertCard(alert, .elevator)
}
}
}.padding(.horizontal, 16)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ struct StopDetailsUnfilteredView: View {
analytics.tappedAlertDetails(
routeId: "",
stopId: stopId,
alertId: alert.id
alertId: alert.id,
elevator: true
)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,4 +470,54 @@ final class StopDetailsFilteredDepartureDetailsTests: XCTestCase {
.alertDetails(alertId: alert.id, line: nil, routes: [route], stop: stop)
)
}

func testShowsElevatorAlert() throws {
let objects = ObjectCollectionBuilder()
let stop = objects.stop { _ in }
let route = objects.route { _ in }
let alert = objects.alert { alert in
alert.effect = .elevatorClosure
alert.header = "Elevator closed at stop"
}

let tile = TileData(
route: route,
headsign: "A",
formatted: RealtimePatterns.FormatSome(
trips: [.init(id: "1", routeType: .heavyRail, format: .Arriving())],
secondaryAlert: nil
)
)
let nearbyVM = NearbyViewModel()
let stopDetailsVM = StopDetailsViewModel()
stopDetailsVM.showElevatorAccessibility = true

let sut = StopDetailsFilteredDepartureDetails(
stopId: stop.id,
stopFilter: .init(routeId: route.id, directionId: 0),
tripFilter: nil,
setStopFilter: { _ in },
setTripFilter: { _ in },
tiles: [tile],
noPredictionsStatus: nil,
alerts: [],
downstreamAlerts: [],
patternsByStop: .init(route: route, stop: stop, patterns: [], elevatorAlerts: [alert]),
pinned: false,
now: Date.now,
errorBannerVM: .init(),
nearbyVM: nearbyVM,
mapVM: .init(),
stopDetailsVM: stopDetailsVM
).environmentObject(ViewportProvider())

XCTAssertNotNil(try sut.inspect().find(DepartureTile.self))
XCTAssertNotNil(try sut.inspect().find(AlertCard.self))
XCTAssertNotNil(try sut.inspect().find(text: alert.header!))
try sut.inspect().find(AlertCard.self).button().tap()
XCTAssertEqual(
nearbyVM.navigationStack.last,
.alertDetails(alertId: alert.id, line: nil, routes: nil, stop: stop)
)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mbta.tid.mbta_app.analytics

import co.touchlab.skie.configuration.annotations.DefaultArgumentInterop
import com.mbta.tid.mbta_app.model.RealtimePatterns
import com.mbta.tid.mbta_app.model.RouteType
import kotlin.experimental.ExperimentalObjCName
Expand Down Expand Up @@ -52,12 +53,19 @@ abstract class Analytics {
)
}

fun tappedAlertDetails(routeId: String, stopId: String, alertId: String) {
@DefaultArgumentInterop.Enabled
fun tappedAlertDetails(
routeId: String,
stopId: String,
alertId: String,
elevator: Boolean = false
) {
logEvent(
"tapped_alert_details",
"route_id" to routeId,
"stop_id" to stopId,
"alertId" to alertId,
"elevator" to elevator.toString()
)
}

Expand Down

0 comments on commit a4650cc

Please sign in to comment.