summaryrefslogtreecommitdiff
path: root/SmartDeviceLinkTests/DevAPISpecs/SDLTextAndGraphicManagerSpec.m
blob: 29e9a775fa69febdf843a9c1ae8a9438e3ceda4e (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
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
#import <Quick/Quick.h>
#import <Nimble/Nimble.h>
#import <OCMock/OCMock.h>

#import "SDLDisplayCapabilities.h"
#import "SDLDisplayCapability.h"
#import "SDLFileManager.h"
#import "SDLHMILevel.h"
#import "SDLImage.h"
#import "SDLImageField.h"
#import "SDLMetadataTags.h"
#import "SDLOnHMIStatus.h"
#import "SDLPredefinedWindows.h"
#import "SDLPutFileResponse.h"
#import "SDLRPCNotificationNotification.h"
#import "SDLShow.h"
#import "SDLSystemCapability.h"
#import "SDLTemplateConfiguration.h"
#import "SDLTextAndGraphicManager.h"
#import "SDLTextAndGraphicState.h"
#import "SDLTextAndGraphicUpdateOperation.h"
#import "SDLTextField.h"
#import "SDLSystemCapabilityManager.h"
#import "SDLWindowCapability.h"
#import "TestConnectionManager.h"

@interface SDLTextAndGraphicManager()

// Dependencies
@property (weak, nonatomic) id<SDLConnectionManagerType> connectionManager;
@property (weak, nonatomic) SDLFileManager *fileManager;
@property (weak, nonatomic) SDLSystemCapabilityManager *systemCapabilityManager;

@property (strong, nonatomic) SDLTextAndGraphicState *currentScreenData;

@property (strong, nonatomic) NSOperationQueue *transactionQueue;

@property (strong, nonatomic, nullable) SDLWindowCapability *windowCapability;
@property (strong, nonatomic, nullable) SDLHMILevel currentLevel;

@property (strong, nonatomic) SDLArtwork *blankArtwork;

@property (assign, nonatomic) BOOL isDirty;

- (void)sdl_displayCapabilityDidUpdate;

@end

@interface SDLTextAndGraphicUpdateOperation ()

@property (copy, nonatomic, nullable) CurrentDataUpdatedHandler currentDataUpdatedHandler;
@property (strong, nonatomic) SDLTextAndGraphicState *updatedState;

@end

QuickSpecBegin(SDLTextAndGraphicManagerSpec)

describe(@"text and graphic manager", ^{
    __block SDLDisplayCapability *testDisplayCapability = nil;
    __block SDLWindowCapability *testWindowCapability = nil;
    __block SDLSystemCapability *testSystemCapability = nil;
    __block SDLOnHMIStatus *testHMIStatus = nil;

    __block SDLTextAndGraphicManager *testManager = nil;
    __block TestConnectionManager *mockConnectionManager = [[TestConnectionManager alloc] init];
    __block SDLFileManager *mockFileManager = nil;
    __block SDLSystemCapabilityManager *mockSystemCapabilityManager = nil;

    __block NSString *testString = @"some string";
    __block NSString *testArtworkName = @"some artwork name";
    __block SDLArtwork *testArtwork = [[SDLArtwork alloc] initWithData:[@"Test data" dataUsingEncoding:NSUTF8StringEncoding] name:testArtworkName fileExtension:@"png" persistent:NO];

    beforeEach(^{
        mockFileManager = OCMClassMock([SDLFileManager class]);
        mockSystemCapabilityManager = OCMClassMock([SDLSystemCapabilityManager class]);
        testManager = [[SDLTextAndGraphicManager alloc] initWithConnectionManager:mockConnectionManager fileManager:mockFileManager systemCapabilityManager:mockSystemCapabilityManager];
        [testManager start];
    });

    // should instantiate correctly
    it(@"should instantiate correctly", ^{
        expect(testManager.connectionManager).to(equal(mockConnectionManager));
        expect(testManager.fileManager).to(equal(mockFileManager));

        expect(testManager.textField1).to(beNil());
        expect(testManager.textField2).to(beNil());
        expect(testManager.textField3).to(beNil());
        expect(testManager.textField4).to(beNil());
        expect(testManager.mediaTrackTextField).to(beNil());
        expect(testManager.title).to(beNil());
        expect(testManager.primaryGraphic).to(beNil());
        expect(testManager.secondaryGraphic).to(beNil());
        expect(testManager.alignment).to(equal(SDLTextAlignmentCenter));
        expect(testManager.textField1Type).to(beNil());
        expect(testManager.textField2Type).to(beNil());
        expect(testManager.textField3Type).to(beNil());
        expect(testManager.textField4Type).to(beNil());

        expect(testManager.currentScreenData).toNot(beNil());
        expect(testManager.transactionQueue).toNot(beNil());
        expect(testManager.windowCapability).to(beNil());
        expect(testManager.currentLevel).to(equal(SDLHMILevelNone));
        expect(testManager.blankArtwork).toNot(beNil());
        expect(testManager.isDirty).to(beFalse());
    });

    // setting setters
    describe(@"setting setters", ^{
        beforeEach(^{
            testManager.currentLevel = SDLHMILevelFull;
        });

        // when in HMI NONE
        context(@"when in HMI NONE", ^{
            beforeEach(^{
                testManager.currentLevel = SDLHMILevelNone;
            });

            it(@"should set text field 1 but be suspended", ^{
                testManager.textField1 = testString;

                expect(testManager.textField1).to(equal(testString));
                expect(testManager.transactionQueue.isSuspended).to(beTrue());
                expect(testManager.transactionQueue.operationCount).to(equal(1));
            });
        });

        // when no HMI level has been received
        context(@"when no HMI level has been received", ^{
            beforeEach(^{
                testManager.currentLevel = nil;
            });

            it(@"should set text field 1 but be suspended", ^{
                testManager.textField1 = testString;

                expect(testManager.textField1).to(equal(testString));
                expect(testManager.transactionQueue.operationCount).to(equal(1));
                expect(testManager.transactionQueue.isSuspended).to(beTrue());
            });
        });

        // without batching
        context(@"without batching", ^{
            beforeEach(^{
                testManager.batchUpdates = NO;
                testManager.textField1 = @"test1";
                testManager.textField2 = @"test2";
                testManager.textField3 = @"test3";
                testManager.textField4 = @"test4";
            });

            it(@"should create individual operations and not be cancelled", ^{
                expect(testManager.transactionQueue.isSuspended).to(beTrue());
                expect(testManager.transactionQueue.operationCount).to(equal(4));
                expect(testManager.transactionQueue.operations[0].cancelled).to(beFalse());
                expect(testManager.transactionQueue.operations[1].cancelled).to(beFalse());
                expect(testManager.transactionQueue.operations[2].cancelled).to(beFalse());
                expect(testManager.transactionQueue.operations[3].cancelled).to(beFalse());
            });
        });

        // while batching
        context(@"while batching", ^{
            beforeEach(^{
                testManager.batchUpdates = YES;
            });

            it(@"should set text field 1", ^{
                testManager.textField1 = testString;

                expect(testManager.textField1).to(equal(testString));
                expect(testManager.transactionQueue.operationCount).to(equal(0));
                expect(testManager.isDirty).to(beTrue());
            });

            it(@"should set text field 2", ^{
                testManager.textField2 = testString;

                expect(testManager.textField2).to(equal(testString));
                expect(testManager.transactionQueue.operationCount).to(equal(0));
                expect(testManager.isDirty).to(beTrue());
            });

            it(@"should set text field 3", ^{
                testManager.textField3 = testString;

                expect(testManager.textField3).to(equal(testString));
                expect(testManager.transactionQueue.operationCount).to(equal(0));
                expect(testManager.isDirty).to(beTrue());
            });

            it(@"should set text field 4", ^{
                testManager.textField4 = testString;

                expect(testManager.textField4).to(equal(testString));
                expect(testManager.transactionQueue.operationCount).to(equal(0));
                expect(testManager.isDirty).to(beTrue());
            });

            it(@"should set media track text field", ^{
                testManager.mediaTrackTextField = testString;

                expect(testManager.mediaTrackTextField).to(equal(testString));
                expect(testManager.transactionQueue.operationCount).to(equal(0));
                expect(testManager.isDirty).to(beTrue());
            });

            it(@"should set template title", ^{
                testManager.title = testString;

                expect(testManager.title).to(equal(testString));
                expect(testManager.transactionQueue.operationCount).to(equal(0));
                expect(testManager.isDirty).to(beTrue());
            });

            it(@"should set primary graphic", ^{
                testManager.primaryGraphic = testArtwork;

                expect(testManager.primaryGraphic.name).to(equal(testArtworkName));
                expect(testManager.transactionQueue.operationCount).to(equal(0));
                expect(testManager.isDirty).to(beTrue());
            });

            it(@"should set secondary graphic", ^{
                testManager.secondaryGraphic = testArtwork;

                expect(testManager.secondaryGraphic.name).to(equal(testArtworkName));
                expect(testManager.transactionQueue.operationCount).to(equal(0));
                expect(testManager.isDirty).to(beTrue());
            });

            it(@"should set the alignment", ^{
                testManager.alignment = SDLTextAlignmentLeft;

                expect(testManager.alignment).to(equal(SDLTextAlignmentLeft));
                expect(testManager.transactionQueue.operationCount).to(equal(0));
                expect(testManager.isDirty).to(beTrue());
            });

            it(@"should set textFieldType1", ^{
                testManager.textField1Type = SDLMetadataTypeMediaAlbum;

                expect(testManager.textField1Type).to(equal(SDLMetadataTypeMediaAlbum));
                expect(testManager.transactionQueue.operationCount).to(equal(0));
                expect(testManager.isDirty).to(beTrue());
            });

            it(@"should set textFieldType2", ^{
                testManager.textField2Type = SDLMetadataTypeMediaAlbum;

                expect(testManager.textField2Type).to(equal(SDLMetadataTypeMediaAlbum));
                expect(testManager.transactionQueue.operationCount).to(equal(0));
                expect(testManager.isDirty).to(beTrue());
            });

            it(@"should set textFieldType3", ^{
                testManager.textField3Type = SDLMetadataTypeMediaAlbum;

                expect(testManager.textField3Type).to(equal(SDLMetadataTypeMediaAlbum));
                expect(testManager.transactionQueue.operationCount).to(equal(0));
                expect(testManager.isDirty).to(beTrue());
            });

            it(@"should set textFieldType4", ^{
                testManager.textField4Type = SDLMetadataTypeMediaAlbum;

                expect(testManager.textField4Type).to(equal(SDLMetadataTypeMediaAlbum));
                expect(testManager.transactionQueue.operationCount).to(equal(0));
                expect(testManager.isDirty).to(beTrue());
            });
        });

        // while not batching
        context(@"while not batching", ^{
            beforeEach(^{
                testManager.batchUpdates = NO;
            });

            it(@"should set text field 1", ^{
                testManager.textField1 = testString;

                expect(testManager.textField1).to(equal(testString));
                expect(testManager.transactionQueue.operationCount).to(equal(1));
                expect(testManager.isDirty).to(beFalse());
            });

            it(@"should set text field 2", ^{
                testManager.textField2 = testString;

                expect(testManager.textField2).to(equal(testString));
                expect(testManager.transactionQueue.operationCount).to(equal(1));
                expect(testManager.isDirty).to(beFalse());
            });

            it(@"should set text field 3", ^{
                testManager.textField3 = testString;

                expect(testManager.textField3).to(equal(testString));
                expect(testManager.transactionQueue.operationCount).to(equal(1));
                expect(testManager.isDirty).to(beFalse());
            });

            it(@"should set text field 4", ^{
                testManager.textField4 = testString;

                expect(testManager.textField4).to(equal(testString));
                expect(testManager.transactionQueue.operationCount).to(equal(1));
                expect(testManager.isDirty).to(beFalse());
            });

            it(@"should set media track text field", ^{
                testManager.mediaTrackTextField = testString;

                expect(testManager.mediaTrackTextField).to(equal(testString));
                expect(testManager.transactionQueue.operationCount).to(equal(1));
                expect(testManager.isDirty).to(beFalse());
            });

            it(@"should set template title text field", ^{
                testManager.title = testString;

                expect(testManager.title).to(equal(testString));
                expect(testManager.transactionQueue.operationCount).to(equal(1));
                expect(testManager.isDirty).to(beFalse());
            });

            it(@"should set primary graphic", ^{
                testManager.primaryGraphic = testArtwork;

                expect(testManager.primaryGraphic.name).to(equal(testArtworkName));
                expect(testManager.transactionQueue.operationCount).to(equal(1));
                expect(testManager.isDirty).to(beFalse());
            });

            it(@"should set secondary graphic", ^{
                testManager.secondaryGraphic = testArtwork;

                expect(testManager.secondaryGraphic.name).to(equal(testArtworkName));
                expect(testManager.transactionQueue.operationCount).to(equal(1));
                expect(testManager.isDirty).to(beFalse());
            });

            it(@"should set the alignment", ^{
                testManager.alignment = SDLTextAlignmentLeft;

                expect(testManager.alignment).to(equal(SDLTextAlignmentLeft));
                expect(testManager.transactionQueue.operationCount).to(equal(1));
                expect(testManager.isDirty).to(beFalse());
            });

            it(@"should set textFieldType1", ^{
                testManager.textField1Type = SDLMetadataTypeMediaAlbum;

                expect(testManager.textField1Type).to(equal(SDLMetadataTypeMediaAlbum));
                expect(testManager.transactionQueue.operationCount).to(equal(1));
                expect(testManager.isDirty).to(beFalse());
            });

            it(@"should set textFieldType2", ^{
                testManager.textField2Type = SDLMetadataTypeMediaAlbum;

                expect(testManager.textField2Type).to(equal(SDLMetadataTypeMediaAlbum));
                expect(testManager.transactionQueue.operationCount).to(equal(1));
                expect(testManager.isDirty).to(beFalse());
            });

            it(@"should set textFieldType3", ^{
                testManager.textField3Type = SDLMetadataTypeMediaAlbum;

                expect(testManager.textField3Type).to(equal(SDLMetadataTypeMediaAlbum));
                expect(testManager.transactionQueue.operationCount).to(equal(1));
                expect(testManager.isDirty).to(beFalse());
            });

            it(@"should set textFieldType4", ^{
                testManager.textField4Type = SDLMetadataTypeMediaAlbum;

                expect(testManager.textField4Type).to(equal(SDLMetadataTypeMediaAlbum));
                expect(testManager.transactionQueue.operationCount).to(equal(1));
                expect(testManager.isDirty).to(beFalse());
            });
        });
    });

    // batching an update
    describe(@"batching an update", ^{
        NSString *textLine1 = @"line1";
        NSString *textLine2 = @"line2";
        NSString *textLine3 = @"line3";
        NSString *textLine4 = @"line4";
        NSString *textMediaTrack = @"line5";
        NSString *textTitle = @"title";

        SDLMetadataType line1Type = SDLMetadataTypeMediaTitle;
        SDLMetadataType line2Type = SDLMetadataTypeMediaAlbum;
        SDLMetadataType line3Type = SDLMetadataTypeMediaArtist;
        SDLMetadataType line4Type = SDLMetadataTypeMediaStation;

        beforeEach(^{
            testManager.currentLevel = SDLHMILevelFull;
            testManager.batchUpdates = YES;

            testManager.textField1 = textLine1;
            testManager.textField2 = textLine2;
            testManager.textField3 = textLine3;
            testManager.textField4 = textLine4;
            testManager.mediaTrackTextField = textMediaTrack;
            testManager.title = textTitle;
            testManager.textField1Type = line1Type;
            testManager.textField2Type = line2Type;
            testManager.textField3Type = line3Type;
            testManager.textField4Type = line4Type;
        });

        it(@"should wait until batching ends to create an update operation", ^{
            expect(testManager.transactionQueue.operationCount).to(equal(0));

            testManager.batchUpdates = NO;
            [testManager updateWithCompletionHandler:nil];
            expect(testManager.transactionQueue.operationCount).to(equal(1));
        });
    });

    // changing the layout
    describe(@"changing the layout", ^{
        // while not batching
        context(@"while not batching", ^{
            beforeEach(^{
                SDLTemplateConfiguration *testConfig = [[SDLTemplateConfiguration alloc] initWithTemplate:@"Test Template"];
                [testManager changeLayout:testConfig withCompletionHandler:nil];
            });

            it(@"should create and start the operation", ^{
                expect(testManager.transactionQueue.operationCount).to(equal(1));
            });
        });

        // while batching
        context(@"while batching", ^{
            beforeEach(^{
                testManager.batchUpdates = YES;
                SDLTemplateConfiguration *testConfig = [[SDLTemplateConfiguration alloc] initWithTemplate:@"Test Template"];
                [testManager changeLayout:testConfig withCompletionHandler:nil];
            });

            it(@"should not create and start the operation", ^{
                expect(testManager.transactionQueue.operationCount).to(equal(0));
            });
        });
    });

    // when the operation updates the current screen data
    describe(@"when the operation updates the current screen data", ^{
        __block SDLTextAndGraphicUpdateOperation *testOperation = nil;
        __block SDLTextAndGraphicUpdateOperation *testOperation2 = nil;
        __block SDLTextAndGraphicUpdateOperation *testOperation3 = nil;

        beforeEach(^{
            testManager.textField1 = @"test";
            testManager.textField2 = @"test2";
            testOperation = testManager.transactionQueue.operations[0];
            testOperation2 = testManager.transactionQueue.operations[1];
        });

        // with good data
        context(@"with good data", ^{
            beforeEach(^{
                testOperation.currentDataUpdatedHandler(testOperation.updatedState, nil);
            });

            it(@"should update the manager's and pending operations' current screen data", ^{
                expect(testManager.currentScreenData).to(equal(testOperation.updatedState));
                expect(testOperation2.currentScreenData).to(equal(testOperation.updatedState));
            });
        });

        // with an error
        context(@"with an error", ^{
            beforeEach(^{
                testManager.currentScreenData = [[SDLTextAndGraphicState alloc] init];
                testManager.currentScreenData.textField1 = @"Test1";

                // Create a "bad data" text field 1, then set it in the manager, which should create an operation (op 2)
                SDLTextAndGraphicState *errorState = [[SDLTextAndGraphicState alloc] init];
                errorState.textField1 = @"Bad Data";
                testManager.textField1 = errorState.textField1;
                
                // Create a "good data text field 4, which should create a second operation (op 3)
                testManager.textField4 = @"Good Data";
                testOperation3 = testManager.transactionQueue.operations[3];

                // Simulate a failure of the first operation
                NSDictionary *userInfo = @{
                    SDLTextAndGraphicFailedScreenStateErrorKey: errorState
                };
                testOperation.currentDataUpdatedHandler(nil, [NSError errorWithDomain:@"any" code:1 userInfo:userInfo]);
            });

            it(@"should reset the manager's data and update other operations updated state", ^{
                expect(testManager.textField1).to(equal(testManager.currentScreenData.textField1));
                expect(testOperation3.updatedState.textField1).to(equal(testManager.currentScreenData.textField1));
            });
        });
    });

    // on HMI level update
    describe(@"on hmi level update", ^{
        beforeEach(^{
            testHMIStatus = [[SDLOnHMIStatus alloc] init];

            testWindowCapability = [[SDLWindowCapability alloc] initWithWindowID:@(SDLPredefinedWindowsDefaultWindow) textFields:nil imageFields:nil imageTypeSupported:nil templatesAvailable:nil numCustomPresetsAvailable:nil buttonCapabilities:nil softButtonCapabilities:nil menuLayoutsAvailable:nil dynamicUpdateCapabilities:nil keyboardCapabilities:nil];
            testDisplayCapability = [[SDLDisplayCapability alloc] initWithDisplayName:@"Test display" windowCapabilities:@[testWindowCapability] windowTypeSupported:nil];

            OCMStub([mockSystemCapabilityManager defaultMainWindowCapability]).andReturn(testWindowCapability);
            [testManager sdl_displayCapabilityDidUpdate];
        });

        // with a non-default window
        context(@"with a non-default window", ^{
            beforeEach(^{
                testHMIStatus.hmiLevel = SDLHMILevelFull;
                testHMIStatus.windowID = @435;

                SDLRPCNotificationNotification *notification = [[SDLRPCNotificationNotification alloc] initWithName:SDLDidChangeHMIStatusNotification object:nil rpcNotification:testHMIStatus];
                [[NSNotificationCenter defaultCenter] postNotification:notification];
            });

            it(@"should not alter the current level or update the queue's suspension", ^{
                expect(testManager.currentLevel).toNot(equal(SDLHMILevelFull));
                expect(testManager.transactionQueue.suspended).to(beTrue());
            });
        });

        // with HMI NONE
        context(@"with HMI NONE", ^{
            beforeEach(^{
                testHMIStatus.hmiLevel = SDLHMILevelNone;
                testHMIStatus.windowID = @(SDLPredefinedWindowsDefaultWindow);

                SDLRPCNotificationNotification *notification = [[SDLRPCNotificationNotification alloc] initWithName:SDLDidChangeHMIStatusNotification object:nil rpcNotification:testHMIStatus];
                [[NSNotificationCenter defaultCenter] postNotification:notification];
            });

            it(@"should not alter the current level or update the queue's suspension", ^{
                expect(testManager.currentLevel).to(equal(SDLHMILevelNone));
                expect(testManager.transactionQueue.suspended).to(beTrue());
            });
        });

        // with HMI BACKGROUND
        context(@"with HMI BACKGROUND", ^{
            beforeEach(^{
                testHMIStatus.hmiLevel = SDLHMILevelBackground;
                testHMIStatus.windowID = @(SDLPredefinedWindowsDefaultWindow);

                SDLRPCNotificationNotification *notification = [[SDLRPCNotificationNotification alloc] initWithName:SDLDidChangeHMIStatusNotification object:nil rpcNotification:testHMIStatus];
                [[NSNotificationCenter defaultCenter] postNotification:notification];
            });

            it(@"should alter the current level and update the queue's suspension", ^{
                expect(testManager.currentLevel).to(equal(SDLHMILevelBackground));
                expect(testManager.transactionQueue.suspended).to(beFalse());
            });
        });
    });

    // on display capability update
    describe(@"on display capability update", ^{
        beforeEach(^{
            testHMIStatus = [[SDLOnHMIStatus alloc] init];
            testHMIStatus.windowID = @(SDLPredefinedWindowsDefaultWindow);
            testHMIStatus.hmiLevel = SDLHMILevelFull;
            SDLRPCNotificationNotification *notification = [[SDLRPCNotificationNotification alloc] initWithName:SDLDidChangeHMIStatusNotification object:nil rpcNotification:testHMIStatus];
            [[NSNotificationCenter defaultCenter] postNotification:notification];

            testWindowCapability = [[SDLWindowCapability alloc] initWithWindowID:@(SDLPredefinedWindowsDefaultWindow) textFields:nil imageFields:nil imageTypeSupported:nil templatesAvailable:nil numCustomPresetsAvailable:nil buttonCapabilities:nil softButtonCapabilities:nil menuLayoutsAvailable:nil dynamicUpdateCapabilities:nil keyboardCapabilities:nil];
            testDisplayCapability = [[SDLDisplayCapability alloc] initWithDisplayName:@"Test display" windowCapabilities:@[testWindowCapability] windowTypeSupported:nil];
            testSystemCapability = [[SDLSystemCapability alloc] initWithDisplayCapabilities:@[testDisplayCapability]];
        });

        it(@"should start the transaction queue and not send a transaction", ^{
            OCMStub([mockSystemCapabilityManager defaultMainWindowCapability]).andReturn(testWindowCapability);
            [testManager sdl_displayCapabilityDidUpdate];

            expect(testManager.transactionQueue.isSuspended).to(beFalse());
            expect(testManager.transactionQueue.operationCount).to(equal(0));
        });

        context(@"if there's data", ^{
            beforeEach(^{
                testManager.textField1 = @"test";
                OCMStub([mockSystemCapabilityManager defaultMainWindowCapability]).andReturn(testWindowCapability);
                [testManager sdl_displayCapabilityDidUpdate];
            });

            it(@"should send an update and not supersede the previous update", ^{
                expect(testManager.transactionQueue.isSuspended).to(beFalse());
                expect(testManager.transactionQueue.operationCount).to(equal(2));
                expect(testManager.transactionQueue.operations[0].isCancelled).to(beFalse());
            });
        });
    });

    // on disconnect
    describe(@"on disconnect", ^{
        beforeEach(^{
            [testManager stop];
        });

        it(@"should reset correctly", ^{
            expect(testManager.connectionManager).to(equal(mockConnectionManager));
            expect(testManager.fileManager).to(equal(mockFileManager));

            expect(testManager.textField1).to(beNil());
            expect(testManager.textField2).to(beNil());
            expect(testManager.textField3).to(beNil());
            expect(testManager.textField4).to(beNil());
            expect(testManager.mediaTrackTextField).to(beNil());
            expect(testManager.primaryGraphic).to(beNil());
            expect(testManager.secondaryGraphic).to(beNil());
            expect(testManager.alignment).to(equal(SDLTextAlignmentCenter));
            expect(testManager.textField1Type).to(beNil());
            expect(testManager.textField2Type).to(beNil());
            expect(testManager.textField3Type).to(beNil());
            expect(testManager.textField4Type).to(beNil());

            expect(testManager.currentScreenData).toNot(beNil());
            expect(testManager.windowCapability).to(beNil());
            expect(testManager.currentLevel).to(equal(SDLHMILevelNone));
            expect(testManager.blankArtwork).toNot(beNil());
            expect(testManager.isDirty).to(beFalse());
        });
    });
});

QuickSpecEnd