Add introspection for `NSTabView` (#84)

Add introspection for `NSTabView`
This commit is contained in:
JannThomas 2021-03-17 20:02:44 +01:00 committed by GitHub
parent 2cf3d5f5a6
commit fab6cddbaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 0 deletions

View File

@ -3,6 +3,8 @@ Changelog
## master
- Added `.introspectTabView()` on macOS
## [0.1.3]
- Added `introspectTableViewCell`

View File

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

View File

@ -183,6 +183,26 @@ private struct SegmentedControlTestView: View {
}
}
@available(macOS 10.15.0, *)
private struct TabViewTestView: View {
let spy: () -> Void
var body: some View {
TabView {
Text("Contents")
.tabItem {
Text("Tab 1")
}
Text("Contents")
.tabItem {
Text("Tab 2")
}
}
.introspectTabView { tabView in
self.spy()
}
}
}
@available(macOS 10.15.0, *)
class AppKitTests: XCTestCase {
@ -316,5 +336,15 @@ class AppKitTests: XCTestCase {
TestUtils.present(view: view)
wait(for: [expectation], timeout: TestUtils.Constants.timeout)
}
func testTabView() {
let expectation = XCTestExpectation()
let view = TabViewTestView(spy: {
expectation.fulfill()
})
TestUtils.present(view: view)
wait(for: [expectation], timeout: TestUtils.Constants.timeout)
}
}
#endif