22import AVKit
33import SwiftUI
44import SwiftUIIntrospect
5- import XCTest
5+ import Testing
66
7- @available ( iOS 14 , tvOS 14 , macOS 11 , * )
87@MainActor
9- final class VideoPlayerTests : XCTestCase {
8+ @Suite
9+ struct VideoPlayerTests {
1010 #if canImport(UIKit)
1111 typealias PlatformVideoPlayer = AVPlayerViewController
1212 #elseif canImport(AppKit)
1313 typealias PlatformVideoPlayer = AVPlayerView
1414 #endif
1515
16- func testVideoPlayer( ) throws {
17- guard #available( iOS 14 , tvOS 14 , macOS 11 , * ) else {
18- throw XCTSkip ( )
19- }
20-
21- let videoURL0 = URL ( string: " https://bit.ly/swswift#1 " ) !
22- let videoURL1 = URL ( string: " https://bit.ly/swswift#2 " ) !
23- let videoURL2 = URL ( string: " https://bit.ly/swswift#3 " ) !
24-
25- XCTAssertViewIntrospection ( of: PlatformVideoPlayer . self) { spies in
26- let spy0 = spies [ 0 ]
27- let spy1 = spies [ 1 ]
28- let spy2 = spies [ 2 ]
16+ @Test func introspect( ) async throws {
17+ let videoURL1 = URL ( string: " https://bit.ly/swswift#1 " ) !
18+ let videoURL2 = URL ( string: " https://bit.ly/swswift#2 " ) !
19+ let videoURL3 = URL ( string: " https://bit.ly/swswift#3 " ) !
2920
21+ let ( entity1, entity2, entity3) = try await introspection ( of: PlatformVideoPlayer . self) { spy1, spy2, spy3 in
3022 VStack {
31- VideoPlayer ( player: AVPlayer ( url: videoURL0) )
32- #if os(iOS) || os(tvOS) || os(visionOS)
33- . introspect( . videoPlayer, on: . iOS( . v14, . v15, . v16, . v17, . v18, . v26) , . tvOS( . v14, . v15, . v16, . v17, . v18, . v26) , . visionOS( . v1, . v2, . v26) , customize: spy0)
34- #elseif os(macOS)
35- . introspect( . videoPlayer, on: . macOS( . v11, . v12, . v13, . v14, . v15, . v26) , customize: spy0)
36- #endif
37-
3823 VideoPlayer ( player: AVPlayer ( url: videoURL1) )
3924 #if os(iOS) || os(tvOS) || os(visionOS)
4025 . introspect( . videoPlayer, on: . iOS( . v14, . v15, . v16, . v17, . v18, . v26) , . tvOS( . v14, . v15, . v16, . v17, . v18, . v26) , . visionOS( . v1, . v2, . v26) , customize: spy1)
@@ -48,12 +33,18 @@ final class VideoPlayerTests: XCTestCase {
4833 #elseif os(macOS)
4934 . introspect( . videoPlayer, on: . macOS( . v11, . v12, . v13, . v14, . v15, . v26) , customize: spy2)
5035 #endif
36+
37+ VideoPlayer ( player: AVPlayer ( url: videoURL3) )
38+ #if os(iOS) || os(tvOS) || os(visionOS)
39+ . introspect( . videoPlayer, on: . iOS( . v14, . v15, . v16, . v17, . v18, . v26) , . tvOS( . v14, . v15, . v16, . v17, . v18, . v26) , . visionOS( . v1, . v2, . v26) , customize: spy3)
40+ #elseif os(macOS)
41+ . introspect( . videoPlayer, on: . macOS( . v11, . v12, . v13, . v14, . v15, . v26) , customize: spy3)
42+ #endif
5143 }
52- } extraAssertions: {
53- XCTAssertEqual ( ( $0 [ safe: 0 ] ? . player? . currentItem? . asset as? AVURLAsset ) ? . url, videoURL0)
54- XCTAssertEqual ( ( $0 [ safe: 1 ] ? . player? . currentItem? . asset as? AVURLAsset ) ? . url, videoURL1)
55- XCTAssertEqual ( ( $0 [ safe: 2 ] ? . player? . currentItem? . asset as? AVURLAsset ) ? . url, videoURL2)
5644 }
45+ #expect( ( entity1. player? . currentItem? . asset as? AVURLAsset ) ? . url == videoURL1)
46+ #expect( ( entity2. player? . currentItem? . asset as? AVURLAsset ) ? . url == videoURL2)
47+ #expect( ( entity3. player? . currentItem? . asset as? AVURLAsset ) ? . url == videoURL3)
5748 }
5849}
5950#endif
0 commit comments