Search in sources :

Example 16 with OSTestInAppMessageInternal

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();
}
Also used : OSTestInAppMessageInternal(com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal) Test(org.junit.Test)

Example 17 with OSTestInAppMessageInternal

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());
}
Also used : OSTestInAppMessageInternal(com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal) Test(org.junit.Test)

Example 18 with OSTestInAppMessageInternal

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));
}
Also used : OSTestInAppMessageInternal(com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal) ArrayList(java.util.ArrayList) OSTestTrigger(com.onesignal.OneSignalPackagePrivateHelper.OSTestTrigger) Test(org.junit.Test)

Example 19 with OSTestInAppMessageInternal

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());
}
Also used : OSTestInAppMessageInternal(com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal) MockOSTimeImpl(com.onesignal.MockOSTimeImpl) Test(org.junit.Test)

Example 20 with OSTestInAppMessageInternal

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()));
}
Also used : OSTestInAppMessageInternal(com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal) ArrayList(java.util.ArrayList) OSTestTrigger(com.onesignal.OneSignalPackagePrivateHelper.OSTestTrigger) Test(org.junit.Test)

Aggregations

OSTestInAppMessageInternal (com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal)50 Test (org.junit.Test)43 JSONObject (org.json.JSONObject)19 ShadowOneSignalRestClient (com.onesignal.ShadowOneSignalRestClient)15 JSONArray (org.json.JSONArray)14 OneSignalPackagePrivateHelper (com.onesignal.OneSignalPackagePrivateHelper)8 ArrayList (java.util.ArrayList)5 SuppressLint (android.annotation.SuppressLint)4 OSTestTrigger (com.onesignal.OneSignalPackagePrivateHelper.OSTestTrigger)4 Duration (org.awaitility.Duration)4 MockOSLog (com.onesignal.MockOSLog)3 MockOSSharedPreferences (com.onesignal.MockOSSharedPreferences)3 MockSessionManager (com.onesignal.MockSessionManager)3 OneSignal (com.onesignal.OneSignal)3 OSTrackerFactory (com.onesignal.influence.data.OSTrackerFactory)3 JSONException (org.json.JSONException)3 Cursor (android.database.Cursor)2 OSInAppMessageAction (com.onesignal.OSInAppMessageAction)2 HashSet (java.util.HashSet)2 ThrowingRunnable (org.awaitility.core.ThrowingRunnable)2