33// found in the LICENSE file.
44
55import Flutter
6- import XCTest
6+ import Testing
77
88@ testable import file_selector_ios
99
@@ -25,8 +25,8 @@ final class StubViewPresenterProvider: ViewPresenterProvider {
2525 }
2626}
2727
28- class FileSelectorTests : XCTestCase {
29- func testPickerPresents ( ) throws {
28+ @ Suite @ MainActor struct FileSelectorTests {
29+ @ Test func pickerPresents ( ) throws {
3030 let presenter = TestViewPresenter ( )
3131 let plugin = FileSelectorPlugin (
3232 viewPresenterProvider : StubViewPresenterProvider ( viewPresenter : presenter ) )
@@ -37,58 +37,58 @@ class FileSelectorTests: XCTestCase {
3737 config : FileSelectorConfig ( utis : [ ] , allowMultiSelection : false )
3838 ) { _ in }
3939
40- XCTAssertEqual ( plugin . pendingCompletions . count , 1 )
41- XCTAssertTrue ( picker . delegate === plugin . pendingCompletions . first )
42- XCTAssertTrue ( presenter . presentedController === picker )
40+ # expect ( plugin . pendingCompletions . count == 1 )
41+ # expect ( picker . delegate === plugin . pendingCompletions . first )
42+ # expect ( presenter . presentedController === picker )
4343 }
4444
45- func testReturnsPickedFiles ( ) throws {
45+ @ Test func returnsPickedFiles ( ) async throws {
4646 let plugin = FileSelectorPlugin (
4747 viewPresenterProvider : StubViewPresenterProvider ( viewPresenter : TestViewPresenter ( ) ) )
4848 let picker = UIDocumentPickerViewController ( documentTypes : [ ] , in : UIDocumentPickerMode . import )
4949 plugin . documentPickerViewControllerOverride = picker
50- let completionWasCalled = expectation ( description : " completion " )
5150
52- plugin . openFile (
53- config : FileSelectorConfig ( utis : [ ] , allowMultiSelection : false )
54- ) { result in
55- switch result {
56- case . success ( let paths ) :
57- XCTAssertEqual ( paths , [ " /file1.txt " , " /file2.txt " ] )
58- case . failure ( let error ) :
59- XCTFail ( " \( error ) " )
51+ try await confirmation ( " completion " ) { completionWasCalled in
52+ plugin . openFile (
53+ config : FileSelectorConfig ( utis : [ ] , allowMultiSelection : false )
54+ ) { result in
55+ switch result {
56+ case . success ( let paths ) :
57+ #expect ( paths == [ " /file1.txt " , " /file2.txt " ] )
58+ case . failure ( let error ) :
59+ Issue . record ( " \( error ) " )
60+ }
61+ completionWasCalled ( )
6062 }
61- completionWasCalled . fulfill ( )
63+ let pendingCompletion = try #require ( plugin . pendingCompletions . first )
64+ pendingCompletion . documentPicker (
65+ picker ,
66+ didPickDocumentsAt : [ URL ( string : " file:///file1.txt " ) ! , URL ( string : " file:///file2.txt " ) ! ] )
6267 }
63- plugin . pendingCompletions . first ! . documentPicker (
64- picker ,
65- didPickDocumentsAt : [ URL ( string : " file:///file1.txt " ) ! , URL ( string : " file:///file2.txt " ) ! ] )
66-
67- waitForExpectations ( timeout : 30.0 )
68- XCTAssertTrue ( plugin . pendingCompletions . isEmpty )
68+ #expect ( plugin . pendingCompletions . isEmpty )
6969 }
7070
71- func testCancellingPickerReturnsEmptyList ( ) throws {
71+ @ Test func cancellingPickerReturnsEmptyList ( ) async throws {
7272 let plugin = FileSelectorPlugin (
7373 viewPresenterProvider : StubViewPresenterProvider ( viewPresenter : TestViewPresenter ( ) ) )
7474 let picker = UIDocumentPickerViewController ( documentTypes : [ ] , in : UIDocumentPickerMode . import )
7575 plugin . documentPickerViewControllerOverride = picker
76- let completionWasCalled = expectation ( description : " completion " )
7776
78- plugin . openFile (
79- config : FileSelectorConfig ( utis : [ ] , allowMultiSelection : false )
80- ) { result in
81- switch result {
82- case . success ( let paths ) :
83- XCTAssertEqual ( paths . count , 0 )
84- case . failure ( let error ) :
85- XCTFail ( " \( error ) " )
77+ try await confirmation ( " completion " ) { completionWasCalled in
78+ plugin . openFile (
79+ config : FileSelectorConfig ( utis : [ ] , allowMultiSelection : false )
80+ ) { result in
81+ switch result {
82+ case . success ( let paths ) :
83+ #expect ( paths . count == 0 )
84+ case . failure ( let error ) :
85+ Issue . record ( " \( error ) " )
86+ }
87+ completionWasCalled ( )
8688 }
87- completionWasCalled . fulfill ( )
89+ let pendingCompletion = try #require ( plugin . pendingCompletions . first )
90+ pendingCompletion . documentPickerWasCancelled ( picker )
8891 }
89- plugin . pendingCompletions . first ! . documentPickerWasCancelled ( picker )
90-
91- waitForExpectations ( timeout : 30.0 )
92- XCTAssertTrue ( plugin . pendingCompletions . isEmpty )
92+ #expect ( plugin . pendingCompletions . isEmpty )
9393 }
9494}
0 commit comments