@@ -15,57 +15,73 @@ class QuickActionsPluginTests: XCTestCase {
15
15
" localizedTitle " : " Search the thing " ,
16
16
" icon " : " search_the_thing.png " ,
17
17
]
18
+ let item = UIApplicationShortcutItem (
19
+ type: " SearchTheThing " ,
20
+ localizedTitle: " Search the thing " ,
21
+ localizedSubtitle: nil ,
22
+ icon: UIApplicationShortcutIcon ( templateImageName: " search_the_thing.png " ) ,
23
+ userInfo: nil )
24
+
18
25
let call = FlutterMethodCall ( methodName: " setShortcutItems " , arguments: [ rawItem] )
19
26
20
27
let mockChannel = MockMethodChannel ( )
21
- let mockShortcutStateManager = MockShortcutStateManager ( )
28
+ let mockAppShortcutController = MockAppShortcutController ( )
29
+ let mockShortcutItemParser = MockShortcutItemParser ( )
30
+
22
31
let plugin = QuickActionsPlugin (
23
- channel: mockChannel, shortcutStateManager: mockShortcutStateManager)
32
+ channel: mockChannel,
33
+ appShortcutController: mockAppShortcutController,
34
+ shortcutItemParser: mockShortcutItemParser)
24
35
25
- let setShortcutItemsExpectation = expectation ( description: " setShortcutItems must be called. " )
26
- mockShortcutStateManager. setShortcutItemsStub = { items in
36
+ let parseShortcutItemsExpectation = expectation (
37
+ description: " parseShortcutItems must be called. " )
38
+ mockShortcutItemParser. parseShortcutItemsStub = { items in
27
39
XCTAssertEqual ( items as? [ [ String : String ] ] , [ rawItem] )
28
- setShortcutItemsExpectation. fulfill ( )
40
+ parseShortcutItemsExpectation. fulfill ( )
41
+ return [ item]
29
42
}
30
43
31
44
let resultExpectation = expectation ( description: " result block must be called. " )
32
45
plugin. handle ( call) { result in
33
46
XCTAssertNil ( result, " result block must be called with nil. " )
34
47
resultExpectation. fulfill ( )
35
48
}
36
-
49
+ XCTAssertEqual ( mockAppShortcutController . shortcutItems , [ item ] , " Must set shortcut items. " )
37
50
waitForExpectations ( timeout: 1 )
38
51
}
39
52
40
53
func testHandleMethodCall_clearShortcutItems( ) {
41
54
let call = FlutterMethodCall ( methodName: " clearShortcutItems " , arguments: nil )
42
55
let mockChannel = MockMethodChannel ( )
43
- let mockShortcutStateManager = MockShortcutStateManager ( )
44
- let plugin = QuickActionsPlugin (
45
- channel: mockChannel, shortcutStateManager: mockShortcutStateManager)
56
+ let mockAppShortcutController = MockAppShortcutController ( )
57
+ let mockShortcutItemParser = MockShortcutItemParser ( )
46
58
47
- let setShortcutItemsExpectation = expectation ( description: " setShortcutItems must be called. " )
48
- mockShortcutStateManager. setShortcutItemsStub = { items in
49
- XCTAssert ( items. isEmpty)
50
- setShortcutItemsExpectation. fulfill ( )
51
- }
59
+ let plugin = QuickActionsPlugin (
60
+ channel: mockChannel,
61
+ appShortcutController: mockAppShortcutController,
62
+ shortcutItemParser: mockShortcutItemParser)
52
63
53
64
let resultExpectation = expectation ( description: " result block must be called. " )
54
65
plugin. handle ( call) { result in
55
66
XCTAssertNil ( result, " result block must be called with nil. " )
56
67
resultExpectation. fulfill ( )
57
68
}
58
69
70
+ XCTAssertEqual ( mockAppShortcutController. shortcutItems, [ ] , " Must clear shortcut items. " )
59
71
waitForExpectations ( timeout: 1 )
60
72
}
61
73
62
74
func testHandleMethodCall_getLaunchAction( ) {
63
75
let call = FlutterMethodCall ( methodName: " getLaunchAction " , arguments: nil )
64
76
65
77
let mockChannel = MockMethodChannel ( )
66
- let mockShortcutStateManager = MockShortcutStateManager ( )
78
+ let mockAppShortcutController = MockAppShortcutController ( )
79
+ let mockShortcutItemParser = MockShortcutItemParser ( )
80
+
67
81
let plugin = QuickActionsPlugin (
68
- channel: mockChannel, shortcutStateManager: mockShortcutStateManager)
82
+ channel: mockChannel,
83
+ appShortcutController: mockAppShortcutController,
84
+ shortcutItemParser: mockShortcutItemParser)
69
85
70
86
let resultExpectation = expectation ( description: " result block must be called. " )
71
87
plugin. handle ( call) { result in
@@ -80,9 +96,13 @@ class QuickActionsPluginTests: XCTestCase {
80
96
let call = FlutterMethodCall ( methodName: " nonExist " , arguments: nil )
81
97
82
98
let mockChannel = MockMethodChannel ( )
83
- let mockShortcutStateManager = MockShortcutStateManager ( )
99
+ let mockAppShortcutController = MockAppShortcutController ( )
100
+ let mockShortcutItemParser = MockShortcutItemParser ( )
101
+
84
102
let plugin = QuickActionsPlugin (
85
- channel: mockChannel, shortcutStateManager: mockShortcutStateManager)
103
+ channel: mockChannel,
104
+ appShortcutController: mockAppShortcutController,
105
+ shortcutItemParser: mockShortcutItemParser)
86
106
87
107
let resultExpectation = expectation ( description: " result block must be called. " )
88
108
@@ -98,9 +118,13 @@ class QuickActionsPluginTests: XCTestCase {
98
118
99
119
func testApplicationPerformActionForShortcutItem( ) {
100
120
let mockChannel = MockMethodChannel ( )
101
- let mockShortcutStateManager = MockShortcutStateManager ( )
121
+ let mockAppShortcutController = MockAppShortcutController ( )
122
+ let mockShortcutItemParser = MockShortcutItemParser ( )
123
+
102
124
let plugin = QuickActionsPlugin (
103
- channel: mockChannel, shortcutStateManager: mockShortcutStateManager)
125
+ channel: mockChannel,
126
+ appShortcutController: mockAppShortcutController,
127
+ shortcutItemParser: mockShortcutItemParser)
104
128
105
129
let item = UIApplicationShortcutItem (
106
130
type: " SearchTheThing " ,
@@ -128,9 +152,13 @@ class QuickActionsPluginTests: XCTestCase {
128
152
129
153
func testApplicationDidFinishLaunchingWithOptions_launchWithShortcut( ) {
130
154
let mockChannel = MockMethodChannel ( )
131
- let mockShortcutStateManager = MockShortcutStateManager ( )
155
+ let mockAppShortcutController = MockAppShortcutController ( )
156
+ let mockShortcutItemParser = MockShortcutItemParser ( )
157
+
132
158
let plugin = QuickActionsPlugin (
133
- channel: mockChannel, shortcutStateManager: mockShortcutStateManager)
159
+ channel: mockChannel,
160
+ appShortcutController: mockAppShortcutController,
161
+ shortcutItemParser: mockShortcutItemParser)
134
162
135
163
let item = UIApplicationShortcutItem (
136
164
type: " SearchTheThing " ,
@@ -149,9 +177,13 @@ class QuickActionsPluginTests: XCTestCase {
149
177
150
178
func testApplicationDidFinishLaunchingWithOptions_launchWithoutShortcut( ) {
151
179
let mockChannel = MockMethodChannel ( )
152
- let mockShortcutStateManager = MockShortcutStateManager ( )
180
+ let mockAppShortcutController = MockAppShortcutController ( )
181
+ let mockShortcutItemParser = MockShortcutItemParser ( )
182
+
153
183
let plugin = QuickActionsPlugin (
154
- channel: mockChannel, shortcutStateManager: mockShortcutStateManager)
184
+ channel: mockChannel,
185
+ appShortcutController: mockAppShortcutController,
186
+ shortcutItemParser: mockShortcutItemParser)
155
187
156
188
let launchResult = plugin. application ( UIApplication . shared, didFinishLaunchingWithOptions: [ : ] )
157
189
XCTAssert (
@@ -161,9 +193,13 @@ class QuickActionsPluginTests: XCTestCase {
161
193
162
194
func testApplicationDidBecomeActive_launchWithoutShortcut( ) {
163
195
let mockChannel = MockMethodChannel ( )
164
- let mockShortcutStateManager = MockShortcutStateManager ( )
196
+ let mockAppShortcutController = MockAppShortcutController ( )
197
+ let mockShortcutItemParser = MockShortcutItemParser ( )
198
+
165
199
let plugin = QuickActionsPlugin (
166
- channel: mockChannel, shortcutStateManager: mockShortcutStateManager)
200
+ channel: mockChannel,
201
+ appShortcutController: mockAppShortcutController,
202
+ shortcutItemParser: mockShortcutItemParser)
167
203
168
204
mockChannel. invokeMethodStub = { _, _ in
169
205
XCTFail ( " invokeMethod should not be called if launch without shortcut. " )
@@ -186,9 +222,13 @@ class QuickActionsPluginTests: XCTestCase {
186
222
userInfo: nil )
187
223
188
224
let mockChannel = MockMethodChannel ( )
189
- let mockShortcutStateManager = MockShortcutStateManager ( )
225
+ let mockAppShortcutController = MockAppShortcutController ( )
226
+ let mockShortcutItemParser = MockShortcutItemParser ( )
227
+
190
228
let plugin = QuickActionsPlugin (
191
- channel: mockChannel, shortcutStateManager: mockShortcutStateManager)
229
+ channel: mockChannel,
230
+ appShortcutController: mockAppShortcutController,
231
+ shortcutItemParser: mockShortcutItemParser)
192
232
193
233
let invokeMethodExpectation = expectation ( description: " invokeMethod must be called. " )
194
234
mockChannel. invokeMethodStub = { method, arguments in
@@ -217,9 +257,13 @@ class QuickActionsPluginTests: XCTestCase {
217
257
userInfo: nil )
218
258
219
259
let mockChannel = MockMethodChannel ( )
220
- let mockShortcutStateManager = MockShortcutStateManager ( )
260
+ let mockAppShortcutController = MockAppShortcutController ( )
261
+ let mockShortcutItemParser = MockShortcutItemParser ( )
262
+
221
263
let plugin = QuickActionsPlugin (
222
- channel: mockChannel, shortcutStateManager: mockShortcutStateManager)
264
+ channel: mockChannel,
265
+ appShortcutController: mockAppShortcutController,
266
+ shortcutItemParser: mockShortcutItemParser)
223
267
224
268
let invokeMethodExpectation = expectation ( description: " invokeMethod must be called. " )
225
269
0 commit comments