diff --git a/SmartDeviceLink/SDLAddCommand.h b/SmartDeviceLink/SDLAddCommand.h index 509ea80fa..f7c494df9 100644 --- a/SmartDeviceLink/SDLAddCommand.h +++ b/SmartDeviceLink/SDLAddCommand.h @@ -49,9 +49,9 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)initWithId:(UInt32)commandId vrCommands:(nullable NSArray *)vrCommands handler:(nullable SDLRPCCommandNotificationHandler)handler; -- (instancetype)initWithId:(UInt32)commandId vrCommands:(nullable NSArray *)vrCommands menuName:(NSString *)menuName handler:(SDLRPCCommandNotificationHandler)handler; +- (instancetype)initWithId:(UInt32)commandId vrCommands:(nullable NSArray *)vrCommands menuName:(NSString *)menuName handler:(nullable SDLRPCCommandNotificationHandler)handler; -- (instancetype)initWithId:(UInt32)commandId vrCommands:(nullable NSArray *)vrCommands menuName:(NSString *)menuName parentId:(UInt32)parentId position:(UInt16)position iconValue:(NSString *)iconValue iconType:(SDLImageType)iconType handler:(nullable SDLRPCCommandNotificationHandler)handler; +- (instancetype)initWithId:(UInt32)commandId vrCommands:(nullable NSArray *)vrCommands menuName:(NSString *)menuName parentId:(UInt32)parentId position:(UInt16)position iconValue:(nullable NSString *)iconValue iconType:(nullable SDLImageType)iconType handler:(nullable SDLRPCCommandNotificationHandler)handler; /** * A handler that will let you know when the button you created is subscribed. diff --git a/SmartDeviceLink/SDLAddCommand.m b/SmartDeviceLink/SDLAddCommand.m index bfec12164..28c60219d 100644 --- a/SmartDeviceLink/SDLAddCommand.m +++ b/SmartDeviceLink/SDLAddCommand.m @@ -43,7 +43,7 @@ - (instancetype)initWithId:(UInt32)commandId vrCommands:(nullable NSArray *)vrCommands menuName:(NSString *)menuName handler:(SDLRPCCommandNotificationHandler)handler { +- (instancetype)initWithId:(UInt32)commandId vrCommands:(nullable NSArray *)vrCommands menuName:(NSString *)menuName handler:(nullable SDLRPCCommandNotificationHandler)handler { self = [self initWithId:commandId vrCommands:vrCommands handler:handler]; if (!self) { return nil; @@ -54,7 +54,7 @@ - (instancetype)initWithId:(UInt32)commandId vrCommands:(nullable NSArray *)vrCommands menuName:(NSString *)menuName parentId:(UInt32)parentId position:(UInt16)position iconValue:(NSString *)iconValue iconType:(SDLImageType)iconType handler:(nullable SDLRPCCommandNotificationHandler)handler { +- (instancetype)initWithId:(UInt32)commandId vrCommands:(nullable NSArray *)vrCommands menuName:(NSString *)menuName parentId:(UInt32)parentId position:(UInt16)position iconValue:(nullable NSString *)iconValue iconType:(nullable SDLImageType)iconType handler:(nullable SDLRPCCommandNotificationHandler)handler { self = [self initWithId:commandId vrCommands:vrCommands menuName:menuName handler:handler]; if (!self) { return nil; @@ -63,7 +63,9 @@ - (instancetype)initWithId:(UInt32)commandId vrCommands:(nullable NSArray *vrCommands = @[@"commands"]; + __block NSString *menuName = @"Menu Name"; + void (^handler)(SDLOnCommand *) = ^(SDLOnCommand *command) {}; + + beforeEach(^{ + testCommand = nil; + }); + + context(@"initWithHandler", ^{ + it(@"should initialize correctly", ^{ + testCommand = [[SDLAddCommand alloc] initWithHandler:handler]; + + expect(testCommand).toNot(beNil()); + expect(testCommand.vrCommands).to(beNil()); + expect(testCommand.menuParams).to(beNil()); + expect(testCommand.cmdIcon).to(beNil()); + }); + }); + + context(@"initWithId:vrCommands:handler:", ^{ + it(@"should initialize correctly", ^{ + testCommand = [[SDLAddCommand alloc] initWithId:commandId vrCommands:vrCommands handler:nil]; + + expect(testCommand.cmdID).to(equal(commandId)); + expect(testCommand.vrCommands).to(equal(vrCommands)); + expect(testCommand.menuParams).to(beNil()); + expect(testCommand.cmdIcon).to(beNil()); + }); + }); + + context(@"initWithId:vrCommands:menuName:handler:", ^{ + it(@"should initialize correctly", ^{ + testCommand = [[SDLAddCommand alloc] initWithId:commandId vrCommands:vrCommands menuName:menuName handler:nil]; + + expect(testCommand.cmdID).to(equal(commandId)); + expect(testCommand.vrCommands).to(equal(vrCommands)); + expect(testCommand.menuParams).toNot(beNil()); + expect(testCommand.cmdIcon).to(beNil()); + }); + }); + + context(@"initWithId:vrCommands:menuName:parentId:position:iconValue:iconType:handler:", ^{ + __block UInt32 parentId = 1234; + __block UInt16 position = 2; + + it(@"should initialize with an image", ^{ + NSString *iconValue = @"Icon"; + SDLImageType imageType = SDLImageTypeDynamic; + + testCommand = [[SDLAddCommand alloc] initWithId:commandId vrCommands:vrCommands menuName:menuName parentId:parentId position:position iconValue:iconValue iconType:imageType handler:nil]; + + expect(testCommand.cmdID).to(equal(commandId)); + expect(testCommand.vrCommands).to(equal(vrCommands)); + expect(testCommand.menuParams.menuName).toNot(beNil()); + expect(testCommand.menuParams.parentID).to(equal(parentId)); + expect(testCommand.menuParams.position).to(equal(position)); + expect(testCommand.cmdIcon).toNot(beNil()); + }); + + it(@"should initialize without an image", ^{ + testCommand = [[SDLAddCommand alloc] initWithId:commandId vrCommands:vrCommands menuName:menuName parentId:parentId position:position iconValue:nil iconType:nil handler:nil]; + + expect(testCommand.cmdID).to(equal(commandId)); + expect(testCommand.vrCommands).to(equal(vrCommands)); + expect(testCommand.menuParams.menuName).toNot(beNil()); + expect(testCommand.menuParams.parentID).to(equal(parentId)); + expect(testCommand.menuParams.position).to(equal(position)); + expect(testCommand.cmdIcon).to(beNil()); + }); + }); +}); + QuickSpecEnd