use of com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal in project OneSignal-Android-SDK by OneSignal.
the class InAppMessageIntegrationTests method testMessageDisplayedAfterAddTriggerEqualWithStringVsNumber.
@Test
public void testMessageDisplayedAfterAddTriggerEqualWithStringVsNumber() throws Exception {
// Set IAM with EQUAL trigger with number value as string
final OSTestInAppMessageInternal message = InAppMessagingHelpers.buildTestMessageWithSingleTrigger(OSTriggerKind.CUSTOM, "test", OSTestTrigger.OSTriggerOperator.EQUAL_TO.toString(), "5");
setMockRegistrationResponseWithMessages(new ArrayList<OSTestInAppMessageInternal>() {
{
add(message);
}
});
OneSignalInit();
threadAndTaskWait();
assertEquals(0, OneSignalPackagePrivateHelper.getInAppMessageDisplayQueue().size());
// after setting this trigger the message should be displayed immediately
OneSignal.addTrigger("test", 5.0);
threadAndTaskWait();
// the message should now have been displayed
assertEquals(1, OneSignalPackagePrivateHelper.getInAppMessageDisplayQueue().size());
dismissCurrentMessage();
}
use of com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal in project OneSignal-Android-SDK by OneSignal.
the class InAppMessagingUnitTests method testBuiltMessageReDisplay.
@Test
public void testBuiltMessageReDisplay() throws JSONException {
OSTestInAppMessageInternal message = InAppMessagingHelpers.buildTestMessageWitRedisplay(LIMIT, DELAY);
assertTrue(message.getRedisplayStats().isRedisplayEnabled());
assertEquals(LIMIT, message.getRedisplayStats().getDisplayLimit());
assertEquals(DELAY, message.getRedisplayStats().getDisplayDelay());
assertEquals(-1, message.getRedisplayStats().getLastDisplayTime());
assertEquals(0, message.getRedisplayStats().getDisplayQuantity());
OSTestInAppMessageInternal messageWithoutDisplay = InAppMessagingHelpers.buildTestMessageWithSingleTrigger(OSTriggerKind.SESSION_TIME, null, OSTriggerOperator.GREATER_THAN_OR_EQUAL_TO.toString(), 3);
assertFalse(messageWithoutDisplay.getRedisplayStats().isRedisplayEnabled());
assertEquals(1, messageWithoutDisplay.getRedisplayStats().getDisplayLimit());
assertEquals(0, messageWithoutDisplay.getRedisplayStats().getDisplayDelay());
assertEquals(-1, messageWithoutDisplay.getRedisplayStats().getLastDisplayTime());
assertEquals(0, messageWithoutDisplay.getRedisplayStats().getDisplayQuantity());
}
use of com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal in project OneSignal-Android-SDK by OneSignal.
the class InAppMessagingUnitTests method testShouldTriggerWhen1OutOf3OrsAreMeet.
@Test
public void testShouldTriggerWhen1OutOf3OrsAreMeet() throws JSONException {
setLocalTriggerValue("prop1", 3);
ArrayList<ArrayList<OSTestTrigger>> triggers = new ArrayList<ArrayList<OSTestTrigger>>() {
{
add(new ArrayList<OSTestTrigger>() {
{
add(InAppMessagingHelpers.buildTrigger(OSTriggerKind.CUSTOM, "prop1", OSTriggerOperator.EQUAL_TO.toString(), 1));
}
});
add(new ArrayList<OSTestTrigger>() {
{
add(InAppMessagingHelpers.buildTrigger(OSTriggerKind.CUSTOM, "prop1", OSTriggerOperator.EQUAL_TO.toString(), 2));
}
});
add(new ArrayList<OSTestTrigger>() {
{
add(InAppMessagingHelpers.buildTrigger(OSTriggerKind.CUSTOM, "prop1", OSTriggerOperator.EQUAL_TO.toString(), 3));
}
});
}
};
OSTestInAppMessageInternal testMessage = InAppMessagingHelpers.buildTestMessageWithMultipleTriggers(triggers);
assertTrue(InAppMessagingHelpers.evaluateMessage(testMessage));
}
use of com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal in project OneSignal-Android-SDK by OneSignal.
the class InAppMessagingUnitTests method testBuiltMessageRedisplayDelay.
@Test
public void testBuiltMessageRedisplayDelay() throws JSONException {
MockOSTimeImpl time = new MockOSTimeImpl();
OneSignal_setTime(time);
OSTestInAppMessageInternal message = InAppMessagingHelpers.buildTestMessageWitRedisplay(LIMIT, DELAY);
assertTrue(message.getRedisplayStats().isDelayTimeSatisfied());
message.getRedisplayStats().setLastDisplayTimeToCurrent(time);
time.advanceSystemTimeBy(DELAY);
assertTrue(message.getRedisplayStats().isDelayTimeSatisfied());
message.getRedisplayStats().setLastDisplayTimeToCurrent(time);
time.advanceSystemTimeBy(DELAY - 1);
assertFalse(message.getRedisplayStats().isDelayTimeSatisfied());
}
use of com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal in project OneSignal-Android-SDK by OneSignal.
the class InAppMessagingUnitTests method testMixedTriggersScheduleTimer.
// This test makes sure that time-based triggers are considered once all non-time-based
// triggers evaluate to true and will set up a timer if needed
@Test
public void testMixedTriggersScheduleTimer() throws JSONException {
final OSTestTrigger timeBasedTrigger = InAppMessagingHelpers.buildTrigger(OSTriggerKind.SESSION_TIME, null, OSTriggerOperator.GREATER_THAN.toString(), 5.0);
final OSTestTrigger normalTrigger = InAppMessagingHelpers.buildTrigger(OSTriggerKind.CUSTOM, "prop1", OSTriggerOperator.LESS_THAN_OR_EQUAL_TO.toString(), 3);
// the time based trigger will be false (but should schedule a timer)
// while the normal trigger should evaluate to true
setLocalTriggerValue("prop1", 3);
ArrayList<ArrayList<OSTestTrigger>> triggers = new ArrayList<ArrayList<OSTestTrigger>>() {
{
add(new ArrayList<OSTestTrigger>() {
{
add(timeBasedTrigger);
add(normalTrigger);
}
});
}
};
OSTestInAppMessageInternal testMessage = InAppMessagingHelpers.buildTestMessageWithMultipleTriggers(triggers);
assertFalse(InAppMessagingHelpers.evaluateMessage(testMessage));
assertTrue(ShadowDynamicTimer.hasScheduledTimer);
assertTrue(roughlyEqualTimerValues(5.0, ShadowDynamicTimer.mostRecentTimerDelaySeconds()));
}
Aggregations