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
// On the view's code | |
func setupGestures() { | |
let tap = UITapGestureRecognizer(target: self, action: #selector(callDelegateTap)) | |
addGestureRecognizer(tap) | |
} | |
// On the test code | |
func test_tappingView_shouldCallDelegate() { | |
let sut = MyView() | |
let gesture = sut.gestureRecognizers?.first { $0 is UITapGestureRecognizer } |
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
class MyViewTests: XCTestCase { | |
private let delegateSpy = DelegateSpy() | |
private lazy var sut = { | |
let sut = MyView() | |
sut.delegate = delegateSpy | |
return sut | |
}() | |
func test_pressingActionButton_shouldCallDelegate() { | |
perform(.touchUpInside, from: sut.actionButton, target: sut, args: nil) |
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
extension XCTestCase { | |
public func perform(event: UIControl.Event, from button: UIControl, target: NSObject, args: Any?) { | |
let action = button.actions(forTarget: target, forControlEvent: event)?.first ?? "" | |
target.performSelector(onMainThread: Selector(action), with: args, waitUntilDone: true) | |
} | |
public func performGestureRecognizer<T>(type: T.Type, on view: UIView) { | |
let gesture = view.gestureRecognizers?.first { $0 is T } | |
let target = (gesture?.value(forKey: "_targets") as? [NSObject])?.first |
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
func expand() { | |
bottomSheetController.expand() | |
UIAccessibility.post(notification: .layoutChanged, argument: listView) | |
} | |
func collapse() { | |
bottomSheetController.collapse() | |
UIAccessibility.post(notification: .layoutChanged, argument: searchView) | |
} |
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
class SearchView: UIView { | |
... | |
override func accessibilityPerformMagicTap() -> Bool { | |
expandList() | |
return true | |
} | |
} | |
class ListView: UIView { | |
... |
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
func configureAccessibility() { | |
isAccessibilityElement = true | |
accessibilityTraits = .adjustable | |
} | |
override func accessibilityIncrement() { | |
quickAddButton.increment() | |
UIAccessibility.post(notification: .announcement, argument: "\(quickAdd.value)") | |
} |
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
override public var accessibilityViewIsModal: Bool { | |
get { | |
switch currentListState { | |
case .collapsed: | |
return false | |
case .expanded: | |
return true | |
} | |
} | |
set { } |
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
func configureAccessibilityElementsOrder() { | |
accessibilityElements = [ | |
closeButton, | |
titleLabel, | |
createButton, | |
collectionView, | |
footer | |
] | |
} |
NewerOlder