diff options
author | NicoleYarroch <nicole@livio.io> | 2018-05-14 10:36:45 -0400 |
---|---|---|
committer | NicoleYarroch <nicole@livio.io> | 2018-05-14 10:36:45 -0400 |
commit | 9930e55af021634d23a455b2be43e89d237c88a1 (patch) | |
tree | ed87913ed97b6a3b01365c1249cd2fbd9d6e7c2f | |
parent | 9fceb95a2f9c192ba7ea2648b5bc207c1e32b263 (diff) | |
download | sdl_ios-9930e55af021634d23a455b2be43e89d237c88a1.tar.gz |
Added more soft button manager test cases
Signed-off-by: NicoleYarroch <nicole@livio.io>
-rw-r--r-- | SmartDeviceLink/SDLSoftButtonManager.m | 5 | ||||
-rw-r--r-- | SmartDeviceLinkTests/DevAPISpecs/SDLSoftButtonManagerSpec.m | 73 |
2 files changed, 72 insertions, 6 deletions
diff --git a/SmartDeviceLink/SDLSoftButtonManager.m b/SmartDeviceLink/SDLSoftButtonManager.m index 023dcdc85..967758d9d 100644 --- a/SmartDeviceLink/SDLSoftButtonManager.m +++ b/SmartDeviceLink/SDLSoftButtonManager.m @@ -205,8 +205,9 @@ NS_ASSUME_NONNULL_BEGIN if (self.softButtonObjects == nil) { SDLLogV(@"Soft button objects are nil, sending an empty array"); self.inProgressUpdate.softButtons = @[]; - } else if (([self sdl_currentStateHasImages] && ![self sdl_allCurrentStateImagesAreUploaded]) - && (self.softButtonCapabilities ? !self.softButtonCapabilities.imageSupported : YES)) { + } else if ((([self sdl_currentStateHasImages] && ![self sdl_allCurrentStateImagesAreUploaded]) + && (self.softButtonCapabilities ? self.softButtonCapabilities.imageSupported.boolValue : NO)) + || (self.softButtonCapabilities ? !self.softButtonCapabilities.imageSupported.boolValue : YES)){ // The images don't yet exist on the head unit, or we cannot use images, send a text update if possible, otherwise, don't send anything yet NSArray<SDLSoftButton *> *textOnlyButtons = [self sdl_textButtonsForCurrentState]; if (textOnlyButtons != nil) { diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLSoftButtonManagerSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLSoftButtonManagerSpec.m index 0115d318e..edd06554e 100644 --- a/SmartDeviceLinkTests/DevAPISpecs/SDLSoftButtonManagerSpec.m +++ b/SmartDeviceLinkTests/DevAPISpecs/SDLSoftButtonManagerSpec.m @@ -60,10 +60,13 @@ describe(@"a soft button manager", ^{ __block SDLSoftButtonObject *testObject2 = nil; __block NSString *object2Name = @"O2 Name"; __block NSString *object2State1Name = @"O2S1 Name"; + __block NSString *object2State2Name = @"O2S2 Name"; __block NSString *object2State1Text = @"O2S1 Text"; + __block NSString *object2State2Text = @"O2S2 Text"; __block NSString *object2State1ArtworkName = @"O2S1 Artwork"; __block SDLArtwork *object2State1Art = [[SDLArtwork alloc] initWithData:[@"TestData" dataUsingEncoding:NSUTF8StringEncoding] name:object2State1ArtworkName fileExtension:@"png" persistent:YES]; __block SDLSoftButtonState *object2State1 = [[SDLSoftButtonState alloc] initWithStateName:object2State1Name text:object2State1Text artwork:object2State1Art]; + __block SDLSoftButtonState *object2State2 = [[SDLSoftButtonState alloc] initWithStateName:object2State2Name text:object2State2Text image:nil]; beforeEach(^{ testFileManager = OCMClassMock([SDLFileManager class]); @@ -156,8 +159,14 @@ describe(@"a soft button manager", ^{ }); }); - describe(@"uploading the images", ^{ - context(@"when files are already on the file system", ^{ + describe(@"uploading soft buttons to a head unit that supports images", ^{ + beforeEach(^{ + SDLSoftButtonCapabilities *softButtonImagesSupported = [[SDLSoftButtonCapabilities alloc] init]; + softButtonImagesSupported.imageSupported = @YES; + testManager.softButtonCapabilities = softButtonImagesSupported; + }); + + context(@"when button artworks are already on the file system", ^{ beforeEach(^{ OCMStub([testFileManager hasUploadedFile:[OCMArg isNotNil]]).andReturn(YES); @@ -184,7 +193,7 @@ describe(@"a soft button manager", ^{ }); }); - context(@"when files are not already on the file system, before upload finishes", ^{ + context(@"when button artworks are not already on the file system, before upload finishes", ^{ beforeEach(^{ OCMStub([testFileManager hasUploadedFile:[OCMArg isNotNil]]).andReturn(NO); @@ -211,7 +220,7 @@ describe(@"a soft button manager", ^{ }); }); - context(@"when files are not already on the file system, after upload finishes", ^{ + context(@"when button artworks are not already on the file system, after upload finishes", ^{ beforeEach(^{ OCMStub([testFileManager hasUploadedFile:[OCMArg isNotNil]]).andReturn(NO); OCMStub([testFileManager uploadArtworks:[OCMArg any] completionHandler:[OCMArg invokeBlock]]); @@ -240,6 +249,62 @@ describe(@"a soft button manager", ^{ }); }); + describe(@"uploading soft buttons to a head unit that does not support images", ^{ + beforeEach(^{ + SDLSoftButtonCapabilities *softButtonImagesSupported = [[SDLSoftButtonCapabilities alloc] init]; + softButtonImagesSupported.imageSupported = @NO; + testManager.softButtonCapabilities = softButtonImagesSupported; + }); + + context(@"when the button contains images", ^{ + beforeEach(^{ + testObject1 = [[SDLSoftButtonObject alloc] initWithName:object1Name states:@[object1State1, object1State2] initialStateName:object1State1Name handler:nil]; + testObject2 = [[SDLSoftButtonObject alloc] initWithName:object2Name state:object2State2 handler:nil]; + testManager.softButtonObjects = @[testObject1, testObject2]; + }); + + it(@"should not have attempted to upload any artworks", ^{ + OCMReject([testFileManager uploadArtworks:[OCMArg any] completionHandler:[OCMArg any]]); + }); + + it(@"should set the in progress update to be text buttons", ^{ + NSArray<SDLSoftButton *> *inProgressSoftButtons = testManager.inProgressUpdate.softButtons; + + expect(testManager.hasQueuedUpdate).to(beFalse()); + expect(testManager.inProgressUpdate.mainField1).to(equal(@"")); + expect(inProgressSoftButtons).to(haveCount(2)); + expect(inProgressSoftButtons[0].text).to(equal(object1State1Text)); + expect(inProgressSoftButtons[1].text).to(equal(object2State2Text)); + expect(inProgressSoftButtons[0].image).to(beNil()); + expect(inProgressSoftButtons[1].image.value).to(beNil()); + }); + }); + + context(@"when the button does not contain images", ^{ + beforeEach(^{ + testObject1 = [[SDLSoftButtonObject alloc] initWithName:object1Name states:@[object1State1, object1State2] initialStateName:object1State1Name handler:nil]; + testObject2 = [[SDLSoftButtonObject alloc] initWithName:object2Name state:object2State2 handler:nil]; + testManager.softButtonObjects = @[testObject1, testObject2]; + }); + + it(@"should not have attempted to upload any artworks", ^{ + OCMReject([testFileManager uploadArtworks:[OCMArg any] completionHandler:[OCMArg any]]); + }); + + it(@"should set the in progress update to be text buttons", ^{ + NSArray<SDLSoftButton *> *inProgressSoftButtons = testManager.inProgressUpdate.softButtons; + + expect(testManager.hasQueuedUpdate).to(beFalse()); + expect(testManager.inProgressUpdate.mainField1).to(equal(@"")); + expect(inProgressSoftButtons).to(haveCount(2)); + expect(inProgressSoftButtons[0].text).to(equal(object1State1Text)); + expect(inProgressSoftButtons[1].text).to(equal(object2State2Text)); + expect(inProgressSoftButtons[0].image).to(beNil()); + expect(inProgressSoftButtons[1].image.value).to(beNil()); + }); + }); + }); + describe(@"transitioning soft button states", ^{ beforeEach(^{ OCMStub([testFileManager hasUploadedFile:[OCMArg isNotNil]]).andReturn(YES); |