use of com.onesignal.OneSignalPackagePrivateHelper.OSTestTrigger in project OneSignal-Android-SDK by OneSignal.
the class InAppMessageIntegrationTests method testAfterLastInAppTimeIsDisplayedOncePerSession.
@Test
public void testAfterLastInAppTimeIsDisplayedOncePerSession() throws Exception {
final OSTestInAppMessageInternal message1 = InAppMessagingHelpers.buildTestMessageWithSingleTriggerAndRedisplay(OSTriggerKind.SESSION_TIME, null, OSTestTrigger.OSTriggerOperator.GREATER_THAN.toString(), 0.05, 10, 0);
ArrayList<ArrayList<OSTestTrigger>> triggers2 = new ArrayList<ArrayList<OSTestTrigger>>() {
{
add(new ArrayList<OSTestTrigger>() {
{
add(InAppMessagingHelpers.buildTrigger(OSTriggerKind.SESSION_TIME, null, OSTestTrigger.OSTriggerOperator.GREATER_THAN.toString(), 0.1));
add(InAppMessagingHelpers.buildTrigger(OSTriggerKind.TIME_SINCE_LAST_IN_APP, null, OSTestTrigger.OSTriggerOperator.GREATER_THAN.toString(), 0.05));
}
});
}
};
final OSTestInAppMessageInternal message2 = InAppMessagingHelpers.buildTestMessageWithMultipleTriggersAndRedisplay(triggers2, 10, 0);
setMockRegistrationResponseWithMessages(new ArrayList<OSTestInAppMessageInternal>() {
{
add(message1);
add(message2);
}
});
// the SDK should read the message from registration JSON, set up a timer, and once
// the timer fires the message should get shown.
OneSignalInit();
threadAndTaskWait();
// wait until the timer fires after 50ms and make sure the message gets displayed
// we already have tests to make sure that the timer is actually being scheduled
// for the correct amount of time, so all we are doing here is checking to
// make sure the message actually gets displayed once the timer fires
Awaitility.await().atMost(new Duration(150, TimeUnit.MILLISECONDS)).pollInterval(new Duration(10, TimeUnit.MILLISECONDS)).untilAsserted(() -> {
assertEquals(1, OneSignalPackagePrivateHelper.getInAppMessageDisplayQueue().size());
try {
assertEquals(message1.getMessageId(), OneSignalPackagePrivateHelper.getShowingInAppMessageId());
} catch (NullPointerException e) {
// Awaitility won't retry if something is thrown, but will if an assert fails.
fail("Should not throw");
}
});
OneSignalPackagePrivateHelper.dismissCurrentMessage();
// Second in app should now display
Awaitility.await().atMost(new Duration(1, TimeUnit.SECONDS)).pollInterval(new Duration(100, TimeUnit.MILLISECONDS)).untilAsserted(() -> {
assertEquals(1, OneSignalPackagePrivateHelper.getInAppMessageDisplayQueue().size());
try {
assertEquals(message2.getMessageId(), OneSignalPackagePrivateHelper.getShowingInAppMessageId());
} catch (NullPointerException e) {
// Awaitility won't retry if something is thrown, but will if an assert fails.
fail("Should not throw");
}
});
OneSignalPackagePrivateHelper.dismissCurrentMessage();
// Check that the IAM is not displayed again
assertEquals(0, OneSignalPackagePrivateHelper.getInAppMessageDisplayQueue().size());
}
use of com.onesignal.OneSignalPackagePrivateHelper.OSTestTrigger in project OneSignal-Android-SDK by OneSignal.
the class InAppMessagingHelpers method buildTriggers.
private static JSONArray buildTriggers(ArrayList<ArrayList<OSTestTrigger>> triggers) throws JSONException {
JSONArray ors = new JSONArray();
for (ArrayList<OSTestTrigger> andBlock : triggers) {
JSONArray ands = new JSONArray();
for (final OSTestTrigger trigger : andBlock) {
ands.put(new JSONObject() {
{
put("id", UUID.randomUUID().toString());
put("kind", trigger.kind.toString());
put("property", trigger.property);
put("operator", trigger.operatorType.toString());
put("value", trigger.value);
}
});
}
ors.put(ands);
}
return ors;
}
use of com.onesignal.OneSignalPackagePrivateHelper.OSTestTrigger in project OneSignal-Android-SDK by OneSignal.
the class InAppMessagingUnitTests method testMessageSchedulesSessionDurationTimer.
@Test
public void testMessageSchedulesSessionDurationTimer() throws JSONException {
OSTestTrigger trigger = InAppMessagingHelpers.buildTrigger(OSTriggerKind.SESSION_TIME, null, OSTriggerOperator.EQUAL_TO.toString(), 10);
InAppMessagingHelpers.resetSessionLaunchTime();
// this evaluates the message and should schedule a timer for 10 seconds into the session
assertFalse(InAppMessagingHelpers.dynamicTriggerShouldFire(trigger));
// verify that the timer was scheduled ~10 seconds
assertTrue(roughlyEqualTimerValues(10.0, ShadowDynamicTimer.mostRecentTimerDelaySeconds()));
}
Aggregations