Skip to content

Commit

Permalink
AGNT-397 edit table and elements markdown representation (#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamed-rojbeni authored Mar 4, 2024
1 parent 4a13a12 commit 1b49c06
Show file tree
Hide file tree
Showing 21 changed files with 187 additions and 153 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @since 4/7/17
*/
public class TableCellNode extends CustomBlock {
private final static String DELIMITER = " | ";
private final static String DELIMITER = " ";

public String getDelimiter() {
return DELIMITER;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
* @since 4/7/17
*/
public class TableNode extends CustomBlock {
private final static String LEAD = "Table:";
private final static String DELIMITER = "---";

private final static String DELIMITER = " ";

public String getOpeningDelimiter() {
return LEAD + "\n" + DELIMITER + "\n";
return "\n" + DELIMITER + "\n";
}

public String getClosingDelimiter() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.symphonyoss.symphony.messageml.markdown.nodes.form;

import org.apache.commons.lang3.StringUtils;

/**
* Class that Represents a Markdown Node for the "Checkbox" form element.
*
Expand All @@ -8,6 +10,7 @@
*/
public class CheckboxNode extends FormElementNode {
private final static String MARKDOWN = "Checkbox";
private final static String CHECKBOX_DELIMITER = " ";

private String label;

Expand All @@ -19,9 +22,19 @@ public CheckboxNode(String label) {
super(MARKDOWN);
this.label = label;
}


@Override
public String getOpeningDelimiter() {
return CHECKBOX_DELIMITER;
}

@Override
public String getClosingDelimiter() {
return CHECKBOX_DELIMITER;
}

@Override
public String getText() {
return (label != null) ? ":" + label : "";
return StringUtils.defaultIfBlank(label, StringUtils.EMPTY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

public class FormNode extends FormElementNode {
private final static String MARKDOWN = "Form (log into desktop client to answer):";
private final static String FORM_DELIMITER = "---";
private final static String FORM_DELIMITER = " ";

public FormNode() {
super(MARKDOWN);
}

@Override
public String getOpeningDelimiter() {
return MARKDOWN + "\n" + FORM_DELIMITER + "\n";
return "\n" + FORM_DELIMITER + "\n";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.symphonyoss.symphony.messageml.markdown.nodes.form;

import org.apache.commons.lang3.StringUtils;

/**
* Class that Represents a Markdown Node for the "Radio" form element.
*
Expand All @@ -8,6 +10,7 @@
*/
public class RadioNode extends FormElementNode {
private final static String MARKDOWN = "Radio Button";
private final static String RADIO_DELIMITER = " ";

private String label;

Expand All @@ -19,9 +22,19 @@ public RadioNode(String label) {
super(MARKDOWN, label);
this.label = label;
}

@Override
public String getOpeningDelimiter() {
return RADIO_DELIMITER;
}

@Override
public String getClosingDelimiter() {
return RADIO_DELIMITER;
}

@Override
public String getText() {
return (label != null) ? ":" + label : "";
return StringUtils.defaultIfBlank(label, StringUtils.EMPTY);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.symphonyoss.symphony.messageml.markdown.nodes.form;

import org.apache.commons.lang3.StringUtils;

/**
* Class that Represents a Markdown Node for the "Select" form element.
*
Expand All @@ -8,7 +10,7 @@
*/
public class SelectNode extends FormElementNode implements PlaceholderLabelTooltipNode {
private final static String MARKDOWN = "Dropdown";
private final static String RIGHT_DELIMITER = "):";
private final static String SELECT_DELIMITER = " ";

private String placeholder;
private String label;
Expand All @@ -20,14 +22,18 @@ public SelectNode(String placeholder, String label, String tooltip) {
this.label = label;
this.tooltip = tooltip;
}


@Override
public String getOpeningDelimiter() {
return SELECT_DELIMITER;
}
@Override
public String getClosingDelimiter() {
return RIGHT_DELIMITER + "\n";
return SELECT_DELIMITER + "\n";
}

@Override
public String getText() {
return generateMarkdownPlaceholderLabelAndTooltip(placeholder, label, tooltip);
return StringUtils.defaultIfBlank(label, StringUtils.EMPTY);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ public void testTable() throws Exception {
assertEquals("Element attributes", Collections.emptyMap(), tfoot.getAttributes());
assertEquals("Element children", 1, tfoot.getChildren().size());

assertEquals("Markdown", "Table:\n---\nIt | was\nthe | best\nof | times\n---\n", context.getMarkdown());
assertEquals("Markdown", "\n \nIt was\nthe best\nof times\n \n",
context.getMarkdown());
assertEquals("EntityJSON", new ObjectNode(JsonNodeFactory.instance), context.getEntityJson());
assertEquals("Legacy entities", new ObjectNode(JsonNodeFactory.instance), context.getEntities());

Expand Down Expand Up @@ -161,11 +162,11 @@ public void testParseMarkdownWithOnlyTable() throws Exception {
assertEquals("Generated PresentationML", "<div data-format=\"PresentationML\" data-version=\"2.0\">"
+ "<table><tr><td>A1</td><td>B1</td></tr><tr><td>A2</td><td>B2</td></tr></table></div>",
context.getPresentationML());
assertEquals("Generated Markdown", "Table:\n"
+ "---\n"
+ "A1 | B1\n"
+ "A2 | B2\n"
+ "---\n",
assertEquals("Generated Markdown", "\n"
+ " \n"
+ "A1 B1\n"
+ "A2 B2\n"
+ " \n",
context.getMarkdown());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ public void testNotDirectParent() throws Exception {
assertNull("Button clazz attribute", button.getAttribute(CLASS_ATTR));
assertEquals("Button inner text", "SELECT", button.getChild(0).asText());

assertEquals("Button markdown", "Form (log into desktop client to answer):\n---\n(Button:SELECT)\n\n\n---\n", context.getMarkdown());
assertEquals("Button markdown", "\n \n(Button:SELECT)\n\n\n \n", context.getMarkdown());
assertEquals("Button presentationML", "<div data-format=\"PresentationML\" data-version=\"2.0\"><form id=\"example\"><div><button type=\"action\" name=\"div-button\">SELECT</button></div></form></div>",
context.getPresentationML());
}
Expand Down Expand Up @@ -468,9 +468,9 @@ private String getExpectedButtonPresentation(String name, String type, String cl

private String getExpectedButtonMarkdown(String innerText, Boolean shouldHaveAdditionalStandardActionBtn) {
if (shouldHaveAdditionalStandardActionBtn) {
return "Form (log into desktop client to answer):\n---\n(Button:"+ innerText + ")\n---\n";
return "\n \n(Button:" + innerText + ")\n \n";
} else {
return "Form (log into desktop client to answer):\n---\n(Button:"+ innerText + ")" + ACTION_BTN_MARKDOWN + "\n---\n";
return "\n \n(Button:" + innerText + ")" + ACTION_BTN_MARKDOWN + "\n \n";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ public void testLabelWithUnderscoreMessageMLCheckbox() throws Exception {
+ " </form>"
+ " </div>", id, id);
assertEquals(expectedResult, presentationML);
String expectedMarkdown = " Form (log into desktop client to answer):\n" +
"---\n" +
" (Checkbox:Orange\\_fruit) (Button:Send) \n" +
"---\n" +
String expectedMarkdown = " \n" +
" \n" +
" Orange\\_fruit (Button:Send) \n" +
" \n" +
" ";
assertEquals(expectedMarkdown, context.getMarkdown());
}
Expand Down Expand Up @@ -514,8 +514,8 @@ private void verifyCheckboxMarkdown(MessageMLContext context, String label) {
}

private String buildExpectedMarkdownForCheckbox(String label) {
String expectedMarkdownText = ((label != null) ? ":" + label : "") ;
return String.format("Form (log into desktop client to answer):\n---\n(Checkbox%s)%s\n---\n", expectedMarkdownText,
String expectedMarkdownText = StringUtils.defaultIfBlank(label, StringUtils.EMPTY);
return String.format("\n \n %s %s\n \n", expectedMarkdownText,
ACTION_BTN_MARKDOWN);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ public void testDatePickerBasic() throws Exception {

String presentationML = context.getPresentationML();

String EXPECTED_MARKDOWN = "Form (log into desktop client to answer):\n"
+ "---\n"
String EXPECTED_MARKDOWN = "\n"
+ " \n"
+ "(Date Picker:[Please pick a date])(Button:Send)\n"
+ "---\n";
+ " \n";
String expectedPresentationML = "<div data-format=\"PresentationML\" data-version=\"2"
+ ".0\"><form id=\"datepicker-form\"><input type=\"date\" name=\"date-travel\" value=\"2020-09-15\" "
+ "placeholder=\"Please pick a date\" min=\"2020-09-01\" max=\"2020-09-29\" required=\"true\" "
Expand Down Expand Up @@ -117,10 +117,10 @@ public void testDatePickerWithLabelAndTooltip() throws Exception {
Matcher matcher = pattern.matcher(presentationML);
String uniqueLabelId = matcher.matches() ? matcher.group(2) : null;

String EXPECTED_MARKDOWN = "Form (log into desktop client to answer):\n"
+ "---\n"
String EXPECTED_MARKDOWN = "\n"
+ " \n"
+ "(Date Picker:[Departure date][This is \\n a hint][Please pick a date])(Button:Send)\n"
+ "---\n";
+ " \n";
String expectedPresentationML = String.format("<div data-format=\"PresentationML\" "
+ "data-version=\"2.0\"><form id=\"datepicker-form\"><div class=\"date-picker-group\" "
+ "data-generated=\"true\"><label for=\"date-picker-%s\">Departure "
Expand Down Expand Up @@ -174,10 +174,10 @@ public void testDatePickerWithUnderscores() throws Exception {
Matcher matcher = pattern.matcher(presentationML);
String uniqueLabelId = matcher.matches() ? matcher.group(2) : null;

String EXPECTED_MARKDOWN = "Form (log into desktop client to answer):\n"
+ "---\n"
String EXPECTED_MARKDOWN = "\n"
+ " \n"
+ "(Date Picker:[Departure\\_date][This\\_is\\_a\\_hint][Please\\_pick\\_a\\_date])(Button:Send)\n"
+ "---\n";
+ " \n";
String expectedPresentationML = String.format("<div data-format=\"PresentationML\" "
+ "data-version=\"2.0\"><form id=\"datepicker-form\"><div class=\"date-picker-group\" "
+ "data-generated=\"true\"><label for=\"date-picker-%s\">Departure_"
Expand Down Expand Up @@ -423,10 +423,10 @@ public void testEmptyMarkdown() throws Exception {
String input = "<messageML><form id=\"" + formId + "\">"
+ "<date-picker name=\"date-travel\"/>"
+ ACTION_BTN_ELEMENT + "</form></messageML>";
String EXPECTED_MARKDOWN = "Form (log into desktop client to answer):\n"
+ "---\n"
String EXPECTED_MARKDOWN = "\n"
+ " \n"
+ "(Date Picker)(Button:Send)\n"
+ "---\n";
+ " \n";
context.parseMessageML(input, null, MessageML.MESSAGEML_VERSION);
assertEquals("Markdown", EXPECTED_MARKDOWN, context.getMarkdown());
}
Expand All @@ -436,10 +436,10 @@ public void testPartialMarkdown() throws Exception {
String input = "<messageML><form id=\"" + formId + "\">"
+ "<date-picker name=\"date-travel\" placeholder=\"Please pick a date\"/>"
+ ACTION_BTN_ELEMENT + "</form></messageML>";
String EXPECTED_MARKDOWN = "Form (log into desktop client to answer):\n"
+ "---\n"
String EXPECTED_MARKDOWN = "\n"
+ " \n"
+ "(Date Picker:[Please pick a date])(Button:Send)\n"
+ "---\n";
+ " \n";
context.parseMessageML(input, null, MessageML.MESSAGEML_VERSION);
assertEquals("Markdown", EXPECTED_MARKDOWN, context.getMarkdown());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ public void sendDateSelectorOutsideForm() throws Exception {
assertEquals(dateSelector.getClass(), DateSelector.class);
assertEquals("<div data-format=\"PresentationML\" data-version=\"2.0\"><form id=\"" + FORM_ID_ATTR +
"\"><div><div class=\"date-selector\" data-name=\"some-name\"></div></div>" + ACTION_BTN_ELEMENT + "</form></div>", context.getPresentationML());
assertEquals("Form (log into desktop client to answer):\n---\n(Date Selector)\n\n" + ACTION_BTN_MARKDOWN + "\n---\n", context.getMarkdown());
assertEquals("\n \n(Date Selector)\n\n" + ACTION_BTN_MARKDOWN + "\n \n",
context.getMarkdown());
}

@Test
Expand Down Expand Up @@ -146,8 +147,8 @@ private void assertDataFromValidParsedTag(String dataName, String dataPlaceholde
(dataRequired != null ? " data-required=\"" + dataRequired.toString() + "\"" : "") +
"></div>" + ACTION_BTN_ELEMENT + "</form></div>", context.getPresentationML());
String expectedMarkdownText = (dataPlaceholder != null) ? ":[" + addEscapeCharacter(dataPlaceholder) + "]" : "";
assertEquals("Form (log into desktop client to answer):\n---\n(Date Selector" + expectedMarkdownText + ")" + ACTION_BTN_MARKDOWN
+ "\n---\n", context.getMarkdown());
assertEquals("\n \n(Date Selector" + expectedMarkdownText + ")" + ACTION_BTN_MARKDOWN
+ "\n \n", context.getMarkdown());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public void sendValidPersonSelectorWithLabelAndTitleOnPresentationML() throws Ex
expectedPresentationML, presentationML);

String expectedMarkdownText = "[label here][title here]";
assertEquals("Form (log into desktop client to answer):\n---\n(Person Selector:" + expectedMarkdownText + ")" + ACTION_BTN_MARKDOWN
+ "\n---\n", context.getMarkdown());
assertEquals("\n \n(Person Selector:" + expectedMarkdownText + ")" + ACTION_BTN_MARKDOWN
+ "\n \n", context.getMarkdown());
}

@Test
Expand Down Expand Up @@ -214,8 +214,8 @@ public void sendPersonSelectorOutsideForm() throws Exception {
assertEquals(personSelector.getClass(), PersonSelector.class);
assertEquals("<div data-format=\"PresentationML\" data-version=\"2.0\"><form id=\"" + FORM_ID_ATTR +
"\"><div><div class=\"person-selector\" data-name=\"some-name\"></div></div>" + ACTION_BTN_ELEMENT + "</form></div>", context.getPresentationML());
assertEquals("Form (log into desktop client to answer):\n---\n(Person Selector)\n\n" + ACTION_BTN_MARKDOWN
+ "\n---\n", context.getMarkdown());
assertEquals("\n \n(Person Selector)\n\n" + ACTION_BTN_MARKDOWN
+ "\n \n", context.getMarkdown());
}

@Test
Expand Down Expand Up @@ -280,8 +280,8 @@ private void assertDataFromValidParsedTag(String dataName, String dataPlaceholde
(dataRequired != null ? " data-required=\"" + dataRequired.toString() + "\"" : "") +
"></div>" + ACTION_BTN_ELEMENT + "</form></div>", context.getPresentationML());
String expectedMarkdownText = (dataPlaceholder != null) ? ":[" + addEscapeCharacter(dataPlaceholder) + "]" : "";
assertEquals("Form (log into desktop client to answer):\n---\n(Person Selector" + expectedMarkdownText + ")" + ACTION_BTN_MARKDOWN
+ "\n---\n", context.getMarkdown());
assertEquals("\n \n(Person Selector" + expectedMarkdownText + ")" + ACTION_BTN_MARKDOWN
+ "\n \n", context.getMarkdown());
}

}
Loading

0 comments on commit 1b49c06

Please sign in to comment.