diff options
author | Joel Fischer <joeljfischer@gmail.com> | 2020-09-16 15:04:56 -0400 |
---|---|---|
committer | Joel Fischer <joeljfischer@gmail.com> | 2020-09-16 15:04:56 -0400 |
commit | adfe0098d5c0e968107cc3930a83b2fc39105733 (patch) | |
tree | d4e6b770d20863cdbd045c5d9cf7b73a037ffd13 | |
parent | 6d9df36b00ed43e0239db514fac6c99c07426761 (diff) | |
download | sdl_ios-adfe0098d5c0e968107cc3930a83b2fc39105733.tar.gz |
Add additional tests for canceling and failing text and image operationsfeature/issue-1612-screen-manager-template-management
-rw-r--r-- | SmartDeviceLinkTests/DevAPISpecs/SDLTextAndGraphicUpdateOperationSpec.m | 77 |
1 files changed, 61 insertions, 16 deletions
diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLTextAndGraphicUpdateOperationSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLTextAndGraphicUpdateOperationSpec.m index 7b7265d4d..0c70ec4f7 100644 --- a/SmartDeviceLinkTests/DevAPISpecs/SDLTextAndGraphicUpdateOperationSpec.m +++ b/SmartDeviceLinkTests/DevAPISpecs/SDLTextAndGraphicUpdateOperationSpec.m @@ -764,6 +764,7 @@ describe(@"the text and graphic operation", ^{ }); }); + // should call the currentScreenDataUpdatedHandler when the screen data is updated context(@"should call the currentScreenDataUpdatedHandler when the screen data is updated", ^{ __block SDLTextAndGraphicState *updatedData = nil; beforeEach(^{ @@ -868,26 +869,71 @@ describe(@"the text and graphic operation", ^{ updatedState.textField1 = field1String; updatedState.primaryGraphic = testArtwork; - testOp = [[SDLTextAndGraphicUpdateOperation alloc] initWithConnectionManager:testConnectionManager fileManager:mockFileManager currentCapabilities:windowCapability currentScreenData:emptyCurrentData newState:updatedState currentScreenDataUpdatedHandler:^(SDLTextAndGraphicState * _Nullable newScreenData, NSError * _Nullable error) {} updateCompletionHandler:nil]; + testOp = [[SDLTextAndGraphicUpdateOperation alloc] initWithConnectionManager:testConnectionManager fileManager:mockFileManager currentCapabilities:windowCapability currentScreenData:emptyCurrentData newState:updatedState currentScreenDataUpdatedHandler:^(SDLTextAndGraphicState * _Nullable newScreenData, NSError * _Nullable error) { + receivedState = newScreenData; + receivedError = error; + } updateCompletionHandler:^(NSError * _Nullable error) { + completionError = error; + }]; [testOp start]; }); - it(@"should send the text, then 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(equal(field1String)); - expect(firstSentRequest.graphic).to(beNil()); - [testConnectionManager respondToLastRequestWithResponse:successShowResponse]; + context(@"when the text show succeeds", ^{ + it(@"should then 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(equal(field1String)); + 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(beNil()); + // expect(secondSentRequest.graphic).toNot(beNil()); + }); + }); - // Then the images should be uploaded - OCMExpect([mockFileManager uploadArtworks:[OCMArg any] progressHandler:[OCMArg any] completionHandler:[OCMArg any]]); + context(@"when the text show fails", ^{ + it(@"should return an error and finish the operation", ^{ + // First the text only show should be sent + expect(testConnectionManager.receivedRequests).to(haveCount(1)); + SDLShow *firstSentRequest = testConnectionManager.receivedRequests[0]; + expect(firstSentRequest.mainField1).to(equal(field1String)); + expect(firstSentRequest.graphic).to(beNil()); + [testConnectionManager respondToLastRequestWithResponse:failShowResponse]; - // 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()); + // Then it should return a failure and finish + expect(receivedState).to(beNil()); + expect(receivedError).toNot(beNil()); + expect(completionError).toNot(beNil()); + + expect(testOp.isFinished).to(beTrue()); + }); + }); + + context(@"when cancelled before the text show returns", ^{ + it(@"should return an error and finish the operation", ^{ + // First the text only show should be sent + expect(testConnectionManager.receivedRequests).to(haveCount(1)); + SDLShow *firstSentRequest = testConnectionManager.receivedRequests[0]; + expect(firstSentRequest.mainField1).to(equal(field1String)); + expect(firstSentRequest.graphic).to(beNil()); + + [testOp cancel]; + [testConnectionManager respondToLastRequestWithResponse:successShowResponse]; + + // Then it should return a failure and finish + expect(receivedState).toNot(beNil()); + expect(receivedError).to(beNil()); + expect(completionError).toNot(beNil()); + + expect(testOp.isFinished).to(beTrue()); + }); }); }); @@ -1208,7 +1254,6 @@ describe(@"the text and graphic operation", ^{ [testConnectionManager respondToLastRequestWithResponse:failShowResponse]; expect(receivedState).to(beNil()); - expect(receivedState).to(beNil()); expect(receivedError).toNot(beNil()); expect(testOp.isFinished).to(beTrue()); |