summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Gluck <justin.gluck@livio.io>2019-07-26 10:54:28 -0400
committerJustin Gluck <justin.gluck@livio.io>2019-07-26 10:54:28 -0400
commitfd726f766c401ef47601a6de15dacbdf8cbbc72e (patch)
treedf121c62e0a32d9fae85e20b82aed69e452eeb44
parentd3c2d373a4689aca6b2aa1d97dcf85ff90160efb (diff)
downloadsdl_ios-fd726f766c401ef47601a6de15dacbdf8cbbc72e.tar.gz
adding more unit tests fixing other tests, added logic to not send RPC is cell in invalid
-rw-r--r--SmartDeviceLink/SDLMenuManager.m10
-rw-r--r--SmartDeviceLinkTests/DevAPISpecs/SDLMenuManagerSpec.m32
-rw-r--r--SmartDeviceLinkTests/SDLScreenManagerSpec.m6
3 files changed, 44 insertions, 4 deletions
diff --git a/SmartDeviceLink/SDLMenuManager.m b/SmartDeviceLink/SDLMenuManager.m
index 46befd151..b0707acba 100644
--- a/SmartDeviceLink/SDLMenuManager.m
+++ b/SmartDeviceLink/SDLMenuManager.m
@@ -643,12 +643,20 @@ UInt32 const MenuCellIdMin = 1;
[self.connectionManager sendConnectionRequest:[[SDLShowAppMenu alloc] init] withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) {
if (error != nil) {
SDLLogE(@"Error opening application menu: %@", error);
+ return;
}
}];
}
- (void)openSubmenu:(SDLMenuCell *)cell {
- [self.connectionManager sendConnectionRequest:[[SDLShowAppMenu alloc] initWithMenuID:cell.cellId] withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) {
+ if (cell.subCells == 0) {
+ SDLLogW(@"The cell does not contain any sub cells, RPC will not be sent");
+ return;
+ }
+
+ SDLShowAppMenu *subMenu = [[SDLShowAppMenu alloc] initWithMenuID:cell.cellId];
+
+ [self.connectionManager sendConnectionRequest:subMenu withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) {
if (error != nil) {
SDLLogE(@"Error opening application menu: %@", error);
}
diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLMenuManagerSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLMenuManagerSpec.m
index 6980fb02a..c435f7b4e 100644
--- a/SmartDeviceLinkTests/DevAPISpecs/SDLMenuManagerSpec.m
+++ b/SmartDeviceLinkTests/DevAPISpecs/SDLMenuManagerSpec.m
@@ -610,6 +610,38 @@ describe(@"menu manager", ^{
});
});
+ describe(@"Opening Menu", ^{
+ it(@"should send showAppMenu RPC", ^{
+ [testManager openMenu];
+
+ NSPredicate *addSubmenuPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass: %@", [SDLShowAppMenu class]];
+ NSArray *openMenu = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:addSubmenuPredicate];
+
+ expect(mockConnectionManager.receivedRequests).toNot(beEmpty());
+ expect(openMenu).to(haveCount(0));
+ });
+
+ it(@"should send showAppMenu RPC with cellID ", ^ {
+ [testManager openSubmenu:submenuCell];
+
+ NSPredicate *addSubmenuPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass: %@", [SDLShowAppMenu class]];
+ NSArray *openMenu = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:addSubmenuPredicate];
+
+ expect(mockConnectionManager.receivedRequests).toNot(beEmpty());
+ expect(openMenu).to(haveCount(1));
+ });
+
+ it(@"should not send a showAppMenu RPC when cellID is invalid ", ^ {
+ [testManager openSubmenu:textOnlyCell];
+
+ NSPredicate *addSubmenuPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass: %@", [SDLShowAppMenu class]];
+ NSArray *openMenu = [[mockConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:addSubmenuPredicate];
+
+ expect(mockConnectionManager.receivedRequests).to(beEmpty());
+ expect(openMenu).to(haveCount(0));
+ });
+ });
+
afterEach(^{
testManager = nil;
});
diff --git a/SmartDeviceLinkTests/SDLScreenManagerSpec.m b/SmartDeviceLinkTests/SDLScreenManagerSpec.m
index b3585fe63..71fb9acd6 100644
--- a/SmartDeviceLinkTests/SDLScreenManagerSpec.m
+++ b/SmartDeviceLinkTests/SDLScreenManagerSpec.m
@@ -152,7 +152,7 @@ describe(@"screen manager", ^{
});
});
- describe(@"open menu when RPC is not supported", ^{
+ describe(@"open menu when spec versioning is not supported", ^{
beforeEach(^{
SDLVersion *oldVersion = [SDLVersion versionWithMajor:5 minor:0 patch:0];
id globalMock = OCMPartialMock([SDLGlobals sharedGlobals]);
@@ -172,7 +172,7 @@ describe(@"screen manager", ^{
});
- describe(@"open menu when RPC is supported", ^{
+ describe(@"open menu when spec versioning supported", ^{
beforeEach(^{
SDLVersion *oldVersion = [SDLVersion versionWithMajor:6 minor:0 patch:0];
id globalMock = OCMPartialMock([SDLGlobals sharedGlobals]);
@@ -189,7 +189,7 @@ describe(@"screen manager", ^{
OCMVerify([mockMenuManger openMenu]);
});
- it(@"should return NO if spec versioning is supported when openSubMenu is called", ^{
+ it(@"should return YES if spec versioning is supported when openSubMenu is called", ^{
SDLMenuCell *cell = [[SDLMenuCell alloc] init];
BOOL canSendRPC = [testScreenManager openSubmenu:cell];