use of com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal in project OneSignal-Android-SDK by OneSignal.
the class InAppMessageIntegrationTests method testInAppMessageDisplayMultipleTimes_RemoveTrigger.
@Test
public void testInAppMessageDisplayMultipleTimes_RemoveTrigger() throws Exception {
final OSTestInAppMessageInternal message = InAppMessagingHelpers.buildTestMessageWithSingleTriggerAndRedisplay(OSTriggerKind.CUSTOM, "test_1", OSTestTrigger.OSTriggerOperator.NOT_EXISTS.toString(), 2, LIMIT, DELAY);
setMockRegistrationResponseWithMessages(new ArrayList<OSTestInAppMessageInternal>() {
{
add(message);
}
});
// Init OneSignal with IAM with redisplay
OneSignalInit();
threadAndTaskWait();
// Because trigger doesn't exist IAM will be shown immediately
assertEquals(1, OneSignalPackagePrivateHelper.getInAppMessageDisplayQueue().size());
// Dismiss IAM will make display quantity increase and last display time to change
OneSignalPackagePrivateHelper.dismissCurrentMessage();
// Check IAM was removed from queue
assertEquals(0, OneSignalPackagePrivateHelper.getInAppMessageDisplayQueue().size());
// Check if data after dismiss is set correctly
assertEquals(1, OneSignalPackagePrivateHelper.getRedisplayInAppMessages().size());
assertEquals(1, OneSignalPackagePrivateHelper.getRedisplayInAppMessages().get(0).getRedisplayStats().getDisplayQuantity());
long lastDisplayTime = OneSignalPackagePrivateHelper.getRedisplayInAppMessages().get(0).getRedisplayStats().getLastDisplayTime();
assertTrue(lastDisplayTime > 0);
OneSignal.addTrigger("test_1", 2);
// Wait for the delay between redisplay
time.advanceSystemTimeBy(DELAY);
assertEquals(0, OneSignalPackagePrivateHelper.getInAppMessageDisplayQueue().size());
// Remove trigger, IAM should display again
OneSignal.removeTriggerForKey("test_1");
// Check that IAM is queue for redisplay
assertEquals(1, OneSignalPackagePrivateHelper.getInAppMessageDisplayQueue().size());
}
use of com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal in project OneSignal-Android-SDK by OneSignal.
the class InAppMessageIntegrationTests method testInAppMessageDisplayMultipleTimes.
@Test
public void testInAppMessageDisplayMultipleTimes() throws Exception {
final OSTestInAppMessageInternal message = InAppMessagingHelpers.buildTestMessageWithSingleTriggerAndRedisplay(OSTriggerKind.CUSTOM, "test_1", OSTestTrigger.OSTriggerOperator.EQUAL_TO.toString(), 2, LIMIT, DELAY);
setMockRegistrationResponseWithMessages(new ArrayList<OSTestInAppMessageInternal>() {
{
add(message);
}
});
// Init OneSignal IAM with redisplay
OneSignalInit();
threadAndTaskWait();
// Add trigger to make IAM display
OneSignal.addTrigger("test_1", 2);
assertEquals(1, OneSignalPackagePrivateHelper.getInAppMessageDisplayQueue().size());
// Check impression request
int requestSize = ShadowOneSignalRestClient.requests.size();
ShadowOneSignalRestClient.Request iamImpressionRequest = ShadowOneSignalRestClient.requests.get(requestSize - 1);
assertEquals("in_app_messages/" + message.getMessageId() + "/impression", iamImpressionRequest.url);
// Dismiss IAM will make display quantity increase and last display time to change
OneSignalPackagePrivateHelper.dismissCurrentMessage();
// Check IAMs was removed from queue
assertEquals(0, OneSignalPackagePrivateHelper.getInAppMessageDisplayQueue().size());
// Check if data after dismiss is set correctly
assertEquals(1, OneSignalPackagePrivateHelper.getRedisplayInAppMessages().size());
assertEquals(1, OneSignalPackagePrivateHelper.getRedisplayInAppMessages().get(0).getRedisplayStats().getDisplayQuantity());
long lastDisplayTime = OneSignalPackagePrivateHelper.getRedisplayInAppMessages().get(0).getRedisplayStats().getLastDisplayTime();
assertTrue(lastDisplayTime > 0);
// Change time for delay to be covered
time.advanceSystemTimeBy(DELAY);
// Set same trigger, should display again
OneSignal.addTrigger("test_1", 2);
assertEquals(1, OneSignalPackagePrivateHelper.getInAppMessageDisplayQueue().size());
// Check impression request is sent again
int requestSizeAfterRedisplay = ShadowOneSignalRestClient.requests.size();
ShadowOneSignalRestClient.Request iamImpressionRequestAfterRedisplay = ShadowOneSignalRestClient.requests.get(requestSizeAfterRedisplay - 1);
assertEquals("in_app_messages/" + message.getMessageId() + "/impression", iamImpressionRequestAfterRedisplay.url);
OneSignalPackagePrivateHelper.dismissCurrentMessage();
// Check IAMs was removed from queue
assertEquals(0, OneSignalPackagePrivateHelper.getInAppMessageDisplayQueue().size());
// Check if data after dismiss is set correctly
assertEquals(1, OneSignalPackagePrivateHelper.getRedisplayInAppMessages().size());
assertEquals(2, OneSignalPackagePrivateHelper.getRedisplayInAppMessages().get(0).getRedisplayStats().getDisplayQuantity());
assertTrue(OneSignalPackagePrivateHelper.getRedisplayInAppMessages().get(0).getRedisplayStats().getLastDisplayTime() - lastDisplayTime >= DELAY);
}
use of com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal 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();
}
}
use of com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal in project OneSignal-Android-SDK by OneSignal.
the class InAppMessagingUnitTests method testBuiltMessageRedisplayLimit.
@Test
public void testBuiltMessageRedisplayLimit() throws JSONException {
OSTestInAppMessageInternal message = InAppMessagingHelpers.buildTestMessageWitRedisplay(LIMIT, DELAY);
for (int i = 0; i < LIMIT; i++) {
assertTrue(message.getRedisplayStats().shouldDisplayAgain());
message.getRedisplayStats().incrementDisplayQuantity();
}
message.getRedisplayStats().incrementDisplayQuantity();
assertFalse(message.getRedisplayStats().shouldDisplayAgain());
}
use of com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal in project OneSignal-Android-SDK by OneSignal.
the class InAppMessagingUnitTests method testBuiltMessageRedisplayCLickId.
@Test
public void testBuiltMessageRedisplayCLickId() throws JSONException {
OSTestInAppMessageInternal message = InAppMessagingHelpers.buildTestMessageWitRedisplay(LIMIT, DELAY);
assertTrue(message.getClickedClickIds().isEmpty());
assertTrue(message.isClickAvailable(IAM_CLICK_ID));
message.addClickId(IAM_CLICK_ID);
message.clearClickIds();
assertTrue(message.getClickedClickIds().isEmpty());
message.addClickId(IAM_CLICK_ID);
message.addClickId(IAM_CLICK_ID);
assertEquals(1, message.getClickedClickIds().size());
assertFalse(message.isClickAvailable(IAM_CLICK_ID));
OSTestInAppMessageInternal messageWithoutDisplay = InAppMessagingHelpers.buildTestMessageWithSingleTrigger(OSTriggerKind.SESSION_TIME, null, OSTriggerOperator.GREATER_THAN_OR_EQUAL_TO.toString(), 3);
messageWithoutDisplay.addClickId(IAM_CLICK_ID);
assertFalse(messageWithoutDisplay.isClickAvailable(IAM_CLICK_ID));
}
Aggregations