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
1 change: 1 addition & 0 deletions Normal/Shared/Components/ExpandableSection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct ExpandableSection<Content: View>: View {
.padding(.vertical, DS.Spacing.md)
.contentShape(Rectangle())
}
.accessibilityIdentifier("expandableSection")
.buttonStyle(.plain)

if isExpanded {
Expand Down
1 change: 1 addition & 0 deletions Normal/Views/Settings/FAQ/FAQItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ struct FAQItem: View {
var body: some View {
ExpandableSection(title: LocalizedStringKey(question), isExpanded: $isExpanded) {
answer
.fixedSize(horizontal: false, vertical: true)
}
}
}
59 changes: 59 additions & 0 deletions NormalUITests/NormalUITests.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Vision
import XCTest

final class NormalUITests: XCTestCase {
Expand Down Expand Up @@ -304,4 +305,62 @@ final class NormalUITests: XCTestCase {
require(resetSave, "Reset time page should open")
XCTAssertFalse(resetSave.isEnabled, "An unchanged reset time can't be saved")
}

@MainActor
func testFAQAnswersAreNotCutOff() throws {
try requireFAQIsNotCutOff([])
}

@MainActor
func testFAQAnswersAreNotCutOffAtLargeTextSizes() throws {
try requireFAQIsNotCutOff(["-UIPreferredContentSizeCategoryName", "UICTContentSizeCategoryAccessibilityL"])
}

@MainActor
private func requireFAQIsNotCutOff(_ extra: [String]) throws {
let app = launch(["-uiTestMode", "-uiTestSkipOnboarding"] + extra)
app.buttons["nav.settings"].tap()
let faqTab = app.tabBars.buttons["FAQ"]
require(faqTab, "Settings should have an FAQ tab")
faqTab.tap()

var opened = Set<String>()
var cutOff = Set<String>()
var previousPage: [String] = []
for _ in 0 ..< 300 {
let headers = app.buttons.matching(identifier: "expandableSection").allElementsBoundByIndex
if let next = headers.first(where: { $0.isHittable && !opened.contains($0.label) }) {
opened.insert(next.label)
next.tap()
sleep(1)
continue
}
let page = try visibleLines(in: app)
cutOff.formUnion(page.filter { $0.hasSuffix("\u{2026}") || $0.hasSuffix("...") })
if page == previousPage { break }
previousPage = page
app.swipeUp(velocity: .slow)
sleep(1)
}

XCTAssertGreaterThan(opened.count, 10, "Every FAQ question should have been opened")
XCTAssertEqual(cutOff, [], "FAQ text should never end in an ellipsis")
}

@MainActor
private func visibleLines(in app: XCUIApplication) throws -> [String] {
let screenshot = XCUIScreen.main.screenshot().image
guard let image = screenshot.cgImage else { return [] }
let scale = screenshot.scale
let top = app.buttons["Close"].frame.maxY * scale
let bottom = app.tabBars.firstMatch.frame.minY * scale
guard bottom > top, let band = image.cropping(to: CGRect(x: 0, y: top, width: CGFloat(image.width), height: bottom - top)) else {
return []
}
let request = VNRecognizeTextRequest()
request.recognitionLevel = .accurate
request.usesLanguageCorrection = false
try VNImageRequestHandler(cgImage: band).perform([request])
return (request.results ?? []).compactMap { $0.topCandidates(1).first?.string }
}
}
Loading