|
51 | 51 | import static org.mockito.ArgumentMatchers.argThat; |
52 | 52 | import static org.junit.Assert.assertNull; |
53 | 53 | import static org.junit.Assert.assertNotNull; |
| 54 | +import static org.mockito.Mockito.when; |
54 | 55 |
|
55 | 56 | public class IterableInAppManagerTest extends BaseTest { |
56 | 57 |
|
@@ -713,6 +714,67 @@ public void testJsonOnlyMessageIgnoresContentPayload() throws Exception { |
713 | 714 | assertEquals("customValue", messages.get(0).getCustomPayload().getString("key")); |
714 | 715 | } |
715 | 716 |
|
| 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 | + |
716 | 778 | private String createJsonOnlyPayload() throws JSONException { |
717 | 779 | return new JSONObject() |
718 | 780 | .put("inAppMessages", new JSONArray() |
|
0 commit comments