Skip to content

Commit

Permalink
Merge branch 'master' into MML-291
Browse files Browse the repository at this point in the history
  • Loading branch information
symphony-mariacristina authored Jul 21, 2021
2 parents 20a3211 + daebdca commit 2d5b32e
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public enum BiFields {
CASHTAGS("cashtags", BiEventType.MESSAGEML_MESSAGE_SENT),
BULLET_LIST("lists", BiEventType.MESSAGEML_MESSAGE_SENT),
CARD("cards", BiEventType.MESSAGEML_MESSAGE_SENT),
EXPANDABLE_CARDS("expandablecards", BiEventType.MESSAGEML_MESSAGE_SENT),
EXPANDABLE_CARDS_COLLAPSED("expandablecards_collapsed", BiEventType.MESSAGEML_MESSAGE_SENT),
EXPANDABLE_CARDS_CROPPED("expandablecards_cropped", BiEventType.MESSAGEML_MESSAGE_SENT),
EXPANDABLE_CARDS_EXPANDED("expandablecards_expanded", BiEventType.MESSAGEML_MESSAGE_SENT),
Expand Down Expand Up @@ -72,6 +71,8 @@ public enum BiFields {
ENTITY_JSON_SIZE("entities_json_size", BiEventType.MESSAGEML_MESSAGE_SENT),
FREEMARKER("use_freemarker", BiEventType.MESSAGEML_MESSAGE_SENT),
POPUPS("popups", BiEventType.MESSAGEML_MESSAGE_SENT),
OPENIM("uiactions_openim", BiEventType.MESSAGEML_MESSAGE_SENT),
OPENDIALOG("uiactions_opendialog", BiEventType.MESSAGEML_MESSAGE_SENT),
COUNT("count", BiEventType.NONE);

private final String value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ void validate() throws InvalidInputException {
@Override
void updateBiContext(BiContext context) {
super.updateBiContext(context);
context.updateItemCount(BiFields.EXPANDABLE_CARDS.getValue());
if (getAttribute(ATTR_STATE) == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import org.symphonyoss.symphony.messageml.MessageMLContext;
import org.symphonyoss.symphony.messageml.MessageMLParser;
import org.symphonyoss.symphony.messageml.bi.BiContext;
import org.symphonyoss.symphony.messageml.bi.BiFields;
import org.symphonyoss.symphony.messageml.exceptions.InvalidInputException;
import org.symphonyoss.symphony.messageml.util.XmlPrintStream;

Expand Down Expand Up @@ -153,6 +155,23 @@ public String getPresentationMLTag() {
return PRESENTATIONML_TAG;
}

@Override
void updateBiContext(BiContext context) {
super.updateBiContext(context);

final String actionAttribute = getAttribute(ACTION_ATTR);
if (actionAttribute != null) {
switch (actionAttribute) {
case OPEN_IM:
context.updateItemCount(BiFields.OPENIM.getValue());
break;
case OPEN_DIALOG:
context.updateItemCount(BiFields.OPENDIALOG.getValue());
break;
}
}
}

private void validateUserIdsAttribute() throws InvalidInputException {
String userIds = getAttribute(USER_IDS_ATTR);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ public void testCardsBi() throws Exception {

private List<BiItem> getExpectedCardBiItems() {
List<BiItem> biItems = new ArrayList<>();
biItems.add(new BiItem(BiFields.EXPANDABLE_CARDS.getValue(), Collections.singletonMap(BiFields.COUNT.getValue(), 4)));
biItems.add(new BiItem(BiFields.EXPANDABLE_CARDS_COLLAPSED.getValue(), Collections.singletonMap(BiFields.COUNT.getValue(), 1)));
biItems.add(new BiItem(BiFields.EXPANDABLE_CARDS_CROPPED.getValue(), Collections.singletonMap(BiFields.COUNT.getValue(), 2)));
biItems.add(new BiItem(BiFields.EXPANDABLE_CARDS_EXPANDED.getValue(), Collections.singletonMap(BiFields.COUNT.getValue(), 1)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertIterableEquals;

import org.junit.Test;
import org.symphonyoss.symphony.messageml.bi.BiFields;
import org.symphonyoss.symphony.messageml.bi.BiItem;
import org.symphonyoss.symphony.messageml.exceptions.InvalidInputException;
import org.symphonyoss.symphony.messageml.exceptions.ProcessingException;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -442,6 +448,75 @@ public void testUIActionOpenDialogWithMatchingDialogId() throws Exception {
assertEquals(m.group(1), m.group(2)); // assert the generated IDs are the same
}

@Test
public void testBiContextOpenIm() throws Exception {
String inputMessageML =
"<messageML><ui-action action=\"open-im\" user-ids=\"[123]\">" +
"<button>Open by stream ID</button>" +
"</ui-action></messageML>";
context.parseMessageML(inputMessageML, null, MessageML.MESSAGEML_VERSION);

List<BiItem> expectedBiItems =
Arrays.asList(new BiItem(BiFields.BUTTON.getValue(), new HashMap<>()),
new BiItem(BiFields.OPENIM.getValue(), Collections.singletonMap(BiFields.COUNT.getValue(), 1)),
new BiItem(BiFields.MESSAGE_LENGTH.getValue(), Collections.singletonMap(BiFields.COUNT.getValue(), 114)));

List<BiItem> biItems = context.getBiContext().getItems();
assertIterableEquals(expectedBiItems, biItems);
}

@Test
public void testBiContextOpenDialog() throws Exception {
String inputMessageML =
"<messageML>" +
"<dialog id=\"target-dialog-id\">" +
"<title>title</title>" +
"<body>body</body>" +
"</dialog>" +
"<ui-action trigger=\"click\" action=\"open-dialog\" target-id=\"target-dialog-id\">" +
"<button>Open the dialog</button>" +
"</ui-action></messageML>";
context.parseMessageML(inputMessageML, null, MessageML.MESSAGEML_VERSION);

List<BiItem> expectedBiItems =
Arrays.asList(new BiItem(BiFields.POPUPS.getValue(), Collections.singletonMap(BiFields.COUNT.getValue(), 1)),
new BiItem(BiFields.BUTTON.getValue(), new HashMap<>()),
new BiItem(BiFields.OPENDIALOG.getValue(), Collections.singletonMap(BiFields.COUNT.getValue(), 1)),
new BiItem(BiFields.MESSAGE_LENGTH.getValue(), Collections.singletonMap(BiFields.COUNT.getValue(), 220)));

List<BiItem> biItems = context.getBiContext().getItems();
assertIterableEquals(expectedBiItems, biItems);
}

@Test
public void testBiContextWithMultipleUIActions() throws Exception {
String inputMessageML =
"<messageML>" +
"<dialog id=\"target-dialog-id\">" +
"<title>title</title>" +
"<body>body</body>" +
"</dialog>" +
"<ui-action trigger=\"click\" action=\"open-dialog\" target-id=\"target-dialog-id\">" +
"<button>Open the dialog</button>" +
"</ui-action>" +
"<ui-action action=\"open-im\" user-ids=\"[123]\">" +
"<button>Open by stream ID</button>" +
"</ui-action>" +
"</messageML>";
context.parseMessageML(inputMessageML, null, MessageML.MESSAGEML_VERSION);

List<BiItem> expectedBiItems =
Arrays.asList(new BiItem(BiFields.POPUPS.getValue(), Collections.singletonMap(BiFields.COUNT.getValue(), 1)),
new BiItem(BiFields.BUTTON.getValue(), new HashMap<>()),
new BiItem(BiFields.OPENDIALOG.getValue(), Collections.singletonMap(BiFields.COUNT.getValue(), 1)),
new BiItem(BiFields.BUTTON.getValue(), new HashMap<>()),
new BiItem(BiFields.OPENIM.getValue(), Collections.singletonMap(BiFields.COUNT.getValue(), 1)),
new BiItem(BiFields.MESSAGE_LENGTH.getValue(), Collections.singletonMap(BiFields.COUNT.getValue(), 311)));

List<BiItem> biItems = context.getBiContext().getItems();
assertIterableEquals(expectedBiItems, biItems);
}

private void validateMessageMLSimpleStructure() {
Element messageML = context.getMessageML();
Element uiAction = messageML.getChildren().get(0);
Expand Down

0 comments on commit 2d5b32e

Please sign in to comment.