From dbf046ef682bc111205e9afd7ae5f1ae00e17cfb Mon Sep 17 00:00:00 2001 From: yogevbd Date: Tue, 30 Jul 2019 23:09:59 +0300 Subject: [PATCH] Add test coverage for iOS --- .../RNNotifications.xcodeproj/project.pbxproj | 8 ----- .../RNNotificationEventHandlerTests.m | 30 +++++++++++++++++++ 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/RNNotifications/RNNotifications.xcodeproj/project.pbxproj b/RNNotifications/RNNotifications.xcodeproj/project.pbxproj index 9bb00f2..fe2bba1 100644 --- a/RNNotifications/RNNotifications.xcodeproj/project.pbxproj +++ b/RNNotifications/RNNotifications.xcodeproj/project.pbxproj @@ -192,17 +192,9 @@ name = Products; sourceTree = ""; }; - 50002A7222E8874F008F6742 /* Utils */ = { - isa = PBXGroup; - children = ( - ); - path = Utils; - sourceTree = ""; - }; 504D54BC22E4B83E0088F2E4 /* Integration */ = { isa = PBXGroup; children = ( - 50002A7222E8874F008F6742 /* Utils */, 504D54BD22E4B8660088F2E4 /* RNBridgeModuleIntegrationTest.m */, 50002A4C22E88266008F6742 /* RNCommandsHandlerIntegrationTest.m */, ); diff --git a/RNNotifications/RNNotificationsTests/RNNotificationEventHandlerTests.m b/RNNotifications/RNNotificationsTests/RNNotificationEventHandlerTests.m index 35ab8b3..609be7c 100644 --- a/RNNotifications/RNNotificationsTests/RNNotificationEventHandlerTests.m +++ b/RNNotifications/RNNotificationsTests/RNNotificationEventHandlerTests.m @@ -68,6 +68,28 @@ [_mockedNotificationCenter verify]; } +- (void)testDidReceiveNotificationResponse_ShouldEmitEvent { + UNNotification* notification = [self createNotificationWithIdentifier:@"id" andUserInfo:@{@"extraKey": @"extraValue"}]; + UNNotificationResponse* response = [self createNotificationResponseWithIdentifier:@"id" andNotification:notification]; + void (^testBlock)(void) = ^void() {}; + + [[_mockedNotificationCenter expect] postNotificationName:RNNotificationOpened object:[OCMArg any] userInfo:[OCMArg checkWithBlock:^BOOL(id obj) { + return ([[obj valueForKey:@"identifier"] isEqualToString:@"id"] && + [[[obj valueForKey:@"payload"] valueForKey:@"extraKey"] isEqualToString:@"extraValue"]); + }]]; + [_uut didReceiveNotificationResponse:response completionHandler:testBlock]; + [_mockedNotificationCenter verify]; +} + +- (void)testDidReceiveNotificationResponse_ShouldSaveCompletionBlockToStore { + UNNotification* notification = [self createNotificationWithIdentifier:@"id" andUserInfo:@{@"extraKey": @"extraValue"}]; + UNNotificationResponse* response = [self createNotificationResponseWithIdentifier:@"id" andNotification:notification]; + void (^testBlock)(void) = ^void() {}; + + [_uut didReceiveNotificationResponse:response completionHandler:testBlock]; + XCTAssertEqual([_store getActionCompletionHandler:@"id"], testBlock); +} + - (UNNotification *)createNotificationWithIdentifier:(NSString *)identifier andUserInfo:(NSDictionary *)userInfo { UNNotification* notification = [OCMockObject niceMockForClass:[UNNotification class]]; UNNotificationContent* content = [OCMockObject niceMockForClass:[UNNotificationContent class]]; @@ -79,6 +101,14 @@ return notification; } +- (UNNotificationResponse *)createNotificationResponseWithIdentifier:(NSString *)identifier andNotification:(UNNotification *)notification { + UNNotificationResponse* notificationResponse = [OCMockObject niceMockForClass:[UNNotificationResponse class]]; + OCMStub(notificationResponse.actionIdentifier).andReturn(identifier); + OCMStub(notificationResponse.notification).andReturn(notification); + + return notificationResponse; +} + @end -- 2.26.2