Skip to content

Commit

Permalink
Fix accessibility for ListRow (#28)
Browse files Browse the repository at this point in the history
# Fix accessibility for ListRow

## ♻️ Current situation & Problem
We have a great capability to make `ListRow` more accessible out of the
box. This PR adds this small modifier and adds respective unit tests.


## ⚙️ Release Notes 
* Make ListRow more accessible


## 📚 Documentation
--


## ✅ Testing
Added unit testing to test this behavior.


## 📝 Code of Conduct & Contributing Guidelines 

By submitting creating this pull request, you agree to follow our [Code
of
Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md):
- [x] I agree to follow the [Code of
Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md).
  • Loading branch information
Supereg authored Feb 1, 2024
1 parent 2772604 commit 138d332
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions Sources/SpeziViews/Views/List/ListRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public struct ListRow<Label: View, Content: View>: View {
Spacer()
}
}
.accessibilityElement(children: .combine)
.onPreferenceChange(DynamicLayout.self) { value in
layout = value
}
Expand Down
14 changes: 13 additions & 1 deletion Tests/UITests/TestApp/ViewsTests/SpeziViewsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ enum SpeziViewsTests: String, TestAppTests {
case defaultErrorOnly = "Default Error Only"
case defaultErrorDescription = "Default Error Description"
case asyncButton = "Async Button"
case listRow = "List Row"


@ViewBuilder
Expand Down Expand Up @@ -104,7 +105,16 @@ enum SpeziViewsTests: String, TestAppTests {
private var asyncButton: some View {
AsyncButtonTestView()
}


@MainActor
@ViewBuilder
private var listRow: some View {
List {
ListRow(verbatim: "Hello") {
Text(verbatim: "World")
}
}
}

func view(withNavigationPath path: Binding<NavigationPath>) -> some View { // swiftlint:disable:this cyclomatic_complexity
switch self {
Expand All @@ -130,6 +140,8 @@ enum SpeziViewsTests: String, TestAppTests {
defaultErrorDescription
case .asyncButton:
asyncButton
case .listRow:
listRow
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions Tests/UITests/TestAppUITests/SpeziViews/ViewsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,13 @@ final class ViewsTests: XCTestCase {

XCTAssert(app.collectionViews.buttons["Hello Throwing World"].isEnabled)
}

func testListRowAccessibility() throws {
let app = XCUIApplication()

XCTAssert(app.collectionViews.buttons["List Row"].waitForExistence(timeout: 2))
app.collectionViews.buttons["List Row"].tap()

XCTAssert(app.collectionViews.staticTexts["Hello, World"].waitForExistence(timeout: 2))
}
}

0 comments on commit 138d332

Please sign in to comment.