diff options
author | NicoleYarroch <nicole@livio.io> | 2019-12-18 12:11:34 -0500 |
---|---|---|
committer | NicoleYarroch <nicole@livio.io> | 2019-12-18 12:11:34 -0500 |
commit | a01243d8b4136cefb53ab35b3240740ae690298c (patch) | |
tree | c06fca4ca37de62e4c145a798217359cbd66c585 | |
parent | 044503cd5f5a5c05b46a4cf970cbcf577f4ab530 (diff) | |
download | sdl_ios-a01243d8b4136cefb53ab35b3240740ae690298c.tar.gz |
Fixed broken test cases
4 files changed, 42 insertions, 98 deletions
diff --git a/SmartDeviceLink/SDLLockScreenPresenter.m b/SmartDeviceLink/SDLLockScreenPresenter.m index 36d59014b..51e7b0749 100644 --- a/SmartDeviceLink/SDLLockScreenPresenter.m +++ b/SmartDeviceLink/SDLLockScreenPresenter.m @@ -18,7 +18,7 @@ NS_ASSUME_NONNULL_BEGIN @interface SDLLockScreenPresenter () @property (strong, nonatomic, nullable) UIWindow *lockWindow; -@property (assign, nonatomic) BOOL presented; +@property (assign, nonatomic, readwrite) BOOL presented; @end @@ -27,9 +27,18 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - Lifecycle -- (void)stop { +- (instancetype)init { + self = [super init]; + if (!self) { return nil; } + _presented = NO; + return self; +} + +- (void)stop { + self.presented = NO; + if (!self.lockWindow) { return; } diff --git a/SmartDeviceLink/SDLViewControllerPresentable.h b/SmartDeviceLink/SDLViewControllerPresentable.h index 0d4eea459..4d6d5fc7d 100644 --- a/SmartDeviceLink/SDLViewControllerPresentable.h +++ b/SmartDeviceLink/SDLViewControllerPresentable.h @@ -13,9 +13,12 @@ NS_ASSUME_NONNULL_BEGIN /// A protocol used to tell a view controller to present another view controller. This makes testing of modal VCs' presentation easier. @protocol SDLViewControllerPresentable <NSObject> -/// The view controller to be presented as a lock screen +/// The view controller to be presented as a lockscreen @property (strong, nonatomic, nullable) UIViewController *lockViewController; +/// Whether or not the lockscreen should be presented +@property (assign, nonatomic, readonly) BOOL presented; + /// Dismisses and destroys the lock screen window - (void)stop; @@ -23,6 +26,8 @@ NS_ASSUME_NONNULL_BEGIN /// @param show True if the lock screen should be presented; false if dismissed. - (void)updateLockScreenToShow:(BOOL)show; + + @end NS_ASSUME_NONNULL_END diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLFakeViewControllerPresenter.m b/SmartDeviceLinkTests/DevAPISpecs/SDLFakeViewControllerPresenter.m index 6518b2aa1..0944eec97 100644 --- a/SmartDeviceLinkTests/DevAPISpecs/SDLFakeViewControllerPresenter.m +++ b/SmartDeviceLinkTests/DevAPISpecs/SDLFakeViewControllerPresenter.m @@ -12,7 +12,6 @@ @interface SDLFakeViewControllerPresenter () @property (assign, nonatomic) BOOL presented; -@property (assign, nonatomic) BOOL dismissed; @end @@ -24,34 +23,19 @@ if (!self) { return nil; } _presented = NO; - _dismissed = NO; return self; } -- (void)present { - if (!self.lockViewController) { return; } - - _presented = YES; - _dismissed = NO; -} - -- (void)dismiss { - if (!self.lockViewController) { return; } - - _presented = NO; - _dismissed = YES; -} - - (void)stop { if (!self.lockViewController) { return; } _presented = NO; - _dismissed = YES; } -- (void)lockScreenPresentationStatusWithHandler:(nonnull SDLLockScreenPresentationStatusHandler)handler { - return handler(_presented, _dismissed); +- (void)updateLockScreenToShow:(BOOL)show { + _presented = show; } + @end diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLLockScreenManagerSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLLockScreenManagerSpec.m index f42153d92..196f8bb1b 100644 --- a/SmartDeviceLinkTests/DevAPISpecs/SDLLockScreenManagerSpec.m +++ b/SmartDeviceLinkTests/DevAPISpecs/SDLLockScreenManagerSpec.m @@ -12,6 +12,7 @@ #import "SDLOnLockScreenStatus.h" #import "SDLOnDriverDistraction.h" #import "SDLRPCNotificationNotification.h" +#import "SDLViewControllerPresentable.h" @interface SDLLockScreenManager () @@ -48,10 +49,7 @@ describe(@"a lock screen manager", ^{ 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 - [fakePresenter lockScreenPresentationStatusWithHandler:^(BOOL isPresented, BOOL isBeingDismissed) { - expect(isPresented).to(beFalse()); - expect(isBeingDismissed).to(beFalse()); - }]; + expect(fakePresenter.presented).toEventually(beFalse()); expect(testManager.lockScreenViewController).to(beNil()); }); @@ -61,10 +59,7 @@ describe(@"a lock screen manager", ^{ }); it(@"should not have a lock screen controller", ^{ - [fakePresenter lockScreenPresentationStatusWithHandler:^(BOOL isPresented, BOOL isBeingDismissed) { - expect(isPresented).to(beFalse()); - expect(isBeingDismissed).to(beFalse()); - }]; + expect(fakePresenter.presented).toEventually(beFalse()); expect(testManager.lockScreenViewController).to(beNil()); }); @@ -86,10 +81,7 @@ describe(@"a lock screen manager", ^{ }); it(@"should not have presented the lock screen", ^{ - [fakePresenter lockScreenPresentationStatusWithHandler:^(BOOL isPresented, BOOL isBeingDismissed) { - expect(isPresented).to(beFalse()); - expect(isBeingDismissed).to(beFalse()); - }]; + expect(fakePresenter.presented).toEventually(beFalse()); }); }); }); @@ -101,10 +93,7 @@ describe(@"a lock screen manager", ^{ }); it(@"should set properties correctly", ^{ - [fakePresenter lockScreenPresentationStatusWithHandler:^(BOOL isPresented, BOOL isBeingDismissed) { - expect(isPresented).to(beFalse()); - expect(isBeingDismissed).to(beFalse()); - }]; + expect(fakePresenter.presented).toEventually(beFalse()); expect(testManager.lockScreenViewController).to(beNil()); }); @@ -114,11 +103,7 @@ describe(@"a lock screen manager", ^{ }); it(@"should set up the view controller correctly", ^{ - [fakePresenter lockScreenPresentationStatusWithHandler:^(BOOL isPresented, BOOL isBeingDismissed) { - expect(isPresented).to(beFalse()); - expect(isBeingDismissed).to(beFalse()); - }]; - + expect(fakePresenter.presented).toEventually(beFalse()); expect(testManager.lockScreenViewController).toNot(beNil()); expect(testManager.lockScreenViewController).to(beAnInstanceOf([SDLLockScreenViewController class])); }); @@ -142,10 +127,7 @@ describe(@"a lock screen manager", ^{ }); it(@"should have presented the lock screen", ^{ - [fakePresenter lockScreenPresentationStatusWithHandler:^(BOOL isPresented, BOOL isBeingDismissed) { - expect(isPresented).to(beTrue()); - expect(isBeingDismissed).to(beFalse()); - }]; + expect(fakePresenter.presented).toEventually(beTrue()); }); it(@"should not have a vehicle icon", ^{ @@ -224,10 +206,7 @@ describe(@"a lock screen manager", ^{ }); it(@"should have dismissed the lock screen", ^{ - [fakePresenter lockScreenPresentationStatusWithHandler:^(BOOL isPresented, BOOL isBeingDismissed) { - expect(isPresented).to(beFalse()); - expect(isBeingDismissed).to(beTrue()); - }]; + expect(fakePresenter.presented).toEventually(beFalse()); }); }); @@ -249,10 +228,7 @@ describe(@"a lock screen manager", ^{ }); it(@"should have dismissed the lock screen", ^{ - [fakePresenter lockScreenPresentationStatusWithHandler:^(BOOL isPresented, BOOL isBeingDismissed) { - expect(isPresented).to(beFalse()); - expect(isBeingDismissed).to(beTrue()); - }]; + expect(fakePresenter.presented).toEventually(beFalse()); }); }); }); @@ -295,11 +271,7 @@ describe(@"a lock screen manager", ^{ }); it(@"should set properties correctly", ^{ - [fakePresenter lockScreenPresentationStatusWithHandler:^(BOOL isPresented, BOOL isBeingDismissed) { - expect(isPresented).to(beFalse()); - expect(isBeingDismissed).to(beFalse()); - }]; - + expect(fakePresenter.presented).toEventually(beFalse()); expect(testManager.lockScreenViewController).to(beNil()); }); @@ -309,11 +281,7 @@ describe(@"a lock screen manager", ^{ }); it(@"should set up the view controller correctly", ^{ - [fakePresenter lockScreenPresentationStatusWithHandler:^(BOOL isPresented, BOOL isBeingDismissed) { - expect(isPresented).to(beFalse()); - expect(isBeingDismissed).to(beFalse()); - }]; - + expect(fakePresenter.presented).toEventually(beFalse()); expect(testManager.lockScreenViewController).toNot(beNil()); expect(testManager.lockScreenViewController).to(beAnInstanceOf([SDLLockScreenViewController class])); expect(((SDLLockScreenViewController *)testManager.lockScreenViewController).backgroundColor).to(equal(testColor)); @@ -331,11 +299,7 @@ describe(@"a lock screen manager", ^{ }); it(@"should set properties correctly", ^{ - [fakePresenter lockScreenPresentationStatusWithHandler:^(BOOL isPresented, BOOL isBeingDismissed) { - expect(isPresented).to(beFalse()); - expect(isBeingDismissed).to(beFalse()); - }]; - + expect(fakePresenter.presented).toEventually(beFalse()); expect(testManager.lockScreenViewController).to(beNil()); }); @@ -345,11 +309,7 @@ describe(@"a lock screen manager", ^{ }); it(@"should set up the view controller correctly", ^{ - [fakePresenter lockScreenPresentationStatusWithHandler:^(BOOL isPresented, BOOL isBeingDismissed) { - expect(isPresented).to(beFalse()); - expect(isBeingDismissed).to(beFalse()); - }]; - + expect(fakePresenter.presented).toEventually(beFalse()); expect(testManager.lockScreenViewController).toNot(beNil()); expect(testManager.lockScreenViewController).toNot(beAnInstanceOf([SDLLockScreenViewController class])); expect(testManager.lockScreenViewController).to(equal(testViewController)); @@ -424,10 +384,7 @@ describe(@"a lock screen manager", ^{ }); it(@"should present the lock screen if not already presented", ^{ - [fakePresenter lockScreenPresentationStatusWithHandler:^(BOOL isPresented, BOOL isBeingDismissed) { - expect(isPresented).to(beTrue()); - expect(isBeingDismissed).to(beFalse()); - }]; + expect(fakePresenter.presented).toEventually(beTrue()); }); }); @@ -440,10 +397,7 @@ describe(@"a lock screen manager", ^{ }); it(@"should present the lock screen if not already presented", ^{ - [fakePresenter lockScreenPresentationStatusWithHandler:^(BOOL isPresented, BOOL isBeingDismissed) { - expect(isPresented).to(beTrue()); - expect(isBeingDismissed).to(beFalse()); - }]; + expect(fakePresenter.presented).toEventually(beTrue()); }); }); }); @@ -456,13 +410,13 @@ describe(@"a lock screen manager", ^{ beforeEach(^{ mockViewControllerPresenter = OCMClassMock([SDLFakeViewControllerPresenter class]); + //OCMClassMock([SDLFakeViewControllerPresenter class]); #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" SDLOnLockScreenStatus *testOptionalStatus = [[SDLOnLockScreenStatus alloc] init]; #pragma clang diagnostic pop testOptionalStatus.lockScreenStatus = SDLLockScreenStatusOptional; testLockStatusNotification = [[SDLRPCNotificationNotification alloc] initWithName:SDLDidChangeLockScreenStatusNotification object:nil rpcNotification:testOptionalStatus]; - testLockScreenConfig = [SDLLockScreenConfiguration enabledConfiguration]; }); @@ -481,15 +435,11 @@ describe(@"a lock screen manager", ^{ it(@"should present the lock screen if not already presented", ^{ OCMStub([mockViewControllerPresenter lockViewController]).andReturn([OCMArg any]); - [OCMStub([mockViewControllerPresenter lockScreenPresentationStatusWithHandler:[OCMArg any]]) andDo:^(NSInvocation *invocation) { - void(^ handler)(BOOL isPresented, BOOL isBeingDismissed); - [invocation getArgument:&handler atIndex:2]; - handler(NO, YES); - }]; - [[NSNotificationCenter defaultCenter] postNotification:testLockStatusNotification]; - OCMVerify([mockViewControllerPresenter present]); + // Since lock screen must be presented/dismissed on the main thread, force the test to execute manually on the main thread. If this is not done, the test case may fail. + [[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]]; + OCMVerify([mockViewControllerPresenter updateLockScreenToShow:YES]); }); }); @@ -508,15 +458,11 @@ describe(@"a lock screen manager", ^{ it(@"should dismiss the lock screen if already presented", ^{ OCMStub([mockViewControllerPresenter lockViewController]).andReturn([OCMArg any]); - [OCMStub([mockViewControllerPresenter lockScreenPresentationStatusWithHandler:[OCMArg any]]) andDo:^(NSInvocation *invocation) { - void(^ handler)(BOOL isPresented, BOOL isBeingDismissed); - [invocation getArgument:&handler atIndex:2]; - handler(YES, NO); - }]; - [[NSNotificationCenter defaultCenter] postNotification:testLockStatusNotification]; - OCMVerify([mockViewControllerPresenter dismiss]); + // Since lock screen must be presented/dismissed on the main thread, force the test to execute manually on the main thread. If this is not done, the test case may fail. + [[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]]; + OCMVerify([mockViewControllerPresenter updateLockScreenToShow:NO]); }); }); }); |