-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
298dc3e
commit 0338f2c
Showing
3 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import BlueprintUI | ||
import UIKit | ||
import XCTest | ||
|
||
|
||
class UIAccessibilityTraits_Tests: XCTestCase { | ||
|
||
func test_backButton() throws { | ||
|
||
let root = UIViewController() | ||
let second = UIViewController() | ||
let navigationController = UINavigationController() | ||
navigationController.viewControllers = [root, second] | ||
|
||
try show(vc: navigationController) { _ in | ||
let button = try XCTUnwrap( | ||
navigationController.navigationBar.findSubview(ofType: UIControl.self) | ||
) | ||
|
||
/// The `.backButton` trait is private, so this test is here to verify it does not change. | ||
|
||
XCTAssertEqual(button.accessibilityTraits, .backButton) | ||
Check failure on line 22 in BlueprintUI/Tests/AccessibililtyTraitsTests.swift
|
||
} | ||
} | ||
|
||
func test_toggleSwitch() { | ||
if #available(iOS 17.0, *) { | ||
/// The `.toggleButton` trait is exposed iOS 17, so this test is here to verify it matches ours. | ||
XCTAssertEqual(UIAccessibilityTraits._toggleButton, UIAccessibilityTraits.toggleButton) | ||
} | ||
let uiSwitch = UISwitch() | ||
/// The `.toggleButton` trait is private prior to iOS 17, so this test is here to verify it exists on prior versions. | ||
XCTAssertTrue(uiSwitch.accessibilityTraits.contains(._toggleButton)) | ||
Check failure on line 33 in BlueprintUI/Tests/AccessibililtyTraitsTests.swift
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import UIKit | ||
import XCTest | ||
|
||
extension UIView { | ||
/// Does a breadth-first search for a subview of the given type, optionally matching a | ||
/// predicate. | ||
public func findSubview<View: UIView>( | ||
ofType viewType: View.Type, | ||
where predicate: (View) -> Bool = { _ in true } | ||
) -> View? { | ||
for subview in subviews { | ||
if let match = subview as? View, predicate(match) { | ||
return match | ||
} | ||
} | ||
|
||
for view in subviews { | ||
if let match = view.findSubview(ofType: viewType, where: predicate) { | ||
return match | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
public func expectedChild<T: UIView>(ofType viewType: T.Type) throws -> T { | ||
try XCTUnwrap( | ||
findSubview(ofType: viewType), | ||
"Expected to find child of type \(T.self) but no child was found" | ||
) | ||
} | ||
} |
File renamed without changes.