diff --git a/iOS_SDK/OneSignalSDK/UnitTests/Shadows/OneSignalHelperOverrider.h b/iOS_SDK/OneSignalSDK/UnitTests/Shadows/OneSignalHelperOverrider.h index eec211832..73f337bf8 100644 --- a/iOS_SDK/OneSignalSDK/UnitTests/Shadows/OneSignalHelperOverrider.h +++ b/iOS_SDK/OneSignalSDK/UnitTests/Shadows/OneSignalHelperOverrider.h @@ -28,6 +28,11 @@ #import #import #import +#import "OneSignalHelper.h" + +@interface OneSignalHelper (Tests) ++ (UNNotificationAction *)createActionForButton:(NSDictionary *)button; +@end @interface OneSignalHelperOverrider : NSObject + (void)reset; diff --git a/iOS_SDK/OneSignalSDK/UnitTests/UnitTests.m b/iOS_SDK/OneSignalSDK/UnitTests/UnitTests.m index 7ca89dee9..5b8796e64 100644 --- a/iOS_SDK/OneSignalSDK/UnitTests/UnitTests.m +++ b/iOS_SDK/OneSignalSDK/UnitTests/UnitTests.m @@ -3157,6 +3157,71 @@ - (void)testParseNotificationTemplateActionIconJson { XCTAssertEqualObjects(notification.actionButtons[0][@"templateIcon"], @"myImage/thumbsup"); } +- (void)testCreateActionForButtonsWithIcon { + if (@available(iOS 15.0, *)) { + NSDictionary *aps = @{ + @"aps": @{ + @"content-available": @1, + @"mutable-content": @1, + @"alert": @"Message Body", + }, + @"os_data": @{ + @"i": @"notif id", + @"ti": @"templateId123", + @"tn": @"Template name", + @"buttons": @[@{ + @"i": @"id1", + @"n": @"text1", + @"path": @"myImage/thumbsup", + @"icon_type": @"template" + }] + }}; + OSNotification *notification = [OSNotification parseWithApns:aps]; + UNNotificationAction *action = [OneSignalHelper createActionForButton:notification.actionButtons[0]]; + XCTAssertNotNil(action.icon); + + aps = @{ + @"aps": @{ + @"content-available": @1, + @"mutable-content": @1, + @"alert": @"Message Body", + }, + @"os_data": @{ + @"i": @"notif id", + @"ti": @"templateId123", + @"tn": @"Template name", + @"buttons": @[@{ + @"i": @"id1", + @"n": @"text1", + @"path": @"hand.thumbsup", + @"icon_type": @"system" + }] + }}; + notification = [OSNotification parseWithApns:aps]; + action = [OneSignalHelper createActionForButton:notification.actionButtons[0]]; + XCTAssertNotNil(action.icon); + + aps = @{ + @"aps": @{ + @"content-available": @1, + @"mutable-content": @1, + @"alert": @"Message Body", + }, + @"os_data": @{ + @"i": @"notif id", + @"ti": @"templateId123", + @"tn": @"Template name", + @"buttons": @[@{ + @"i": @"id1", + @"n": @"text1" + }] + }}; + notification = [OSNotification parseWithApns:aps]; + action = [OneSignalHelper createActionForButton:notification.actionButtons[0]]; + XCTAssertNil(action.icon); + } +} + - (void)testNotificationJson { NSDictionary *aps = @{ @"aps": @{