Skip to content
Merged
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

94 changes: 35 additions & 59 deletions iosApp/iosApp/ComponentViews/SaveFavoritesFlow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,40 +197,42 @@ struct FavoriteConfirmationDialog: View {
.map { ($0, proposedFavorites[$0.id] ?? nil) })
showDialog = true
}
.customAlert(
isPresented: $showDialog,
content: {
FavoriteConfirmationDialogContents(
lineOrRoute: lineOrRoute,
stop: stop, directions: directions,
selectedDirection: selectedDirection,
context: context,
favoritesToSave: favoritesToSave,
updateLocalFavorite: { direction, isFavorite in
favoritesToSave[direction] = isFavorite
}
)
},
actions: {
if directions.isEmpty {
.customAlert(isPresented: $showDialog) {
FavoriteConfirmationDialogContents(
lineOrRoute: lineOrRoute,
stop: stop, directions: directions,
selectedDirection: selectedDirection,
context: context,
favoritesToSave: favoritesToSave,
updateLocalFavorite: { direction, isFavorite in
favoritesToSave[direction] = isFavorite
}
)
} actions: {
if directions.isEmpty {
Button { onClose() } label: { Text("Okay") }
} else {
MultiButton {
Button { onClose() } label: { Text("Cancel") }

Button {
updateFavorites(favoritesToSave
.reduce(
into: [RouteStopDirection: FavoriteSettings?]()
) { partialResult, entry in
partialResult[RouteStopDirection(
route: lineOrRoute.id,
stop: stop.id,
direction: entry.key.id
)] = entry.value
})
onClose()
} label: {
Text("Okay")
}
} else {
MultiButton {
FavoriteConfirmationDialogActions(
lineOrRoute: lineOrRoute,
stop: stop,
favoritesToSave: favoritesToSave,
updateFavorites: updateFavorites,
onClose: onClose
)
}
Text("Add")
}.disabled(favoritesToSave.values.allSatisfy { $0 == nil })
}
}
)
}
}
}

Expand Down Expand Up @@ -262,18 +264,21 @@ struct FavoriteConfirmationDialogContents: View {
VStack {
Text(AttributedString.tryMarkdown(headerText))
.font(Typography.body)
.foregroundStyle(Color.text)
.accessibilityAddTraits(.isHeader)
.accessibilityHeading(.h1)
if directions.count == 1, directions.first!.id != selectedDirection {
Text("\(DirectionLabel.directionNameFormatted(directions.first!)) service only")
.font(Typography.footnoteSemibold)
.foregroundStyle(Color.text)
.padding(.horizontal, 16)
.padding(.top, 8)
}

if directions.isEmpty {
Text("This stop is drop-off only")
.font(Typography.footnoteSemibold)
.foregroundStyle(Color.text)
.padding(.horizontal, 16)
.padding(.top, 8)
} else {
Expand Down Expand Up @@ -321,6 +326,7 @@ struct DirectionButtons: View {
VStack(spacing: 0) {
HStack(spacing: 0) {
DirectionLabel(direction: directionValue.direction)
.foregroundStyle(Color.text)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
Spacer()
StarIcon(
Expand All @@ -345,33 +351,3 @@ struct DirectionButtons: View {
.padding(.top, 8)
}
}

struct FavoriteConfirmationDialogActions: View {
let lineOrRoute: LineOrRoute
let stop: Stop
let favoritesToSave: [Direction: FavoriteSettings?]
let updateFavorites: ([RouteStopDirection: FavoriteSettings?]) -> Void
let onClose: () -> Void

var body: some View {
Button {
onClose()
} label: {
Text("Cancel")
}

Button {
updateFavorites(favoritesToSave
.reduce(into: [RouteStopDirection: FavoriteSettings?]()) { partialResult, entry in
partialResult[RouteStopDirection(
route: lineOrRoute.id,
stop: stop.id,
direction: entry.key.id
)] = entry.value
})
onClose()
} label: {
Text("Add")
}.disabled(favoritesToSave.values.allSatisfy { $0 == nil })
}
}
57 changes: 0 additions & 57 deletions iosApp/iosAppTests/Views/SaveFavoritesFlowTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,46 +34,6 @@ final class SaveFavoritesFlowTest: XCTestCase {
let direction1 = Direction(name: "East", destination: "Park St & North", id: 1)
var directions: [Direction] { [direction0, direction1] }

func testWithoutTappingAnyButtonSavesProposedChanges() throws {
var updateFavoritesCalledFor: [RouteStopDirection: FavoriteSettings?] = [:]
var onCloseCalled = false

let sut = FavoriteConfirmationDialogActions(
lineOrRoute: line,
stop: stop,
favoritesToSave: [direction0: .init()],
updateFavorites: { updateFavoritesCalledFor = $0 },
onClose: { onCloseCalled = true },
)

ViewHosting.host(view: sut.withFixedSettings([:]))

try sut.inspect().find(button: "Add").tap()

XCTAssertEqual(updateFavoritesCalledFor, [.init(route: line.id, stop: stop.id, direction: 0): .init()])
XCTAssertTrue(onCloseCalled)
}

func testCancelDoesntUpdateFavorites() throws {
var updateFavoritesCalled = false
var onCloseCalled = false

let sut = FavoriteConfirmationDialogActions(
lineOrRoute: line,
stop: stop,
favoritesToSave: [direction0: .init()],
updateFavorites: { _ in updateFavoritesCalled = true },
onClose: { onCloseCalled = true },
)

ViewHosting.host(view: sut.withFixedSettings([:]))

try sut.inspect().find(button: "Cancel").tap()

XCTAssertTrue(onCloseCalled)
XCTAssertFalse(updateFavoritesCalled)
}

func testAddingOtherDirectionUpdates() throws {
var updateLocalFavoriteCalledFor: [Direction: FavoriteSettings?] = [:]

Expand Down Expand Up @@ -114,23 +74,6 @@ final class SaveFavoritesFlowTest: XCTestCase {
XCTAssertEqual(updateLocalFavoriteCalledFor, [direction1: nil])
}

func testRemovingProposedFavoriteDisablesAddButton() throws {
var updateFavoritesCalled = false
var onCloseCalled = false

let sut = FavoriteConfirmationDialogActions(
lineOrRoute: line,
stop: stop,
favoritesToSave: [direction0: nil, direction1: nil],
updateFavorites: { _ in updateFavoritesCalled = true },
onClose: { onCloseCalled = true },
)

ViewHosting.host(view: sut.withFixedSettings([:]))

XCTAssertTrue(try sut.inspect().find(button: "Add").isDisabled())
}

@MainActor
func testFavoritingOnlyDirectionPresentsDialogWhenNonBus() throws {
var updateFavoritesCalledFor: [RouteStopDirection: FavoriteSettings?] = [:]
Expand Down
2 changes: 1 addition & 1 deletion iosApp/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ settingGroups:
packages:
CustomAlert:
url: https://github.com/divadretlaw/CustomAlert.git
from: 4.1.1
from: 6.0.1
Firebase:
url: https://github.com/firebase/firebase-ios-sdk
from: 12.1.0
Expand Down
Loading