Skip to content

Commit fb83758

Browse files
committed
WIP
1 parent d72aaa7 commit fb83758

File tree

1 file changed

+48
-68
lines changed

1 file changed

+48
-68
lines changed
Lines changed: 48 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,90 @@
11
import SwiftUI
22
import SwiftUIIntrospect
3-
import XCTest
3+
import Testing
44

55
@MainActor
6-
final class ScrollViewTests: XCTestCase {
6+
@Suite
7+
struct ScrollViewTests {
78
#if canImport(UIKit)
89
typealias PlatformScrollView = UIScrollView
910
#elseif canImport(AppKit)
1011
typealias PlatformScrollView = NSScrollView
1112
#endif
1213

13-
func testScrollView() {
14-
XCTAssertViewIntrospection(of: PlatformScrollView.self) { spies in
15-
let spy0 = spies[0]
16-
let spy1 = spies[1]
17-
14+
@Test func introspect() async throws {
15+
let (entity1, entity2) = try await introspection(of: PlatformScrollView.self) { spy1, spy2 in
1816
HStack {
1917
ScrollView(showsIndicators: false) {
2018
Text("Item 1")
2119
}
2220
#if os(iOS) || os(tvOS) || os(visionOS)
23-
.introspect(.scrollView, on: .iOS(.v13, .v14, .v15, .v16, .v17, .v18, .v26), .tvOS(.v13, .v14, .v15, .v16, .v17, .v18, .v26), .visionOS(.v1, .v2, .v26), customize: spy0)
21+
.introspect(.scrollView, on: .iOS(.v13, .v14, .v15, .v16, .v17, .v18, .v26), .tvOS(.v13, .v14, .v15, .v16, .v17, .v18, .v26), .visionOS(.v1, .v2, .v26), customize: spy1)
2422
#elseif os(macOS)
25-
.introspect(.scrollView, on: .macOS(.v10_15, .v11, .v12, .v13, .v14, .v15, .v26), customize: spy0)
23+
.introspect(.scrollView, on: .macOS(.v10_15, .v11, .v12, .v13, .v14, .v15, .v26), customize: spy1)
2624
#endif
2725

2826
ScrollView(showsIndicators: true) {
2927
Text("Item 1")
3028
#if os(iOS) || os(tvOS) || os(visionOS)
31-
.introspect(.scrollView, on: .iOS(.v13, .v14, .v15, .v16, .v17, .v18, .v26), .tvOS(.v13, .v14, .v15, .v16, .v17, .v18, .v26), .visionOS(.v1, .v2, .v26), scope: .ancestor, customize: spy1)
29+
.introspect(.scrollView, on: .iOS(.v13, .v14, .v15, .v16, .v17, .v18, .v26), .tvOS(.v13, .v14, .v15, .v16, .v17, .v18, .v26), .visionOS(.v1, .v2, .v26), scope: .ancestor, customize: spy2)
3230
#elseif os(macOS)
33-
.introspect(.scrollView, on: .macOS(.v10_15, .v11, .v12, .v13, .v14, .v15, .v26), scope: .ancestor, customize: spy1)
31+
.introspect(.scrollView, on: .macOS(.v10_15, .v11, .v12, .v13, .v14, .v15, .v26), scope: .ancestor, customize: spy2)
3432
#endif
3533
}
3634
}
37-
} extraAssertions: {
38-
#if canImport(UIKit)
39-
XCTAssertEqual($0[safe: 0]?.showsVerticalScrollIndicator, false)
40-
XCTAssertEqual($0[safe: 1]?.showsVerticalScrollIndicator, true)
41-
#elseif canImport(AppKit)
42-
// FIXME: these assertions don't pass on macOS 12, not sure why... maybe callback is too premature in relation to view lifecycle?
43-
if #available(macOS 13, *) {
44-
XCTAssert($0[safe: 0]?.verticalScroller == nil)
45-
XCTAssert($0[safe: 1]?.verticalScroller != nil)
46-
}
47-
#endif
48-
49-
XCTAssert($0[safe: 0] !== $0[safe: 1])
5035
}
51-
}
36+
#if canImport(UIKit)
37+
#expect(entity1.showsVerticalScrollIndicator == false)
38+
#expect(entity2.showsVerticalScrollIndicator == true)
39+
#elseif canImport(AppKit)
40+
#expect(entity1.verticalScroller == nil)
41+
#expect(entity2.verticalScroller != nil)
42+
#endif
5243

53-
func testNestedScrollView() {
54-
XCTAssertViewIntrospection(of: PlatformScrollView.self) { spies in
55-
let spy0 = spies[0]
56-
let spy1 = spies[1]
44+
#expect(entity1 !== entity2)
45+
}
5746

47+
@Test func introspectNested() async throws {
48+
let (entity1, entity2) = try await introspection(of: PlatformScrollView.self) { spy1, spy2 in
5849
ScrollView(showsIndicators: true) {
5950
Text("Item 1")
6051

6152
ScrollView(showsIndicators: false) {
6253
Text("Item 1")
6354
}
6455
#if os(iOS) || os(tvOS) || os(visionOS)
65-
.introspect(.scrollView, on: .iOS(.v13, .v14, .v15, .v16, .v17, .v18, .v26), .tvOS(.v13, .v14, .v15, .v16, .v17, .v18, .v26), .visionOS(.v1, .v2, .v26), customize: spy1)
56+
.introspect(.scrollView, on: .iOS(.v13, .v14, .v15, .v16, .v17, .v18, .v26), .tvOS(.v13, .v14, .v15, .v16, .v17, .v18, .v26), .visionOS(.v1, .v2, .v26), customize: spy2)
6657
#elseif os(macOS)
67-
.introspect(.scrollView, on: .macOS(.v10_15, .v11, .v12, .v13, .v14, .v15, .v26), customize: spy1)
58+
.introspect(.scrollView, on: .macOS(.v10_15, .v11, .v12, .v13, .v14, .v15, .v26), customize: spy2)
6859
#endif
6960
}
7061
#if os(iOS) || os(tvOS) || os(visionOS)
71-
.introspect(.scrollView, on: .iOS(.v13, .v14, .v15, .v16, .v17, .v18, .v26), .tvOS(.v13, .v14, .v15, .v16, .v17, .v18, .v26), .visionOS(.v1, .v2, .v26), customize: spy0)
62+
.introspect(.scrollView, on: .iOS(.v13, .v14, .v15, .v16, .v17, .v18, .v26), .tvOS(.v13, .v14, .v15, .v16, .v17, .v18, .v26), .visionOS(.v1, .v2, .v26), customize: spy1)
7263
#elseif os(macOS)
73-
.introspect(.scrollView, on: .macOS(.v10_15, .v11, .v12, .v13, .v14, .v15, .v26), customize: spy0)
64+
.introspect(.scrollView, on: .macOS(.v10_15, .v11, .v12, .v13, .v14, .v15, .v26), customize: spy1)
7465
#endif
75-
} extraAssertions: {
76-
#if canImport(UIKit)
77-
XCTAssertEqual($0[safe: 0]?.showsVerticalScrollIndicator, true)
78-
XCTAssertEqual($0[safe: 1]?.showsVerticalScrollIndicator, false)
79-
#elseif canImport(AppKit)
80-
// FIXME: these assertions don't pass on macOS 12, not sure why... maybe callback is too premature in relation to view lifecycle?
81-
if #available(macOS 13, *) {
82-
XCTAssert($0[safe: 0]?.verticalScroller != nil)
83-
XCTAssert($0[safe: 1]?.verticalScroller == nil)
84-
}
85-
#endif
86-
87-
XCTAssert($0[safe: 0] !== $0[safe: 1])
8866
}
89-
}
67+
#if canImport(UIKit)
68+
#expect(entity1.showsVerticalScrollIndicator == true)
69+
#expect(entity2.showsVerticalScrollIndicator == false)
70+
#elseif canImport(AppKit)
71+
#expect(entity1.verticalScroller != nil)
72+
#expect(entity2.verticalScroller == nil)
73+
#endif
9074

91-
func testMaskedScrollView() {
92-
XCTAssertViewIntrospection(of: PlatformScrollView.self) { spies in
93-
let spy0 = spies[0]
94-
let spy1 = spies[1]
75+
#expect(entity1 !== entity2)
76+
}
9577

78+
@Test func introspectMasked() async throws {
79+
let (entity1, entity2) = try await introspection(of: PlatformScrollView.self) { spy1, spy2 in
9680
HStack {
9781
ScrollView(showsIndicators: false) {
9882
Text("Item 1")
9983
}
10084
#if os(iOS) || os(tvOS) || os(visionOS)
101-
.introspect(.scrollView, on: .iOS(.v13, .v14, .v15, .v16, .v17, .v18, .v26), .tvOS(.v13, .v14, .v15, .v16, .v17, .v18, .v26), .visionOS(.v1, .v2, .v26), customize: spy0)
85+
.introspect(.scrollView, on: .iOS(.v13, .v14, .v15, .v16, .v17, .v18, .v26), .tvOS(.v13, .v14, .v15, .v16, .v17, .v18, .v26), .visionOS(.v1, .v2, .v26), customize: spy1)
10286
#elseif os(macOS)
103-
.introspect(.scrollView, on: .macOS(.v10_15, .v11, .v12, .v13, .v14, .v15, .v26), customize: spy0)
87+
.introspect(.scrollView, on: .macOS(.v10_15, .v11, .v12, .v13, .v14, .v15, .v26), customize: spy1)
10488
#endif
10589
.clipped()
10690
.clipShape(RoundedRectangle(cornerRadius: 20.0))
@@ -109,25 +93,21 @@ final class ScrollViewTests: XCTestCase {
10993
ScrollView(showsIndicators: true) {
11094
Text("Item 1")
11195
#if os(iOS) || os(tvOS) || os(visionOS)
112-
.introspect(.scrollView, on: .iOS(.v13, .v14, .v15, .v16, .v17, .v18, .v26), .tvOS(.v13, .v14, .v15, .v16, .v17, .v18, .v26), .visionOS(.v1, .v2, .v26), scope: .ancestor, customize: spy1)
96+
.introspect(.scrollView, on: .iOS(.v13, .v14, .v15, .v16, .v17, .v18, .v26), .tvOS(.v13, .v14, .v15, .v16, .v17, .v18, .v26), .visionOS(.v1, .v2, .v26), scope: .ancestor, customize: spy2)
11397
#elseif os(macOS)
114-
.introspect(.scrollView, on: .macOS(.v10_15, .v11, .v12, .v13, .v14, .v15, .v26), scope: .ancestor, customize: spy1)
98+
.introspect(.scrollView, on: .macOS(.v10_15, .v11, .v12, .v13, .v14, .v15, .v26), scope: .ancestor, customize: spy2)
11599
#endif
116100
}
117101
}
118-
} extraAssertions: {
119-
#if canImport(UIKit)
120-
XCTAssertEqual($0[safe: 0]?.showsVerticalScrollIndicator, false)
121-
XCTAssertEqual($0[safe: 1]?.showsVerticalScrollIndicator, true)
122-
#elseif canImport(AppKit)
123-
// FIXME: these assertions don't pass on macOS 12, not sure why... maybe callback is too premature in relation to view lifecycle?
124-
if #available(macOS 13, *) {
125-
XCTAssert($0[safe: 0]?.verticalScroller == nil)
126-
XCTAssert($0[safe: 1]?.verticalScroller != nil)
127-
}
128-
#endif
129-
130-
XCTAssert($0[safe: 0] !== $0[safe: 1])
131102
}
103+
#if canImport(UIKit)
104+
#expect(entity1.showsVerticalScrollIndicator == false)
105+
#expect(entity2.showsVerticalScrollIndicator == true)
106+
#elseif canImport(AppKit)
107+
#expect(entity1.verticalScroller == nil)
108+
#expect(entity2.verticalScroller != nil)
109+
#endif
110+
111+
#expect(entity1 !== entity2)
132112
}
133113
}

0 commit comments

Comments
 (0)