From d07e71cfd229a6d2b16939eb9e7184a77484ae25 Mon Sep 17 00:00:00 2001 From: Emma Simon Date: Sat, 2 Nov 2024 09:46:35 -0400 Subject: [PATCH] fix: Fix formatting of alert details text (#519) --- .../Pages/AlertDetails/AlertDetails.swift | 17 +++++++++++++---- .../AlertDetails/AlertDetailsPageTests.swift | 2 +- .../Pages/AlertDetails/AlertDetailsTests.swift | 6 +++--- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/iosApp/iosApp/Pages/AlertDetails/AlertDetails.swift b/iosApp/iosApp/Pages/AlertDetails/AlertDetails.swift index 0b6983b18..f0442b52a 100644 --- a/iosApp/iosApp/Pages/AlertDetails/AlertDetails.swift +++ b/iosApp/iosApp/Pages/AlertDetails/AlertDetails.swift @@ -98,6 +98,18 @@ struct AlertDetails: View { } } + private var affectedStopsLabel: AttributedString { + let text = String(format: NSLocalizedString( + "**%ld** affected stops", + comment: "The number of stops affected by an alert" + ), affectedStops.count) + do { + return try AttributedString(markdown: text) + } catch { + return AttributedString(text.filter { $0 != "*" }) + } + } + @ViewBuilder private var alertTitle: some View { VStack(alignment: .leading, spacing: 10) { @@ -151,10 +163,7 @@ struct AlertDetails: View { }, label: { HStack(alignment: .center, spacing: 16) { - Text( - "**\(affectedStops.count, specifier: "%ld")** affected stops", - comment: "The number of stops affected by an alert" - ).multilineTextAlignment(.leading) + Text(affectedStopsLabel).multilineTextAlignment(.leading) Spacer() Image(.faChevronRight) .resizable() diff --git a/iosApp/iosAppTests/Pages/AlertDetails/AlertDetailsPageTests.swift b/iosApp/iosAppTests/Pages/AlertDetails/AlertDetailsPageTests.swift index 21cf00039..4b543035c 100644 --- a/iosApp/iosAppTests/Pages/AlertDetails/AlertDetailsPageTests.swift +++ b/iosApp/iosAppTests/Pages/AlertDetails/AlertDetailsPageTests.swift @@ -111,7 +111,7 @@ final class AlertDetailsPageTests: XCTestCase { let exp = sut.inspection.inspect(onReceive: globalDataLoaded, after: 1) { view in XCTAssertNotNil(try view.find(text: "Orange Line Stop Closure")) XCTAssertNotNil(try view.find(text: "Fire")) - XCTAssertNotNil(try view.find(text: "**3** affected stops")) + XCTAssertNotNil(try view.find(text: "3 affected stops")) XCTAssertNotNil(try view.find(text: "Stop 1")) XCTAssertNotNil(try view.find(text: "Stop 2")) XCTAssertNotNil(try view.find(text: "Stop 3")) diff --git a/iosApp/iosAppTests/Pages/AlertDetails/AlertDetailsTests.swift b/iosApp/iosAppTests/Pages/AlertDetails/AlertDetailsTests.swift index 63f180e11..94de20dbb 100644 --- a/iosApp/iosAppTests/Pages/AlertDetails/AlertDetailsTests.swift +++ b/iosApp/iosAppTests/Pages/AlertDetails/AlertDetailsTests.swift @@ -45,7 +45,7 @@ final class AlertDetailsTests: XCTestCase { XCTAssertNotNil(try sut.inspect().find(text: "Red Line Stop Closure")) XCTAssertNotNil(try sut.inspect().find(text: "Unruly Passenger")) XCTAssertNotNil(try sut.inspect().find(text: String(alert.activePeriod[0].formatStart().characters))) - XCTAssertNotNil(try sut.inspect().find(text: "**3** affected stops")) + XCTAssertNotNil(try sut.inspect().find(text: "3 affected stops")) XCTAssertNotNil(try sut.inspect().find(ViewType.DisclosureGroup.self)) XCTAssertNotNil(try sut.inspect().find(text: stop1.name)) XCTAssertNotNil(try sut.inspect().find(text: stop2.name)) @@ -159,7 +159,7 @@ final class AlertDetailsTests: XCTestCase { ) try print(sutWithoutStops.inspect().findAll(ViewType.Text.self).map { text in try text.string() }) - XCTAssertNil(try? sutWithoutStops.inspect().find(text: "**3** affected stops")) + XCTAssertNil(try? sutWithoutStops.inspect().find(text: "3 affected stops")) XCTAssertNotNil(try? sutWithoutStops.inspect().find(text: "Alert description")) XCTAssertNotNil(try? sutWithoutStops.inspect().find(text: "Affected stops:\nStop 1\nStop 2\nStop 3")) XCTAssertNotNil(try? sutWithoutStops.inspect().find(text: "More details")) @@ -170,7 +170,7 @@ final class AlertDetailsTests: XCTestCase { ) XCTAssertNotNil(try? sutWithStops.inspect().find(text: "Alert description")) - XCTAssertNotNil(try? sutWithStops.inspect().find(text: "**3** affected stops")) + XCTAssertNotNil(try? sutWithStops.inspect().find(text: "3 affected stops")) XCTAssertNil(try? sutWithStops.inspect().find(text: "Affected stops:\nStop 1\nStop 2\nStop 3")) XCTAssertNotNil(try? sutWithStops.inspect().find(text: "More details")) }