77@import image_picker;
88@import XCTest;
99
10+ @interface MockViewController : UIViewController
11+ @property (nonatomic , retain ) UIViewController *mockPresented;
12+ @end
13+
14+ @implementation MockViewController
15+ @synthesize mockPresented;
16+
17+ - (UIViewController *)presentedViewController {
18+ return mockPresented;
19+ }
20+
21+ @end
22+
1023@interface FLTImagePickerPlugin (Test)
1124@property (copy , nonatomic ) FlutterResult result;
1225- (void )handleSavedPath : (NSString *)path ;
@@ -23,8 +36,7 @@ - (void)testPluginPickImageDeviceBack {
2336 if (![UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
2437 return ;
2538 }
26- FLTImagePickerPlugin *plugin =
27- [[FLTImagePickerPlugin alloc ] initWithViewController: [UIViewController new ]];
39+ FLTImagePickerPlugin *plugin = [FLTImagePickerPlugin new ];
2840 FlutterMethodCall *call =
2941 [FlutterMethodCall methodCallWithMethodName: @" pickImage"
3042 arguments: @{@" source" : @(0 ), @" cameraDevice" : @(0 )}];
@@ -39,8 +51,7 @@ - (void)testPluginPickImageDeviceFront {
3951 if (![UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
4052 return ;
4153 }
42- FLTImagePickerPlugin *plugin =
43- [[FLTImagePickerPlugin alloc ] initWithViewController: [UIViewController new ]];
54+ FLTImagePickerPlugin *plugin = [FLTImagePickerPlugin new ];
4455 FlutterMethodCall *call =
4556 [FlutterMethodCall methodCallWithMethodName: @" pickImage"
4657 arguments: @{@" source" : @(0 ), @" cameraDevice" : @(1 )}];
@@ -55,8 +66,7 @@ - (void)testPluginPickVideoDeviceBack {
5566 if (![UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
5667 return ;
5768 }
58- FLTImagePickerPlugin *plugin =
59- [[FLTImagePickerPlugin alloc ] initWithViewController: [UIViewController new ]];
69+ FLTImagePickerPlugin *plugin = [FLTImagePickerPlugin new ];
6070 FlutterMethodCall *call =
6171 [FlutterMethodCall methodCallWithMethodName: @" pickVideo"
6272 arguments: @{@" source" : @(0 ), @" cameraDevice" : @(0 )}];
@@ -71,8 +81,7 @@ - (void)testPluginPickImageDeviceCancelClickMultipleTimes {
7181 if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
7282 return ;
7383 }
74- FLTImagePickerPlugin *plugin =
75- [[FLTImagePickerPlugin alloc ] initWithViewController: [UIViewController new ]];
84+ FLTImagePickerPlugin *plugin = [FLTImagePickerPlugin new ];
7685 FlutterMethodCall *call =
7786 [FlutterMethodCall methodCallWithMethodName: @" pickImage"
7887 arguments: @{@" source" : @(0 ), @" cameraDevice" : @(1 )}];
@@ -90,8 +99,7 @@ - (void)testPluginPickVideoDeviceFront {
9099 if (![UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
91100 return ;
92101 }
93- FLTImagePickerPlugin *plugin =
94- [[FLTImagePickerPlugin alloc ] initWithViewController: [UIViewController new ]];
102+ FLTImagePickerPlugin *plugin = [FLTImagePickerPlugin new ];
95103 FlutterMethodCall *call =
96104 [FlutterMethodCall methodCallWithMethodName: @" pickVideo"
97105 arguments: @{@" source" : @(0 ), @" cameraDevice" : @(1 )}];
@@ -104,8 +112,7 @@ - (void)testPluginPickVideoDeviceFront {
104112
105113#pragma mark - Test video duration
106114- (void )testPickingVideoWithDuration {
107- FLTImagePickerPlugin *plugin =
108- [[FLTImagePickerPlugin alloc ] initWithViewController: [UIViewController new ]];
115+ FLTImagePickerPlugin *plugin = [FLTImagePickerPlugin new ];
109116 FlutterMethodCall *call = [FlutterMethodCall
110117 methodCallWithMethodName: @" pickVideo"
111118 arguments: @{@" source" : @(0 ), @" cameraDevice" : @(0 ), @" maxDuration" : @95 }];
@@ -116,8 +123,7 @@ - (void)testPickingVideoWithDuration {
116123}
117124
118125- (void )testPluginPickImageSelectMultipleTimes {
119- FLTImagePickerPlugin *plugin =
120- [[FLTImagePickerPlugin alloc ] initWithViewController: [UIViewController new ]];
126+ FLTImagePickerPlugin *plugin = [FLTImagePickerPlugin new ];
121127 FlutterMethodCall *call =
122128 [FlutterMethodCall methodCallWithMethodName: @" pickImage"
123129 arguments: @{@" source" : @(0 ), @" cameraDevice" : @(0 )}];
@@ -131,4 +137,16 @@ - (void)testPluginPickImageSelectMultipleTimes {
131137 [plugin handleSavedPath: @" test" ];
132138}
133139
140+ - (void )testViewController {
141+ UIWindow *window = [UIWindow new ];
142+ MockViewController *vc1 = [MockViewController new ];
143+ window.rootViewController = vc1;
144+
145+ UIViewController *vc2 = [UIViewController new ];
146+ vc1.mockPresented = vc2;
147+
148+ FLTImagePickerPlugin *plugin = [FLTImagePickerPlugin new ];
149+ XCTAssertEqual ([plugin viewControllerWithWindow: window], vc2);
150+ }
151+
134152@end
0 commit comments