Skip to content

Commit

Permalink
feat(DebugView): trip, stop, vehicle ids
Browse files Browse the repository at this point in the history
  • Loading branch information
KaylaBrady committed Nov 13, 2024
1 parent 4210711 commit e15920b
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 2 deletions.
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 @@ struct ErrorBanner: View {
DebugView {
ForEach(state.messages.sorted(), id: \.self) { errorName in
Text(errorName)
}.font(Typography.footnote)
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions iosApp/iosApp/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ struct ContentView: View {
.onReceive(inspection.notice) { inspection.visit(self, $0) }
.onAppear {
Task { await contentVM.loadOnboardingScreens() }
Task { await nearbyVM.loadDebugSetting() }
}
.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
5 changes: 5 additions & 0 deletions iosApp/iosApp/Pages/TripDetails/TripDetailsPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ struct TripDetailsPage: View {
var body: some View {
VStack(spacing: 16) {
header
if nearbyVM.showDebugMessages {
DebugView {
Text(verbatim: "trip id: \(tripId) | 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 | vehicle id: vehicleId"))
}

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 | vehicle id: vehicleId"))
}

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

0 comments on commit e15920b

Please sign in to comment.