Skip to content

Add introspection for NSTabView #84

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 2 commits into from
Mar 17, 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Changelog

## master

- Added `.introspectTabView()` on macOS

## [0.1.3]

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

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