summaryrefslogtreecommitdiff
path: root/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceOperationSpec.m
blob: 9fb4a78833db91aafd8a4c20c571aa156003028c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
//
//  SDLMenuReplaceOperationSpec.m
//  SmartDeviceLinkTests
//
//  Created by Joel Fischer on 2/16/21.
//  Copyright © 2021 smartdevicelink. All rights reserved.
//

#import <Nimble/Nimble.h>
#import <OCMock/OCMock.h>
#import <Quick/Quick.h>

#import <SmartDeviceLink/SmartDeviceLink.h>
#import "SDLMenuReplaceOperation.h"
#import "SDLMenuReplaceUtilities.h"
#import "TestConnectionManager.h"

@interface SDLMenuCell ()

@property (assign, nonatomic) UInt32 parentCellId;
@property (assign, nonatomic) UInt32 cellId;

@end

QuickSpecBegin(SDLMenuReplaceOperationSpec)

describe(@"a menu replace operation", ^{
    __block SDLMenuReplaceOperation *testOp = nil;

    __block TestConnectionManager *testConnectionManager = nil;
    __block SDLFileManager *testFileManager = nil;
    __block SDLWindowCapability *testWindowCapability = nil;
    __block SDLMenuConfiguration *testMenuConfiguration = nil;
    __block NSArray<SDLMenuCell *> *testCurrentMenu = nil;
    __block NSArray<SDLMenuCell *> *testNewMenu = nil;

    __block SDLArtwork *testArtwork = nil;
    __block SDLArtwork *testArtwork2 = nil;
    __block SDLArtwork *testArtwork3 = nil;

    __block SDLMenuCell *textOnlyCell = nil;
    __block SDLMenuCell *textOnlyCell2 = nil;
    __block SDLMenuCell *textAndImageCell = nil;
    __block SDLMenuCell *submenuCell = nil;
    __block SDLMenuCell *submenuImageCell = nil;

    __block SDLAddCommandResponse *addCommandSuccessResponse = nil;
    __block SDLAddSubMenuResponse *addSubMenuSuccessResponse = nil;
    __block SDLDeleteCommandResponse *deleteCommandSuccessResponse = nil;
    __block SDLDeleteSubMenuResponse *deleteSubMenuSuccessResponse = nil;

    __block NSArray<SDLMenuCell *> *resultMenuCells = nil;
    __block NSError *resultError = nil;
    __block SDLCurrentMenuUpdatedBlock testCurrentMenuUpdatedBlock = nil;

    __block SDLMenuReplaceUtilities *mockReplaceUtilities = nil;

    beforeEach(^{
        testArtwork = [[SDLArtwork alloc] initWithData:[@"Test data" dataUsingEncoding:NSUTF8StringEncoding] name:@"some artwork name" fileExtension:@"png" persistent:NO];
        testArtwork2 = [[SDLArtwork alloc] initWithData:[@"Test data 2" dataUsingEncoding:NSUTF8StringEncoding] name:@"some artwork name 2" fileExtension:@"png" persistent:NO];
        testArtwork3 = [[SDLArtwork alloc] initWithData:[@"Test data 3" dataUsingEncoding:NSUTF8StringEncoding] name:@"some artwork name" fileExtension:@"png" persistent:NO];
        testArtwork3.overwrite = YES;

        textOnlyCell = [[SDLMenuCell alloc] initWithTitle:@"Test 1" secondaryText:nil tertiaryText:nil icon:nil secondaryArtwork:nil voiceCommands:nil handler:^(SDLTriggerSource  _Nonnull triggerSource) {}];
        textOnlyCell2 = [[SDLMenuCell alloc] initWithTitle:@"Test 5" secondaryText:nil tertiaryText:nil icon:nil secondaryArtwork:nil voiceCommands:nil handler:^(SDLTriggerSource  _Nonnull triggerSource) {}];
        textAndImageCell = [[SDLMenuCell alloc] initWithTitle:@"Test 2" secondaryText:nil tertiaryText:nil icon:testArtwork secondaryArtwork:nil voiceCommands:nil handler:^(SDLTriggerSource  _Nonnull triggerSource) {}];
        submenuCell = [[SDLMenuCell alloc] initWithTitle:@"Test 3" secondaryText:nil tertiaryText:nil icon:nil secondaryArtwork:nil submenuLayout:nil subCells:@[textOnlyCell, textAndImageCell]];
        submenuImageCell = [[SDLMenuCell alloc] initWithTitle:@"Test 4" secondaryText:nil tertiaryText:nil icon:testArtwork2 secondaryArtwork:nil submenuLayout:SDLMenuLayoutTiles subCells:@[textOnlyCell]];

        addCommandSuccessResponse = [[SDLAddCommandResponse alloc] init];
        addCommandSuccessResponse.success = @YES;
        addCommandSuccessResponse.resultCode = SDLResultSuccess;
        addSubMenuSuccessResponse = [[SDLAddSubMenuResponse alloc] init];
        addSubMenuSuccessResponse.success = @YES;
        addSubMenuSuccessResponse.resultCode = SDLResultSuccess;
        deleteCommandSuccessResponse = [[SDLDeleteCommandResponse alloc] init];
        deleteCommandSuccessResponse.success = @YES;
        deleteCommandSuccessResponse.resultCode = SDLResultSuccess;
        deleteSubMenuSuccessResponse = [[SDLDeleteSubMenuResponse alloc] init];
        deleteSubMenuSuccessResponse.success = @YES;
        deleteSubMenuSuccessResponse.resultCode = SDLResultSuccess;

        testOp = nil;
        testConnectionManager = [[TestConnectionManager alloc] init];
        testFileManager = OCMClassMock([SDLFileManager class]);

        SDLImageField *commandImageField = [[SDLImageField alloc] initWithName:SDLImageFieldNameCommandIcon imageTypeSupported:@[SDLFileTypePNG] imageResolution:nil];
        SDLImageField *submenuImageField = [[SDLImageField alloc] initWithName:SDLImageFieldNameSubMenuIcon imageTypeSupported:@[SDLFileTypePNG] imageResolution:nil];
        testWindowCapability = [[SDLWindowCapability alloc] initWithWindowID:@0 textFields:nil imageFields:@[commandImageField, submenuImageField] imageTypeSupported:nil templatesAvailable:nil numCustomPresetsAvailable:nil buttonCapabilities:nil softButtonCapabilities:nil menuLayoutsAvailable:nil dynamicUpdateCapabilities:nil keyboardCapabilities:nil];
        testMenuConfiguration = [[SDLMenuConfiguration alloc] initWithMainMenuLayout:SDLMenuLayoutList defaultSubmenuLayout:SDLMenuLayoutList];
        testCurrentMenu = @[];
        testNewMenu = nil;

        resultMenuCells = nil;
        resultError = nil;
        testCurrentMenuUpdatedBlock = ^(NSArray<SDLMenuCell *> *currentMenuCells, NSError *error) {
            resultMenuCells = currentMenuCells;
            resultError = error;
        };

        mockReplaceUtilities = OCMClassMock([SDLMenuReplaceUtilities class]);
    });

    describe(@"sending initial batch of cells", ^{
        context(@"when setting no cells", ^{
            it(@"should finish without doing anything", ^{
                testOp = [[SDLMenuReplaceOperation alloc] initWithConnectionManager:testConnectionManager fileManager:testFileManager windowCapability:testWindowCapability menuConfiguration:testMenuConfiguration currentMenu:testCurrentMenu updatedMenu:testNewMenu compatibilityModeEnabled:YES currentMenuUpdatedHandler:testCurrentMenuUpdatedBlock];
                [testOp start];

                expect(testConnectionManager.receivedRequests).to(beEmpty());
                expect(testOp.isFinished).to(beTrue());
                expect(resultError).to(beNil());
                expect(resultMenuCells).to(beEmpty());
            });
        });

        context(@"when starting while cancelled", ^{
            it(@"should finish without doing anything", ^{
                testOp = [[SDLMenuReplaceOperation alloc] initWithConnectionManager:testConnectionManager fileManager:testFileManager windowCapability:testWindowCapability menuConfiguration:testMenuConfiguration currentMenu:testCurrentMenu updatedMenu:testNewMenu compatibilityModeEnabled:YES currentMenuUpdatedHandler:testCurrentMenuUpdatedBlock];
                [testOp cancel];
                [testOp start];

                expect(testConnectionManager.receivedRequests).to(beEmpty());
                expect(testOp.isFinished).to(beTrue());
                expect(resultError).to(beNil());
                expect(resultMenuCells).to(beNil());
            });
        });

        context(@"when uploading a text-only cell", ^{
            beforeEach(^{
                testNewMenu = @[textOnlyCell];
                OCMStub([testFileManager fileNeedsUpload:[OCMArg any]]).andReturn(NO);
            });

            it(@"should properly send the RPCs and finish the operation", ^{
                testOp = [[SDLMenuReplaceOperation alloc] initWithConnectionManager:testConnectionManager fileManager:testFileManager windowCapability:testWindowCapability menuConfiguration:testMenuConfiguration currentMenu:testCurrentMenu updatedMenu:testNewMenu compatibilityModeEnabled:YES currentMenuUpdatedHandler:testCurrentMenuUpdatedBlock];
                [testOp start];

                OCMReject([testFileManager uploadArtworks:[OCMArg any] progressHandler:[OCMArg any] completionHandler:[OCMArg any]]);

                NSPredicate *deleteCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass: %@", [SDLDeleteCommand class]];
                NSArray *deletes = [[testConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:deleteCommandPredicate];
                expect(deletes).to(beEmpty());

                NSPredicate *addCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass: %@", [SDLAddCommand class]];
                NSArray *add = [[testConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:addCommandPredicate];
                expect(add).to(haveCount(1));

                [testConnectionManager respondToLastRequestWithResponse:addCommandSuccessResponse];
                [testConnectionManager respondToLastMultipleRequestsWithSuccess:YES];

                expect(testOp.isFinished).to(beTrue());
                expect(resultError).to(beNil());
                expect(resultMenuCells).to(haveCount(1));
            });
        });

        context(@"when uploading text and image cell", ^{
            beforeEach(^{
                testNewMenu = @[textAndImageCell];

                OCMStub([testFileManager uploadArtworks:[OCMArg any] progressHandler:([OCMArg invokeBlockWithArgs:textAndImageCell.icon.name, @1.0, [NSNull null], nil]) completionHandler:([OCMArg invokeBlockWithArgs: @[textAndImageCell.icon.name], [NSNull null], nil])]);
            });

            // when the image is already on the head unit
            context(@"when the image is already on the head unit", ^{
                beforeEach(^{
                    OCMStub([testFileManager hasUploadedFile:[OCMArg isNotNil]]).andReturn(YES);
                    OCMStub([testFileManager fileNeedsUpload:[OCMArg isNotNil]]).andReturn(NO);
                });

                it(@"should properly update an image cell", ^{
                    OCMReject([testFileManager uploadArtworks:[OCMArg any] progressHandler:[OCMArg any] completionHandler:[OCMArg any]]);


                    testOp = [[SDLMenuReplaceOperation alloc] initWithConnectionManager:testConnectionManager fileManager:testFileManager windowCapability:testWindowCapability menuConfiguration:testMenuConfiguration currentMenu:testCurrentMenu updatedMenu:testNewMenu compatibilityModeEnabled:YES currentMenuUpdatedHandler:testCurrentMenuUpdatedBlock];
                    [testOp start];

                    NSPredicate *addCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass: %@", [SDLAddCommand class]];
                    NSArray *add = [[testConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:addCommandPredicate];
                    SDLAddCommand *sentCommand = add.firstObject;

                    expect(add).to(haveCount(1));
                    expect(sentCommand.cmdIcon.value).to(equal(testArtwork.name));

                    [testConnectionManager respondToLastRequestWithResponse:addCommandSuccessResponse];
                    [testConnectionManager respondToLastMultipleRequestsWithSuccess:YES];

                    expect(testOp.isFinished).to(beTrue());
                    expect(resultError).to(beNil());
                    expect(resultMenuCells).to(haveCount(1));
                });
            });

            // when the image is not on the head unit
            context(@"when the image is not on the head unit", ^{
                beforeEach(^{
                    OCMStub([testFileManager hasUploadedFile:[OCMArg isNotNil]]).andReturn(NO);
                    OCMStub([testFileManager fileNeedsUpload:[OCMArg isNotNil]]).andReturn(YES);
                });

                it(@"should attempt to upload artworks then send the add", ^{
                    testOp = [[SDLMenuReplaceOperation alloc] initWithConnectionManager:testConnectionManager fileManager:testFileManager windowCapability:testWindowCapability menuConfiguration:testMenuConfiguration currentMenu:testCurrentMenu updatedMenu:testNewMenu compatibilityModeEnabled:YES currentMenuUpdatedHandler:testCurrentMenuUpdatedBlock];
                    [testOp start];

                    OCMVerify([testFileManager uploadArtworks:[OCMArg any] progressHandler:[OCMArg any] completionHandler:[OCMArg any]]);

                    NSPredicate *deleteCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass: %@", [SDLDeleteCommand class]];
                    NSArray *deletesArray = [[testConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:deleteCommandPredicate];
                    expect(deletesArray).to(beEmpty());

                    NSPredicate *addCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass: %@", [SDLAddCommand class]];
                    NSArray *addsArray = [[testConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:addCommandPredicate];
                    expect(addsArray).toNot(beEmpty());

                    [testConnectionManager respondToLastRequestWithResponse:addCommandSuccessResponse];
                    [testConnectionManager respondToLastMultipleRequestsWithSuccess:YES];

                    expect(testOp.isFinished).to(beTrue());
                    expect(resultError).to(beNil());
                    expect(resultMenuCells).to(haveCount(1));
                });
            });
        });

        context(@"when uploading a cell with subcells", ^{
            beforeEach(^{
                testNewMenu = @[submenuCell];
            });

            it(@"should send an appropriate number of AddSubmenu and AddCommandRequests", ^{
                testOp = [[SDLMenuReplaceOperation alloc] initWithConnectionManager:testConnectionManager fileManager:testFileManager windowCapability:testWindowCapability menuConfiguration:testMenuConfiguration currentMenu:testCurrentMenu updatedMenu:testNewMenu compatibilityModeEnabled:YES currentMenuUpdatedHandler:testCurrentMenuUpdatedBlock];
                [testOp start];

                [testConnectionManager respondToLastRequestWithResponse:addSubMenuSuccessResponse];
                [testConnectionManager respondToLastMultipleRequestsWithSuccess:YES];

                NSPredicate *addCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass: %@", [SDLAddCommand class]];
                NSArray *adds = [[testConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:addCommandPredicate];

                NSPredicate *submenuCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass: %@", [SDLAddSubMenu class]];
                NSArray *submenus = [[testConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:submenuCommandPredicate];

                expect(adds).to(haveCount(2));
                expect(submenus).to(haveCount(1));

                [testConnectionManager respondToRequestWithResponse:addCommandSuccessResponse requestNumber:1 error:nil];
                [testConnectionManager respondToRequestWithResponse:addCommandSuccessResponse requestNumber:2 error:nil];
                [testConnectionManager respondToLastMultipleRequestsWithSuccess:YES];

                expect(testOp.isFinished).to(beTrue());
                expect(resultError).to(beNil());
                expect(resultMenuCells).to(haveCount(1));
                expect(resultMenuCells[0].subCells).to(haveCount(2));
            });
        });
    });

    describe(@"updating a menu without dynamic updates", ^{
        context(@"adding a text cell", ^{
            beforeEach(^{
                testCurrentMenu = @[textOnlyCell];
                testNewMenu = @[textOnlyCell, textOnlyCell2];
            });

            it(@"should send a delete and two adds", ^{
                testOp = [[SDLMenuReplaceOperation alloc] initWithConnectionManager:testConnectionManager fileManager:testFileManager windowCapability:testWindowCapability menuConfiguration:testMenuConfiguration currentMenu:testCurrentMenu updatedMenu:testNewMenu compatibilityModeEnabled:YES currentMenuUpdatedHandler:testCurrentMenuUpdatedBlock];
                [testOp start];

                [testConnectionManager respondToLastRequestWithResponse:deleteCommandSuccessResponse];
                [testConnectionManager respondToLastMultipleRequestsWithSuccess:YES];

                NSPredicate *deleteCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass:%@", [SDLDeleteCommand class]];
                NSArray *deletes = [[testConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:deleteCommandPredicate];

                NSPredicate *addCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass:%@", [SDLAddCommand class]];
                NSArray *adds = [[testConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:addCommandPredicate];

                expect(deletes).to(haveCount(1));
                expect(adds).to(haveCount(2));

                [testConnectionManager respondToRequestWithResponse:addCommandSuccessResponse requestNumber:1 error:nil];
                [testConnectionManager respondToRequestWithResponse:addCommandSuccessResponse requestNumber:2 error:nil];
                [testConnectionManager respondToLastMultipleRequestsWithSuccess:YES];

                expect(testOp.isFinished).to(beTrue());
                expect(resultError).to(beNil());
                expect(resultMenuCells).to(haveCount(2));
                expect(resultMenuCells[0]).to(equal(textOnlyCell));
                expect(resultMenuCells[1]).to(equal(textOnlyCell2));
            });
        });
    });

    // updating a menu with dynamic updates
    describe(@"updating a menu with dynamic updates", ^{
        context(@"adding a text cell", ^{
            beforeEach(^{
                testCurrentMenu = @[textOnlyCell];
                testNewMenu = @[textOnlyCell, textOnlyCell2];
            });

            it(@"should only send an add", ^{
                testOp = [[SDLMenuReplaceOperation alloc] initWithConnectionManager:testConnectionManager fileManager:testFileManager windowCapability:testWindowCapability menuConfiguration:testMenuConfiguration currentMenu:testCurrentMenu updatedMenu:testNewMenu compatibilityModeEnabled:NO currentMenuUpdatedHandler:testCurrentMenuUpdatedBlock];
                [testOp start];

                NSPredicate *deleteCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass:%@", [SDLDeleteCommand class]];
                NSArray *deletes = [[testConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:deleteCommandPredicate];

                NSPredicate *addCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass:%@", [SDLAddCommand class]];
                NSArray *adds = [[testConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:addCommandPredicate];

                expect(deletes).to(haveCount(0));
                expect(adds).to(haveCount(1));

                [testConnectionManager respondToLastRequestWithResponse:addCommandSuccessResponse];
                [testConnectionManager respondToLastMultipleRequestsWithSuccess:YES];

                expect(testOp.isFinished).to(beTrue());
                expect(resultError).to(beNil());
                expect(resultMenuCells).to(haveCount(2));
            });
        });

        context(@"rearranging cells with subcells", ^{
            beforeEach(^{
                testCurrentMenu = @[textOnlyCell, submenuCell, submenuImageCell];
                testNewMenu = @[submenuCell, submenuImageCell, textOnlyCell];

                OCMStub([testFileManager uploadArtworks:[OCMArg any] progressHandler:([OCMArg invokeBlockWithArgs:textAndImageCell.icon.name, @1.0, [NSNull null], nil]) completionHandler:([OCMArg invokeBlockWithArgs: @[textAndImageCell.icon.name], [NSNull null], nil])]);
            });

            it(@"should send dynamic deletes first then dynamic adds case with 2 submenu cells", ^{
                testOp = [[SDLMenuReplaceOperation alloc] initWithConnectionManager:testConnectionManager fileManager:testFileManager windowCapability:testWindowCapability menuConfiguration:testMenuConfiguration currentMenu:testCurrentMenu updatedMenu:testNewMenu compatibilityModeEnabled:NO currentMenuUpdatedHandler:testCurrentMenuUpdatedBlock];
                [testOp start];

                // Delete textOnlyCell
                [testConnectionManager respondToLastRequestWithResponse:deleteCommandSuccessResponse];
                [testConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
                expect(testOp.currentMenu).toNot(contain(textOnlyCell));

                // Add textOnlyCell
                [testConnectionManager respondToLastRequestWithResponse:addCommandSuccessResponse];
                [testConnectionManager respondToLastMultipleRequestsWithSuccess:YES];

                NSPredicate *deleteCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass:%@", [SDLDeleteCommand class]];
                NSArray *deletes = [[testConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:deleteCommandPredicate];

                NSPredicate *addCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass:%@", [SDLAddCommand class]];
                NSArray *adds = [[testConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:addCommandPredicate];

                NSPredicate *addSubmenuPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass: %@", [SDLAddSubMenu class]];
                NSArray *submenu = [[testConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:addSubmenuPredicate];

                expect(deletes).to(haveCount(1));
                expect(adds).to(haveCount(1));
                expect(submenu).to(haveCount(0));

                expect(testOp.isFinished).to(beTrue());
                expect(resultError).to(beNil());
                expect(resultMenuCells).to(haveCount(3));
            });
        });
    });

//
//        it(@"should send dynamic deletes first then dynamic adds when removing one submenu cell", ^{
//            testManager.menuCells = @[textOnlyCell, textAndImageCell, submenuCell, submenuImageCell];
//            [mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
//            [mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
//
//            testManager.menuCells = @[textOnlyCell, textAndImageCell, submenuCell];
//            [mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
//            [mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
//
//            NSPredicate *deleteCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass:%@", [SDLDeleteCommand class]];
//            NSArray *deletes = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:deleteCommandPredicate];
//
//            NSPredicate *deleteSubCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass:%@", [SDLDeleteSubMenu class]];
//            NSArray *subDeletes = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:deleteSubCommandPredicate];
//
//            NSPredicate *addCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass:%@", [SDLAddCommand class]];
//            NSArray *adds = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:addCommandPredicate];
//
//            NSPredicate *addSubmenuPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass: %@", [SDLAddSubMenu class]];
//            NSArray *submenu = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:addSubmenuPredicate];
//
//            expect(deletes).to(haveCount(0));
//            expect(subDeletes).to(haveCount(1));
//            expect(adds).to(haveCount(5));
//            expect(submenu).to(haveCount(2));
//        });
//
//        it(@"should send dynamic deletes first then dynamic adds when adding one new cell", ^{
//            testManager.menuCells = @[textOnlyCell, textAndImageCell, submenuCell, submenuImageCell];
//            [mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
//            [mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
//
//            testManager.menuCells = @[textOnlyCell, textAndImageCell, submenuCell, submenuImageCell, textOnlyCell2];
//            [mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
//            [mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
//
//            NSPredicate *deleteCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass:%@", [SDLDeleteCommand class]];
//            NSArray *deletes = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:deleteCommandPredicate];
//
//            NSPredicate *addCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass:%@", [SDLAddCommand class]];
//            NSArray *adds = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:addCommandPredicate];
//
//            NSPredicate *addSubmenuPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass: %@", [SDLAddSubMenu class]];
//            NSArray *submenu = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:addSubmenuPredicate];
//
//            expect(deletes).to(haveCount(0));
//            expect(adds).to(haveCount(6));
//            expect(submenu).to(haveCount(2));
//        });
//
//        it(@"should send dynamic deletes first then dynamic adds when cells stay the same", ^{
//            testManager.menuCells = @[textOnlyCell, textOnlyCell2, textAndImageCell];
//            [mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
//            [mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
//
//            testManager.menuCells = @[textOnlyCell, textOnlyCell2, textAndImageCell];
//            [mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
//            [mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
//
//            NSPredicate *deleteCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass:%@", [SDLDeleteCommand class]];
//            NSArray *deletes = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:deleteCommandPredicate];
//
//            NSPredicate *addCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass:%@", [SDLAddCommand class]];
//            NSArray *adds = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:addCommandPredicate];
//
//            expect(deletes).to(haveCount(0));
//            expect(adds).to(haveCount(3));
//        });
//    });
//
//    describe(@"updating when a menu already exists with dynamic updates off", ^{
//        beforeEach(^{
//             testManager.dynamicMenuUpdatesMode = SDLDynamicMenuUpdatesModeForceOff;
//             OCMStub([mockFileManager uploadArtworks:[OCMArg any] completionHandler:[OCMArg invokeBlock]]);
//        });
//
//        it(@"should send deletes first", ^{
//            testManager.menuCells = @[textOnlyCell];
//            [mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
//            [mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
//
//            testManager.menuCells = @[textAndImageCell];
//            [mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
//            [mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
//
//            NSPredicate *deleteCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass:%@", [SDLDeleteCommand class]];
//            NSArray *deletes = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:deleteCommandPredicate];
//
//            NSPredicate *addCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass:%@", [SDLAddCommand class]];
//            NSArray *adds = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:addCommandPredicate];
//
//            expect(deletes).to(haveCount(1));
//            expect(adds).to(haveCount(2));
//        });
//
//        it(@"should deletes first case 2", ^{
//            testManager.menuCells = @[textOnlyCell, textAndImageCell];
//            [mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
//            [mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
//
//            testManager.menuCells = @[textAndImageCell, textOnlyCell];
//            [mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
//            [mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
//
//            NSPredicate *deleteCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass:%@", [SDLDeleteCommand class]];
//            NSArray *deletes = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:deleteCommandPredicate];
//
//            NSPredicate *addCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass:%@", [SDLAddCommand class]];
//            NSArray *adds = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:addCommandPredicate];
//
//            expect(deletes).to(haveCount(2));
//            expect(adds).to(haveCount(4));
//        });
//
//        it(@"should send deletes first case 3", ^{
//            testManager.menuCells = @[textOnlyCell, textAndImageCell, submenuCell, submenuImageCell];
//            [mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
//            [mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
//
//            testManager.menuCells = @[textOnlyCell, textAndImageCell, submenuCell];
//            [mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
//            [mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
//
//            NSPredicate *deleteCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass:%@", [SDLDeleteCommand class]];
//            NSArray *deletes = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:deleteCommandPredicate];
//
//            NSPredicate *deleteSubCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass:%@", [SDLDeleteSubMenu class]];
//            NSArray *subDeletes = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:deleteSubCommandPredicate];
//
//            NSPredicate *addCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass:%@", [SDLAddCommand class]];
//            NSArray *adds = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:addCommandPredicate];
//
//            NSPredicate *addSubmenuPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass: %@", [SDLAddSubMenu class]];
//            NSArray *submenu = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:addSubmenuPredicate];
//
//            expect(deletes).to(haveCount(2));
//            expect(subDeletes).to(haveCount(2));
//            expect(adds).to(haveCount(9));
//            expect(submenu).to(haveCount(3));
//        });
//
//        it(@"should send deletes first case 4", ^{
//            testManager.menuCells = @[textOnlyCell, textAndImageCell, submenuCell];
//            [mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
//            [mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
//
//            testManager.menuCells = @[textOnlyCell, textAndImageCell, submenuCell, textOnlyCell2];
//            [mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
//            [mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
//
//
//            NSPredicate *deleteCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass:%@", [SDLDeleteCommand class]];
//            NSArray *deletes = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:deleteCommandPredicate];
//
//            NSPredicate *addCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass:%@", [SDLAddCommand class]];
//            NSArray *adds = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:addCommandPredicate];
//
//            NSPredicate *addSubmenuPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass: %@", [SDLAddSubMenu class]];
//            NSArray *submenu = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:addSubmenuPredicate];
//
//            NSPredicate *deleteSubCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass:%@", [SDLDeleteSubMenu class]];
//            NSArray *subDeletes = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:deleteSubCommandPredicate];
//
//            expect(deletes).to(haveCount(2));
//            expect(adds).to(haveCount(9));
//            expect(submenu).to(haveCount(2));
//            expect(subDeletes).to(haveCount(1));
//        });
//
//        it(@"should deletes first case 5", ^{
//            testManager.menuCells = @[textOnlyCell, textOnlyCell2, textAndImageCell];
//            [mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
//            [mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
//
//            testManager.menuCells = @[textOnlyCell, textOnlyCell2, textAndImageCell];
//            [mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
//            [mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
//
//            NSPredicate *deleteCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass:%@", [SDLDeleteCommand class]];
//            NSArray *deletes = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:deleteCommandPredicate];
//
//            NSPredicate *addCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass:%@", [SDLAddCommand class]];
//            NSArray *adds = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:addCommandPredicate];
//
//            expect(deletes).to(haveCount(3));
//            expect(adds).to(haveCount(6));
//        });
//    });
});

QuickSpecEnd