Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(DebugView): trip, stop, vehicle ids #538

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions iosApp/iosApp/ComponentViews/DebugView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ struct DebugView<Content: View>: View {
.strokeBorder(Color(.text), style: .init(lineWidth: 2, dash: [10]))
VStack(alignment: .leading) {
content()
.font(Typography.footnote)
}.padding(4)
}
.fixedSize(horizontal: false, vertical: true)
}
}
2 changes: 1 addition & 1 deletion iosApp/iosApp/ComponentViews/ErrorBanner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
DebugView {
ForEach(state.messages.sorted(), id: \.self) { errorName in
Text(errorName)
}.font(Typography.footnote)
}
}
}
}
Expand All @@ -53,7 +53,7 @@
ErrorCard {
Text(
"Updated \(state.minutesAgo(), specifier: "%ld") minutes ago",
comment: "Displayed when prediction data has not been able to update for an unexpected amount of time"

Check notice on line 56 in iosApp/iosApp/ComponentViews/ErrorBanner.swift

View check run for this annotation

Xcode Cloud / MBTA Transit Staging | PR Branch Workflow | iosAppRetries - iOS

iosApp/iosApp/ComponentViews/ErrorBanner.swift#L56

Line Length Violation: Line should be 120 characters or less; currently it has 126 characters (line_length)
)
}
.refreshable(
Expand Down
1 change: 1 addition & 0 deletions iosApp/iosApp/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import SwiftPhoenixClient
import SwiftUI

struct ContentView: View {

Check notice on line 7 in iosApp/iosApp/ContentView.swift

View check run for this annotation

Xcode Cloud / MBTA Transit Staging | PR Branch Workflow | iosAppRetries - iOS

iosApp/iosApp/ContentView.swift#L7

Type Body Length Violation: Type body should span 250 lines or less excluding comments and whitespace: currently spans 287 lines (type_body_length)
@Environment(\.scenePhase) private var scenePhase

let platform = Platform_iosKt.getPlatform().name
Expand Down Expand Up @@ -51,6 +51,7 @@
.onReceive(inspection.notice) { inspection.visit(self, $0) }
.onAppear {
Task { await contentVM.loadOnboardingScreens() }
Task { await nearbyVM.loadDebugSetting() }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not seeing the debug info if I just toggle the setting on without restarting the app (and vice versa). I think the nearby VM needs to reload when the setting changes.

}
.task {
// We can't set stale caches in ResponseCache on init because of our Koin setup,
Expand Down
1 change: 1 addition & 0 deletions iosApp/iosApp/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -4368,6 +4368,7 @@
},
"Map Debug" : {
"comment" : "A setting on the More page to display map debug information (only visible for developers)",
"extractionState" : "stale",
"localizations" : {
"es" : {
"stringUnit" : {
Expand Down
5 changes: 5 additions & 0 deletions iosApp/iosApp/Pages/StopDetails/StopDetailsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ struct StopDetailsView: View {
onBack: nearbyVM.navigationStack.count > 1 ? { nearbyVM.goBack() } : nil,
onClose: { nearbyVM.navigationStack.removeAll() }
)
if nearbyVM.showDebugMessages {
DebugView {
Text(verbatim: "stop id: \(stop.id)")
}
}
ErrorBanner(errorBannerVM).padding(.horizontal, 16)
if servedRoutes.count > 1 {
StopDetailsFilterPills(
Expand Down
8 changes: 8 additions & 0 deletions iosApp/iosApp/Pages/TripDetails/TripDetailsPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import SwiftPhoenixClient
import SwiftUI

struct TripDetailsPage: View {

Check notice on line 14 in iosApp/iosApp/Pages/TripDetails/TripDetailsPage.swift

View check run for this annotation

Xcode Cloud / MBTA Transit Staging | PR Branch Workflow | iosAppRetries - iOS

iosApp/iosApp/Pages/TripDetails/TripDetailsPage.swift#L14

Type Body Length Violation: Type body should span 250 lines or less excluding comments and whitespace: currently spans 307 lines (type_body_length)
let tripId: String
let vehicleId: String
let routeId: String
Expand Down Expand Up @@ -72,6 +72,14 @@
var body: some View {
VStack(spacing: 16) {
header
if nearbyVM.showDebugMessages {
DebugView {
VStack {
Text(verbatim: "trip id \(tripId)")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: Add a : after trip id 😛

Text(verbatim: "vehicle id: \(vehicleId)")
}
}
}
if tripPredictionsLoaded, let globalResponse, let vehicle = vehicleResponse?.vehicle,
let stops = TripDetailsStopList.companion.fromPieces(
tripId: tripId,
Expand Down
17 changes: 16 additions & 1 deletion iosApp/iosApp/ViewModels/NearbyViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,32 +37,47 @@ class NearbyViewModel: ObservableObject {
}}
}

@Published
var showDebugMessages: Bool = false

@Published var alerts: AlertsStreamDataResponse?
@Published var nearbyState = NearbyTransitState()
@Published var selectingLocation = false

private let alertsRepository: IAlertsRepository
private let errorBannerRepository: IErrorBannerStateRepository
private let nearbyRepository: INearbyRepository
private let visitHistoryUsecase: VisitHistoryUsecase
private var fetchNearbyTask: Task<Void, Never>?
private var analytics: NearbyTransitAnalytics
private let settingsRepository: ISettingsRepository

init(
departures: StopDetailsDepartures? = nil,
navigationStack: [SheetNavigationStackEntry] = [],
showDebugMessages: Bool = false,
alertsRepository: IAlertsRepository = RepositoryDI().alerts,
errorBannerRepository: IErrorBannerStateRepository = RepositoryDI().errorBanner,
nearbyRepository: INearbyRepository = RepositoryDI().nearby,
visitHistoryUsecase: VisitHistoryUsecase = UsecaseDI().visitHistoryUsecase,
analytics: NearbyTransitAnalytics = AnalyticsProvider.shared
analytics: NearbyTransitAnalytics = AnalyticsProvider.shared,
settingsRepository: ISettingsRepository = RepositoryDI().settings
) {
self.departures = departures
self.navigationStack = navigationStack
self.showDebugMessages = showDebugMessages

self.alertsRepository = alertsRepository
self.errorBannerRepository = errorBannerRepository
self.nearbyRepository = nearbyRepository
self.visitHistoryUsecase = visitHistoryUsecase
self.analytics = analytics
self.settingsRepository = settingsRepository
}

@MainActor
func loadDebugSetting() async {
showDebugMessages = await (try? settingsRepository.getSettings()[.devDebugMode]?.boolValue) ?? false
}

/**
Expand Down
44 changes: 44 additions & 0 deletions iosApp/iosAppTests/Pages/StopDetails/StopDetailsViewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,48 @@ final class StopDetailsViewTests: XCTestCase {
ViewHosting.host(view: sut)
XCTAssertNil(try? sut.inspect().find(viewWithAccessibilityLabel: "Back"))
}

func testDebugModeNotShownByDefault() throws {
let objects = ObjectCollectionBuilder()
let stop = objects.stop { stop in
stop.id = "FAKE_STOP_ID"
}

let nearbyVM: NearbyViewModel = .init(navigationStack: [.stopDetails(stop, nil)], showDebugMessages: false)
let sut = StopDetailsView(
stop: stop,
filter: nil,
setFilter: { _ in },
departures: nil,
errorBannerVM: .init(),
nearbyVM: nearbyVM,
now: Date.now,
pinnedRoutes: [], togglePinnedRoute: { _ in }
)

ViewHosting.host(view: sut)
XCTAssertThrowsError(try sut.inspect().find(text: "stop id: FAKE_STOP_ID"))
}

func testDebugModeShown() throws {
let objects = ObjectCollectionBuilder()
let stop = objects.stop { stop in
stop.id = "FAKE_STOP_ID"
}

let nearbyVM: NearbyViewModel = .init(navigationStack: [.stopDetails(stop, nil)], showDebugMessages: true)
let sut = StopDetailsView(
stop: stop,
filter: nil,
setFilter: { _ in },
departures: nil,
errorBannerVM: .init(),
nearbyVM: nearbyVM,
now: Date.now,
pinnedRoutes: [], togglePinnedRoute: { _ in }
)

ViewHosting.host(view: sut)
XCTAssertNotNil(try sut.inspect().find(text: "stop id: FAKE_STOP_ID"))
}
}
52 changes: 52 additions & 0 deletions iosApp/iosAppTests/Pages/TripDetails/TripDetailsPageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,58 @@ final class TripDetailsPageTests: XCTestCase {
wait(for: [vehicleLeaveExp, vehicleJoinExp], timeout: 2)
}

func testDebugModeNotShownByDefault() throws {
let objects = ObjectCollectionBuilder()
objects.stop { _ in }
let sut = TripDetailsPage(
tripId: "tripId",
vehicleId: "vehicleId",
routeId: "routeId",
target: nil,
errorBannerVM: .init(),
nearbyVM: .init(),
mapVM: .init(),
tripPredictionsRepository: FakeTripPredictionsRepository(response: .init(objects: objects)),
tripRepository: FakeTripRepository(
tripResponse: .init(trip: objects.trip { _ in }),
scheduleResponse: TripSchedulesResponse.StopIds(stopIds: [])
),
vehicleRepository: FakeVehicleRepository(
response: .init(vehicle: nil),
onConnect: {},
onDisconnect: {}
)
)
ViewHosting.host(view: sut)
XCTAssertThrowsError(try sut.inspect().find(text: "trip id: tripId"))
}

func testDebugModeShown() throws {
let objects = ObjectCollectionBuilder()
objects.stop { _ in }
let sut = TripDetailsPage(
tripId: "tripId",
vehicleId: "vehicleId",
routeId: "routeId",
target: nil,
errorBannerVM: .init(),
nearbyVM: .init(showDebugMessages: true),
mapVM: .init(),
tripPredictionsRepository: FakeTripPredictionsRepository(response: .init(objects: objects)),
tripRepository: FakeTripRepository(
tripResponse: .init(trip: objects.trip { _ in }),
scheduleResponse: TripSchedulesResponse.StopIds(stopIds: [])
),
vehicleRepository: FakeVehicleRepository(
response: .init(vehicle: nil),
onConnect: {},
onDisconnect: {}
)
)
ViewHosting.host(view: sut)
XCTAssertNotNil(try sut.inspect().find(text: "trip id: tripId"))
}

class FakeTripRepository: IdleTripRepository {
let tripResponse: ApiResult<TripResponse>
let scheduleResponse: TripSchedulesResponse
Expand Down