Skip to content

Commit

Permalink
Merge pull request #1313 from smartdevicelink/bugfix/issue-1312-Cell-…
Browse files Browse the repository at this point in the history
…Icons-dont-show

Cell Icons do not show up on first menu set
  • Loading branch information
joeljfischer committed Jun 25, 2019
2 parents c5cb8a3 + 0b507d3 commit cb4f94e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 44 deletions.
19 changes: 9 additions & 10 deletions SmartDeviceLink/SDLMenuManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -273,16 +273,16 @@ - (void)sdl_startDynamicMenuUpdate {
[weakself sdl_startSubMenuUpdatesWithOldKeptCells:oldKeeps newKeptCells:newKeeps atIndex:0];
}];
}];
} else {
// Cells have no artwork to load
__weak typeof(self) weakself = self;
[self sdl_updateMenuWithCellsToDelete:cellsToDelete cellsToAdd:cellsToAdd completionHandler:^(NSError * _Nullable error) {
[weakself sdl_startSubMenuUpdatesWithOldKeptCells:oldKeeps newKeptCells:newKeeps atIndex:0];
}];
}
// Update cells without artworks
__weak typeof(self) weakself = self;
[self sdl_updateMenuWithCellsToDelete:cellsToDelete cellsToAdd:cellsToAdd completionHandler:^(NSError * _Nullable error) {
[weakself sdl_startSubMenuUpdatesWithOldKeptCells:oldKeeps newKeptCells:newKeeps atIndex:0];
}];
}

- (void)sdl_startNonDynamicMenuUpdate {
self.lastMenuId = MenuCellIdMin;
[self sdl_updateIdsOnMenuCells:self.menuCells parentId:ParentIdNotFound];

NSArray<SDLArtwork *> *artworksToBeUploaded = [self sdl_findAllArtworksToBeUploadedFromCells:self.menuCells];
Expand All @@ -293,12 +293,12 @@ - (void)sdl_startNonDynamicMenuUpdate {
}

SDLLogD(@"Menu artworks uploaded");
// Update cells with artworks once they're uploaded
[self sdl_updateMenuWithCellsToDelete:self.oldMenuCells cellsToAdd:self.menuCells completionHandler:nil];
}];
} else {
// Cells have no artwork to load
[self sdl_updateMenuWithCellsToDelete:self.oldMenuCells cellsToAdd:self.menuCells completionHandler:nil];
}
// Update cells without artworks
[self sdl_updateMenuWithCellsToDelete:self.oldMenuCells cellsToAdd:self.menuCells completionHandler:nil];
}

- (void)sdl_updateMenuWithCellsToDelete:(NSArray<SDLMenuCell *> *)deleteCells cellsToAdd:(NSArray<SDLMenuCell *> *)addCells completionHandler:(nullable SDLMenuUpdateCompletionHandler)completionHandler {
Expand All @@ -315,7 +315,6 @@ - (void)sdl_updateMenuWithCellsToDelete:(NSArray<SDLMenuCell *> *)deleteCells ce
self.hasQueuedUpdate = YES;
return;
}

__weak typeof(self) weakself = self;
[self sdl_sendDeleteCurrentMenu:deleteCells withCompletionHandler:^(NSError * _Nullable error) {
[weakself sdl_sendUpdatedMenu:addCells usingMenu:weakself.menuCells withCompletionHandler:^(NSError * _Nullable error) {
Expand Down
66 changes: 32 additions & 34 deletions SmartDeviceLinkTests/DevAPISpecs/SDLMenuManagerSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ @interface SDLMenuManager()
});

it(@"should properly update with subcells", ^{
OCMStub([mockFileManager uploadArtworks:[OCMArg any] completionHandler:[OCMArg invokeBlock]]);
testManager.menuCells = @[submenuCell];
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];

Expand Down Expand Up @@ -278,12 +279,14 @@ @interface SDLMenuManager()
});
});

// No longer a valid unit test
context(@"when the image is not on the head unit", ^{
beforeEach(^{
OCMStub([mockFileManager hasUploadedFile:[OCMArg isNotNil]]).andReturn(NO);
testManager.dynamicMenuUpdatesMode = SDLDynamicMenuUpdatesModeForceOff;
OCMStub([mockFileManager uploadArtworks:[OCMArg any] completionHandler:[OCMArg invokeBlock]]);
});

it(@"should immediately attempt to update without the image", ^{
it(@"should wait till image is on head unit and attempt to update without the image", ^{
testManager.menuCells = @[textAndImageCell, submenuImageCell];

NSPredicate *addCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass: %@", [SDLAddCommand class]];
Expand Down Expand Up @@ -314,28 +317,24 @@ @interface SDLMenuManager()
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];

testManager.menuCells = @[textAndImageCell];
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES]; // Without Artwork
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES]; // Without Artwork
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES]; // With Artwork
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES]; // With Artwork

[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];

expect(deletes).to(haveCount(2));
expect(adds).to(haveCount(3));
expect(deletes).to(haveCount(1));
expect(adds).to(haveCount(2));
});

