@@ -362,6 +362,26 @@ class InAppTests: XCTestCase {
362
362
363
363
wait ( for: [ expectation1, expectation2] , timeout: testExpectationTimeout)
364
364
}
365
+
366
+ func testShowInAppWithCustomActionBackwardCompatibility( ) {
367
+ let customActionScheme = " itbl "
368
+ let customActionName = " my_custom_action "
369
+ let expectation1 = expectation ( description: " verify custom action is called, customActionScheme: \( customActionScheme) , customActionName: \( customActionName) " )
370
+ verifyCustomActionIsCalled ( expectation: expectation1,
371
+ customActionScheme: customActionScheme,
372
+ customActionName: customActionName)
373
+ wait ( for: [ expectation1] , timeout: testExpectationTimeout)
374
+ }
375
+
376
+ func testShowInAppWithCustomAction1( ) {
377
+ let customActionScheme = " action "
378
+ let customActionName = " my_custom_action "
379
+ let expectation1 = expectation ( description: " verify custom action is called, customActionScheme: \( customActionScheme) , customActionName: \( customActionName) " )
380
+ verifyCustomActionIsCalled ( expectation: expectation1,
381
+ customActionScheme: customActionScheme,
382
+ customActionName: customActionName)
383
+ wait ( for: [ expectation1] , timeout: testExpectationTimeout)
384
+ }
365
385
366
386
// Check that onNew is called just once if the messageId is same.
367
387
func testOnNewNotCalledMultipleTimes( ) {
@@ -1005,6 +1025,50 @@ class InAppTests: XCTestCase {
1005
1025
1006
1026
XCTAssertEqual ( IterableAPI . inAppManager. getMessages ( ) . count, 0 )
1007
1027
}
1028
+
1029
+ fileprivate func verifyCustomActionIsCalled( expectation: XCTestExpectation , customActionScheme: String , customActionName: String ) {
1030
+ let mockInAppSynchronizer = MockInAppSynchronizer ( )
1031
+
1032
+ let customActionUrl = " \( customActionScheme) :// \( customActionName) "
1033
+ let mockInAppDisplayer = MockInAppDisplayer ( )
1034
+ mockInAppDisplayer. onShowCallback = { ( _, _) in
1035
+ mockInAppDisplayer. click ( url: URL ( string: customActionUrl) !)
1036
+ }
1037
+
1038
+ let mockCustomActionDelegate = MockCustomActionDelegate ( returnValue: true )
1039
+ mockCustomActionDelegate. callback = { ( actionName, context) in
1040
+ XCTAssertEqual ( actionName, customActionName)
1041
+ expectation. fulfill ( )
1042
+ }
1043
+
1044
+ let config = IterableConfig ( )
1045
+ config. inAppDelegate = MockInAppDelegate ( showInApp: . show)
1046
+ config. customActionDelegate = mockCustomActionDelegate
1047
+
1048
+ IterableAPI . initializeForTesting (
1049
+ config: config,
1050
+ inAppSynchronizer: mockInAppSynchronizer,
1051
+ inAppDisplayer: mockInAppDisplayer
1052
+ )
1053
+
1054
+ let payload = """
1055
+ { " inAppMessages " :
1056
+ [
1057
+ {
1058
+ " saveToInbox " : true,
1059
+ " content " : { " contentType " : " html " , " inAppDisplaySettings " : { " bottom " : { " displayOption " : " AutoExpand " }, " backgroundAlpha " : 0.5, " left " : { " percentage " : 60}, " right " : { " percentage " : 60}, " top " : { " displayOption " : " AutoExpand " }}, " html " : " <a href= \' \( customActionUrl) '>Click Here</a> " },
1060
+ " trigger " : { " type " : " immediate " },
1061
+ " messageId " : " message0 " ,
1062
+ " campaignId " : " campaign1 " ,
1063
+ " customPayload " : { " title " : " Product 1 Available " , " date " : " 2018-11-14T14:00:00:00.32Z " }
1064
+ },
1065
+ ]
1066
+ }
1067
+ """ . toJsonDict ( )
1068
+
1069
+ mockInAppSynchronizer. mockInAppPayloadFromServer ( payload)
1070
+ }
1071
+
1008
1072
}
1009
1073
1010
1074
extension IterableInAppTrigger {
0 commit comments