diff options
author | Joel Fischer <joeljfischer@gmail.com> | 2022-09-22 09:27:46 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-22 09:27:46 -0400 |
commit | bbdaa7bf0d24498cd6aefd4582d8128c23640e8e (patch) | |
tree | 83834b72195037f757f198d2552023d7c5893c2b /SmartDeviceLinkTests | |
parent | 9aec1f6391d109faabbfe335f3bf90e5a5e00ac1 (diff) | |
parent | 34a43ef8e59d42abc718d6d364404c3be86a4d6c (diff) | |
download | sdl_ios-bbdaa7bf0d24498cd6aefd4582d8128c23640e8e.tar.gz |
Merge pull request #2107 from smartdevicelink/bugfix/issue-1781-good-text-failing
Bugfix/issue 1781 good text failing
Diffstat (limited to 'SmartDeviceLinkTests')
-rw-r--r-- | SmartDeviceLinkTests/DevAPISpecs/SDLTextAndGraphicManagerSpec.m | 42 | ||||
-rw-r--r-- | SmartDeviceLinkTests/DevAPISpecs/SDLTextAndGraphicUpdateOperationSpec.m | 114 |
2 files changed, 145 insertions, 11 deletions
diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLTextAndGraphicManagerSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLTextAndGraphicManagerSpec.m index ea230248c..29e9a775f 100644 --- a/SmartDeviceLinkTests/DevAPISpecs/SDLTextAndGraphicManagerSpec.m +++ b/SmartDeviceLinkTests/DevAPISpecs/SDLTextAndGraphicManagerSpec.m @@ -140,19 +140,23 @@ describe(@"text and graphic manager", ^{ }); }); - // when previous updates have bene cancelled - context(@"when previous updates have bene cancelled", ^{ + // without batching + context(@"without batching", ^{ beforeEach(^{ - testManager.textField1 = @"Hello"; - - // This should cancel the first operation - testManager.textField2 = @"Goodbye"; + testManager.batchUpdates = NO; + testManager.textField1 = @"test1"; + testManager.textField2 = @"test2"; + testManager.textField3 = @"test3"; + testManager.textField4 = @"test4"; }); - it(@"should properly queue the new update", ^{ + it(@"should create individual operations and not be cancelled", ^{ expect(testManager.transactionQueue.isSuspended).to(beTrue()); - expect(testManager.transactionQueue.operationCount).to(equal(2)); - expect(testManager.transactionQueue.operations[0].cancelled).to(beTrue()); + expect(testManager.transactionQueue.operationCount).to(equal(4)); + expect(testManager.transactionQueue.operations[0].cancelled).to(beFalse()); + expect(testManager.transactionQueue.operations[1].cancelled).to(beFalse()); + expect(testManager.transactionQueue.operations[2].cancelled).to(beFalse()); + expect(testManager.transactionQueue.operations[3].cancelled).to(beFalse()); }); }); @@ -450,6 +454,7 @@ describe(@"text and graphic manager", ^{ describe(@"when the operation updates the current screen data", ^{ __block SDLTextAndGraphicUpdateOperation *testOperation = nil; __block SDLTextAndGraphicUpdateOperation *testOperation2 = nil; + __block SDLTextAndGraphicUpdateOperation *testOperation3 = nil; beforeEach(^{ testManager.textField1 = @"test"; @@ -475,11 +480,26 @@ describe(@"text and graphic manager", ^{ beforeEach(^{ testManager.currentScreenData = [[SDLTextAndGraphicState alloc] init]; testManager.currentScreenData.textField1 = @"Test1"; - testOperation.currentDataUpdatedHandler(nil, [NSError errorWithDomain:@"any" code:1 userInfo:nil]); + + // Create a "bad data" text field 1, then set it in the manager, which should create an operation (op 2) + SDLTextAndGraphicState *errorState = [[SDLTextAndGraphicState alloc] init]; + errorState.textField1 = @"Bad Data"; + testManager.textField1 = errorState.textField1; + + // Create a "good data text field 4, which should create a second operation (op 3) + testManager.textField4 = @"Good Data"; + testOperation3 = testManager.transactionQueue.operations[3]; + + // Simulate a failure of the first operation + NSDictionary *userInfo = @{ + SDLTextAndGraphicFailedScreenStateErrorKey: errorState + }; + testOperation.currentDataUpdatedHandler(nil, [NSError errorWithDomain:@"any" code:1 userInfo:userInfo]); }); - it(@"should reset the manager's data", ^{ + it(@"should reset the manager's data and update other operations updated state", ^{ expect(testManager.textField1).to(equal(testManager.currentScreenData.textField1)); + expect(testOperation3.updatedState.textField1).to(equal(testManager.currentScreenData.textField1)); }); }); }); diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLTextAndGraphicUpdateOperationSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLTextAndGraphicUpdateOperationSpec.m index b03252c25..a3f780ab0 100644 --- a/SmartDeviceLinkTests/DevAPISpecs/SDLTextAndGraphicUpdateOperationSpec.m +++ b/SmartDeviceLinkTests/DevAPISpecs/SDLTextAndGraphicUpdateOperationSpec.m @@ -797,6 +797,116 @@ describe(@"the text and graphic operation", ^{ }); }); + // updating with error state + describe(@"updating with error state", ^{ + beforeEach(^{ + updatedState = [[SDLTextAndGraphicState alloc] init]; + updatedState.textField1 = field1String; + updatedState.textField2 = field2String; + updatedState.textField3 = field3String; + updatedState.textField4 = field4String; + updatedState.mediaTrackTextField = mediaTrackString; + updatedState.title = titleString; + updatedState.primaryGraphic = testArtwork; + updatedState.secondaryGraphic = testArtwork2; + updatedState.alignment = SDLTextAlignmentLeft; + updatedState.textField1Type = SDLMetadataTypeMediaTitle; + updatedState.textField2Type = SDLMetadataTypeMediaArtist; + updatedState.textField3Type = SDLMetadataTypeMediaAlbum; + updatedState.textField4Type = SDLMetadataTypeMediaYear; + + emptyCurrentData = [[SDLTextAndGraphicState alloc] init]; + + testOp = [[SDLTextAndGraphicUpdateOperation alloc] initWithConnectionManager:testConnectionManager fileManager:mockFileManager currentCapabilities:windowCapability currentScreenData:emptyCurrentData newState:updatedState currentScreenDataUpdatedHandler:^(SDLTextAndGraphicState * _Nullable newScreenData, NSError * _Nullable error) {} updateCompletionHandler:nil]; + [testOp start]; + }); + + it(@"should reset to current screen data for equivalent properties in updated state and error state", ^{ + // Create an error state that matches the updated state, which should reset the updated state + SDLTextAndGraphicState *errorState = [updatedState copy]; + errorState.primaryGraphic = testArtwork; + errorState.secondaryGraphic = testArtwork2; + + [testOp updateTargetStateWithErrorState:errorState]; + + expect(updatedState.textField1).to(beNil()); + expect(updatedState.textField2).to(beNil()); + expect(updatedState.textField3).to(beNil()); + expect(updatedState.textField4).to(beNil()); + expect(updatedState.mediaTrackTextField).to(beNil()); + expect(updatedState.title).to(beNil()); + expect(updatedState.primaryGraphic).to(beNil()); + expect(updatedState.secondaryGraphic).to(beNil()); + expect(updatedState.textField1Type).to(beNil()); + expect(updatedState.textField2Type).to(beNil()); + expect(updatedState.textField3Type).to(beNil()); + expect(updatedState.textField4Type).to(beNil()); + }); + + it(@"should not reset to current screen data for non equivalent properties in updated state and error state", ^{ + // Save an original of the updatedState for confirming no changes later + SDLTextAndGraphicState *originalState = [updatedState copy]; + originalState.primaryGraphic = testArtwork; + originalState.secondaryGraphic = testArtwork2; + + // Create an error state that does not match the updated state, which should not reset the updated state + SDLTextAndGraphicState *errorState = [[SDLTextAndGraphicState alloc] init]; + errorState.textField1 = @"Error Text"; + errorState.textField2 = @"Error Text"; + errorState.textField3 = @"Error Text"; + errorState.textField4 = @"Error Text"; + errorState.mediaTrackTextField = @"Error Text"; + errorState.title = @"Error Text"; + errorState.primaryGraphic = testArtwork2; + errorState.secondaryGraphic = testArtwork; + errorState.alignment = SDLTextAlignmentRight; + errorState.textField1Type = SDLMetadataTypeMediaYear; + errorState.textField2Type = SDLMetadataTypeMediaAlbum; + errorState.textField3Type = SDLMetadataTypeMediaArtist; + errorState.textField4Type = SDLMetadataTypeMediaTitle; + + [testOp updateTargetStateWithErrorState:errorState]; + + expect(updatedState.textField1).to(equal(originalState.textField1)); + expect(updatedState.textField2).to(equal(originalState.textField2)); + expect(updatedState.textField3).to(equal(originalState.textField3)); + expect(updatedState.textField4).to(equal(originalState.textField4)); + expect(updatedState.mediaTrackTextField).to(equal(originalState.mediaTrackTextField)); + expect(updatedState.title).to(equal(originalState.title)); + expect(updatedState.primaryGraphic).to(equal(originalState.primaryGraphic)); + expect(updatedState.secondaryGraphic).to(equal(originalState.secondaryGraphic)); + expect(updatedState.textField1Type).to(equal(originalState.textField1Type)); + expect(updatedState.textField2Type).to(equal(originalState.textField2Type)); + expect(updatedState.textField3Type).to(equal(originalState.textField3Type)); + expect(updatedState.textField4Type).to(equal(originalState.textField4Type)); + }); + + it(@"should not reset to current screen data for nil error state", ^{ + // Save an original of the updatedState for confirming no changes later + SDLTextAndGraphicState *originalState = [updatedState copy]; + originalState.primaryGraphic = testArtwork; + originalState.secondaryGraphic = testArtwork2; + + // Create an empty error state + SDLTextAndGraphicState *errorState = [[SDLTextAndGraphicState alloc] init]; + + [testOp updateTargetStateWithErrorState:errorState]; + + expect(updatedState.textField1).to(equal(originalState.textField1)); + expect(updatedState.textField2).to(equal(originalState.textField2)); + expect(updatedState.textField3).to(equal(originalState.textField3)); + expect(updatedState.textField4).to(equal(originalState.textField4)); + expect(updatedState.mediaTrackTextField).to(equal(originalState.mediaTrackTextField)); + expect(updatedState.title).to(equal(originalState.title)); + expect(updatedState.primaryGraphic).to(equal(originalState.primaryGraphic)); + expect(updatedState.secondaryGraphic).to(equal(originalState.secondaryGraphic)); + expect(updatedState.textField1Type).to(equal(originalState.textField1Type)); + expect(updatedState.textField2Type).to(equal(originalState.textField2Type)); + expect(updatedState.textField3Type).to(equal(originalState.textField3Type)); + expect(updatedState.textField4Type).to(equal(originalState.textField4Type)); + }); + }); + // updating image fields describe(@"updating image fields", ^{ beforeEach(^{ @@ -933,6 +1043,8 @@ describe(@"the text and graphic operation", ^{ // Then it should return a failure and finish expect(receivedState).to(beNil()); expect(receivedError).toNot(beNil()); + expect(receivedError.userInfo[NSUnderlyingErrorKey]).toNot(beNil()); + expect(receivedError.userInfo[SDLTextAndGraphicFailedScreenStateErrorKey]).to(equal(updatedState)); expect(completionError).toNot(beNil()); expect(testOp.isFinished).to(beTrue()); @@ -1295,6 +1407,8 @@ describe(@"the text and graphic operation", ^{ [testConnectionManager respondToLastRequestWithResponse:failShowResponse]; expect(receivedState).to(beNil()); expect(receivedError).toNot(beNil()); + expect(receivedError.userInfo[NSUnderlyingErrorKey]).toNot(beNil()); + expect(receivedError.userInfo[SDLTextAndGraphicFailedScreenStateErrorKey]).to(equal(updatedState)); expect(testOp.isFinished).to(beTrue()); }); |