Add an introspect method for UITableViewCell (#18)
* Adds an introspect method for UITableViewCell * Added NSTableCellView introspection Added line to CHANGELOG Added tests for UIKit and AppKit * Removed additional spaces Co-authored-by: SplittyDev <splittydev@gmail.com>
This commit is contained in:
parent
868a7e8ca3
commit
f246b0715c
|
@ -3,6 +3,7 @@ Changelog
|
|||
|
||||
## master
|
||||
|
||||
- Added `introspectTableViewCell`
|
||||
- Add Github Action
|
||||
- Added `.introspectTextView()`.
|
||||
- Update CircleCI config to use Xcode 12.4.0
|
||||
|
|
|
@ -75,6 +75,11 @@ extension View {
|
|||
return introspect(selector: TargetViewSelector.ancestorOrSiblingContaining, customize: customize)
|
||||
}
|
||||
|
||||
/// Finds a `UITableViewCell` from a `SwiftUI.List`, or `SwiftUI.List` child. You can attach this directly to the element inside the list.
|
||||
public func introspectTableViewCell(customize: @escaping (UITableViewCell) -> ()) -> some View {
|
||||
return introspect(selector: TargetViewSelector.ancestorOrSiblingContaining, customize: customize)
|
||||
}
|
||||
|
||||
/// Finds a `UIScrollView` from a `SwiftUI.ScrollView`, or `SwiftUI.ScrollView` child.
|
||||
public func introspectScrollView(customize: @escaping (UIScrollView) -> ()) -> some View {
|
||||
if #available(iOS 14.0, tvOS 14.0, macOS 11.0, *) {
|
||||
|
@ -144,7 +149,12 @@ extension View {
|
|||
public func introspectTableView(customize: @escaping (NSTableView) -> ()) -> some View {
|
||||
return introspect(selector: TargetViewSelector.ancestorOrSiblingContaining, customize: customize)
|
||||
}
|
||||
|
||||
|
||||
/// Finds a `NSTableCellView` from a `SwiftUI.List`, or `SwiftUI.List` child. You can attach this directly to the element inside the list.
|
||||
public func introspectTableViewCell(customize: @escaping (NSTableCellView) -> ()) -> some View {
|
||||
return introspect(selector: TargetViewSelector.ancestorOrSiblingContaining, customize: customize)
|
||||
}
|
||||
|
||||
/// Finds a `NSScrollView` from a `SwiftUI.ScrollView`, or `SwiftUI.ScrollView` child.
|
||||
public func introspectScrollView(customize: @escaping (NSScrollView) -> ()) -> some View {
|
||||
return introspect(selector: TargetViewSelector.ancestorOrSiblingContaining, customize: customize)
|
||||
|
|
|
@ -28,7 +28,9 @@ private struct ListTestView: View {
|
|||
|
||||
let spy1: () -> Void
|
||||
let spy2: () -> Void
|
||||
|
||||
let spyCell1: () -> Void
|
||||
let spyCell2: () -> Void
|
||||
|
||||
var body: some View {
|
||||
List {
|
||||
Text("Item 1")
|
||||
|
@ -36,10 +38,17 @@ private struct ListTestView: View {
|
|||
.introspectTableView { tableView in
|
||||
self.spy2()
|
||||
}
|
||||
.introspectTableViewCell { cell in
|
||||
self.spyCell2()
|
||||
}
|
||||
|
||||
}
|
||||
.introspectTableView { tableView in
|
||||
self.spy1()
|
||||
}
|
||||
.introspectTableViewCell { cell in
|
||||
self.spyCell1()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,17 +160,21 @@ private struct SegmentedControlTestView: View {
|
|||
class AppKitTests: XCTestCase {
|
||||
|
||||
func testList() {
|
||||
|
||||
let expectation1 = XCTestExpectation()
|
||||
let expectation2 = XCTestExpectation()
|
||||
let cellExpectation1 = XCTestExpectation()
|
||||
let cellExpectation2 = XCTestExpectation()
|
||||
|
||||
let view = ListTestView(
|
||||
spy1: { expectation1.fulfill() },
|
||||
spy2: { expectation2.fulfill() }
|
||||
spy2: { expectation2.fulfill() },
|
||||
spyCell1: { cellExpectation1.fulfill() },
|
||||
spyCell2: { cellExpectation2.fulfill() }
|
||||
)
|
||||
TestUtils.present(view: view)
|
||||
wait(for: [expectation1, expectation2], timeout: TestUtils.Constants.timeout)
|
||||
wait(for: [expectation1, expectation2, cellExpectation1, cellExpectation2], timeout: TestUtils.Constants.timeout)
|
||||
}
|
||||
|
||||
|
||||
func testScrollView() {
|
||||
|
||||
let expectation1 = XCTestExpectation()
|
||||
|
|
|
@ -112,7 +112,9 @@ private struct ListTestView: View {
|
|||
|
||||
let spy1: () -> Void
|
||||
let spy2: () -> Void
|
||||
|
||||
let spyCell1: () -> Void
|
||||
let spyCell2: () -> Void
|
||||
|
||||
var body: some View {
|
||||
List {
|
||||
Text("Item 1")
|
||||
|
@ -120,10 +122,17 @@ private struct ListTestView: View {
|
|||
.introspectTableView { tableView in
|
||||
self.spy2()
|
||||
}
|
||||
.introspectTableViewCell { cell in
|
||||
self.spyCell2()
|
||||
}
|
||||
|
||||
}
|
||||
.introspectTableView { tableView in
|
||||
self.spy1()
|
||||
}
|
||||
.introspectTableViewCell { cell in
|
||||
self.spyCell1()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -294,12 +303,17 @@ class UIKitTests: XCTestCase {
|
|||
|
||||
let expectation1 = XCTestExpectation()
|
||||
let expectation2 = XCTestExpectation()
|
||||
let cellExpectation1 = XCTestExpectation()
|
||||
let cellExpectation2 = XCTestExpectation()
|
||||
|
||||
let view = ListTestView(
|
||||
spy1: { expectation1.fulfill() },
|
||||
spy2: { expectation2.fulfill() }
|
||||
spy2: { expectation2.fulfill() },
|
||||
spyCell1: { cellExpectation1.fulfill() },
|
||||
spyCell2: { cellExpectation2.fulfill() }
|
||||
)
|
||||
TestUtils.present(view: view)
|
||||
wait(for: [expectation1, expectation2], timeout: TestUtils.Constants.timeout)
|
||||
wait(for: [expectation1, expectation2, cellExpectation1, cellExpectation2], timeout: TestUtils.Constants.timeout)
|
||||
}
|
||||
|
||||
func testScrollView() {
|
||||
|
|
Loading…
Reference in New Issue