diff options
author | Joel Fischer <joeljfischer@gmail.com> | 2020-08-20 15:03:30 -0400 |
---|---|---|
committer | Joel Fischer <joeljfischer@gmail.com> | 2020-08-20 15:03:30 -0400 |
commit | 863a81abda906f1b93f4f184dfc2cfb591f0be63 (patch) | |
tree | a7b83badae9d6fb7a791383f1c29d44cd8ce5dc6 | |
parent | cf07f375b05704f8d890a537d10a268e29c4a125 (diff) | |
download | sdl_ios-863a81abda906f1b93f4f184dfc2cfb591f0be63.tar.gz |
Text and graphic operation spec updates
-rw-r--r-- | SmartDeviceLink/SDLTextAndGraphicState.m | 10 | ||||
-rw-r--r-- | SmartDeviceLinkTests/DevAPISpecs/SDLTextAndGraphicUpdateOperationSpec.m | 121 |
2 files changed, 127 insertions, 4 deletions
diff --git a/SmartDeviceLink/SDLTextAndGraphicState.m b/SmartDeviceLink/SDLTextAndGraphicState.m index 24c94089e..d91b4a6aa 100644 --- a/SmartDeviceLink/SDLTextAndGraphicState.m +++ b/SmartDeviceLink/SDLTextAndGraphicState.m @@ -8,6 +8,8 @@ #import "SDLTextAndGraphicState.h" +#import "SDLArtwork.h" + @implementation SDLTextAndGraphicState - (instancetype)initWithTextField1:(NSString *)textField1 textField2:(NSString *)textField2 textField3:(NSString *)textField3 textField4:(NSString *)textField4 mediaText:(NSString *)mediaTrackTextField title:(NSString *)title primaryGraphic:(SDLArtwork *)primaryGraphic secondaryGraphic:(SDLArtwork *)secondaryGraphic alignment:(SDLTextAlignment)alignment textField1Type:(SDLMetadataType)textField1Type textField2Type:(SDLMetadataType)textField2Type textField3Type:(SDLMetadataType)textField3Type textField4Type:(SDLMetadataType)textField4Type { @@ -31,4 +33,12 @@ return self; } +- (NSString *)description { + return [NSString stringWithFormat:@"Text Field 1: %@, 2: %@, 3: %@, 4: %@, media track: %@, title: %@, alignment: %@, text 1 type: %@, 2: %@, 3: %@, 4: %@, primary graphic: %@, secondary graphic: %@", _textField1, _textField2, _textField3, _textField4, _mediaTrackTextField, _title, _alignment, _textField1Type, _textField2Type, _textField3Type, _textField4Type, _primaryGraphic, _secondaryGraphic]; +} + +- (id)copyWithZone:(nullable NSZone *)zone { + return [[SDLTextAndGraphicState allocWithZone:zone] initWithTextField1:[_textField1 copy] textField2:[_textField2 copy] textField3:[_textField3 copy] textField4:[_textField4 copy] mediaText:[_mediaTrackTextField copy] title:[_title copy] primaryGraphic:[_primaryGraphic copy] secondaryGraphic:[_secondaryGraphic copy] alignment:[_alignment copy] textField1Type:[_textField1Type copy] textField2Type:[_textField2Type copy] textField3Type:[_textField3Type copy] textField4Type:[_textField4Type copy]]; +} + @end diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLTextAndGraphicUpdateOperationSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLTextAndGraphicUpdateOperationSpec.m index e1980540c..1f5b34426 100644 --- a/SmartDeviceLinkTests/DevAPISpecs/SDLTextAndGraphicUpdateOperationSpec.m +++ b/SmartDeviceLinkTests/DevAPISpecs/SDLTextAndGraphicUpdateOperationSpec.m @@ -60,7 +60,7 @@ describe(@"the text and graphic operation", ^{ beforeEach(^{ testConnectionManager = [[TestConnectionManager alloc] init]; - mockFileManager = OCMStrictClassMock([SDLFileManager class]); + mockFileManager = OCMClassMock([SDLFileManager class]); successShowResponse.success = @YES; successShowResponse.resultCode = SDLResultSuccess; @@ -626,6 +626,32 @@ describe(@"the text and graphic operation", ^{ }); }); }); + + // should call the update handler when done + context(@"should call the update handler when done", ^{ + __block BOOL didCallHandler = NO; + beforeEach(^{ + windowCapability = [[SDLWindowCapability alloc] init]; + windowCapability.textFields = @[fieldLine1, fieldLine2, fieldLine3, fieldLine4]; + + updatedState = [[SDLTextAndGraphicState alloc] init]; + updatedState.textField1 = field1String; + updatedState.textField2 = field2String; + updatedState.textField3 = field3String; + updatedState.textField4 = field4String; + + testOp = [[SDLTextAndGraphicUpdateOperation alloc] initWithConnectionManager:testConnectionManager fileManager:mockFileManager currentCapabilities:windowCapability currentScreenData:emptyCurrentDataShow newState:updatedState updateCompletionHandler:^(NSError * _Nullable error) { + didCallHandler = YES; + }]; + [testOp start]; + + [testConnectionManager respondToLastRequestWithResponse:successShowResponse]; + }); + + it(@"should send the text and then call the update handler", ^{ + expect(didCallHandler).to(equal(YES)); + }); + }); }); // updating image fields @@ -644,12 +670,48 @@ describe(@"the text and graphic operation", ^{ // when only graphic is supported context(@"when only graphic is supported", ^{ + beforeEach(^{ + windowCapability.imageFields = @[fieldGraphic]; + + updatedState = [[SDLTextAndGraphicState alloc] init]; + updatedState.textField1 = field1String; + updatedState.primaryGraphic = testArtwork; + updatedState.secondaryGraphic = testArtwork2; + + testOp = [[SDLTextAndGraphicUpdateOperation alloc] initWithConnectionManager:testConnectionManager fileManager:mockFileManager currentCapabilities:windowCapability currentScreenData:emptyCurrentDataShow newState:updatedState updateCompletionHandler:nil]; + [testOp start]; + }); + it(@"should send a show and not upload any artworks", ^{ + expect(testConnectionManager.receivedRequests).to(haveCount(1)); + SDLShow *firstSentRequest = testConnectionManager.receivedRequests[0]; + expect(firstSentRequest.mainField1).to(equal(field1String)); + expect(firstSentRequest.mainField2).to(beEmpty()); + expect(firstSentRequest.graphic).toNot(beNil()); + expect(firstSentRequest.secondaryGraphic).to(beNil()); + }); }); // when both image fields are supported context(@"when both image fields are supported", ^{ + beforeEach(^{ + updatedState = [[SDLTextAndGraphicState alloc] init]; + updatedState.textField1 = field1String; + updatedState.primaryGraphic = testArtwork; + updatedState.secondaryGraphic = testArtwork2; + + testOp = [[SDLTextAndGraphicUpdateOperation alloc] initWithConnectionManager:testConnectionManager fileManager:mockFileManager currentCapabilities:windowCapability currentScreenData:emptyCurrentDataShow newState:updatedState updateCompletionHandler:nil]; + [testOp start]; + }); + it(@"should send a show and not upload any artworks", ^{ + expect(testConnectionManager.receivedRequests).to(haveCount(1)); + SDLShow *firstSentRequest = testConnectionManager.receivedRequests[0]; + expect(firstSentRequest.mainField1).to(equal(field1String)); + expect(firstSentRequest.mainField2).to(beEmpty()); + expect(firstSentRequest.graphic).toNot(beNil()); + expect(firstSentRequest.secondaryGraphic).toNot(beNil()); + }); }); }); // TODO @@ -657,6 +719,7 @@ describe(@"the text and graphic operation", ^{ context(@"when images are not on the head unit", ^{ beforeEach(^{ OCMStub([mockFileManager hasUploadedFile:[OCMArg isNotNil]]).andReturn(NO); + OCMStub([mockFileManager uploadArtworks:[OCMArg any] progressHandler:[OCMArg any] completionHandler:([OCMArg invokeBlockWithArgs:[NSNull null], [NSNull null], nil])]); }); // when there is text to update as well @@ -679,17 +742,67 @@ describe(@"the text and graphic operation", ^{ [testConnectionManager respondToLastRequestWithResponse:successShowResponse]; // Then the images should be uploaded + OCMExpect([mockFileManager uploadArtworks:[OCMArg any] progressHandler:[OCMArg any] completionHandler:[OCMArg any]]); - // Then the full show should be sent - }); // TODO + // Then the full show should be sent, this is currently not testable because the `mockFileManager hasUploadedFile` should change mid-call of `uploadArtworks` after the artwork is uploaded but before the final Show is sent in sdl_createImageOnlyShowWithPrimaryArtwork. +// expect(testConnectionManager.receivedRequests).to(haveCount(2)); +// SDLShow *secondSentRequest = testConnectionManager.receivedRequests[1]; +// expect(secondSentRequest.mainField1).to(beNil()); +// expect(secondSentRequest.graphic).toNot(beNil()); + }); }); // when there is no text to update context(@"when there is no text to update", ^{ + beforeEach(^{ + updatedState = [[SDLTextAndGraphicState alloc] init]; + updatedState.primaryGraphic = testArtwork; + + testOp = [[SDLTextAndGraphicUpdateOperation alloc] initWithConnectionManager:testConnectionManager fileManager:mockFileManager currentCapabilities:windowCapability currentScreenData:emptyCurrentDataShow newState:updatedState updateCompletionHandler:nil]; + [testOp start]; + }); + it(@"should just upload the images, then send the full show", ^{ + // First the text only show should be sent + expect(testConnectionManager.receivedRequests).to(haveCount(1)); + SDLShow *firstSentRequest = testConnectionManager.receivedRequests[0]; + expect(firstSentRequest.mainField1).to(beEmpty()); + expect(firstSentRequest.graphic).to(beNil()); + [testConnectionManager respondToLastRequestWithResponse:successShowResponse]; + + // Then the images should be uploaded + OCMExpect([mockFileManager uploadArtworks:[OCMArg any] progressHandler:[OCMArg any] completionHandler:[OCMArg any]]); + // Then the full show should be sent, this is currently not testable because the `mockFileManager hasUploadedFile` should change mid-call of `uploadArtworks` after the artwork is uploaded but before the final Show is sent in sdl_createImageOnlyShowWithPrimaryArtwork. +// expect(testConnectionManager.receivedRequests).to(haveCount(2)); +// SDLShow *secondSentRequest = testConnectionManager.receivedRequests[1]; +// expect(secondSentRequest.mainField1).to(beEmpty()); +// expect(secondSentRequest.graphic).toNot(beNil()); + }); + }); + + // when the image is a static icon + context(@"when the image is a static icon", ^{ + beforeEach(^{ + updatedState = [[SDLTextAndGraphicState alloc] init]; + updatedState.primaryGraphic = testStaticIcon; + + testOp = [[SDLTextAndGraphicUpdateOperation alloc] initWithConnectionManager:testConnectionManager fileManager:mockFileManager currentCapabilities:windowCapability currentScreenData:emptyCurrentDataShow newState:updatedState updateCompletionHandler:nil]; + [testOp start]; }); - }); // TODO + + it(@"should not upload the artwork", ^{ + // The full show should be sent immediately + expect(testConnectionManager.receivedRequests).to(haveCount(1)); + SDLShow *firstSentRequest = testConnectionManager.receivedRequests[0]; + expect(firstSentRequest.mainField1).to(beEmpty()); + expect(firstSentRequest.graphic).toNot(beNil()); + [testConnectionManager respondToLastRequestWithResponse:successShowResponse]; + + // Then the images should be uploaded + OCMReject([mockFileManager uploadArtworks:[OCMArg any] progressHandler:[OCMArg any] completionHandler:[OCMArg any]]); + }); + }); }); }); }); |