summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Beharry <justin.beharry@livio.io>2022-09-01 14:07:49 -0400
committerJustin Beharry <justin.beharry@livio.io>2022-09-01 14:07:49 -0400
commitb5465e668952f8a5f665a167326e3cef28346f68 (patch)
tree696aa62e420ecefb8bd147201c7735e4876968ff
parent927b5cea26db309a578bff8c4e1de95910e2e581 (diff)
downloadsdl_ios-b5465e668952f8a5f665a167326e3cef28346f68.tar.gz
Update errorState to use isEqual and improve test
-rw-r--r--SmartDeviceLink/private/SDLTextAndGraphicUpdateOperation.m29
-rw-r--r--SmartDeviceLinkTests/DevAPISpecs/SDLTextAndGraphicUpdateOperationSpec.m89
2 files changed, 94 insertions, 24 deletions
diff --git a/SmartDeviceLink/private/SDLTextAndGraphicUpdateOperation.m b/SmartDeviceLink/private/SDLTextAndGraphicUpdateOperation.m
index a2479570b..6f0680581 100644
--- a/SmartDeviceLink/private/SDLTextAndGraphicUpdateOperation.m
+++ b/SmartDeviceLink/private/SDLTextAndGraphicUpdateOperation.m
@@ -100,20 +100,21 @@ NSString *const SDLTextAndGraphicFailedScreenStateErrorKey = @"failedScreenState
}
- (void)updateTargetStateWithErrorState:(SDLTextAndGraphicState *)errorState {
- self.updatedState.textField1 = (errorState.textField1 == self.updatedState.textField1) ? self.currentScreenData.textField1 : self.updatedState.textField1;
- self.updatedState.textField2 = (errorState.textField2 == self.updatedState.textField2) ? self.currentScreenData.textField2 : self.updatedState.textField2;
- self.updatedState.textField3 = (errorState.textField3 == self.updatedState.textField3) ? self.currentScreenData.textField3 : self.updatedState.textField3;
- self.updatedState.textField4 = (errorState.textField4 == self.updatedState.textField4) ? self.currentScreenData.textField4 : self.updatedState.textField4;
- self.updatedState.mediaTrackTextField = (errorState.mediaTrackTextField == self.updatedState.mediaTrackTextField) ? self.currentScreenData.mediaTrackTextField : self.updatedState.mediaTrackTextField;
- self.updatedState.title = (errorState.title == self.updatedState.title) ? self.currentScreenData.title : self.updatedState.title;
- self.updatedState.primaryGraphic = (errorState.primaryGraphic == self.updatedState.primaryGraphic) ? self.currentScreenData.primaryGraphic : self.updatedState.primaryGraphic;
- self.updatedState.secondaryGraphic = (errorState.secondaryGraphic == self.updatedState.secondaryGraphic) ? self.currentScreenData.secondaryGraphic : self.updatedState.secondaryGraphic;
- self.updatedState.alignment = (errorState.alignment == self.updatedState.alignment) ? self.currentScreenData.alignment : self.updatedState.alignment;
- self.updatedState.textField1Type = (errorState.textField1Type == self.updatedState.textField1Type) ? self.currentScreenData.textField1Type : self.updatedState.textField1Type;
- self.updatedState.textField2Type = (errorState.textField2Type == self.updatedState.textField2Type) ? self.currentScreenData.textField2Type : self.updatedState.textField2Type;
- self.updatedState.textField3Type = (errorState.textField3Type == self.updatedState.textField3Type) ? self.currentScreenData.textField3Type : self.updatedState.textField3Type;
- self.updatedState.textField4Type = (errorState.textField4Type == self.updatedState.textField4Type) ? self.currentScreenData.textField4Type : self.updatedState.textField4Type;
- self.updatedState.templateConfig = (errorState.templateConfig == self.updatedState.templateConfig) ? self.currentScreenData.templateConfig : self.updatedState.templateConfig;
+ self.updatedState.textField1 = [errorState.textField1 isEqualToString:self.updatedState.textField1] ? self.currentScreenData.textField1 : self.updatedState.textField1;
+ self.updatedState.textField2 = [errorState.textField2 isEqualToString:self.updatedState.textField2] ? self.currentScreenData.textField2 : self.updatedState.textField2;
+ self.updatedState.textField3 = [errorState.textField3 isEqualToString:self.updatedState.textField3] ? self.currentScreenData.textField3 : self.updatedState.textField3;
+ self.updatedState.textField4 = [errorState.textField4 isEqualToString:self.updatedState.textField4] ? self.currentScreenData.textField4 : self.updatedState.textField4;
+ self.updatedState.mediaTrackTextField = [errorState.mediaTrackTextField isEqualToString:self.updatedState.mediaTrackTextField] ? self.currentScreenData.mediaTrackTextField : self.updatedState.mediaTrackTextField;
+ self.updatedState.title = [errorState.title isEqualToString:self.updatedState.title] ? self.currentScreenData.title : self.updatedState.title;
+ self.updatedState.primaryGraphic = [errorState.primaryGraphic isEqual:self.updatedState.primaryGraphic] ? self.currentScreenData.primaryGraphic : self.updatedState.primaryGraphic;
+ [errorState.primaryGraphic isEqual:self.updatedState.primaryGraphic];
+ self.updatedState.secondaryGraphic = [errorState.secondaryGraphic isEqual:self.updatedState.secondaryGraphic] ? self.currentScreenData.secondaryGraphic : self.updatedState.secondaryGraphic;
+ self.updatedState.alignment = [errorState.alignment isEqualToEnum:self.updatedState.alignment] ? self.currentScreenData.alignment : self.updatedState.alignment;
+ self.updatedState.textField1Type = [errorState.textField1Type isEqualToEnum:self.updatedState.textField1Type] ? self.currentScreenData.textField1Type : self.updatedState.textField1Type;
+ self.updatedState.textField2Type = [errorState.textField2Type isEqualToEnum:self.updatedState.textField2Type] ? self.currentScreenData.textField2Type : self.updatedState.textField2Type;
+ self.updatedState.textField3Type = [errorState.textField3Type isEqualToEnum:self.updatedState.textField3Type] ? self.currentScreenData.textField3Type : self.updatedState.textField3Type;
+ self.updatedState.textField4Type = [errorState.textField4Type isEqualToEnum:self.updatedState.textField4Type] ? self.currentScreenData.textField4Type : self.updatedState.textField4Type;
+ self.updatedState.templateConfig = [errorState.templateConfig isEqual:self.updatedState.templateConfig] ? self.currentScreenData.templateConfig : self.updatedState.templateConfig;
}
#pragma mark - Send Show / Set Display Layout
diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLTextAndGraphicUpdateOperationSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLTextAndGraphicUpdateOperationSpec.m
index 004ee66ab..a3f780ab0 100644
--- a/SmartDeviceLinkTests/DevAPISpecs/SDLTextAndGraphicUpdateOperationSpec.m
+++ b/SmartDeviceLinkTests/DevAPISpecs/SDLTextAndGraphicUpdateOperationSpec.m
@@ -802,8 +802,20 @@ describe(@"the text and graphic operation", ^{
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];
@@ -811,30 +823,87 @@ describe(@"the text and graphic operation", ^{
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 = [[SDLTextAndGraphicState alloc] init];
- errorState.textField1 = updatedState.textField1;
- errorState.primaryGraphic = updatedState.primaryGraphic;
- errorState.secondaryGraphic = updatedState.secondaryGraphic;
+ 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 = nil;
- errorState.primaryGraphic = nil;
- errorState.secondaryGraphic = nil;
+ 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).toNot(beNil());
- expect(updatedState.primaryGraphic).toNot(beNil());
- expect(updatedState.secondaryGraphic).toNot(beNil());
+ 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));
});
});