use of com.onesignal.MockOSSharedPreferences in project OneSignal-Android-SDK by OneSignal.
the class InAppMessageIntegrationTests method testOnIAMActionSendsOutcome_afterDismiss_usingOutcomesV2.
@Test
public void testOnIAMActionSendsOutcome_afterDismiss_usingOutcomesV2() throws Exception {
// Enable IAM v2
preferences = new MockOSSharedPreferences();
preferences.saveBool(preferences.getPreferencesName(), preferences.getOutcomesV2KeyName(), true);
trackerFactory = new OSTrackerFactory(preferences, new MockOSLog(), time);
sessionManager = new MockSessionManager(OneSignal_getSessionListener(), trackerFactory, new MockOSLog());
OneSignal_setSharedPreferences(preferences);
OneSignal_setTrackerFactory(trackerFactory);
OneSignal_setSessionManager(sessionManager);
final OSTestInAppMessageInternal message = InAppMessagingHelpers.buildTestMessageWithSingleTrigger(OSTriggerKind.CUSTOM, "test_1", OSTestTrigger.OSTriggerOperator.EQUAL_TO.toString(), 2);
setMockRegistrationResponseWithMessages(new ArrayList<OSTestInAppMessageInternal>() {
{
add(message);
}
});
// 1. Init OneSignal
OneSignalInit();
threadAndTaskWait();
// Enable influence outcomes
trackerFactory.saveInfluenceParams(new OneSignalPackagePrivateHelper.RemoteOutcomeParams());
final OSInAppMessageAction[] lastAction = new OSInAppMessageAction[1];
OneSignal.setInAppMessageClickHandler(new OneSignal.OSInAppMessageClickHandler() {
@Override
public void inAppMessageClicked(OSInAppMessageAction result) {
lastAction[0] = result;
// Ensure we are on the main thread when running the callback, since the app developer
// will most likely need to update UI.
assertMainThread();
}
});
threadAndTaskWait();
// Add trigger to make IAM display
OneSignal.addTrigger("test_1", 2);
assertEquals(1, OneSignalPackagePrivateHelper.getInAppMessageDisplayQueue().size());
OneSignalPackagePrivateHelper.onMessageActionOccurredOnMessage(message, new JSONObject() {
{
put("id", "button_id_123");
put("name", "my_click_name");
}
});
// Ensure we fire public callback that In-App was clicked.
assertEquals(lastAction[0].getClickName(), "my_click_name");
OneSignalPackagePrivateHelper.dismissCurrentMessage();
OneSignal.sendOutcome("test1");
try {
// Ensure outcome is sent but with INDIRECT influence from IAM
assertMeasureOnV2AtIndex(5, "test1", null, null, new JSONArray().put(message.getMessageId()), new JSONArray());
} catch (JSONException e) {
e.printStackTrace();
}
}
Aggregations