summaryrefslogtreecommitdiff
path: root/SmartDeviceLinkTests/DevAPISpecs
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2021-02-25 16:05:21 -0500
committerJoel Fischer <joeljfischer@gmail.com>2021-02-25 16:05:21 -0500
commit3e238f0ecebfb067c4dae10ff6b35364f4c6243a (patch)
tree5acea2af435f039a961abd0501c7985f9f3ca700 /SmartDeviceLinkTests/DevAPISpecs
parent2ecf74d2d34d5e71e139eeef54633f1a9ef8fe7c (diff)
downloadsdl_ios-3e238f0ecebfb067c4dae10ff6b35364f4c6243a.tar.gz
New tests and fixes
Diffstat (limited to 'SmartDeviceLinkTests/DevAPISpecs')
-rw-r--r--SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceOperationSpec.m69
1 files changed, 46 insertions, 23 deletions
diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceOperationSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceOperationSpec.m
index 702c1a3e0..5eea34c80 100644
--- a/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceOperationSpec.m
+++ b/SmartDeviceLinkTests/DevAPISpecs/SDLMenuReplaceOperationSpec.m
@@ -37,6 +37,8 @@ describe(@"a menu replace operation", ^{
__block SDLMenuCell *submenuCell = nil;
__block SDLMenuCell *submenuImageCell = nil;
+ __block SDLAddCommandResponse *addCommandSuccessResponse = nil;
+
__block NSArray<SDLMenuCell *> *receivedMenuCells = nil;
__block NSError *receivedError = nil;
__block SDLCurrentMenuUpdatedBlock testCurrentMenuUpdatedBlock = nil;
@@ -55,6 +57,10 @@ describe(@"a menu replace operation", ^{
submenuImageCell = [[SDLMenuCell alloc] initWithTitle:@"Test 4" icon:testArtwork2 submenuLayout:SDLMenuLayoutTiles subCells:@[textOnlyCell]];
textOnlyCell2 = [[SDLMenuCell alloc] initWithTitle:@"Test 5" icon:nil voiceCommands:nil handler:^(SDLTriggerSource _Nonnull triggerSource) {}];
+ addCommandSuccessResponse = [[SDLAddCommandResponse alloc] init];
+ addCommandSuccessResponse.success = @YES;
+ addCommandSuccessResponse.resultCode = SDLResultSuccess;
+
testOp = nil;
testConnectionManager = [[TestConnectionManager alloc] init];
testFileManager = OCMClassMock([SDLFileManager class]);
@@ -89,6 +95,46 @@ describe(@"a menu replace operation", ^{
});
});
+ // when starting while cancelled
+ context(@"when starting while cancelled", ^{
+ it(@"should finish without doing anything", ^{
+ testOp = [[SDLMenuReplaceOperation alloc] initWithConnectionManager:testConnectionManager fileManager:testFileManager windowCapability:testWindowCapability menuConfiguration:testMenuConfiguration currentMenu:testCurrentMenu updatedMenu:testNewMenu compatibilityModeEnabled:YES currentMenuUpdatedHandler:testCurrentMenuUpdatedBlock];
+ [testOp cancel];
+ [testOp start];
+
+ expect(testConnectionManager.receivedRequests).to(beEmpty());
+ expect(testOp.isFinished).to(beTrue());
+ });
+ });
+
+ // when uploading a text-only cell
+ context(@"when uploading a text-only cell", ^{
+ beforeEach(^{
+ testNewMenu = @[textOnlyCell];
+ OCMStub([testFileManager fileNeedsUpload:[OCMArg any]]).andReturn(NO);
+ });
+
+ fit(@"should properly send the RPCs and finish the operation", ^{
+ testOp = [[SDLMenuReplaceOperation alloc] initWithConnectionManager:testConnectionManager fileManager:testFileManager windowCapability:testWindowCapability menuConfiguration:testMenuConfiguration currentMenu:testCurrentMenu updatedMenu:testNewMenu compatibilityModeEnabled:YES currentMenuUpdatedHandler:testCurrentMenuUpdatedBlock];
+ [testOp start];
+
+ OCMReject([testFileManager uploadArtworks:[OCMArg any] progressHandler:[OCMArg any] completionHandler:[OCMArg any]]);
+
+ NSPredicate *deleteCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass: %@", [SDLDeleteCommand class]];
+ NSArray *deletes = [[testConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:deleteCommandPredicate];
+ expect(deletes).to(beEmpty());
+
+ NSPredicate *addCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass: %@", [SDLAddCommand class]];
+ NSArray *add = [[testConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:addCommandPredicate];
+ expect(add).to(haveCount(1));
+
+ [testConnectionManager respondToLastRequestWithResponse:addCommandSuccessResponse];
+ [testConnectionManager respondToLastMultipleRequestsWithSuccess:YES];
+
+ expect(testOp.isFinished).to(beTrue());
+ });
+ });
+
// when uploading text and image cell
context(@"when uploading text and image cell", ^{
beforeEach(^{
@@ -142,29 +188,6 @@ describe(@"a menu replace operation", ^{
});
});
- // when uploading a text-only cell
- context(@"when uploading a text-only cell", ^{
- beforeEach(^{
- testNewMenu = @[textOnlyCell];
- OCMStub([testFileManager fileNeedsUpload:[OCMArg any]]).andReturn(NO);
- });
-
- it(@"should properly update a text cell", ^{
- testOp = [[SDLMenuReplaceOperation alloc] initWithConnectionManager:testConnectionManager fileManager:testFileManager windowCapability:testWindowCapability menuConfiguration:testMenuConfiguration currentMenu:testCurrentMenu updatedMenu:testNewMenu compatibilityModeEnabled:YES currentMenuUpdatedHandler:testCurrentMenuUpdatedBlock];
- [testOp start];
-
- OCMReject([testFileManager uploadArtworks:[OCMArg any] progressHandler:[OCMArg any] completionHandler:[OCMArg any]]);
-
- NSPredicate *deleteCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass: %@", [SDLDeleteCommand class]];
- NSArray *deletes = [[testConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:deleteCommandPredicate];
- expect(deletes).to(beEmpty());
-
- NSPredicate *addCommandPredicate = [NSPredicate predicateWithFormat:@"self isMemberOfClass: %@", [SDLAddCommand class]];
- NSArray *add = [[testConnectionManager.receivedRequests copy] filteredArrayUsingPredicate:addCommandPredicate];
- expect(add).toNot(beEmpty());
- });
- });
-
// when uploading a cell with subcells
context(@"when uploading a cell with subcells", ^{
beforeEach(^{