summaryrefslogtreecommitdiff
path: root/SmartDeviceLinkTests/DevAPISpecs/SDLLockScreenManagerSpec.m
blob: 3889c37d10dbbe01f4da57c34f4a9f27611959b1 (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
#import <Quick/Quick.h>
#import <Nimble/Nimble.h>

#import "SDLFakeViewControllerPresenter.h"
#import "SDLLockScreenConfiguration.h"
#import "SDLLockScreenManager.h"
#import "SDLLockScreenStatus.h"
#import "SDLLockScreenViewController.h"
#import "SDLNotificationConstants.h"
#import "SDLNotificationDispatcher.h"
#import "SDLOnLockScreenStatus.h"
#import "SDLRPCNotificationNotification.h"


QuickSpecBegin(SDLLockScreenManagerSpec)

describe(@"a lock screen manager", ^{
    __block SDLLockScreenManager *testManager = nil;
    __block SDLFakeViewControllerPresenter *fakePresenter = nil;
    __block SDLNotificationDispatcher *testNotificationDispatcher = nil;
    
    beforeEach(^{
        fakePresenter = [[SDLFakeViewControllerPresenter alloc] init];
    });
    
    context(@"with a disabled configuration", ^{
        beforeEach(^{
            testManager = [[SDLLockScreenManager alloc] initWithConfiguration:[SDLLockScreenConfiguration disabledConfiguration] notificationDispatcher:nil presenter:fakePresenter];
        });
        
        it(@"should set properties correctly", ^{
            // Note: We can't check the "lockScreenPresented" flag on the Lock Screen Manager because it's a computer property checking the window
            expect(@(fakePresenter.presented)).to(beFalsy());
            expect(testManager.lockScreenViewController).to(beNil());
        });
        
        describe(@"after it is started", ^{
            beforeEach(^{
                [testManager start];
            });
            
            it(@"should not have a lock screen controller", ^{
                expect(@(fakePresenter.presented)).to(beFalsy());
                expect(testManager.lockScreenViewController).to(beNil());
            });
            
            describe(@"when the lock screen status becomes REQUIRED", ^{
                __block SDLOnLockScreenStatus *testRequiredStatus = nil;
                
                beforeEach(^{
                    testRequiredStatus = [[SDLOnLockScreenStatus alloc] init];
                    testRequiredStatus.lockScreenStatus = SDLLockScreenStatusRequired;
                    
                    [testNotificationDispatcher postNotificationName:SDLDidChangeLockScreenStatusNotification infoObject:testRequiredStatus];
                });
                
                it(@"should not have presented the lock screen", ^{
                    expect(@(fakePresenter.presented)).to(beFalsy());
                });
            });
        });
    });
    
    context(@"with an enabled configuration", ^{
        beforeEach(^{
            testManager = [[SDLLockScreenManager alloc] initWithConfiguration:[SDLLockScreenConfiguration enabledConfiguration] notificationDispatcher:nil presenter:fakePresenter];
        });
        
        it(@"should set properties correctly", ^{
            expect(@(fakePresenter.presented)).to(beFalsy());
            expect(testManager.lockScreenViewController).to(beNil());
        });
        
        describe(@"after it's started", ^{
            beforeEach(^{
                [testManager start];
            });
            
            it(@"should set up the view controller correctly", ^{
                expect(@(fakePresenter.presented)).to(beFalsy());
                expect(testManager.lockScreenViewController).toNot(beNil());
                expect(testManager.lockScreenViewController).to(beAnInstanceOf([SDLLockScreenViewController class]));
            });
            
            describe(@"when the lock screen status becomes REQUIRED", ^{
                __block SDLOnLockScreenStatus *testRequiredStatus = nil;
                
                beforeEach(^{
                    testRequiredStatus = [[SDLOnLockScreenStatus alloc] init];
                    testRequiredStatus.lockScreenStatus = SDLLockScreenStatusRequired;
                    
                    SDLRPCNotificationNotification *testLockStatusNotification = [[SDLRPCNotificationNotification alloc] initWithName:SDLDidChangeLockScreenStatusNotification object:nil rpcNotification:testRequiredStatus];
                    [[NSNotificationCenter defaultCenter] postNotification:testLockStatusNotification];
                });
                
                it(@"should have presented the lock screen", ^{
                    expect(@(fakePresenter.presented)).to(beTruthy());
                });
                
                it(@"should not have a vehicle icon", ^{
                    expect(((SDLLockScreenViewController *)testManager.lockScreenViewController).vehicleIcon).to(beNil());
                });
                
                describe(@"when a vehicle icon is received", ^{
                    __block UIImage *testIcon = nil;
                    
                    beforeEach(^{
                        testIcon = [UIImage imageNamed:@"testImagePNG" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil];
                        [[NSNotificationCenter defaultCenter] postNotificationName:SDLDidReceiveLockScreenIcon object:nil userInfo:@{ SDLNotificationUserInfoObject: testIcon }];
                    });
                    
                    it(@"should have a vehicle icon", ^{
                        expect(((SDLLockScreenViewController *)testManager.lockScreenViewController).vehicleIcon).toNot(beNil());
                        expect(((SDLLockScreenViewController *)testManager.lockScreenViewController).vehicleIcon).to(equal(testIcon));
                    });
                });
                
                describe(@"then the manager is stopped", ^{
                    beforeEach(^{
                        [testManager stop];
                    });
                    
                    it(@"should have dismissed the lock screen", ^{
                        expect(@(fakePresenter.presented)).to(beFalsy());
                    });
                });
                
                describe(@"then the status becomes OFF", ^{
                    __block SDLOnLockScreenStatus *testOffStatus = nil;
                    
                    beforeEach(^{
                        testOffStatus = [[SDLOnLockScreenStatus alloc] init];
                        testOffStatus.lockScreenStatus = SDLLockScreenStatusOff;
                        
                        SDLRPCNotificationNotification *testLockStatusNotification = [[SDLRPCNotificationNotification alloc] initWithName:SDLDidChangeLockScreenStatusNotification object:nil rpcNotification:testOffStatus];
                        [[NSNotificationCenter defaultCenter] postNotification:testLockStatusNotification];
                    });
                    
                    it(@"should have dismissed the lock screen", ^{
                        expect(@(fakePresenter.presented)).to(beFalsy());
                    });
                });
            });
        });
    });
    
    context(@"with a custom color configuration", ^{
        __block UIColor *testColor = nil;
        __block UIImage *testImage = nil;
        
        beforeEach(^{
            testColor = [UIColor blueColor];
            testImage = [UIImage imageNamed:@"testImagePNG" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil];
            
            testManager = [[SDLLockScreenManager alloc] initWithConfiguration:[SDLLockScreenConfiguration enabledConfigurationWithAppIcon:testImage backgroundColor:testColor] notificationDispatcher:nil presenter:fakePresenter];
        });
        
        it(@"should set properties correctly", ^{
            expect(@(fakePresenter.presented)).to(beFalsy());
            expect(testManager.lockScreenViewController).to(beNil());
        });
        
        describe(@"after it's started", ^{
            beforeEach(^{
                [testManager start];
            });
            
            it(@"should set up the view controller correctly", ^{
                expect(@(fakePresenter.presented)).to(beFalsy());
                expect(testManager.lockScreenViewController).toNot(beNil());
                expect(testManager.lockScreenViewController).to(beAnInstanceOf([SDLLockScreenViewController class]));
                expect(((SDLLockScreenViewController *)testManager.lockScreenViewController).backgroundColor).to(equal(testColor));
                expect(((SDLLockScreenViewController *)testManager.lockScreenViewController).appIcon).to(equal(testImage));
            });
        });
    });
    
    context(@"with a custom view controller configuration", ^{
        __block UIViewController *testViewController = nil;
        
        beforeEach(^{
            testViewController = [[UIViewController alloc] init];
            testManager = [[SDLLockScreenManager alloc] initWithConfiguration:[SDLLockScreenConfiguration enabledConfigurationWithViewController:testViewController] notificationDispatcher:nil presenter:fakePresenter];
        });
        
        it(@"should set properties correctly", ^{
            expect(@(fakePresenter.presented)).to(beFalsy());
            expect(testManager.lockScreenViewController).to(beNil());
        });
        
        describe(@"after it's started", ^{
            beforeEach(^{
                [testManager start];
            });
            
            it(@"should set up the view controller correctly", ^{
                expect(@(fakePresenter.presented)).to(beFalsy());
                expect(testManager.lockScreenViewController).toNot(beNil());
                expect(testManager.lockScreenViewController).toNot(beAnInstanceOf([SDLLockScreenViewController class]));
                expect(testManager.lockScreenViewController).to(equal(testViewController));
            });
        });
    });
});

QuickSpecEnd