Skip to content

Commit fab6cdd

Browse files
authored
Add introspection for NSTabView (#84)
Add introspection for `NSTabView`
1 parent 2cf3d5f commit fab6cdd

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Changelog
33

44
## master
55

6+
- Added `.introspectTabView()` on macOS
7+
68
## [0.1.3]
79

810
- Added `introspectTableViewCell`

Introspect/ViewExtensions.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,5 +193,10 @@ extension View {
193193
public func introspectSegmentedControl(customize: @escaping (NSSegmentedControl) -> ()) -> some View {
194194
return introspect(selector: TargetViewSelector.siblingContaining, customize: customize)
195195
}
196+
197+
/// Finds a `NSTabView` from a `SwiftUI.TabView`
198+
public func introspectTabView(customize: @escaping (NSTabView) -> ()) -> some View {
199+
return introspect(selector: TargetViewSelector.siblingContaining, customize: customize)
200+
}
196201
}
197202
#endif

IntrospectTests/AppKitTests.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,26 @@ private struct SegmentedControlTestView: View {
183183
}
184184
}
185185

186+
@available(macOS 10.15.0, *)
187+
private struct TabViewTestView: View {
188+
let spy: () -> Void
189+
var body: some View {
190+
TabView {
191+
Text("Contents")
192+
.tabItem {
193+
Text("Tab 1")
194+
}
195+
Text("Contents")
196+
.tabItem {
197+
Text("Tab 2")
198+
}
199+
}
200+
.introspectTabView { tabView in
201+
self.spy()
202+
}
203+
}
204+
}
205+
186206
@available(macOS 10.15.0, *)
187207
class AppKitTests: XCTestCase {
188208

@@ -316,5 +336,15 @@ class AppKitTests: XCTestCase {
316336
TestUtils.present(view: view)
317337
wait(for: [expectation], timeout: TestUtils.Constants.timeout)
318338
}
339+
340+
func testTabView() {
341+
342+
let expectation = XCTestExpectation()
343+
let view = TabViewTestView(spy: {
344+
expectation.fulfill()
345+
})
346+
TestUtils.present(view: view)
347+
wait(for: [expectation], timeout: TestUtils.Constants.timeout)
348+
}
319349
}
320350
#endif

0 commit comments

Comments
 (0)