Skip to content

Commit

Permalink
adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RoyalPineapple committed Feb 6, 2025
1 parent 298dc3e commit 0338f2c
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
35 changes: 35 additions & 0 deletions BlueprintUI/Tests/AccessibililtyTraitsTests.swift
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

View workflow job for this annotation

GitHub Actions / iOS 15.4

test_backButton, XCTAssertEqual failed: ("UIAccessibilityTraits(rawValue: 0)") is not equal to ("UIAccessibilityTraits(rawValue: 134217728)")

Check failure on line 22 in BlueprintUI/Tests/AccessibililtyTraitsTests.swift

View workflow job for this annotation

GitHub Actions / iOS 16.2

test_backButton, XCTAssertEqual failed: ("UIAccessibilityTraits(rawValue: 0)") is not equal to ("UIAccessibilityTraits(rawValue: 134217728)")

Check failure on line 22 in BlueprintUI/Tests/AccessibililtyTraitsTests.swift

View workflow job for this annotation

GitHub Actions / iOS 17.2

test_backButton, XCTAssertEqual failed: ("UIAccessibilityTraits(rawValue: 0)") is not equal to ("UIAccessibilityTraits(rawValue: 134217728)")
}
}

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

View workflow job for this annotation

GitHub Actions / iOS 15.4

test_toggleSwitch, XCTAssertTrue failed

Check failure on line 33 in BlueprintUI/Tests/AccessibililtyTraitsTests.swift

View workflow job for this annotation

GitHub Actions / iOS 16.2

test_toggleSwitch, XCTAssertTrue failed

Check failure on line 33 in BlueprintUI/Tests/AccessibililtyTraitsTests.swift

View workflow job for this annotation

GitHub Actions / iOS 17.2

test_toggleSwitch, XCTAssertTrue failed
}
}
32 changes: 32 additions & 0 deletions BlueprintUI/Tests/Extensions/UIView+Testing.swift
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.

0 comments on commit 0338f2c

Please sign in to comment.