Skip to content

Commit 5b7f5a0

Browse files
committed
[MOB-10364] Update according to new discussiom
1 parent 595d2b6 commit 5b7f5a0

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

iterableapi/src/test/java/com/iterable/iterableapi/IterableInAppManagerTest.java

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import static org.mockito.ArgumentMatchers.argThat;
5252
import static org.junit.Assert.assertNull;
5353
import static org.junit.Assert.assertNotNull;
54+
import static org.mockito.Mockito.when;
5455

5556
public class IterableInAppManagerTest extends BaseTest {
5657

@@ -713,6 +714,67 @@ public void testJsonOnlyMessageIgnoresContentPayload() throws Exception {
713714
assertEquals("customValue", messages.get(0).getCustomPayload().getString("key"));
714715
}
715716

717+
@Test
718+
public void testJsonOnlyInAppMessageProcessingAndDisplay() throws Exception {
719+
// Create payload similar to iOS test
720+
JSONObject payload = new JSONObject()
721+
.put("inAppMessages", new JSONArray()
722+
.put(new JSONObject()
723+
.put("saveToInbox", false)
724+
.put("jsonOnly", 1)
725+
.put("customPayload", new JSONObject()
726+
.put("key", "value"))
727+
.put("content", new JSONObject()
728+
.put("html", "<meta name=\"viewport\" content=\"width=device-width\">")
729+
.put("inAppDisplaySettings", new JSONObject()
730+
.put("left", new JSONObject().put("percentage", 0))
731+
.put("top", new JSONObject().put("percentage", 0))
732+
.put("right", new JSONObject().put("percentage", 0))
733+
.put("bottom", new JSONObject().put("percentage", 0))))
734+
.put("trigger", new JSONObject().put("type", "immediate"))
735+
.put("messageId", "message1")
736+
.put("campaignId", 1)));
737+
738+
dispatcher.enqueueResponse("/inApp/getMessages", new MockResponse().setBody(payload.toString()));
739+
740+
// Create InAppManager with mock handler and displayer
741+
IterableInAppDisplayer mockDisplayer = mock(IterableInAppDisplayer.class);
742+
final IterableInAppHandler inAppHandler = mock(IterableInAppHandler.class);
743+
// Configure mock handler to return SHOW response
744+
when(inAppHandler.onNewInApp(any(IterableInAppMessage.class))).thenReturn(IterableInAppHandler.InAppResponse.SHOW);
745+
746+
IterableInAppManager inAppManager = spy(new IterableInAppManager(
747+
IterableApi.sharedInstance,
748+
inAppHandler,
749+
30.0,
750+
new IterableInAppMemoryStorage(),
751+
IterableActivityMonitor.getInstance(),
752+
mockDisplayer));
753+
IterableApi.sharedInstance = new IterableApi(inAppManager);
754+
755+
// First sync to get messages
756+
inAppManager.syncInApp();
757+
shadowOf(getMainLooper()).idle();
758+
759+
// Process messages by bringing app to foreground
760+
Robolectric.buildActivity(Activity.class).create().start().resume();
761+
shadowOf(getMainLooper()).idle();
762+
763+
// Verify handler was called with correct message
764+
ArgumentCaptor<IterableInAppMessage> messageCaptor = ArgumentCaptor.forClass(IterableInAppMessage.class);
765+
verify(inAppHandler).onNewInApp(messageCaptor.capture());
766+
assertEquals("value", messageCaptor.getValue().getCustomPayload().getString("key"));
767+
768+
// Verify displayer was never called
769+
verify(mockDisplayer, never()).showMessage(
770+
any(IterableInAppMessage.class),
771+
any(IterableInAppLocation.class),
772+
any(IterableHelper.IterableUrlCallback.class));
773+
774+
// Verify message was consumed (not in queue)
775+
assertEquals(0, inAppManager.getMessages().size());
776+
}
777+
716778
private String createJsonOnlyPayload() throws JSONException {
717779
return new JSONObject()
718780
.put("inAppMessages", new JSONArray()

0 commit comments

Comments
 (0)