summaryrefslogtreecommitdiff
path: root/SmartDeviceLinkTests/DevAPISpecs
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2021-08-24 15:52:34 -0400
committerJoel Fischer <joeljfischer@gmail.com>2021-08-24 15:52:34 -0400
commitc776099c68bc2e1a7dfeda100e50f55de069d02e (patch)
treeef66c6adf37f2b37bacb392dee54f699ee523564 /SmartDeviceLinkTests/DevAPISpecs
parent7053b9de012c8f2cf736f902d8fe2c0576e27014 (diff)
downloadsdl_ios-c776099c68bc2e1a7dfeda100e50f55de069d02e.tar.gz
Add menu replace utility tests
Diffstat (limited to 'SmartDeviceLinkTests/DevAPISpecs')
-rw-r--r--SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceUtilitiesSpec.m63
1 files changed, 56 insertions, 7 deletions
diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceUtilitiesSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceUtilitiesSpec.m
index aba198781..51f6bca6a 100644
--- a/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceUtilitiesSpec.m
+++ b/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceUtilitiesSpec.m
@@ -48,7 +48,7 @@ describe(@"adding ids", ^{
SDLMenuReplaceUtilities.nextMenuId = 0;
testMenuCells = SDLMenuReplaceUtilitiesSpecHelpers.deepMenu;
- [SDLMenuReplaceUtilities updateIdsOnMenuCells:testMenuCells parentId:ParentIdNotFound];
+ [SDLMenuReplaceUtilities addIdsToMenuCells:testMenuCells parentId:ParentIdNotFound];
expect(testMenuCells[0].cellId).to(equal(1));
expect(testMenuCells[1].cellId).to(equal(6));
@@ -74,6 +74,55 @@ describe(@"adding ids", ^{
});
});
+describe(@"transferring cell ids", ^{
+ it(@"should properly transfer ids and set parent ids", ^{
+ testMenuCells = [[NSMutableArray alloc] initWithArray:SDLMenuReplaceUtilitiesSpecHelpers.deepMenu copyItems:YES];
+ [SDLMenuReplaceUtilities addIdsToMenuCells:testMenuCells parentId:ParentIdNotFound];
+
+ NSArray<SDLMenuCell *> *toCells = [[NSArray alloc] initWithArray:SDLMenuReplaceUtilitiesSpecHelpers.deepMenu copyItems:YES];
+ [SDLMenuReplaceUtilities transferCellIDsFromCells:testMenuCells toCells:toCells];
+
+ // Top-level cells should have same cell ids
+ for (NSUInteger i = 0; i < testMenuCells.count; i++) {
+ expect(toCells[i].cellId).to(equal(testMenuCells[i].cellId));
+ }
+
+ // Sub-cells should _not_ have the same cell ids
+ for (NSUInteger i = 0; i < testMenuCells[0].subCells.count; i++) {
+ expect(toCells[0].subCells[i].cellId).toNot(equal(testMenuCells[0].subCells[i].cellId));
+ }
+
+ // Sub-cells should have proper parent ids
+ for (NSUInteger i = 0; i < testMenuCells[0].subCells.count; i++) {
+ expect(toCells[0].subCells[i].parentCellId).to(equal(toCells[0].cellId));
+ }
+ });
+});
+
+describe(@"transferring cell handlers", ^{
+ __block BOOL cell1HandlerTriggered = NO;
+ __block BOOL cell2HandlerTriggered = NO;
+ beforeEach(^{
+ cell1HandlerTriggered = NO;
+ cell2HandlerTriggered = NO;
+ });
+
+ it(@"should properly transfer cell handlers", ^{
+ SDLMenuCell *cell1 = [[SDLMenuCell alloc] initWithTitle:@"Cell1" secondaryText:nil tertiaryText:nil icon:nil secondaryArtwork:nil voiceCommands:nil handler:^(SDLTriggerSource _Nonnull triggerSource) {
+ cell1HandlerTriggered = YES;
+ }];
+ SDLMenuCell *cell2 = [[SDLMenuCell alloc] initWithTitle:@"Cell1" secondaryText:nil tertiaryText:nil icon:nil secondaryArtwork:nil voiceCommands:nil handler:^(SDLTriggerSource _Nonnull triggerSource) {
+ cell2HandlerTriggered = YES;
+ }];
+
+ [SDLMenuReplaceUtilities transferCellHandlersFromCells:@[cell1] toCells:@[cell2]];
+ cell2.handler(SDLTriggerSourceMenu);
+
+ expect(cell1HandlerTriggered).to(beTrue());
+ expect(cell2HandlerTriggered).to(beFalse());
+ });
+});
+
describe(@"finding all artworks from cells", ^{
beforeEach(^{
mockFileManager = OCMClassMock([SDLFileManager class]);
@@ -259,7 +308,7 @@ describe(@"generating RPCs", ^{
});
it(@"should generate the correct RPCs", ^{
- NSArray<SDLRPCRequest *> *requests = [SDLMenuReplaceUtilities mainMenuCommandsForCells:testMenuCells fileManager:mockFileManager usingIndexesFrom:testMenuCells windowCapability:testWindowCapability defaultSubmenuLayout:testMenuLayout];
+ NSArray<SDLRPCRequest *> *requests = [SDLMenuReplaceUtilities mainMenuCommandsForCells:testMenuCells fileManager:mockFileManager usingPositionsFromFullMenu:testMenuCells windowCapability:testWindowCapability defaultSubmenuLayout:testMenuLayout];
expect(requests).to(haveCount(3));
expect(requests[0]).to(beAnInstanceOf(SDLAddCommand.class));
expect(requests[1]).to(beAnInstanceOf(SDLAddCommand.class));
@@ -273,7 +322,7 @@ describe(@"generating RPCs", ^{
});
it(@"should generate the correct RPCs", ^{
- NSArray<SDLRPCRequest *> *requests = [SDLMenuReplaceUtilities mainMenuCommandsForCells:testMenuCells fileManager:mockFileManager usingIndexesFrom:testMenuCells windowCapability:testWindowCapability defaultSubmenuLayout:testMenuLayout];
+ NSArray<SDLRPCRequest *> *requests = [SDLMenuReplaceUtilities mainMenuCommandsForCells:testMenuCells fileManager:mockFileManager usingPositionsFromFullMenu:testMenuCells windowCapability:testWindowCapability defaultSubmenuLayout:testMenuLayout];
expect(requests).to(haveCount(3));
expect(requests[0]).to(beAnInstanceOf(SDLAddSubMenu.class));
expect(requests[1]).to(beAnInstanceOf(SDLAddCommand.class));
@@ -305,7 +354,7 @@ describe(@"updating menu cell lists", ^{
context(@"from a shallow list", ^{
beforeEach(^{
testMenuCells = SDLMenuReplaceUtilitiesSpecHelpers.topLevelOnlyMenu;
- [SDLMenuReplaceUtilities updateIdsOnMenuCells:testMenuCells parentId:ParentIdNotFound];
+ [SDLMenuReplaceUtilities addIdsToMenuCells:testMenuCells parentId:ParentIdNotFound];
});
context(@"when the cell is in the menu", ^{
@@ -342,7 +391,7 @@ describe(@"updating menu cell lists", ^{
context(@"from a deep list", ^{
beforeEach(^{
testMenuCells = SDLMenuReplaceUtilitiesSpecHelpers.deepMenu;
- [SDLMenuReplaceUtilities updateIdsOnMenuCells:testMenuCells parentId:ParentIdNotFound];
+ [SDLMenuReplaceUtilities addIdsToMenuCells:testMenuCells parentId:ParentIdNotFound];
});
context(@"when the cell is in the top menu", ^{
@@ -400,7 +449,7 @@ describe(@"updating menu cell lists", ^{
context(@"from a shallow list", ^{
beforeEach(^{
testMenuCells = SDLMenuReplaceUtilitiesSpecHelpers.topLevelOnlyMenu;
- [SDLMenuReplaceUtilities updateIdsOnMenuCells:testMenuCells parentId:ParentIdNotFound];
+ [SDLMenuReplaceUtilities addIdsToMenuCells:testMenuCells parentId:ParentIdNotFound];
SDLMenuCell *newCell = [[SDLMenuCell alloc] initWithTitle:@"New Cell" secondaryText:nil tertiaryText:nil icon:nil secondaryArtwork:nil voiceCommands:nil handler:^(SDLTriggerSource _Nonnull triggerSource) {}];
newCell.cellId = 99;
@@ -456,7 +505,7 @@ describe(@"updating menu cell lists", ^{
beforeEach(^{
testMenuCells = SDLMenuReplaceUtilitiesSpecHelpers.deepMenu.copy;
- [SDLMenuReplaceUtilities updateIdsOnMenuCells:testMenuCells parentId:ParentIdNotFound];
+ [SDLMenuReplaceUtilities addIdsToMenuCells:testMenuCells parentId:ParentIdNotFound];
newMenu = [[NSMutableArray alloc] initWithArray:testMenuCells copyItems:YES];
NSMutableArray<SDLMenuCell *> *subMenuToUpdate = newMenu[0].subCells.mutableCopy;