summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2021-08-11 15:53:55 -0400
committerJoel Fischer <joeljfischer@gmail.com>2021-08-11 15:53:55 -0400
commitd0ddd9a546bf09451d721a3670ecfd1315871759 (patch)
tree0ec76e06d7e0d3aaf736e2d1b725aa6316b8b413
parent24905c8223f133d8d867650e98e3b884c3846c86 (diff)
downloadsdl_ios-d0ddd9a546bf09451d721a3670ecfd1315871759.tar.gz
Menu manager fixes
* Fix inserting cells with subcells into list * Cell Ids now handled by operations * A whole host of test updates
-rw-r--r--SmartDeviceLink/private/SDLMenuManager.m24
-rw-r--r--SmartDeviceLink/private/SDLMenuReplaceOperation.m3
-rw-r--r--SmartDeviceLink/private/SDLMenuReplaceUtilities.h4
-rw-r--r--SmartDeviceLink/private/SDLMenuReplaceUtilities.m90
-rw-r--r--SmartDeviceLinkTests/DevAPISpecs/SDLMenuManagerSpec.m4
-rw-r--r--SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceOperationSpec.m98
-rw-r--r--SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceUtilitiesSpec.m66
-rw-r--r--SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceUtilitiesSpecHelpers.m18
8 files changed, 196 insertions, 111 deletions
diff --git a/SmartDeviceLink/private/SDLMenuManager.m b/SmartDeviceLink/private/SDLMenuManager.m
index a70c6b56a..3d7047eb3 100644
--- a/SmartDeviceLink/private/SDLMenuManager.m
+++ b/SmartDeviceLink/private/SDLMenuManager.m
@@ -80,19 +80,14 @@ NS_ASSUME_NONNULL_BEGIN
@property (copy, nonatomic) NSArray<SDLMenuCell *> *currentMenuCells;
@property (strong, nonatomic, nullable) SDLMenuConfiguration *currentMenuConfiguration;
-@property (assign, nonatomic) UInt32 lastMenuId;
-
@end
-UInt32 const MenuCellIdMin = 1;
-
@implementation SDLMenuManager
- (instancetype)init {
self = [super init];
if (!self) { return nil; }
- _lastMenuId = MenuCellIdMin;
_menuConfiguration = [[SDLMenuConfiguration alloc] init];
_menuCells = @[];
_currentMenuCells = @[];
@@ -121,7 +116,6 @@ UInt32 const MenuCellIdMin = 1;
}
- (void)stop {
- _lastMenuId = MenuCellIdMin;
_menuCells = @[];
_currentMenuCells = @[];
_transactionQueue = [self sdl_newTransactionQueue];
@@ -200,7 +194,6 @@ UInt32 const MenuCellIdMin = 1;
}
_menuCells = [[NSArray alloc] initWithArray:menuCells copyItems:YES];
- [self sdl_updateIdsOnMenuCells:self.menuCells parentId:ParentIdNotFound];
__weak typeof(self) weakself = self;
SDLMenuReplaceOperation *menuReplaceOperation = [[SDLMenuReplaceOperation alloc] initWithConnectionManager:self.connectionManager fileManager:self.fileManager windowCapability:self.windowCapability menuConfiguration:self.menuConfiguration currentMenu:self.currentMenuCells updatedMenu:self.menuCells compatibilityModeEnabled:(![self sdl_isDynamicMenuUpdateActive:self.dynamicMenuUpdatesMode]) currentMenuUpdatedHandler:^(NSArray<SDLMenuCell *> * _Nonnull currentMenuCells, NSError *error) {
@@ -336,23 +329,6 @@ UInt32 const MenuCellIdMin = 1;
return YES;
}
-#pragma mark IDs
-
-/// Assign cell ids on an array of menu cells given a parent id (or no parent id)
-/// @param menuCells The array of menu cells to update
-/// @param parentId The parent id to assign if needed
-- (void)sdl_updateIdsOnMenuCells:(NSArray<SDLMenuCell *> *)menuCells parentId:(UInt32)parentId {
- for (SDLMenuCell *cell in menuCells) {
- cell.cellId = self.lastMenuId++;
- if (parentId != ParentIdNotFound) {
- cell.parentCellId = parentId;
- }
- if (cell.subCells.count > 0) {
- [self sdl_updateIdsOnMenuCells:cell.subCells parentId:cell.cellId];
- }
- }
-}
-
#pragma mark - Calling handlers
/// Call a handler for a currently displayed SDLMenuCell based on the incoming SDLOnCommand notification
diff --git a/SmartDeviceLink/private/SDLMenuReplaceOperation.m b/SmartDeviceLink/private/SDLMenuReplaceOperation.m
index 531ba6294..5de4a6dd6 100644
--- a/SmartDeviceLink/private/SDLMenuReplaceOperation.m
+++ b/SmartDeviceLink/private/SDLMenuReplaceOperation.m
@@ -18,6 +18,7 @@
#import "SDLLogMacros.h"
#import "SDLMenuCell.h"
#import "SDLMenuConfiguration.h"
+#import "SDLMenuManagerPrivateConstants.h"
#import "SDLTextFieldName.h"
#import "SDLVersion.h"
#import "SDLWindowCapability.h"
@@ -79,6 +80,8 @@ NS_ASSUME_NONNULL_BEGIN
[super start];
if (self.isCancelled) { return; }
+ [SDLMenuReplaceUtilities updateIdsOnMenuCells:self.updatedMenu parentId:ParentIdNotFound];
+
SDLDynamicMenuUpdateRunScore *runScore = nil;
if (self.compatibilityModeEnabled) {
SDLLogV(@"Dynamic menu update inactive. Forcing the deletion of all old cells and adding all new ones, even if they're the same.");
diff --git a/SmartDeviceLink/private/SDLMenuReplaceUtilities.h b/SmartDeviceLink/private/SDLMenuReplaceUtilities.h
index c90845382..35defac10 100644
--- a/SmartDeviceLink/private/SDLMenuReplaceUtilities.h
+++ b/SmartDeviceLink/private/SDLMenuReplaceUtilities.h
@@ -21,6 +21,10 @@ NS_ASSUME_NONNULL_BEGIN
@interface SDLMenuReplaceUtilities : NSObject
+#pragma mark - Ids
+
++ (void)updateIdsOnMenuCells:(NSArray<SDLMenuCell *> *)menuCells parentId:(UInt32)parentId;
+
#pragma mark - Artworks
/// Finds all artworks that need to be uploaded from the given list of menu cells
diff --git a/SmartDeviceLink/private/SDLMenuReplaceUtilities.m b/SmartDeviceLink/private/SDLMenuReplaceUtilities.m
index 3412b1b92..22ab00762 100644
--- a/SmartDeviceLink/private/SDLMenuReplaceUtilities.m
+++ b/SmartDeviceLink/private/SDLMenuReplaceUtilities.m
@@ -23,7 +23,7 @@
#import "SDLWindowCapability.h"
#import "SDLWindowCapability+ScreenManagerExtensions.h"
-@interface SDLMenuCell()
+@interface SDLMenuCell ()
@property (assign, nonatomic) UInt32 parentCellId;
@property (assign, nonatomic) UInt32 cellId;
@@ -31,7 +31,39 @@
@end
+@interface SDLMenuReplaceUtilities ()
+
+@property (class, assign, nonatomic) UInt32 nextMenuId;
+
+@end
+
@implementation SDLMenuReplaceUtilities
+static UInt32 _menuId = 0;
+
+#pragma mark Ids
+
++ (void)setNextMenuId:(UInt32)nextMenuId {
+ _menuId = nextMenuId;
+}
+
++ (UInt32)nextMenuId {
+ return ++_menuId;
+}
+
+/// Assign cell ids on an array of menu cells given a parent id (or no parent id)
+/// @param menuCells The array of menu cells to update
+/// @param parentId The parent id to assign if needed
++ (void)updateIdsOnMenuCells:(NSArray<SDLMenuCell *> *)menuCells parentId:(UInt32)parentId {
+ for (SDLMenuCell *cell in menuCells) {
+ cell.cellId = self.class.nextMenuId;
+ if (parentId != ParentIdNotFound) {
+ cell.parentCellId = parentId;
+ }
+ if (cell.subCells.count > 0) {
+ [self updateIdsOnMenuCells:cell.subCells parentId:cell.cellId];
+ }
+ }
+}
#pragma mark Artworks
@@ -237,38 +269,38 @@
}
+ (BOOL)sdl_addMenuCell:(SDLMenuCell *)cell toList:(NSMutableArray<SDLMenuCell *> *)menuCellList atPosition:(UInt16)position {
- if (cell.parentCellId != ParentIdNotFound) {
- // If the cell has a parent id, we need to find the cell with a matching cell id and insert it into its submenu
- for (SDLMenuCell *menuCell in menuCellList) {
- if (menuCell.cellId == cell.parentCellId) {
- // If we found the correct submenu, insert it into that submenu
- NSMutableArray<SDLMenuCell *> *newList = nil;
- if (menuCell.subCells != nil) {
- newList = [menuCell.subCells mutableCopy];
- } else {
- newList = [NSMutableArray array];
- }
+ if (cell.parentCellId == ParentIdNotFound) {
+ // The cell does not have a parent id, just insert it into the main menu
+ [self sdl_insertMenuCell:cell intoList:menuCellList atPosition:position];
+ return YES;
+ }
- [self sdl_insertMenuCell:cell intoList:newList atPosition:position];
+ // If the cell has a parent id, we need to find the cell with a matching cell id and insert it into its submenu
+ for (SDLMenuCell *menuCell in menuCellList) {
+ if (menuCell.cellId == cell.parentCellId) {
+ // If we found the correct submenu, insert it into that submenu
+ NSMutableArray<SDLMenuCell *> *newList = nil;
+ if (menuCell.subCells != nil) {
+ newList = [menuCell.subCells mutableCopy];
+ } else {
+ newList = [NSMutableArray array];
+ }
+
+ [self sdl_insertMenuCell:cell intoList:newList atPosition:position];
+ menuCell.subCells = [newList copy];
+ return YES;
+ } else if (menuCell.subCells.count > 0) {
+ // Check the subcells of this cell to see if any of those have cell ids that match the parent cell id
+ NSMutableArray<SDLMenuCell *> *newList = [menuCell.subCells mutableCopy];
+ BOOL foundAndAddedItem = [self sdl_addMenuCell:cell toList:newList atPosition:position];
+ if (foundAndAddedItem) {
menuCell.subCells = [newList copy];
return YES;
- } else if (menuCell.subCells.count > 0) {
- // Check the subcells of this cell to see if any of those have cell ids that match the parent cell id
- NSMutableArray<SDLMenuCell *> *newList = [menuCell.subCells mutableCopy];
- BOOL foundAndAddedItem = [self sdl_addMenuCell:cell toList:newList atPosition:position];
- if (foundAndAddedItem) {
- menuCell.subCells = [newList copy];
- return YES;
- }
}
}
-
- return NO;
- } else {
- // The cell does not have a parent id, just insert it into the main menu
- [self sdl_insertMenuCell:cell intoList:menuCellList atPosition:position];
- return YES;
}
+
+ return NO;
}
+ (void)sdl_insertMenuCell:(SDLMenuCell *)cell intoList:(NSMutableArray<SDLMenuCell *> *)cellList atPosition:(UInt16)position {
@@ -279,9 +311,9 @@
}
if (position > cellList.count) {
- [cellList addObject:cell];
+ [cellList addObject:cellToInsert];
} else {
- [cellList insertObject:cell atIndex:position];
+ [cellList insertObject:cellToInsert atIndex:position];
}
}
diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLMenuManagerSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLMenuManagerSpec.m
index b1b99bee5..f0623ab49 100644
--- a/SmartDeviceLinkTests/DevAPISpecs/SDLMenuManagerSpec.m
+++ b/SmartDeviceLinkTests/DevAPISpecs/SDLMenuManagerSpec.m
@@ -31,8 +31,6 @@
@property (copy, nonatomic) NSArray<SDLMenuCell *> *currentMenuCells;
@property (strong, nonatomic, nullable) SDLMenuConfiguration *currentMenuConfiguration;
-@property (assign, nonatomic) UInt32 lastMenuId;
-
@end
QuickSpecBegin(SDLMenuManagerSpec)
@@ -83,7 +81,6 @@ describe(@"menu manager", ^{
expect(testManager.currentSystemContext).to(beNil());
expect(testManager.currentMenuCells).to(beEmpty());
expect(testManager.currentMenuConfiguration).to(beNil());
- expect(testManager.lastMenuId).to(equal(1));
});
// when the manager stops
@@ -105,7 +102,6 @@ describe(@"menu manager", ^{
expect(testManager.currentSystemContext).to(beNil());
expect(testManager.currentMenuCells).to(beEmpty());
expect(testManager.currentMenuConfiguration).to(beNil());
- expect(testManager.lastMenuId).to(equal(1));
});
});
diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceOperationSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceOperationSpec.m
index b3b0c53da..9fb4a7883 100644
--- a/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceOperationSpec.m
+++ b/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceOperationSpec.m
@@ -17,13 +17,14 @@
@interface SDLMenuCell ()
+@property (assign, nonatomic) UInt32 parentCellId;
@property (assign, nonatomic) UInt32 cellId;
@end
QuickSpecBegin(SDLMenuReplaceOperationSpec)
-fdescribe(@"a menu replace operation", ^{
+describe(@"a menu replace operation", ^{
__block SDLMenuReplaceOperation *testOp = nil;
__block TestConnectionManager *testConnectionManager = nil;
@@ -61,15 +62,10 @@ fdescribe(@"a menu replace operation", ^{
testArtwork3.overwrite = YES;
textOnlyCell = [[SDLMenuCell alloc] initWithTitle:@"Test 1" secondaryText:nil tertiaryText:nil icon:nil secondaryArtwork:nil voiceCommands:nil handler:^(SDLTriggerSource _Nonnull triggerSource) {}];
- textOnlyCell.cellId = 1;
+ textOnlyCell2 = [[SDLMenuCell alloc] initWithTitle:@"Test 5" secondaryText:nil tertiaryText:nil icon:nil secondaryArtwork:nil voiceCommands:nil handler:^(SDLTriggerSource _Nonnull triggerSource) {}];
textAndImageCell = [[SDLMenuCell alloc] initWithTitle:@"Test 2" secondaryText:nil tertiaryText:nil icon:testArtwork secondaryArtwork:nil voiceCommands:nil handler:^(SDLTriggerSource _Nonnull triggerSource) {}];
- textAndImageCell.cellId = 2;
submenuCell = [[SDLMenuCell alloc] initWithTitle:@"Test 3" secondaryText:nil tertiaryText:nil icon:nil secondaryArtwork:nil submenuLayout:nil subCells:@[textOnlyCell, textAndImageCell]];
- submenuCell.cellId = 3;
submenuImageCell = [[SDLMenuCell alloc] initWithTitle:@"Test 4" secondaryText:nil tertiaryText:nil icon:testArtwork2 secondaryArtwork:nil submenuLayout:SDLMenuLayoutTiles subCells:@[textOnlyCell]];
- submenuImageCell.cellId = 4;
- textOnlyCell2 = [[SDLMenuCell alloc] initWithTitle:@"Test 5" secondaryText:nil tertiaryText:nil icon:nil secondaryArtwork:nil voiceCommands:nil handler:^(SDLTriggerSource _Nonnull triggerSource) {}];
- textOnlyCell2.cellId = 5;
addCommandSuccessResponse = [[SDLAddCommandResponse alloc] init];
addCommandSuccessResponse.success = @YES;
@@ -233,7 +229,7 @@ fdescribe(@"a menu replace operation", ^{
testNewMenu = @[submenuCell];
});
- fit(@"should send an appropriate number of AddSubmenu and AddCommandRequests", ^{
+ it(@"should send an appropriate number of AddSubmenu and AddCommandRequests", ^{
testOp = [[SDLMenuReplaceOperation alloc] initWithConnectionManager:testConnectionManager fileManager:testFileManager windowCapability:testWindowCapability menuConfiguration:testMenuConfiguration currentMenu:testCurrentMenu updatedMenu:testNewMenu compatibilityModeEnabled:YES currentMenuUpdatedHandler:testCurrentMenuUpdatedBlock];
[testOp start];
@@ -261,7 +257,6 @@ fdescribe(@"a menu replace operation", ^{
});
});
- // updating a menu without dynamic updates
describe(@"updating a menu without dynamic updates", ^{
context(@"adding a text cell", ^{
beforeEach(^{
@@ -273,10 +268,7 @@ fdescribe(@"a menu replace operation", ^{
testOp = [[SDLMenuReplaceOperation alloc] initWithConnectionManager:testConnectionManager fileManager:testFileManager windowCapability:testWindowCapability menuConfiguration:testMenuConfiguration currentMenu:testCurrentMenu updatedMenu:testNewMenu compatibilityModeEnabled:YES currentMenuUpdatedHandler:testCurrentMenuUpdatedBlock];
[testOp start];
- SDLDeleteCommandResponse *deleteCommandResponse = [[SDLDeleteCommandResponse alloc] init];
- deleteCommandResponse.success = @YES;
- deleteCommandResponse.resultCode = SDLResultSuccess;
- [testConnectionManager respondToLastRequestWithResponse:deleteCommandResponse];
+ [testConnectionManager respondToLastRequestWithResponse:deleteCommandSuccessResponse];
[testConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
NSPredicate *deleteCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass:%@", [SDLDeleteCommand class]];
@@ -287,6 +279,16 @@ fdescribe(@"a menu replace operation", ^{
expect(deletes).to(haveCount(1));
expect(adds).to(haveCount(2));
+
+ [testConnectionManager respondToRequestWithResponse:addCommandSuccessResponse requestNumber:1 error:nil];
+ [testConnectionManager respondToRequestWithResponse:addCommandSuccessResponse requestNumber:2 error:nil];
+ [testConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
+
+ expect(testOp.isFinished).to(beTrue());
+ expect(resultError).to(beNil());
+ expect(resultMenuCells).to(haveCount(2));
+ expect(resultMenuCells[0]).to(equal(textOnlyCell));
+ expect(resultMenuCells[1]).to(equal(textOnlyCell2));
});
});
});
@@ -311,33 +313,57 @@ fdescribe(@"a menu replace operation", ^{
expect(deletes).to(haveCount(0));
expect(adds).to(haveCount(1));
+
+ [testConnectionManager respondToLastRequestWithResponse:addCommandSuccessResponse];
+ [testConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
+
+ expect(testOp.isFinished).to(beTrue());
+ expect(resultError).to(beNil());
+ expect(resultMenuCells).to(haveCount(2));
+ });
+ });
+
+ context(@"rearranging cells with subcells", ^{
+ beforeEach(^{
+ testCurrentMenu = @[textOnlyCell, submenuCell, submenuImageCell];
+ testNewMenu = @[submenuCell, submenuImageCell, textOnlyCell];
+
+ OCMStub([testFileManager uploadArtworks:[OCMArg any] progressHandler:([OCMArg invokeBlockWithArgs:textAndImageCell.icon.name, @1.0, [NSNull null], nil]) completionHandler:([OCMArg invokeBlockWithArgs: @[textAndImageCell.icon.name], [NSNull null], nil])]);
+ });
+
+ it(@"should send dynamic deletes first then dynamic adds case with 2 submenu cells", ^{
+ testOp = [[SDLMenuReplaceOperation alloc] initWithConnectionManager:testConnectionManager fileManager:testFileManager windowCapability:testWindowCapability menuConfiguration:testMenuConfiguration currentMenu:testCurrentMenu updatedMenu:testNewMenu compatibilityModeEnabled:NO currentMenuUpdatedHandler:testCurrentMenuUpdatedBlock];
+ [testOp start];
+
+ // Delete textOnlyCell
+ [testConnectionManager respondToLastRequestWithResponse:deleteCommandSuccessResponse];
+ [testConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
+ expect(testOp.currentMenu).toNot(contain(textOnlyCell));
+
+ // Add textOnlyCell
+ [testConnectionManager respondToLastRequestWithResponse:addCommandSuccessResponse];
+ [testConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
+
+ NSPredicate *deleteCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass:%@", [SDLDeleteCommand class]];
+ NSArray *deletes = [[testConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:deleteCommandPredicate];
+
+ NSPredicate *addCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass:%@", [SDLAddCommand class]];
+ NSArray *adds = [[testConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:addCommandPredicate];
+
+ NSPredicate *addSubmenuPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass: %@", [SDLAddSubMenu class]];
+ NSArray *submenu = [[testConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:addSubmenuPredicate];
+
+ expect(deletes).to(haveCount(1));
+ expect(adds).to(haveCount(1));
+ expect(submenu).to(haveCount(0));
+
+ expect(testOp.isFinished).to(beTrue());
+ expect(resultError).to(beNil());
+ expect(resultMenuCells).to(haveCount(3));
});
});
});
-// it(@"should send dynamic deletes first then dynamic adds case with 2 submenu cells", ^{
-// testManager.menuCells = @[textOnlyCell, submenuCell, submenuImageCell];
-// [mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
-// [mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
-// [mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
-//
-// testManager.menuCells = @[submenuCell, submenuImageCell, textOnlyCell];
-// [mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
-// [mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
-//
-// NSPredicate *deleteCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass:%@", [SDLDeleteCommand class]];
-// NSArray *deletes = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:deleteCommandPredicate];
-//
-// NSPredicate *addCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass:%@", [SDLAddCommand class]];
-// NSArray *adds = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:addCommandPredicate];
-//
-// NSPredicate *addSubmenuPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass: %@", [SDLAddSubMenu class]];
-// NSArray *submenu = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:addSubmenuPredicate];
-//
-// expect(deletes).to(haveCount(1));
-// expect(adds).to(haveCount(5));
-// expect(submenu).to(haveCount(2));
-// });
//
// it(@"should send dynamic deletes first then dynamic adds when removing one submenu cell", ^{
// testManager.menuCells = @[textOnlyCell, textAndImageCell, submenuCell, submenuImageCell];
diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceUtilitiesSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceUtilitiesSpec.m
index fd1a19b01..e3a28a796 100644
--- a/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceUtilitiesSpec.m
+++ b/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceUtilitiesSpec.m
@@ -7,6 +7,7 @@
#import "SDLFileManager.h"
#import "SDLMenuCell.h"
#import "SDLMenuReplaceUtilitiesSpecHelpers.h"
+#import "SDLMenuManagerPrivateConstants.h"
#import "SDLWindowCapability.h"
#import "TestConnectionManager.h"
@@ -18,6 +19,12 @@
@end
+@interface SDLMenuReplaceUtilities ()
+
+@property (class, assign, nonatomic) UInt32 nextMenuId;
+
+@end
+
QuickSpecBegin(SDLMenuReplaceUtilitiesSpec)
__block NSMutableArray<SDLMenuCell *> *testMenuCells = nil;
@@ -36,6 +43,37 @@ __block NSArray<SDLImageField *> *allSupportedImageFields = @[
[[SDLImageField alloc] initWithName:SDLImageFieldNameMenuSubMenuSecondaryImage imageTypeSupported:@[SDLImageTypeDynamic] imageResolution:nil]
];
+describe(@"adding ids", ^{
+ it(@"should properly add ids", ^{
+ SDLMenuReplaceUtilities.nextMenuId = 0;
+ testMenuCells = SDLMenuReplaceUtilitiesSpecHelpers.deepMenu;
+
+ [SDLMenuReplaceUtilities updateIdsOnMenuCells:testMenuCells parentId:ParentIdNotFound];
+
+ expect(testMenuCells[0].cellId).to(equal(1));
+ expect(testMenuCells[1].cellId).to(equal(6));
+ expect(testMenuCells[2].cellId).to(equal(7));
+
+ NSArray<SDLMenuCell *> *subCellList1 = testMenuCells[0].subCells;
+ expect(subCellList1[0].cellId).to(equal(2));
+ expect(subCellList1[0].parentCellId).to(equal(1));
+ expect(subCellList1[1].cellId).to(equal(5));
+ expect(subCellList1[1].parentCellId).to(equal(1));
+
+ NSArray<SDLMenuCell *> *subCell1SubCellList1 = subCellList1[0].subCells;
+ expect(subCell1SubCellList1[0].cellId).to(equal(3));
+ expect(subCell1SubCellList1[0].parentCellId).to(equal(2));
+ expect(subCell1SubCellList1[1].cellId).to(equal(4));
+ expect(subCell1SubCellList1[1].parentCellId).to(equal(2));
+
+ NSArray<SDLMenuCell *> *subCellList2 = testMenuCells[2].subCells;
+ expect(subCellList2[0].cellId).to(equal(8));
+ expect(subCellList2[0].parentCellId).to(equal(7));
+ expect(subCellList2[1].cellId).to(equal(9));
+ expect(subCellList2[1].parentCellId).to(equal(7));
+ });
+});
+
describe(@"finding all artworks from cells", ^{
beforeEach(^{
mockFileManager = OCMClassMock([SDLFileManager class]);
@@ -267,6 +305,7 @@ describe(@"updating menu cell lists", ^{
context(@"from a shallow list", ^{
beforeEach(^{
testMenuCells = SDLMenuReplaceUtilitiesSpecHelpers.topLevelOnlyMenu;
+ [SDLMenuReplaceUtilities updateIdsOnMenuCells:testMenuCells parentId:ParentIdNotFound];
});
context(@"when the cell is in the menu", ^{
@@ -303,6 +342,7 @@ describe(@"updating menu cell lists", ^{
context(@"from a deep list", ^{
beforeEach(^{
testMenuCells = SDLMenuReplaceUtilitiesSpecHelpers.deepMenu;
+ [SDLMenuReplaceUtilities updateIdsOnMenuCells:testMenuCells parentId:ParentIdNotFound];
});
context(@"when the cell is in the top menu", ^{
@@ -360,6 +400,7 @@ describe(@"updating menu cell lists", ^{
context(@"from a shallow list", ^{
beforeEach(^{
testMenuCells = SDLMenuReplaceUtilitiesSpecHelpers.topLevelOnlyMenu;
+ [SDLMenuReplaceUtilities updateIdsOnMenuCells: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;
@@ -409,23 +450,30 @@ describe(@"updating menu cell lists", ^{
});
});
- context(@"from a deep list", ^{
+ fcontext(@"from a deep list", ^{
+ __block SDLMenuCell *subCell = nil;
+ __block NSMutableArray<SDLMenuCell *> *newMenu = nil;
+
beforeEach(^{
testMenuCells = SDLMenuReplaceUtilitiesSpecHelpers.deepMenu;
+ [SDLMenuReplaceUtilities updateIdsOnMenuCells:testMenuCells parentId:ParentIdNotFound];
- 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];
+ newMenu = SDLMenuReplaceUtilitiesSpecHelpers.deepMenu.mutableCopy;
+ NSMutableArray<SDLMenuCell *> *subMenuToUpdate = newMenu[0].subCells.mutableCopy;
+ subCell = [[SDLMenuCell alloc] initWithTitle:@"New SubCell" secondaryText:nil tertiaryText:nil icon:nil secondaryArtwork:nil voiceCommands:nil handler:^(SDLTriggerSource _Nonnull triggerSource) {}];
+ [subMenuToUpdate insertObject:subCell atIndex:0];
+ newMenu[0].subCells = subMenuToUpdate.copy;
+
+ [SDLMenuReplaceUtilities updateIdsOnMenuCells:newMenu parentId:ParentIdNotFound];
});
it(@"should properly add the subcell to the list", ^{
- BOOL didAddCell = [SDLMenuReplaceUtilities addCellWithCellId:98 position:0 fromNewMenuList:newCellList toMainMenuList:testMenuCells];
+ BOOL didAddCell = [SDLMenuReplaceUtilities addCellWithCellId:newMenu[0].subCells[0].cellId position:0 fromNewMenuList:newMenu toMainMenuList:testMenuCells];
expect(didAddCell).to(beTrue());
- expect(testMenuCells).to(haveCount(4));
- expect(testMenuCells[0]).to(equal(newCellList[0].subCells[0]));
+ expect(testMenuCells).to(haveCount(3));
+ expect(testMenuCells[0].subCells).to(haveCount(3));
+ expect(testMenuCells[0].subCells[0]).to(equal(subCell));
});
});
});
diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceUtilitiesSpecHelpers.m b/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceUtilitiesSpecHelpers.m
index 2b9bef2b9..acb885b67 100644
--- a/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceUtilitiesSpecHelpers.m
+++ b/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceUtilitiesSpecHelpers.m
@@ -49,29 +49,29 @@
SDLArtwork *artwork4 = [[SDLArtwork alloc] initWithData:cellArtData4 name:@"Test Art 4" fileExtension:@"png" persistent:NO];
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;
+// 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;
+// 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;
+// 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;
+// 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;
+// 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;
+// 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;
+// 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;
+// 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;
+// topListCell3.cellId = 9;
return [@[topListCell1, topListCell2, topListCell3] mutableCopy];
}