7
7
@import image_picker;
8
8
@import XCTest;
9
9
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
+
10
23
@interface FLTImagePickerPlugin (Test)
11
24
@property (copy , nonatomic ) FlutterResult result;
12
25
- (void )handleSavedPath : (NSString *)path ;
@@ -23,8 +36,7 @@ - (void)testPluginPickImageDeviceBack {
23
36
if (![UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
24
37
return ;
25
38
}
26
- FLTImagePickerPlugin *plugin =
27
- [[FLTImagePickerPlugin alloc ] initWithViewController: [UIViewController new ]];
39
+ FLTImagePickerPlugin *plugin = [FLTImagePickerPlugin new ];
28
40
FlutterMethodCall *call =
29
41
[FlutterMethodCall methodCallWithMethodName: @" pickImage"
30
42
arguments: @{@" source" : @(0 ), @" cameraDevice" : @(0 )}];
@@ -39,8 +51,7 @@ - (void)testPluginPickImageDeviceFront {
39
51
if (![UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
40
52
return ;
41
53
}
42
- FLTImagePickerPlugin *plugin =
43
- [[FLTImagePickerPlugin alloc ] initWithViewController: [UIViewController new ]];
54
+ FLTImagePickerPlugin *plugin = [FLTImagePickerPlugin new ];
44
55
FlutterMethodCall *call =
45
56
[FlutterMethodCall methodCallWithMethodName: @" pickImage"
46
57
arguments: @{@" source" : @(0 ), @" cameraDevice" : @(1 )}];
@@ -55,8 +66,7 @@ - (void)testPluginPickVideoDeviceBack {
55
66
if (![UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
56
67
return ;
57
68
}
58
- FLTImagePickerPlugin *plugin =
59
- [[FLTImagePickerPlugin alloc ] initWithViewController: [UIViewController new ]];
69
+ FLTImagePickerPlugin *plugin = [FLTImagePickerPlugin new ];
60
70
FlutterMethodCall *call =
61
71
[FlutterMethodCall methodCallWithMethodName: @" pickVideo"
62
72
arguments: @{@" source" : @(0 ), @" cameraDevice" : @(0 )}];
@@ -71,8 +81,7 @@ - (void)testPluginPickImageDeviceCancelClickMultipleTimes {
71
81
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
72
82
return ;
73
83
}
74
- FLTImagePickerPlugin *plugin =
75
- [[FLTImagePickerPlugin alloc ] initWithViewController: [UIViewController new ]];
84
+ FLTImagePickerPlugin *plugin = [FLTImagePickerPlugin new ];
76
85
FlutterMethodCall *call =
77
86
[FlutterMethodCall methodCallWithMethodName: @" pickImage"
78
87
arguments: @{@" source" : @(0 ), @" cameraDevice" : @(1 )}];
@@ -90,8 +99,7 @@ - (void)testPluginPickVideoDeviceFront {
90
99
if (![UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
91
100
return ;
92
101
}
93
- FLTImagePickerPlugin *plugin =
94
- [[FLTImagePickerPlugin alloc ] initWithViewController: [UIViewController new ]];
102
+ FLTImagePickerPlugin *plugin = [FLTImagePickerPlugin new ];
95
103
FlutterMethodCall *call =
96
104
[FlutterMethodCall methodCallWithMethodName: @" pickVideo"
97
105
arguments: @{@" source" : @(0 ), @" cameraDevice" : @(1 )}];
@@ -104,8 +112,7 @@ - (void)testPluginPickVideoDeviceFront {
104
112
105
113
#pragma mark - Test video duration
106
114
- (void )testPickingVideoWithDuration {
107
- FLTImagePickerPlugin *plugin =
108
- [[FLTImagePickerPlugin alloc ] initWithViewController: [UIViewController new ]];
115
+ FLTImagePickerPlugin *plugin = [FLTImagePickerPlugin new ];
109
116
FlutterMethodCall *call = [FlutterMethodCall
110
117
methodCallWithMethodName: @" pickVideo"
111
118
arguments: @{@" source" : @(0 ), @" cameraDevice" : @(0 ), @" maxDuration" : @95 }];
@@ -116,8 +123,7 @@ - (void)testPickingVideoWithDuration {
116
123
}
117
124
118
125
- (void )testPluginPickImageSelectMultipleTimes {
119
- FLTImagePickerPlugin *plugin =
120
- [[FLTImagePickerPlugin alloc ] initWithViewController: [UIViewController new ]];
126
+ FLTImagePickerPlugin *plugin = [FLTImagePickerPlugin new ];
121
127
FlutterMethodCall *call =
122
128
[FlutterMethodCall methodCallWithMethodName: @" pickImage"
123
129
arguments: @{@" source" : @(0 ), @" cameraDevice" : @(0 )}];
@@ -131,4 +137,16 @@ - (void)testPluginPickImageSelectMultipleTimes {
131
137
[plugin handleSavedPath: @" test" ];
132
138
}
133
139
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
+
134
152
@end
0 commit comments