Skip to content

Commit

Permalink
unit test for adding icon to notification action
Browse files Browse the repository at this point in the history
  • Loading branch information
emawby committed Sep 3, 2021
1 parent 6543a06 commit 80b8131
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
#import "OneSignalHelper.h"

@interface OneSignalHelper (Tests)
+ (UNNotificationAction *)createActionForButton:(NSDictionary *)button;
@end

@interface OneSignalHelperOverrider : NSObject
+ (void)reset;
Expand Down
65 changes: 65 additions & 0 deletions iOS_SDK/OneSignalSDK/UnitTests/UnitTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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": @{
Expand Down

0 comments on commit 80b8131

Please sign in to comment.