From 731ad74437e7ef62347cd21b8ef82b099c2877c4 Mon Sep 17 00:00:00 2001 From: Joel Fischer Date: Thu, 21 Oct 2021 09:11:02 -0400 Subject: Fix submenu layout is not copied on menu cells --- SmartDeviceLink/public/SDLMenuCell.m | 1 + SmartDeviceLinkTests/DevAPISpecs/SDLMenuCellSpec.m | 32 +++++++++++++++------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/SmartDeviceLink/public/SDLMenuCell.m b/SmartDeviceLink/public/SDLMenuCell.m index 4f780a579..845d10f04 100644 --- a/SmartDeviceLink/public/SDLMenuCell.m +++ b/SmartDeviceLink/public/SDLMenuCell.m @@ -134,6 +134,7 @@ NS_ASSUME_NONNULL_BEGIN if (_subCells.count > 0) { newCell.subCells = [[NSArray alloc] initWithArray:_subCells copyItems:YES]; + newCell->_submenuLayout = _submenuLayout; } return newCell; diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLMenuCellSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLMenuCellSpec.m index 4958e7674..02bb07a1c 100644 --- a/SmartDeviceLinkTests/DevAPISpecs/SDLMenuCellSpec.m +++ b/SmartDeviceLinkTests/DevAPISpecs/SDLMenuCellSpec.m @@ -15,6 +15,8 @@ describe(@"a menu cell", ^{ __block NSString *someTertiaryTitle = nil; __block SDLArtwork *someArtwork = nil; __block SDLArtwork *someSecondaryArtwork = nil; + __block NSArray *someVoiceCommands = nil; + __block NSArray *someSubcells = nil; beforeEach(^{ someTitle = @"Some Title"; @@ -22,19 +24,11 @@ describe(@"a menu cell", ^{ someTertiaryTitle = @"Some Title 3"; someArtwork = [[SDLArtwork alloc] initWithData:[[NSData alloc] initWithBase64EncodedString:@"data" options:kNilOptions] name:@"Some artwork" fileExtension:@"png" persistent:NO]; someSecondaryArtwork = [[SDLArtwork alloc] initWithData:[[NSData alloc] initWithBase64EncodedString:@"data" options:kNilOptions] name:@"Some artwork 2" fileExtension:@"png" persistent:NO]; + someVoiceCommands = @[@"some command"]; + someSubcells = @[[[SDLMenuCell alloc] initWithTitle:@"Test Subcell" secondaryText:nil tertiaryText:nil icon:nil secondaryArtwork:nil voiceCommands:nil handler:^(SDLTriggerSource _Nonnull triggerSource) {}], [[SDLMenuCell alloc] initWithTitle:@"Test Subcell2" secondaryText:nil tertiaryText:nil icon:nil secondaryArtwork:nil voiceCommands:nil handler:^(SDLTriggerSource _Nonnull triggerSource) {}]]; }); describe(@"initializing", ^{ - __block NSArray *someVoiceCommands = nil; - __block NSArray *someSubcells = nil; - - beforeEach(^{ - someVoiceCommands = @[@"some command"]; - - SDLMenuCell *subcell = [[SDLMenuCell alloc] initWithTitle:@"Hello" secondaryText:nil tertiaryText:nil icon:nil secondaryArtwork:nil voiceCommands:nil handler:^(SDLTriggerSource _Nonnull triggerSource) {}]; - someSubcells = @[subcell]; - }); - it(@"should set initWithTitle:icon:submenuLayout:subCells: propertly", ^{ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" @@ -135,6 +129,24 @@ describe(@"a menu cell", ^{ expect([testCell isEqual:testCell2]).to(beFalse()); }); }); + + describe(@"copying a cell", ^{ + context(@"a submenu cell", ^{ + it(@"should copy correctly", ^{ + testCell = [[SDLMenuCell alloc] initWithTitle:someTitle secondaryText:someSecondaryTitle tertiaryText:someTertiaryTitle icon:someArtwork secondaryArtwork:someSecondaryArtwork submenuLayout:testLayout subCells:someSubcells]; + testCell2 = [testCell copy]; + + expect(testCell2).to(equal(testCell)); + }); + }); + + context(@"a normal cell", ^{ + testCell = [[SDLMenuCell alloc] initWithTitle:someTitle secondaryText:someSecondaryTitle tertiaryText:someTertiaryTitle icon:someArtwork secondaryArtwork:someSecondaryArtwork voiceCommands:someVoiceCommands handler:^(SDLTriggerSource _Nonnull triggerSource) {}]; + testCell2 = [testCell copy]; + + expect(testCell2).to(equal(testCell)); + }); + }); }); QuickSpecEnd -- cgit v1.2.1