use of org.infobip.mobile.messaging.interactive.NotificationAction in project mobile-messaging-sdk-android by infobip.
the class NotificationActionTapReceiverTest method test_should_trigger_sdk_actions_when_clicked_on_action_button.
@Test
public void test_should_trigger_sdk_actions_when_clicked_on_action_button() throws Exception {
// Given
Message givenMessage = createMessage(context, "SomeMessageId", false);
NotificationAction givenTappedNotificationAction = givenNotificationAction("actionId").withMoMessage().build();
NotificationCategory givenNotificationCategory = givenNotificationCategory(givenTappedNotificationAction);
Intent givenIntent = givenIntent(givenMessage, givenNotificationCategory, givenTappedNotificationAction, 1234, notificationSettings.getIntentFlags());
// When
notificationActionTapReceiver.onReceive(contextMock, givenIntent);
// Then
Mockito.verify(broadcastSender, Mockito.times(1)).notificationActionTapped(messageArgumentCaptor.capture(), notificationCategoryArgumentCaptor.capture(), notificationActionArgumentCaptor.capture());
Message actualMessage = messageArgumentCaptor.getValue();
NotificationAction actualAction = notificationActionArgumentCaptor.getValue();
NotificationCategory actualCategory = notificationCategoryArgumentCaptor.getValue();
Mockito.verify(mobileInteractive, Mockito.times(1)).triggerSdkActionsFor(actualCategory.getCategoryId(), actualAction, actualMessage);
}
use of org.infobip.mobile.messaging.interactive.NotificationAction in project mobile-messaging-sdk-android by infobip.
the class AndroidInteractiveBroadcasterTest method test_should_send_notification_action_tapped_event.
@Test
public void test_should_send_notification_action_tapped_event() throws Exception {
// Given
Message givenMessage = createMessage(context, "SomeMessageId", false);
NotificationAction notificationAction = givenNotificationAction("actionIdNotTapped").build();
NotificationAction givenTappedNotificationAction = givenNotificationAction("actionId").build();
NotificationCategory givenNotificationCategory = new NotificationCategory("categoryId", notificationAction, givenTappedNotificationAction);
// When
broadcastSender.notificationActionTapped(givenMessage, givenNotificationCategory, givenTappedNotificationAction);
// Then
Mockito.verify(contextMock, Mockito.times(1)).sendBroadcast(intentArgumentCaptor.capture());
Intent intent = intentArgumentCaptor.getValue();
assertEquals(InteractiveEvent.NOTIFICATION_ACTION_TAPPED.getKey(), intent.getAction());
Message messageAfter = Message.createFrom(intent.getExtras());
NotificationAction actionAfter = NotificationAction.createFrom(intent.getExtras());
NotificationCategory categoryAfter = NotificationCategory.createFrom(intent.getExtras());
assertNotSame(message, messageAfter);
assertEquals("SomeMessageId", messageAfter.getMessageId());
assertJEquals(givenMessage, messageAfter);
assertJEquals(givenTappedNotificationAction, actionAfter);
assertJEquals(givenNotificationCategory, categoryAfter);
}
use of org.infobip.mobile.messaging.interactive.NotificationAction in project mobile-messaging-sdk-android by infobip.
the class InteractiveNotificationHandler method setNotificationActions.
private void setNotificationActions(NotificationCompat.Builder notificationBuilder, Message message, NotificationCategory triggeredNotificationCategory, int notificationId) {
if (triggeredNotificationCategory == null) {
return;
}
NotificationAction[] notificationActions = triggeredNotificationCategory.getNotificationActions();
for (NotificationAction notificationAction : notificationActions) {
PendingIntent pendingIntent = createActionTapPendingIntent(message, triggeredNotificationCategory, notificationAction, notificationId);
notificationBuilder.addAction(createAndroidNotificationAction(notificationAction, pendingIntent));
}
}
Aggregations