Skip to content

Commit 3b63db4

Browse files
authored
Merge pull request #157 from Iterable/chore/MOB-857-add-text-input-test
[MOB-857] Add a test for text input action buttons
2 parents 3211898 + 393725c commit 3b63db4

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package com.iterable.iterableapi;
22

3+
import android.content.ClipData;
34
import android.content.Context;
45
import android.content.Intent;
6+
import android.os.Bundle;
7+
import android.support.v4.app.RemoteInput;
58

69
import org.json.JSONObject;
710
import org.junit.After;
@@ -17,6 +20,7 @@
1720
import okhttp3.mockwebserver.MockWebServer;
1821
import okhttp3.mockwebserver.RecordedRequest;
1922

23+
import static android.support.v4.app.RemoteInput.RESULTS_CLIP_LABEL;
2024
import static com.iterable.iterableapi.IterableTestUtils.stubAnyRequestReturningStatusCode;
2125
import static junit.framework.Assert.assertEquals;
2226
import static junit.framework.Assert.assertNotNull;
@@ -107,6 +111,33 @@ public void testPushActionWithSilentAction() throws Exception {
107111
assertNull(activityIntent);
108112
}
109113

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+
110141
@Test
111142
public void testLegacyDeepLinkPayload() throws Exception {
112143
stubAnyRequestReturningStatusCode(server, 200, "{}");

0 commit comments

Comments
 (0)