11import SwiftUI
2- import SwiftUIIntrospect
2+ @ testable import SwiftUIIntrospect
33import XCTest
44
55@MainActor
@@ -8,33 +8,57 @@ final class ViewTests: XCTestCase {
88 XCTAssertViewIntrospection ( of: PlatformView . self) { spies in
99 let spy0 = spies [ 0 ]
1010 let spy1 = spies [ 1 ]
11- let spy2 = spies [ 2 ]
1211
1312 VStack ( spacing: 10 ) {
14- Image ( systemName : " scribble " ) . resizable ( ) . frame ( height: 30 )
13+ SUTView ( ) . frame ( height: 30 )
1514 #if os(iOS) || os(tvOS) || os(visionOS)
1615 . introspect( . view, on: . iOS( . v13, . v14, . v15, . v16, . v17, . v18, . v26) , . tvOS( . v13, . v14, . v15, . v16, . v17, . v18, . v26) , . visionOS( . v1, . v2, . v26) , customize: spy0)
1716 #elseif os(macOS)
1817 . introspect( . view, on: . macOS( . v10_15, . v11, . v12, . v13, . v14, . v15, . v26) , customize: spy0)
1918 #endif
2019
21- Text ( " Text " ) . frame ( height: 40 )
20+ SUTView ( ) . frame ( height: 40 )
2221 #if os(iOS) || os(tvOS) || os(visionOS)
2322 . introspect( . view, on: . iOS( . v13, . v14, . v15, . v16, . v17, . v18, . v26) , . tvOS( . v13, . v14, . v15, . v16, . v17, . v18, . v26) , . visionOS( . v1, . v2, . v26) , customize: spy1)
2423 #elseif os(macOS)
2524 . introspect( . view, on: . macOS( . v10_15, . v11, . v12, . v13, . v14, . v15, . v26) , customize: spy1)
2625 #endif
2726 }
2827 . padding ( 10 )
29- #if os(iOS) || os(tvOS) || os(visionOS)
30- . introspect( . view, on: . iOS( . v13, . v14, . v15, . v16, . v17, . v18, . v26) , . tvOS( . v13, . v14, . v15, . v16, . v17, . v18, . v26) , . visionOS( . v1, . v2, . v26) , customize: spy2)
31- #elseif os(macOS)
32- . introspect( . view, on: . macOS( . v10_15, . v11, . v12, . v13, . v14, . v15, . v26) , customize: spy2)
33- #endif
3428 } extraAssertions: {
3529 XCTAssertEqual ( $0 [ safe: 0 ] ? . frame. height, 30 )
3630 XCTAssertEqual ( $0 [ safe: 1 ] ? . frame. height, 40 )
37- XCTAssertEqual ( $0 [ safe: 2 ] ? . frame. height, 100 )
3831 }
3932 }
4033}
34+
35+ struct SUTView : PlatformViewControllerRepresentable {
36+ #if canImport(UIKit)
37+ typealias UIViewControllerType = PlatformViewController
38+ #elseif canImport(AppKit)
39+ typealias NSViewControllerType = PlatformViewController
40+ #endif
41+
42+ func makePlatformViewController( context: Context ) -> PlatformViewController {
43+ let controller = PlatformViewController ( nibName: nil , bundle: nil )
44+ controller. view. translatesAutoresizingMaskIntoConstraints = false
45+
46+ let widthConstraint = controller. view. widthAnchor. constraint ( greaterThanOrEqualToConstant: . greatestFiniteMagnitude)
47+ widthConstraint. priority = . defaultLow
48+
49+ let heightConstraint = controller. view. heightAnchor. constraint ( greaterThanOrEqualToConstant: . greatestFiniteMagnitude)
50+ heightConstraint. priority = . defaultLow
51+
52+ NSLayoutConstraint . activate ( [ widthConstraint, heightConstraint] )
53+
54+ return controller
55+ }
56+
57+ func updatePlatformViewController( _ controller: PlatformViewController , context: Context ) {
58+ // NO-OP
59+ }
60+
61+ static func dismantlePlatformViewController( _ controller: PlatformViewController , coordinator: Coordinator ) {
62+ // NO-OP
63+ }
64+ }
0 commit comments