@@ -15,57 +15,73 @@ class QuickActionsPluginTests: XCTestCase {
1515 " localizedTitle " : " Search the thing " ,
1616 " icon " : " search_the_thing.png " ,
1717 ]
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+
1825 let call = FlutterMethodCall ( methodName: " setShortcutItems " , arguments: [ rawItem] )
1926
2027 let mockChannel = MockMethodChannel ( )
21- let mockShortcutStateManager = MockShortcutStateManager ( )
28+ let mockAppShortcutController = MockAppShortcutController ( )
29+ let mockShortcutItemParser = MockShortcutItemParser ( )
30+
2231 let plugin = QuickActionsPlugin (
23- channel: mockChannel, shortcutStateManager: mockShortcutStateManager)
32+ channel: mockChannel,
33+ appShortcutController: mockAppShortcutController,
34+ shortcutItemParser: mockShortcutItemParser)
2435
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
2739 XCTAssertEqual ( items as? [ [ String : String ] ] , [ rawItem] )
28- setShortcutItemsExpectation. fulfill ( )
40+ parseShortcutItemsExpectation. fulfill ( )
41+ return [ item]
2942 }
3043
3144 let resultExpectation = expectation ( description: " result block must be called. " )
3245 plugin. handle ( call) { result in
3346 XCTAssertNil ( result, " result block must be called with nil. " )
3447 resultExpectation. fulfill ( )
3548 }
36-
49+ XCTAssertEqual ( mockAppShortcutController . shortcutItems , [ item ] , " Must set shortcut items. " )
3750 waitForExpectations ( timeout: 1 )
3851 }
3952
4053 func testHandleMethodCall_clearShortcutItems( ) {
4154 let call = FlutterMethodCall ( methodName: " clearShortcutItems " , arguments: nil )
4255 let mockChannel = MockMethodChannel ( )
43- let mockShortcutStateManager = MockShortcutStateManager ( )
44- let plugin = QuickActionsPlugin (
45- channel: mockChannel, shortcutStateManager: mockShortcutStateManager)
56+ let mockAppShortcutController = MockAppShortcutController ( )
57+ let mockShortcutItemParser = MockShortcutItemParser ( )
4658
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)
5263
5364 let resultExpectation = expectation ( description: " result block must be called. " )
5465 plugin. handle ( call) { result in
5566 XCTAssertNil ( result, " result block must be called with nil. " )
5667 resultExpectation. fulfill ( )
5768 }
5869
70+ XCTAssertEqual ( mockAppShortcutController. shortcutItems, [ ] , " Must clear shortcut items. " )
5971 waitForExpectations ( timeout: 1 )
6072 }
6173
6274 func testHandleMethodCall_getLaunchAction( ) {
6375 let call = FlutterMethodCall ( methodName: " getLaunchAction " , arguments: nil )
6476
6577 let mockChannel = MockMethodChannel ( )
66- let mockShortcutStateManager = MockShortcutStateManager ( )
78+ let mockAppShortcutController = MockAppShortcutController ( )
79+ let mockShortcutItemParser = MockShortcutItemParser ( )
80+
6781 let plugin = QuickActionsPlugin (
68- channel: mockChannel, shortcutStateManager: mockShortcutStateManager)
82+ channel: mockChannel,
83+ appShortcutController: mockAppShortcutController,
84+ shortcutItemParser: mockShortcutItemParser)
6985
7086 let resultExpectation = expectation ( description: " result block must be called. " )
7187 plugin. handle ( call) { result in
@@ -80,9 +96,13 @@ class QuickActionsPluginTests: XCTestCase {
8096 let call = FlutterMethodCall ( methodName: " nonExist " , arguments: nil )
8197
8298 let mockChannel = MockMethodChannel ( )
83- let mockShortcutStateManager = MockShortcutStateManager ( )
99+ let mockAppShortcutController = MockAppShortcutController ( )
100+ let mockShortcutItemParser = MockShortcutItemParser ( )
101+
84102 let plugin = QuickActionsPlugin (
85- channel: mockChannel, shortcutStateManager: mockShortcutStateManager)
103+ channel: mockChannel,
104+ appShortcutController: mockAppShortcutController,
105+ shortcutItemParser: mockShortcutItemParser)
86106
87107 let resultExpectation = expectation ( description: " result block must be called. " )
88108
@@ -98,9 +118,13 @@ class QuickActionsPluginTests: XCTestCase {
98118
99119 func testApplicationPerformActionForShortcutItem( ) {
100120 let mockChannel = MockMethodChannel ( )
101- let mockShortcutStateManager = MockShortcutStateManager ( )
121+ let mockAppShortcutController = MockAppShortcutController ( )
122+ let mockShortcutItemParser = MockShortcutItemParser ( )
123+
102124 let plugin = QuickActionsPlugin (
103- channel: mockChannel, shortcutStateManager: mockShortcutStateManager)
125+ channel: mockChannel,
126+ appShortcutController: mockAppShortcutController,
127+ shortcutItemParser: mockShortcutItemParser)
104128
105129 let item = UIApplicationShortcutItem (
106130 type: " SearchTheThing " ,
@@ -128,9 +152,13 @@ class QuickActionsPluginTests: XCTestCase {
128152
129153 func testApplicationDidFinishLaunchingWithOptions_launchWithShortcut( ) {
130154 let mockChannel = MockMethodChannel ( )
131- let mockShortcutStateManager = MockShortcutStateManager ( )
155+ let mockAppShortcutController = MockAppShortcutController ( )
156+ let mockShortcutItemParser = MockShortcutItemParser ( )
157+
132158 let plugin = QuickActionsPlugin (
133- channel: mockChannel, shortcutStateManager: mockShortcutStateManager)
159+ channel: mockChannel,
160+ appShortcutController: mockAppShortcutController,
161+ shortcutItemParser: mockShortcutItemParser)
134162
135163 let item = UIApplicationShortcutItem (
136164 type: " SearchTheThing " ,
@@ -149,9 +177,13 @@ class QuickActionsPluginTests: XCTestCase {
149177
150178 func testApplicationDidFinishLaunchingWithOptions_launchWithoutShortcut( ) {
151179 let mockChannel = MockMethodChannel ( )
152- let mockShortcutStateManager = MockShortcutStateManager ( )
180+ let mockAppShortcutController = MockAppShortcutController ( )
181+ let mockShortcutItemParser = MockShortcutItemParser ( )
182+
153183 let plugin = QuickActionsPlugin (
154- channel: mockChannel, shortcutStateManager: mockShortcutStateManager)
184+ channel: mockChannel,
185+ appShortcutController: mockAppShortcutController,
186+ shortcutItemParser: mockShortcutItemParser)
155187
156188 let launchResult = plugin. application ( UIApplication . shared, didFinishLaunchingWithOptions: [ : ] )
157189 XCTAssert (
@@ -161,9 +193,13 @@ class QuickActionsPluginTests: XCTestCase {
161193
162194 func testApplicationDidBecomeActive_launchWithoutShortcut( ) {
163195 let mockChannel = MockMethodChannel ( )
164- let mockShortcutStateManager = MockShortcutStateManager ( )
196+ let mockAppShortcutController = MockAppShortcutController ( )
197+ let mockShortcutItemParser = MockShortcutItemParser ( )
198+
165199 let plugin = QuickActionsPlugin (
166- channel: mockChannel, shortcutStateManager: mockShortcutStateManager)
200+ channel: mockChannel,
201+ appShortcutController: mockAppShortcutController,
202+ shortcutItemParser: mockShortcutItemParser)
167203
168204 mockChannel. invokeMethodStub = { _, _ in
169205 XCTFail ( " invokeMethod should not be called if launch without shortcut. " )
@@ -186,9 +222,13 @@ class QuickActionsPluginTests: XCTestCase {
186222 userInfo: nil )
187223
188224 let mockChannel = MockMethodChannel ( )
189- let mockShortcutStateManager = MockShortcutStateManager ( )
225+ let mockAppShortcutController = MockAppShortcutController ( )
226+ let mockShortcutItemParser = MockShortcutItemParser ( )
227+
190228 let plugin = QuickActionsPlugin (
191- channel: mockChannel, shortcutStateManager: mockShortcutStateManager)
229+ channel: mockChannel,
230+ appShortcutController: mockAppShortcutController,
231+ shortcutItemParser: mockShortcutItemParser)
192232
193233 let invokeMethodExpectation = expectation ( description: " invokeMethod must be called. " )
194234 mockChannel. invokeMethodStub = { method, arguments in
@@ -217,9 +257,13 @@ class QuickActionsPluginTests: XCTestCase {
217257 userInfo: nil )
218258
219259 let mockChannel = MockMethodChannel ( )
220- let mockShortcutStateManager = MockShortcutStateManager ( )
260+ let mockAppShortcutController = MockAppShortcutController ( )
261+ let mockShortcutItemParser = MockShortcutItemParser ( )
262+
221263 let plugin = QuickActionsPlugin (
222- channel: mockChannel, shortcutStateManager: mockShortcutStateManager)
264+ channel: mockChannel,
265+ appShortcutController: mockAppShortcutController,
266+ shortcutItemParser: mockShortcutItemParser)
223267
224268 let invokeMethodExpectation = expectation ( description: " invokeMethod must be called. " )
225269
0 commit comments