11import SwiftUI
22import SwiftUIIntrospect
3- import XCTest
3+ import Testing
44
55@MainActor
6- final class SecureFieldTests : XCTestCase {
6+ @Suite
7+ struct SecureFieldTests {
78 #if canImport(UIKit)
89 typealias PlatformSecureField = UITextField
910 #elseif canImport(AppKit)
1011 typealias PlatformSecureField = NSTextField
1112 #endif
1213
13- func testSecureField( ) {
14- XCTAssertViewIntrospection ( of: PlatformSecureField . self) { spies in
15- let spy0 = spies [ 0 ]
16- let spy1 = spies [ 1 ]
17- let spy2 = spies [ 2 ]
18-
14+ @Test func introspect( ) async throws {
15+ let ( entity1, entity2, entity3) = try await introspection ( of: PlatformSecureField . self) { spy1, spy2, spy3 in
1916 VStack {
20- SecureField ( " " , text: . constant( " Secure Field 0 " ) )
21- #if os(iOS) || os(tvOS) || os(visionOS)
22- . introspect( . secureField, on: . iOS( . v13, . v14, . v15, . v16, . v17, . v18, . v26) , . tvOS( . v13, . v14, . v15, . v16, . v17, . v18, . v26) , . visionOS( . v1, . v2, . v26) , customize: spy0)
23- #elseif os(macOS)
24- . introspect( . secureField, on: . macOS( . v10_15, . v11, . v12, . v13, . v14, . v15, . v26) , customize: spy0)
25- #endif
26- . cornerRadius( 8 )
27-
2817 SecureField ( " " , text: . constant( " Secure Field 1 " ) )
2918 #if os(iOS) || os(tvOS) || os(visionOS)
3019 . introspect( . secureField, on: . iOS( . v13, . v14, . v15, . v16, . v17, . v18, . v26) , . tvOS( . v13, . v14, . v15, . v16, . v17, . v18, . v26) , . visionOS( . v1, . v2, . v26) , customize: spy1)
@@ -39,34 +28,30 @@ final class SecureFieldTests: XCTestCase {
3928 #elseif os(macOS)
4029 . introspect( . secureField, on: . macOS( . v10_15, . v11, . v12, . v13, . v14, . v15, . v26) , customize: spy2)
4130 #endif
42- }
43- } extraAssertions: {
44- #if canImport(UIKit)
45- XCTAssertEqual ( $0 [ safe: 0 ] ? . text, " Secure Field 0 " )
46- XCTAssertEqual ( $0 [ safe: 1 ] ? . text, " Secure Field 1 " )
47- XCTAssertEqual ( $0 [ safe: 2 ] ? . text, " Secure Field 2 " )
48- #elseif canImport(AppKit)
49- XCTAssertEqual ( $0 [ safe: 0 ] ? . stringValue, " Secure Field 0 " )
50- XCTAssertEqual ( $0 [ safe: 1 ] ? . stringValue, " Secure Field 1 " )
51- XCTAssertEqual ( $0 [ safe: 2 ] ? . stringValue, " Secure Field 2 " )
52- #endif
53- }
54- }
55-
56- func testSecureFieldsEmbeddedInList( ) {
57- XCTAssertViewIntrospection ( of: PlatformSecureField . self) { spies in
58- let spy0 = spies [ 0 ]
59- let spy1 = spies [ 1 ]
60- let spy2 = spies [ 2 ]
31+ . cornerRadius( 8 )
6132
62- List {
63- SecureField ( " " , text: . constant( " Secure Field 0 " ) )
33+ SecureField ( " " , text: . constant( " Secure Field 3 " ) )
6434 #if os(iOS) || os(tvOS) || os(visionOS)
65- . introspect( . secureField, on: . iOS( . v13, . v14, . v15, . v16, . v17, . v18, . v26) , . tvOS( . v13, . v14, . v15, . v16, . v17, . v18, . v26) , . visionOS( . v1, . v2, . v26) , customize: spy0 )
35+ . introspect( . secureField, on: . iOS( . v13, . v14, . v15, . v16, . v17, . v18, . v26) , . tvOS( . v13, . v14, . v15, . v16, . v17, . v18, . v26) , . visionOS( . v1, . v2, . v26) , customize: spy3 )
6636 #elseif os(macOS)
67- . introspect( . secureField, on: . macOS( . v10_15, . v11, . v12, . v13, . v14, . v15, . v26) , customize: spy0 )
37+ . introspect( . secureField, on: . macOS( . v10_15, . v11, . v12, . v13, . v14, . v15, . v26) , customize: spy3 )
6838 #endif
39+ }
40+ }
41+ #if canImport(UIKit)
42+ #expect( entity1. text == " Secure Field 1 " )
43+ #expect( entity2. text == " Secure Field 2 " )
44+ #expect( entity3. text == " Secure Field 3 " )
45+ #elseif canImport(AppKit)
46+ #expect( entity1. stringValue == " Secure Field 1 " )
47+ #expect( entity2. stringValue == " Secure Field 2 " )
48+ #expect( entity3. stringValue == " Secure Field 3 " )
49+ #endif
50+ }
6951
52+ @Test func introspectEmbeddedInList( ) async throws {
53+ let ( entity1, entity2, entity3) = try await introspection ( of: PlatformSecureField . self) { spy1, spy2, spy3 in
54+ List {
7055 SecureField ( " " , text: . constant( " Secure Field 1 " ) )
7156 #if os(iOS) || os(tvOS) || os(visionOS)
7257 . introspect( . secureField, on: . iOS( . v13, . v14, . v15, . v16, . v17, . v18, . v26) , . tvOS( . v13, . v14, . v15, . v16, . v17, . v18, . v26) , . visionOS( . v1, . v2, . v26) , customize: spy1)
@@ -80,17 +65,23 @@ final class SecureFieldTests: XCTestCase {
8065 #elseif os(macOS)
8166 . introspect( . secureField, on: . macOS( . v10_15, . v11, . v12, . v13, . v14, . v15, . v26) , customize: spy2)
8267 #endif
68+
69+ SecureField ( " " , text: . constant( " Secure Field 3 " ) )
70+ #if os(iOS) || os(tvOS) || os(visionOS)
71+ . introspect( . secureField, on: . iOS( . v13, . v14, . v15, . v16, . v17, . v18, . v26) , . tvOS( . v13, . v14, . v15, . v16, . v17, . v18, . v26) , . visionOS( . v1, . v2, . v26) , customize: spy3)
72+ #elseif os(macOS)
73+ . introspect( . secureField, on: . macOS( . v10_15, . v11, . v12, . v13, . v14, . v15, . v26) , customize: spy3)
74+ #endif
8375 }
84- } extraAssertions: {
85- #if canImport(UIKit)
86- XCTAssertEqual ( $0 [ safe: 0 ] ? . text, " Secure Field 0 " )
87- XCTAssertEqual ( $0 [ safe: 1 ] ? . text, " Secure Field 1 " )
88- XCTAssertEqual ( $0 [ safe: 2 ] ? . text, " Secure Field 2 " )
89- #elseif canImport(AppKit)
90- XCTAssertEqual ( $0 [ safe: 0 ] ? . stringValue, " Secure Field 0 " )
91- XCTAssertEqual ( $0 [ safe: 1 ] ? . stringValue, " Secure Field 1 " )
92- XCTAssertEqual ( $0 [ safe: 2 ] ? . stringValue, " Secure Field 2 " )
93- #endif
9476 }
77+ #if canImport(UIKit)
78+ #expect( entity1. text == " Secure Field 1 " )
79+ #expect( entity2. text == " Secure Field 2 " )
80+ #expect( entity3. text == " Secure Field 3 " )
81+ #elseif canImport(AppKit)
82+ #expect( entity1. stringValue == " Secure Field 1 " )
83+ #expect( entity2. stringValue == " Secure Field 2 " )
84+ #expect( entity3. stringValue == " Secure Field 3 " )
85+ #endif
9586 }
9687}
0 commit comments