Add NSButton Introspection (#85)

This commit is contained in:
JannThomas 2021-03-18 19:29:42 +01:00 committed by GitHub
parent 07a80dd280
commit 4232b86790
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 0 deletions

View File

@ -3,6 +3,7 @@ Changelog
## master
- Added `.introspectButton()` on macOS
- Fix UITextField with cornerRadius
- Added `.introspectTabView()` on macOS

View File

@ -198,5 +198,10 @@ extension View {
public func introspectTabView(customize: @escaping (NSTabView) -> ()) -> some View {
return introspect(selector: TargetViewSelector.siblingContaining, customize: customize)
}
/// Finds a `NSButton` from a `SwiftUI.Button`
public func introspectButton(customize: @escaping (NSButton) -> ()) -> some View {
return introspect(selector: TargetViewSelector.siblingContaining, customize: customize)
}
}
#endif

View File

@ -203,6 +203,17 @@ private struct TabViewTestView: View {
}
}
@available(macOS 10.15.0, *)
private struct ButtonTestView: View {
let spy: () -> Void
var body: some View {
Button("Test", action: {})
.introspectButton { button in
self.spy()
}
}
}
@available(macOS 10.15.0, *)
class AppKitTests: XCTestCase {
@ -346,5 +357,15 @@ class AppKitTests: XCTestCase {
TestUtils.present(view: view)
wait(for: [expectation], timeout: TestUtils.Constants.timeout)
}
func testButton() {
let expectation = XCTestExpectation()
let view = ButtonTestView(spy: {
expectation.fulfill()
})
TestUtils.present(view: view)
wait(for: [expectation], timeout: TestUtils.Constants.timeout)
}
}
#endif