Skip to content

Add NSButton Introspection #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Changelog

## master

- Added `.introspectButton()` on macOS
- Fix UITextField with cornerRadius
- Added `.introspectTabView()` on macOS

Expand Down
5 changes: 5 additions & 0 deletions Introspect/ViewExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 21 additions & 0 deletions IntrospectTests/AppKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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