diff options
author | Joel Fischer <joeljfischer@gmail.com> | 2021-08-09 15:35:34 -0400 |
---|---|---|
committer | Joel Fischer <joeljfischer@gmail.com> | 2021-08-09 15:35:34 -0400 |
commit | f7f5aad1a8ca5a285b1240b9dbc79ed1ce543dab (patch) | |
tree | c2f025a87cde0c53dbe9b0b0629c82da022a8183 | |
parent | e37c26fcfaab20aee2abb7a753244fd4a5f92487 (diff) | |
download | sdl_ios-f7f5aad1a8ca5a285b1240b9dbc79ed1ce543dab.tar.gz |
In progress test updates
4 files changed, 196 insertions, 17 deletions
diff --git a/SmartDeviceLink/private/SDLMenuReplaceUtilities.m b/SmartDeviceLink/private/SDLMenuReplaceUtilities.m index 1003cc7e2..08f855ebb 100644 --- a/SmartDeviceLink/private/SDLMenuReplaceUtilities.m +++ b/SmartDeviceLink/private/SDLMenuReplaceUtilities.m @@ -65,6 +65,7 @@ } #pragma mark - RPC Commands +#pragma mark Retrieving Values + (UInt32)commandIdForRPCRequest:(SDLRPCRequest *)request { UInt32 commandId = 0; @@ -92,6 +93,8 @@ return position; } +#pragma mark Generating RPCs + + (NSArray<SDLRPCRequest *> *)deleteCommandsForCells:(NSArray<SDLMenuCell *> *)cells { NSMutableArray<SDLRPCRequest *> *mutableDeletes = [NSMutableArray array]; for (SDLMenuCell *cell in cells) { @@ -188,9 +191,7 @@ return [[SDLAddSubMenu alloc] initWithMenuID:cell.cellId menuName:cell.uniqueTitle position:@(position) menuIcon:icon menuLayout:submenuLayout parentID:nil secondaryText:secondaryText tertiaryText:tertiaryText secondaryImage:secondaryIcon]; } -#pragma mark - Updating Menu Cells - -#pragma mark Remove Cell +#pragma mark - Updating Menu Cells In Lists + (BOOL)removeMenuCellFromList:(NSMutableArray<SDLMenuCell *> *)menuCellList withCmdId:(UInt32)commandId { for (SDLMenuCell *menuCell in menuCellList) { @@ -212,8 +213,6 @@ return NO; } -#pragma mark Inserting Cell - + (BOOL)addMenuRequestWithCommandId:(UInt32)commandId position:(UInt16)position fromNewMenuList:(NSArray<SDLMenuCell *> *)newMenuList toMainMenuList:(NSMutableArray <SDLMenuCell *> *)mainMenuList { SDLMenuCell *addedCell = nil; for (SDLMenuCell *cell in newMenuList) { diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceUtilitiesSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceUtilitiesSpec.m index 3fd3004de..4b72308ec 100644 --- a/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceUtilitiesSpec.m +++ b/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceUtilitiesSpec.m @@ -20,61 +20,241 @@ QuickSpecBegin(SDLMenuReplaceUtilitiesSpec) -describe(@"finding all artworks from cells", ^{ - __block NSArray<SDLMenuCell *> *testMenuCells = nil; - __block SDLFileManager *mockFileManager = nil; - __block SDLWindowCapability *testWindowCapability = nil; - __block NSArray<SDLTextField *> *allSupportedTextFields = nil; - __block NSArray<SDLImageField *> *allSupportedImageFields = nil; +__block NSArray<SDLMenuCell *> *testMenuCells = nil; +__block SDLFileManager *mockFileManager = nil; +__block SDLWindowCapability *testWindowCapability = nil; +__block NSArray<SDLTextField *> *allSupportedTextFields = @[ + [[SDLTextField alloc] initWithName:SDLTextFieldNameMenuCommandSecondaryText characterSet:SDLCharacterSetUtf8 width:100 rows:1], + [[SDLTextField alloc] initWithName:SDLTextFieldNameMenuCommandTertiaryText characterSet:SDLCharacterSetUtf8 width:100 rows:1], + [[SDLTextField alloc] initWithName:SDLTextFieldNameMenuSubMenuSecondaryText characterSet:SDLCharacterSetUtf8 width:100 rows:1], + [[SDLTextField alloc] initWithName:SDLTextFieldNameMenuSubMenuTertiaryText characterSet:SDLCharacterSetUtf8 width:100 rows:1] +]; +__block NSArray<SDLImageField *> *allSupportedImageFields = @[ + [[SDLImageField alloc] initWithName:SDLImageFieldNameCommandIcon imageTypeSupported:@[SDLImageTypeDynamic] imageResolution:nil], + [[SDLImageField alloc] initWithName:SDLImageFieldNameMenuCommandSecondaryImage imageTypeSupported:@[SDLImageTypeDynamic] imageResolution:nil], + [[SDLImageField alloc] initWithName:SDLImageFieldNameSubMenuIcon imageTypeSupported:@[SDLImageTypeDynamic] imageResolution:nil], + [[SDLImageField alloc] initWithName:SDLImageFieldNameMenuSubMenuSecondaryImage imageTypeSupported:@[SDLImageTypeDynamic] imageResolution:nil] +]; +describe(@"finding all artworks from cells", ^{ beforeEach(^{ mockFileManager = OCMClassMock([SDLFileManager class]); + testWindowCapability = [[SDLWindowCapability alloc] init]; }); - context(@"when all the files are uploaded", ^{ + context(@"when all the files need to be uploaded", ^{ beforeEach(^{ - OCMStub([mockFileManager fileNeedsUpload:[OCMArg any]]); + OCMStub([mockFileManager fileNeedsUpload:[OCMArg any]]).andReturn(NO); }); context(@"when the window capability doesn't support the primary image", ^{ beforeEach(^{ + testWindowCapability.textFields = allSupportedTextFields; + }); + it(@"should return an empty list of artworks to upload", ^{ + NSArray<SDLArtwork *> *artworksToUpload = [SDLMenuReplaceUtilities findAllArtworksToBeUploadedFromCells:SDLMenuReplaceUtilitiesSpecHelpers.topLevelOnlyMenu fileManager:mockFileManager windowCapability:testWindowCapability]; + + expect(artworksToUpload).to(beEmpty()); }); }); context(@"when the window capability supports primary but not secondary image", ^{ + beforeEach(^{ + testWindowCapability.textFields = allSupportedTextFields; + testWindowCapability.imageFields = @[allSupportedImageFields[0], allSupportedImageFields[2]]; + }); + + it(@"should only return primary images to upload", ^{ + NSArray<SDLArtwork *> *artworksToUpload = [SDLMenuReplaceUtilities findAllArtworksToBeUploadedFromCells:SDLMenuReplaceUtilitiesSpecHelpers.topLevelOnlyMenu fileManager:mockFileManager windowCapability:testWindowCapability]; + expect(artworksToUpload).to(haveCount(1)); + }); }); context(@"when the window capability supports both images", ^{ + beforeEach(^{ + testWindowCapability.textFields = allSupportedTextFields; + testWindowCapability.imageFields = allSupportedImageFields; + }); + + context(@"with a shallow menu", ^{ + it(@"should only return all images to upload", ^{ + NSArray<SDLArtwork *> *artworksToUpload = [SDLMenuReplaceUtilities findAllArtworksToBeUploadedFromCells:SDLMenuReplaceUtilitiesSpecHelpers.topLevelOnlyMenu fileManager:mockFileManager windowCapability:testWindowCapability]; + + expect(artworksToUpload).to(haveCount(2)); + }); + }); + + context(@"with a deep menu", ^{ + it(@"should only return all images to upload", ^{ + NSArray<SDLArtwork *> *artworksToUpload = [SDLMenuReplaceUtilities findAllArtworksToBeUploadedFromCells:SDLMenuReplaceUtilitiesSpecHelpers.deepMenu fileManager:mockFileManager windowCapability:testWindowCapability]; + expect(artworksToUpload).to(haveCount(2)); + }); + }); }); }); - context(@"when no files are uploaded", ^{ + context(@"when no files need to be uploaded", ^{ + beforeEach(^{ + OCMStub([mockFileManager fileNeedsUpload:[OCMArg any]]).andReturn(YES); + }); + + context(@"when the window capability supports both images", ^{ + beforeEach(^{ + testWindowCapability.textFields = allSupportedTextFields; + testWindowCapability.imageFields = allSupportedImageFields; + }); + it(@"should not return any images to upload", ^{ + NSArray<SDLArtwork *> *artworksToUpload = [SDLMenuReplaceUtilities findAllArtworksToBeUploadedFromCells:SDLMenuReplaceUtilitiesSpecHelpers.topLevelOnlyMenu fileManager:mockFileManager windowCapability:testWindowCapability]; + + expect(artworksToUpload).to(beEmpty()); + }); + }); }); }); describe(@"retrieving a commandId", ^{ + context(@"with an AddCommand", ^{ + it(@"should return the command id", ^{ + SDLAddCommand *rpc = [[SDLAddCommand alloc] init]; + rpc.cmdID = @12345; + expect([SDLMenuReplaceUtilities commandIdForRPCRequest:rpc]).to(equal(12345)); + }); + }); + + context(@"with an AddSubMenu", ^{ + it(@"should return the command id", ^{ + SDLAddSubMenu *rpc = [[SDLAddSubMenu alloc] init]; + rpc.menuID = @12345; + expect([SDLMenuReplaceUtilities commandIdForRPCRequest:rpc]).to(equal(12345)); + }); + }); + + context(@"with a DeleteCommand", ^{ + it(@"should return the command id", ^{ + SDLDeleteCommand *rpc = [[SDLDeleteCommand alloc] init]; + rpc.cmdID = @12345; + expect([SDLMenuReplaceUtilities commandIdForRPCRequest:rpc]).to(equal(12345)); + }); + }); + context(@"with a DeleteSubMenu", ^{ + it(@"should return the command id", ^{ + SDLDeleteSubMenu *rpc = [[SDLDeleteSubMenu alloc] init]; + rpc.menuID = @12345; + expect([SDLMenuReplaceUtilities commandIdForRPCRequest:rpc]).to(equal(12345)); + }); + }); + + context(@"with an Alert", ^{ + it(@"should return 0", ^{ + SDLAlert *rpc = [[SDLAlert alloc] init]; + expect([SDLMenuReplaceUtilities commandIdForRPCRequest:rpc]).to(equal(0)); + }); + }); }); describe(@"retrieving a position", ^{ + context(@"with an AddCommand", ^{ + it(@"should return the position", ^{ + SDLAddCommand *rpc = [[SDLAddCommand alloc] init]; + rpc.menuParams.position = @12345; + expect(@([SDLMenuReplaceUtilities positionForRPCRequest:rpc])).to(equal(@12345)); + }); + }); + context(@"with an AddSubMenu", ^{ + it(@"should return the command id", ^{ + SDLAddSubMenu *rpc = [[SDLAddSubMenu alloc] init]; + rpc.position = @12345; + expect(@([SDLMenuReplaceUtilities positionForRPCRequest:rpc])).to(equal(@12345)); + }); + }); }); describe(@"generating RPCs", ^{ + __block SDLMenuLayout testMenuLayout = SDLMenuLayoutList; + + beforeEach(^{ + mockFileManager = OCMClassMock([SDLFileManager class]); + testWindowCapability = [[SDLWindowCapability alloc] init]; + }); + context(@"delete commands", ^{ + context(@"shallow menu", ^{ + beforeEach(^{ + testMenuCells = SDLMenuReplaceUtilitiesSpecHelpers.topLevelOnlyMenu; + }); + + it(@"should generate the correct RPCs", ^{ + NSArray<SDLRPCRequest *> *requests = [SDLMenuReplaceUtilities deleteCommandsForCells:testMenuCells]; + expect(requests).to(haveCount(3)); + expect(requests[0]).to(beAnInstanceOf(SDLDeleteCommand.class)); + expect(requests[1]).to(beAnInstanceOf(SDLDeleteCommand.class)); + expect(requests[2]).to(beAnInstanceOf(SDLDeleteCommand.class)); + }); + }); + + context(@"deep menu", ^{ + beforeEach(^{ + testMenuCells = SDLMenuReplaceUtilitiesSpecHelpers.deepMenu; + }); + it(@"should generate the correct RPCs", ^{ + NSArray<SDLRPCRequest *> *requests = [SDLMenuReplaceUtilities deleteCommandsForCells:testMenuCells]; + expect(requests).to(haveCount(6)); + expect(requests[0]).to(beAnInstanceOf(SDLDeleteSubMenu.class)); + expect(requests[1]).to(beAnInstanceOf(SDLDeleteCommand.class)); + expect(requests[2]).to(beAnInstanceOf(SDLDeleteSubMenu.class)); + }); + }); }); context(@"main menu commands", ^{ + context(@"shallow menu", ^{ + beforeEach(^{ + testMenuCells = SDLMenuReplaceUtilitiesSpecHelpers.topLevelOnlyMenu; + }); + + it(@"should generate the correct RPCs", ^{ + NSArray<SDLRPCRequest *> *requests = [SDLMenuReplaceUtilities mainMenuCommandsForCells:testMenuCells fileManager:mockFileManager usingIndexesFrom:@[] windowCapability:testWindowCapability defaultSubmenuLayout:testMenuLayout]; + expect(requests).to(haveCount(3)); + expect(requests[0]).to(beAnInstanceOf(SDLAddCommand.class)); + expect(requests[1]).to(beAnInstanceOf(SDLAddCommand.class)); + expect(requests[2]).to(beAnInstanceOf(SDLAddCommand.class)); + }); + }); + + context(@"deep menu", ^{ + beforeEach(^{ + testMenuCells = SDLMenuReplaceUtilitiesSpecHelpers.deepMenu; + }); + it(@"should generate the correct RPCs", ^{ + NSArray<SDLRPCRequest *> *requests = [SDLMenuReplaceUtilities mainMenuCommandsForCells:testMenuCells fileManager:mockFileManager usingIndexesFrom:@[] windowCapability:testWindowCapability defaultSubmenuLayout:testMenuLayout]; + expect(requests).to(haveCount(3)); + expect(requests[0]).to(beAnInstanceOf(SDLAddSubMenu.class)); + expect(requests[1]).to(beAnInstanceOf(SDLAddCommand.class)); + expect(requests[2]).to(beAnInstanceOf(SDLAddSubMenu.class)); + }); + }); }); context(@"sub menu commands", ^{ + context(@"shallow menu", ^{ + beforeEach(^{ + testMenuCells = SDLMenuReplaceUtilitiesSpecHelpers.topLevelOnlyMenu; + }); + }); + context(@"deep menu", ^{ + beforeEach(^{ + testMenuCells = SDLMenuReplaceUtilitiesSpecHelpers.deepMenu; + }); + }); }); }); diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceUtilitiesSpecHelpers.h b/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceUtilitiesSpecHelpers.h index ebe68f865..908e6b59d 100644 --- a/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceUtilitiesSpecHelpers.h +++ b/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceUtilitiesSpecHelpers.h @@ -14,8 +14,8 @@ NS_ASSUME_NONNULL_BEGIN @interface SDLMenuReplaceUtilitiesSpecHelpers : NSObject -@property (nonatomic, readonly) NSArray<SDLMenuCell *> *topLevelOnlyMenu; -@property (nonatomic, readonly) NSArray<SDLMenuCell *> *deepMenu; +@property (class, nonatomic, readonly) NSArray<SDLMenuCell *> *topLevelOnlyMenu; +@property (class, nonatomic, readonly) NSArray<SDLMenuCell *> *deepMenu; @end diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceUtilitiesSpecHelpers.m b/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceUtilitiesSpecHelpers.m index 51b23c3f8..6d6122654 100644 --- a/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceUtilitiesSpecHelpers.m +++ b/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceUtilitiesSpecHelpers.m @@ -13,7 +13,7 @@ @implementation SDLMenuReplaceUtilitiesSpecHelpers -+ (NSArray<SDLMenuCell *> *)topLevelMenuOnly { ++ (NSArray<SDLMenuCell *> *)topLevelOnlyMenu { NSData *cellArtData = [@"testart" dataUsingEncoding:NSUTF8StringEncoding]; NSData *cellArtData2 = [@"testart2" dataUsingEncoding:NSUTF8StringEncoding]; SDLArtwork *artwork1 = [[SDLArtwork alloc] initWithData:cellArtData name:@"Test Art 1" fileExtension:@"png" persistent:NO]; |