diff options
author | Joel Fischer <joeljfischer@gmail.com> | 2021-08-10 13:08:18 -0400 |
---|---|---|
committer | Joel Fischer <joeljfischer@gmail.com> | 2021-08-10 13:08:18 -0400 |
commit | df856a454990e5ffdcb3f7bb8a14c9d53373e3fc (patch) | |
tree | 7d9b9327c8a19c35322880b85485ccee5c4acf70 /SmartDeviceLinkTests/DevAPISpecs | |
parent | 63e70a946890fb119ee02ef62606fd40730c6f5c (diff) | |
download | sdl_ios-df856a454990e5ffdcb3f7bb8a14c9d53373e3fc.tar.gz |
Finish menu replace tests
Diffstat (limited to 'SmartDeviceLinkTests/DevAPISpecs')
3 files changed, 209 insertions, 37 deletions
diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceUtilitiesSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceUtilitiesSpec.m index 3f5e2c2e5..fd1a19b01 100644 --- a/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceUtilitiesSpec.m +++ b/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceUtilitiesSpec.m @@ -20,7 +20,7 @@ QuickSpecBegin(SDLMenuReplaceUtilitiesSpec) -__block NSArray<SDLMenuCell *> *testMenuCells = nil; +__block NSMutableArray<SDLMenuCell *> *testMenuCells = nil; __block SDLFileManager *mockFileManager = nil; __block SDLWindowCapability *testWindowCapability = nil; __block NSArray<SDLTextField *> *allSupportedTextFields = @[ @@ -261,19 +261,173 @@ describe(@"generating RPCs", ^{ // updating menu cells describe(@"updating menu cell lists", ^{ - __block NSArray<SDLMenuCell *> *testNewMenuCells = nil; __block UInt32 testCommandId = 0; - // removeMenuCellFromList:withCmdId: - describe(@"removing commands from a list", ^{ - context(@"the list only has one level", ^{ + describe(@"removing commands", ^{ + context(@"from a shallow list", ^{ + beforeEach(^{ + testMenuCells = SDLMenuReplaceUtilitiesSpecHelpers.topLevelOnlyMenu; + }); + + context(@"when the cell is in the menu", ^{ + beforeEach(^{ + testCommandId = testMenuCells[1].cellId; + }); + + it(@"should return the menu without the cell and return YES", ^{ + NSMutableArray<SDLMenuCell *> *testMutableMenuCells = [testMenuCells mutableCopy]; + BOOL foundItem = [SDLMenuReplaceUtilities removeCellFromList:testMutableMenuCells withCellId:testCommandId]; + + expect(foundItem).to(beTrue()); + expect(testMutableMenuCells).to(haveCount(2)); + expect(testMutableMenuCells[0]).to(equal(testMenuCells[0])); + expect(testMutableMenuCells[1]).to(equal(testMenuCells[2])); + }); + }); + + context(@"when the cell is not in the menu", ^{ + beforeEach(^{ + testCommandId = 100; + }); + + it(@"should return the menu with all cells and return NO", ^{ + NSMutableArray<SDLMenuCell *> *testMutableMenuCells = [testMenuCells mutableCopy]; + BOOL foundItem = [SDLMenuReplaceUtilities removeCellFromList:testMutableMenuCells withCellId:testCommandId]; + + expect(foundItem).to(beFalse()); + expect(testMutableMenuCells).to(haveCount(3)); + }); + }); + }); + + context(@"from a deep list", ^{ + beforeEach(^{ + testMenuCells = SDLMenuReplaceUtilitiesSpecHelpers.deepMenu; + }); + + context(@"when the cell is in the top menu", ^{ + beforeEach(^{ + testCommandId = testMenuCells[1].cellId; + }); + + it(@"should return the menu without the cell and return YES", ^{ + NSMutableArray<SDLMenuCell *> *testMutableMenuCells = [testMenuCells mutableCopy]; + BOOL foundItem = [SDLMenuReplaceUtilities removeCellFromList:testMutableMenuCells withCellId:testCommandId]; + + expect(foundItem).to(beTrue()); + expect(testMutableMenuCells).to(haveCount(2)); + expect(testMutableMenuCells[0]).to(equal(testMenuCells[0])); + expect(testMutableMenuCells[1]).to(equal(testMenuCells[2])); + }); + }); + + context(@"when the cell is in the submenu", ^{ + beforeEach(^{ + testCommandId = 5; + }); + + it(@"should return the menu without the cell and return YES", ^{ + NSMutableArray<SDLMenuCell *> *testMutableMenuCells = [testMenuCells mutableCopy]; + BOOL foundItem = [SDLMenuReplaceUtilities removeCellFromList:testMutableMenuCells withCellId:testCommandId]; + + expect(foundItem).to(beTrue()); + expect(testMutableMenuCells).to(haveCount(3)); + expect(testMutableMenuCells[2].subCells).to(haveCount(1)); + }); + }); + + context(@"when the cell is not in the menu", ^{ + beforeEach(^{ + testCommandId = 100; + }); + + it(@"should return the menu with all cells and return NO", ^{ + NSMutableArray<SDLMenuCell *> *testMutableMenuCells = [testMenuCells mutableCopy]; + BOOL foundItem = [SDLMenuReplaceUtilities removeCellFromList:testMutableMenuCells withCellId:testCommandId]; + expect(foundItem).to(beFalse()); + expect(testMutableMenuCells).to(haveCount(3)); + expect(testMutableMenuCells[0].subCells).to(haveCount(2)); + expect(testMutableMenuCells[2].subCells).to(haveCount(2)); + }); + }); }); }); - describe(@"add commands to the list", ^{ - __block NSMutableArray<SDLMenuCell *> *testMenuCells = nil; - __block UInt16 testPosition = 0; + describe(@"add commands to the main list", ^{ + __block NSMutableArray<SDLMenuCell *> *newCellList = nil; + + context(@"from a shallow list", ^{ + beforeEach(^{ + testMenuCells = SDLMenuReplaceUtilitiesSpecHelpers.topLevelOnlyMenu; + + SDLMenuCell *newCell = [[SDLMenuCell alloc] initWithTitle:@"New Cell" secondaryText:nil tertiaryText:nil icon:nil secondaryArtwork:nil voiceCommands:nil handler:^(SDLTriggerSource _Nonnull triggerSource) {}]; + newCell.cellId = 99; + newCellList = [@[newCell] mutableCopy]; + }); + + describe(@"if the cell is not in the cell list", ^{ + beforeEach(^{ + newCellList = [[NSMutableArray alloc] init]; + }); + + it(@"should return NO", ^{ + BOOL didAddCell = [SDLMenuReplaceUtilities addCellWithCellId:99 position:0 fromNewMenuList:newCellList toMainMenuList:testMenuCells]; + + expect(didAddCell).to(beFalse()); + }); + }); + + context(@"at the beginning", ^{ + it(@"should return YES and the cell should be included", ^{ + BOOL didAddCell = [SDLMenuReplaceUtilities addCellWithCellId:newCellList[0].cellId position:0 fromNewMenuList:newCellList toMainMenuList:testMenuCells]; + + expect(didAddCell).to(beTrue()); + expect(testMenuCells).to(haveCount(4)); + expect(testMenuCells[0]).to(equal(newCellList[0])); + }); + }); + + context(@"in the middle", ^{ + it(@"should return YES and the cell should be included", ^{ + BOOL didAddCell = [SDLMenuReplaceUtilities addCellWithCellId:newCellList[0].cellId position:1 fromNewMenuList:newCellList toMainMenuList:testMenuCells]; + + expect(didAddCell).to(beTrue()); + expect(testMenuCells).to(haveCount(4)); + expect(testMenuCells[1]).to(equal(newCellList[0])); + }); + }); + + context(@"at the end", ^{ + it(@"should return YES and the cell should be included", ^{ + BOOL didAddCell = [SDLMenuReplaceUtilities addCellWithCellId:newCellList[0].cellId position:3 fromNewMenuList:newCellList toMainMenuList:testMenuCells]; + + expect(didAddCell).to(beTrue()); + expect(testMenuCells).to(haveCount(4)); + expect(testMenuCells[3]).to(equal(newCellList[0])); + }); + }); + }); + + context(@"from a deep list", ^{ + beforeEach(^{ + testMenuCells = SDLMenuReplaceUtilitiesSpecHelpers.deepMenu; + + SDLMenuCell *subCell = [[SDLMenuCell alloc] initWithTitle:@"New SubCell" secondaryText:nil tertiaryText:nil icon:nil secondaryArtwork:nil voiceCommands:nil handler:^(SDLTriggerSource _Nonnull triggerSource) {}]; + subCell.cellId = 98; + SDLMenuCell *newCell = [[SDLMenuCell alloc] initWithTitle:@"New Cell" secondaryText:nil tertiaryText:nil icon:nil secondaryArtwork:nil submenuLayout:nil subCells:@[subCell]]; + newCell.cellId = 99; + newCellList = [@[newCell] mutableCopy]; + }); + + it(@"should properly add the subcell to the list", ^{ + BOOL didAddCell = [SDLMenuReplaceUtilities addCellWithCellId:98 position:0 fromNewMenuList:newCellList toMainMenuList:testMenuCells]; + + expect(didAddCell).to(beTrue()); + expect(testMenuCells).to(haveCount(4)); + expect(testMenuCells[0]).to(equal(newCellList[0].subCells[0])); + }); + }); }); }); diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceUtilitiesSpecHelpers.h b/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceUtilitiesSpecHelpers.h index 908e6b59d..7106cb567 100644 --- a/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceUtilitiesSpecHelpers.h +++ b/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceUtilitiesSpecHelpers.h @@ -14,8 +14,8 @@ NS_ASSUME_NONNULL_BEGIN @interface SDLMenuReplaceUtilitiesSpecHelpers : NSObject -@property (class, nonatomic, readonly) NSArray<SDLMenuCell *> *topLevelOnlyMenu; -@property (class, nonatomic, readonly) NSArray<SDLMenuCell *> *deepMenu; +@property (class, nonatomic, readonly) NSMutableArray<SDLMenuCell *> *topLevelOnlyMenu; +@property (class, nonatomic, readonly) NSMutableArray<SDLMenuCell *> *deepMenu; @end diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceUtilitiesSpecHelpers.m b/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceUtilitiesSpecHelpers.m index 8c71d8dc5..2b9bef2b9 100644 --- a/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceUtilitiesSpecHelpers.m +++ b/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceUtilitiesSpecHelpers.m @@ -11,22 +11,34 @@ #import "SDLArtwork.h" #import "SDLMenuCell.h" +@interface SDLMenuCell() + +@property (assign, nonatomic) UInt32 parentCellId; +@property (assign, nonatomic) UInt32 cellId; + +@end + @implementation SDLMenuReplaceUtilitiesSpecHelpers -+ (NSArray<SDLMenuCell *> *)topLevelOnlyMenu { ++ (NSMutableArray<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]; SDLArtwork *artwork2 = [[SDLArtwork alloc] initWithData:cellArtData2 name:@"Test Art 2" fileExtension:@"png" persistent:NO]; - return @[ - [[SDLMenuCell alloc] initWithTitle:@"Item 1" secondaryText:nil tertiaryText:nil icon:artwork1 secondaryArtwork:nil voiceCommands:nil handler:^(SDLTriggerSource _Nonnull triggerSource) {}], - [[SDLMenuCell alloc] initWithTitle:@"Item 2" secondaryText:nil tertiaryText:nil icon:artwork1 secondaryArtwork:nil voiceCommands:nil handler:^(SDLTriggerSource _Nonnull triggerSource) {}], - [[SDLMenuCell alloc] initWithTitle:@"Item 3" secondaryText:nil tertiaryText:nil icon:nil secondaryArtwork:artwork2 voiceCommands:nil handler:^(SDLTriggerSource _Nonnull triggerSource) {}] - ]; + SDLMenuCell *cell1 = [[SDLMenuCell alloc] initWithTitle:@"Item 1" secondaryText:nil tertiaryText:nil icon:artwork1 secondaryArtwork:nil voiceCommands:nil handler:^(SDLTriggerSource _Nonnull triggerSource) {}]; + cell1.cellId = 1; + + SDLMenuCell *cell2 = [[SDLMenuCell alloc] initWithTitle:@"Item 2" secondaryText:nil tertiaryText:nil icon:artwork1 secondaryArtwork:nil voiceCommands:nil handler:^(SDLTriggerSource _Nonnull triggerSource) {}]; + cell2.cellId = 2; + + SDLMenuCell *cell3 = [[SDLMenuCell alloc] initWithTitle:@"Item 3" secondaryText:nil tertiaryText:nil icon:nil secondaryArtwork:artwork2 voiceCommands:nil handler:^(SDLTriggerSource _Nonnull triggerSource) {}]; + cell3.cellId = 3; + + return [@[cell1, cell2, cell3] mutableCopy]; } -+ (NSArray<SDLMenuCell *> *)deepMenu { ++ (NSMutableArray<SDLMenuCell *> *)deepMenu { NSData *cellArtData = [@"testart" dataUsingEncoding:NSUTF8StringEncoding]; NSData *cellArtData2 = [@"testart2" dataUsingEncoding:NSUTF8StringEncoding]; NSData *cellArtData3 = [@"testart3" dataUsingEncoding:NSUTF8StringEncoding]; @@ -36,26 +48,32 @@ SDLArtwork *artwork3 = [[SDLArtwork alloc] initWithData:cellArtData3 name:@"Test Art 3" fileExtension:@"png" persistent:NO]; SDLArtwork *artwork4 = [[SDLArtwork alloc] initWithData:cellArtData4 name:@"Test Art 4" fileExtension:@"png" persistent:NO]; - NSArray<SDLMenuCell *> *subList1SubList1 = @[ - [[SDLMenuCell alloc] initWithTitle:@"Item 1" secondaryText:@"SubItem 1" tertiaryText:@"Sub-SubItem 1" icon:nil secondaryArtwork:artwork3 voiceCommands:nil handler:^(SDLTriggerSource _Nonnull triggerSource) {}], - [[SDLMenuCell alloc] initWithTitle:@"Item 1" secondaryText:@"SubItem 1" tertiaryText:@"Sub-SubItem 2" icon:artwork1 secondaryArtwork:nil voiceCommands:nil handler:^(SDLTriggerSource _Nonnull triggerSource) {}] - ]; - - NSArray<SDLMenuCell *> *subList1 = @[ - [[SDLMenuCell alloc] initWithTitle:@"Item 1" secondaryText:@"SubItem 1" tertiaryText:nil icon:artwork4 secondaryArtwork:nil submenuLayout:nil subCells:subList1SubList1], - [[SDLMenuCell alloc] initWithTitle:@"Item 1" secondaryText:@"SubItem 2" tertiaryText:nil icon:artwork2 secondaryArtwork:nil voiceCommands:nil handler:^(SDLTriggerSource _Nonnull triggerSource) {}] - ]; - - NSArray<SDLMenuCell *> *subList2 = @[ - [[SDLMenuCell alloc] initWithTitle:@"Item 2" secondaryText:@"SubItem 1" tertiaryText:nil icon:artwork1 secondaryArtwork:artwork4 voiceCommands:nil handler:^(SDLTriggerSource _Nonnull triggerSource) {}], - [[SDLMenuCell alloc] initWithTitle:@"Item 1" secondaryText:@"SubItem 2" tertiaryText:nil icon:artwork1 secondaryArtwork:artwork2 voiceCommands:nil handler:^(SDLTriggerSource _Nonnull triggerSource) {}] - ]; - - return @[ - [[SDLMenuCell alloc] initWithTitle:@"Item 1" secondaryText:nil tertiaryText:nil icon:artwork1 secondaryArtwork:nil submenuLayout:nil subCells:subList1], - [[SDLMenuCell alloc] initWithTitle:@"Item 2" secondaryText:nil tertiaryText:nil icon:nil secondaryArtwork:nil voiceCommands:nil handler:^(SDLTriggerSource _Nonnull triggerSource) {}], - [[SDLMenuCell alloc] initWithTitle:@"Item 3" secondaryText:nil tertiaryText:nil icon:nil secondaryArtwork:nil submenuLayout:nil subCells:subList2] - ]; + SDLMenuCell *subList1SubList1Cell1 = [[SDLMenuCell alloc] initWithTitle:@"Item 1" secondaryText:@"SubItem 1" tertiaryText:@"Sub-SubItem 1" icon:nil secondaryArtwork:artwork3 voiceCommands:nil handler:^(SDLTriggerSource _Nonnull triggerSource) {}]; + subList1SubList1Cell1.cellId = 1; + SDLMenuCell *subList1SubList1Cell2 = [[SDLMenuCell alloc] initWithTitle:@"Item 1" secondaryText:@"SubItem 1" tertiaryText:@"Sub-SubItem 2" icon:artwork1 secondaryArtwork:nil voiceCommands:nil handler:^(SDLTriggerSource _Nonnull triggerSource) {}]; + subList1SubList1Cell2.cellId = 2; + NSArray<SDLMenuCell *> *subList1SubList1 = @[subList1SubList1Cell1, subList1SubList1Cell2]; + + SDLMenuCell *subList1Cell1 = [[SDLMenuCell alloc] initWithTitle:@"Item 1" secondaryText:@"SubItem 1" tertiaryText:nil icon:artwork4 secondaryArtwork:nil submenuLayout:nil subCells:subList1SubList1]; + subList1Cell1.cellId = 3; + SDLMenuCell *subList1Cell2 = [[SDLMenuCell alloc] initWithTitle:@"Item 1" secondaryText:@"SubItem 2" tertiaryText:nil icon:artwork2 secondaryArtwork:nil voiceCommands:nil handler:^(SDLTriggerSource _Nonnull triggerSource) {}]; + subList1Cell2.cellId = 4; + NSArray<SDLMenuCell *> *subList1 = @[subList1Cell1, subList1Cell2]; + + SDLMenuCell *subList2Cell1 = [[SDLMenuCell alloc] initWithTitle:@"Item 3" secondaryText:@"SubItem 1" tertiaryText:nil icon:artwork1 secondaryArtwork:artwork4 voiceCommands:nil handler:^(SDLTriggerSource _Nonnull triggerSource) {}]; + subList2Cell1.cellId = 5; + SDLMenuCell *subList2Cell2 = [[SDLMenuCell alloc] initWithTitle:@"Item 3" secondaryText:@"SubItem 2" tertiaryText:nil icon:artwork1 secondaryArtwork:artwork2 voiceCommands:nil handler:^(SDLTriggerSource _Nonnull triggerSource) {}]; + subList2Cell2.cellId = 6; + NSArray<SDLMenuCell *> *subList2 = @[subList2Cell1, subList2Cell2]; + + SDLMenuCell *topListCell1 = [[SDLMenuCell alloc] initWithTitle:@"Item 1" secondaryText:nil tertiaryText:nil icon:artwork1 secondaryArtwork:nil submenuLayout:nil subCells:subList1]; + topListCell1.cellId = 7; + SDLMenuCell *topListCell2 = [[SDLMenuCell alloc] initWithTitle:@"Item 2" secondaryText:nil tertiaryText:nil icon:nil secondaryArtwork:nil voiceCommands:nil handler:^(SDLTriggerSource _Nonnull triggerSource) {}]; + topListCell2.cellId = 8; + SDLMenuCell *topListCell3 = [[SDLMenuCell alloc] initWithTitle:@"Item 3" secondaryText:nil tertiaryText:nil icon:nil secondaryArtwork:nil submenuLayout:nil subCells:subList2]; + topListCell3.cellId = 9; + + return [@[topListCell1, topListCell2, topListCell3] mutableCopy]; } @end |