diff --git a/RNNotifications/RNNotifications.xcodeproj/project.pbxproj b/RNNotifications/RNNotifications.xcodeproj/project.pbxproj index 9bb00f21e5120e9a2c95ce8695b58cf932a39743..fe2bba152d837138377266962ecdef79265d1f52 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 35ab8b3af723c9eb320245cb58e2f6926d1b929a..609be7c3dcb6b105d0eabad003adae825adf6d65 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