|
1 | 1 | package com.iterable.iterableapi; |
2 | 2 |
|
| 3 | +import android.content.ClipData; |
3 | 4 | import android.content.Context; |
4 | 5 | import android.content.Intent; |
| 6 | +import android.os.Bundle; |
| 7 | +import android.support.v4.app.RemoteInput; |
5 | 8 |
|
6 | 9 | import org.json.JSONObject; |
7 | 10 | import org.junit.After; |
|
17 | 20 | import okhttp3.mockwebserver.MockWebServer; |
18 | 21 | import okhttp3.mockwebserver.RecordedRequest; |
19 | 22 |
|
| 23 | +import static android.support.v4.app.RemoteInput.RESULTS_CLIP_LABEL; |
20 | 24 | import static com.iterable.iterableapi.IterableTestUtils.stubAnyRequestReturningStatusCode; |
21 | 25 | import static junit.framework.Assert.assertEquals; |
22 | 26 | import static junit.framework.Assert.assertNotNull; |
@@ -107,6 +111,33 @@ public void testPushActionWithSilentAction() throws Exception { |
107 | 111 | assertNull(activityIntent); |
108 | 112 | } |
109 | 113 |
|
| 114 | + @Test |
| 115 | + public void testPushActionWithTextInput() throws Exception { |
| 116 | + IterablePushActionReceiver iterablePushActionReceiver = new IterablePushActionReceiver(); |
| 117 | + Intent intent = new Intent(IterableConstants.ACTION_PUSH_ACTION); |
| 118 | + intent.putExtra(IterableConstants.ITERABLE_DATA_ACTION_IDENTIFIER, "textInputButton"); |
| 119 | + intent.putExtra(IterableConstants.ITERABLE_DATA_KEY, IterableTestUtils.getResourceString("push_payload_action_buttons.json")); |
| 120 | + |
| 121 | + // Inject input text |
| 122 | + Bundle resultsBundle = new Bundle(); |
| 123 | + Intent clipDataIntent = new Intent(); |
| 124 | + resultsBundle.putString(IterableConstants.USER_INPUT, "input text"); |
| 125 | + clipDataIntent.putExtra(RemoteInput.EXTRA_RESULTS_DATA, resultsBundle); |
| 126 | + intent.setClipData(ClipData.newIntent(RESULTS_CLIP_LABEL, clipDataIntent)); |
| 127 | + |
| 128 | + PowerMockito.mockStatic(IterableActionRunner.class); |
| 129 | + |
| 130 | + iterablePushActionReceiver.onReceive(RuntimeEnvironment.application, intent); |
| 131 | + |
| 132 | + // Verify that IterableActionRunner was called with the proper action |
| 133 | + PowerMockito.verifyStatic(IterableActionRunner.class); |
| 134 | + ArgumentCaptor<IterableAction> actionCaptor = ArgumentCaptor.forClass(IterableAction.class); |
| 135 | + IterableActionRunner.executeAction(any(Context.class), actionCaptor.capture(), eq(IterableActionSource.PUSH)); |
| 136 | + IterableAction capturedAction = actionCaptor.getValue(); |
| 137 | + assertEquals("handleTextInput", capturedAction.getType()); |
| 138 | + assertEquals("input text", capturedAction.userInput); |
| 139 | + } |
| 140 | + |
110 | 141 | @Test |
111 | 142 | public void testLegacyDeepLinkPayload() throws Exception { |
112 | 143 | stubAnyRequestReturningStatusCode(server, 200, "{}"); |
|
0 commit comments