it(@"should send dynamic deletes first then dynamic adds case with 2 submenu cells", ^{
testManager.menuCells = @[textOnlyCell, submenuCell, submenuImageCell];
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES]; // Without Artwork
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES]; // Without Artwork
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES]; // With Artwork
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES]; // With Artwork
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];

testManager.menuCells = @[submenuCell, submenuImageCell, textOnlyCell];
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
Expand All @@ -351,16 +350,14 @@ @interface SDLMenuManager()
NSArray *submenu = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:addSubmenuPredicate];

expect(deletes).to(haveCount(1));
expect(adds).to(haveCount(9));
expect(submenu).to(haveCount(4));
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];
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES]; // Without Artwork
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES]; // Without Artwork
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES]; // With Artwork
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES]; // With Artwork
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];

testManager.menuCells = @[textOnlyCell, textAndImageCell, submenuCell];
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
Expand All @@ -380,17 +377,14 @@ @interface SDLMenuManager()

expect(deletes).to(haveCount(0));
expect(subDeletes).to(haveCount(1));
expect(adds).to(haveCount(10));
expect(submenu).to(haveCount(4));
expect(adds).to(haveCount(5));
expect(submenu).to(haveCount(2));
});

it(@"should send dynamic deletes first then dynamic adds when adding one new cell", ^{
testManager.menuCells = @[textOnlyCell, textAndImageCell, submenuCell, submenuImageCell];
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES]; // Without Artwork
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES]; // Without Artwork
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES]; // With Artwork
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES]; // With Artwork

[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];

testManager.menuCells = @[textOnlyCell, textAndImageCell, submenuCell, submenuImageCell, textOnlyCell2];
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
Expand All @@ -406,18 +400,18 @@ @interface SDLMenuManager()
NSArray *submenu = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:addSubmenuPredicate];

expect(deletes).to(haveCount(0));
expect(adds).to(haveCount(11));
expect(submenu).to(haveCount(4));
expect(adds).to(haveCount(6));
expect(submenu).to(haveCount(2));
});

it(@"should send dynamic deletes first then dynamic adds when cells stay the same", ^{
testManager.menuCells = @[textOnlyCell, textOnlyCell2, textAndImageCell];
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];

testManager.menuCells = @[textOnlyCell, textOnlyCell2, textAndImageCell];
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];

NSPredicate *deleteCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass:%@", [SDLDeleteCommand class]];
NSArray *deletes = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:deleteCommandPredicate];
Expand All @@ -426,22 +420,24 @@ @interface SDLMenuManager()
NSArray *adds = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:addCommandPredicate];

expect(deletes).to(haveCount(0));
expect(adds).to(haveCount(6));
expect(adds).to(haveCount(3));
});
});

describe(@"updating when a menu already exists with dynamic updates off", ^{
beforeEach(^{
testManager.dynamicMenuUpdatesMode = SDLDynamicMenuUpdatesModeForceOff;
testManager.dynamicMenuUpdatesMode = SDLDynamicMenuUpdatesModeForceOff;
OCMStub([mockFileManager uploadArtworks:[OCMArg any] completionHandler:[OCMArg invokeBlock]]);
});

it(@"should send deletes first", ^{
testManager.menuCells = @[textOnlyCell];
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES]; // Adds
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES]; // Submenu
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];

testManager.menuCells = @[textAndImageCell];
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];

NSPredicate *deleteCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass:%@", [SDLDeleteCommand class]];
NSArray *deletes = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:deleteCommandPredicate];
Expand All @@ -460,6 +456,7 @@ @interface SDLMenuManager()

testManager.menuCells = @[textAndImageCell, textOnlyCell];
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];

NSPredicate *deleteCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass:%@", [SDLDeleteCommand class]];
NSArray *deletes = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:deleteCommandPredicate];
Expand Down Expand Up @@ -533,6 +530,7 @@ @interface SDLMenuManager()

testManager.menuCells = @[textOnlyCell, textOnlyCell2, textAndImageCell];
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
[mockConnectionManager respondToLastMultipleRequestsWithSuccess:YES];

NSPredicate *deleteCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass:%@", [SDLDeleteCommand class]];
NSArray *deletes = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:deleteCommandPredicate];
Expand Down

0 comments on commit cb4f94e

Please sign in to comment.