From bda0f94a1b905a5a54b6cd3b4b33c5498d38e9d3 Mon Sep 17 00:00:00 2001 From: Mohamed Rojbeni Date: Mon, 2 Oct 2023 12:11:39 +0200 Subject: [PATCH] [AGNT-366][C2-20897] add disabled or readonly attributes to some components (#381) --- .../symphony/messageml/elements/Checkbox.java | 12 +++++ .../messageml/elements/DatePicker.java | 17 +++++- .../messageml/elements/GroupedElement.java | 12 +++++ .../symphony/messageml/elements/Radio.java | 12 +++++ .../symphony/messageml/elements/Select.java | 21 ++++++-- .../symphony/messageml/elements/TextArea.java | 12 +++++ .../messageml/elements/TextField.java | 21 +++++++- .../messageml/elements/TimePicker.java | 17 ++++++ .../messageml/elements/form/CheckboxTest.java | 52 ++++++++++++++++++ .../elements/form/DatePickerTest.java | 49 +++++++++++++++++ .../messageml/elements/form/RadioTest.java | 52 ++++++++++++++++++ .../elements/form/SelectOptionTest.java | 51 ++++++++++++++++++ .../messageml/elements/form/TextAreaTest.java | 41 ++++++++++++++ .../elements/form/TextFieldTest.java | 41 ++++++++++++++ .../elements/form/TimePickerTest.java | 53 +++++++++++++++++++ 15 files changed, 456 insertions(+), 7 deletions(-) mode change 100755 => 100644 src/main/java/org/symphonyoss/symphony/messageml/elements/TextField.java diff --git a/src/main/java/org/symphonyoss/symphony/messageml/elements/Checkbox.java b/src/main/java/org/symphonyoss/symphony/messageml/elements/Checkbox.java index 4bd6fde5..b6f34072 100644 --- a/src/main/java/org/symphonyoss/symphony/messageml/elements/Checkbox.java +++ b/src/main/java/org/symphonyoss/symphony/messageml/elements/Checkbox.java @@ -39,6 +39,16 @@ public void validate() throws InvalidInputException { assertAttributeValue(CHECKED_ATTR, Arrays.asList(Boolean.TRUE.toString(), Boolean.FALSE.toString())); } + if (getAttribute(DISABLED_ATTR) != null) { + assertAttributeValue(DISABLED_ATTR, + Arrays.asList(Boolean.TRUE.toString(), Boolean.FALSE.toString())); + } + + if (getAttribute(READONLY_ATTR) != null) { + assertAttributeValue(READONLY_ATTR, + Arrays.asList(Boolean.TRUE.toString(), Boolean.FALSE.toString())); + } + if (!getChildren().isEmpty()) { assertContentModel(Arrays.asList(TextNode.class, Bold.class, Italic.class)); } @@ -54,6 +64,8 @@ protected void buildAttribute(MessageMLParser parser, case VALUE_ATTR: case CHECKED_ATTR: case LABEL: + case DISABLED_ATTR: + case READONLY_ATTR: setAttribute(item.getNodeName(), getStringAttribute(item)); break; case ID_ATTR: diff --git a/src/main/java/org/symphonyoss/symphony/messageml/elements/DatePicker.java b/src/main/java/org/symphonyoss/symphony/messageml/elements/DatePicker.java index 5184d7d8..b0dfd4c5 100644 --- a/src/main/java/org/symphonyoss/symphony/messageml/elements/DatePicker.java +++ b/src/main/java/org/symphonyoss/symphony/messageml/elements/DatePicker.java @@ -45,6 +45,8 @@ public class DatePicker extends FormElement implements LabelableElement, Tooltip private static final String PRESENTATIONML_DISABLED_DATE_ATTR = "data-disabled-date"; private static final String PRESENTATIONML_HIGHLIGHTED_DATE_ATTR = "data-highlighted-date"; private static final String PRESENTATIONML_FORMAT_ATTR = "data-format"; + protected static final String DISABLED_ATTR = "disabled"; + protected static final String READONLY_ATTR = "readonly"; private static final String DATE_FORMAT_ALLOWED = "^[0-9Mdy\\/. -:]+$"; @@ -63,6 +65,8 @@ protected void buildAttribute(MessageMLParser parser, Node item) throws InvalidI case MAX_ATTR: case LABEL: case TITLE: + case DISABLED_ATTR: + case READONLY_ATTR: setAttribute(item.getNodeName(), getStringAttribute(item)); break; case DISABLED_DATE_ATTR: @@ -108,6 +112,12 @@ public void validate() throws InvalidInputException { if (getAttribute(MAX_ATTR) != null) { assertDateFormat(MAX_ATTR, DateTimeFormatter.ISO_DATE); } + if (getAttribute(DISABLED_ATTR) != null) { + assertAttributeValue(DISABLED_ATTR, Arrays.asList("true", "false")); + } + if (getAttribute(READONLY_ATTR) != null) { + assertAttributeValue(READONLY_ATTR, Arrays.asList("true", "false")); + } assertJsonDatesRange(DISABLED_DATE_ATTR); assertJsonDatesRange(HIGHLIGHTED_DATE_ATTR); @@ -177,6 +187,12 @@ private Map buildDataPickerInputAttributes() { if (getAttribute(FORMAT_ATTR) != null) { presentationAttrs.put(PRESENTATIONML_FORMAT_ATTR, getAttribute(FORMAT_ATTR)); } + if (getAttribute(DISABLED_ATTR) != null) { + presentationAttrs.put(DISABLED_ATTR, getAttribute(DISABLED_ATTR)); + } + if (getAttribute(READONLY_ATTR) != null) { + presentationAttrs.put(READONLY_ATTR, getAttribute(READONLY_ATTR)); + } // PresentationML compatibility if (getAttribute(PRESENTATIONML_DISABLED_DATE_ATTR) != null) { presentationAttrs.put(PRESENTATIONML_DISABLED_DATE_ATTR, getAttribute(PRESENTATIONML_DISABLED_DATE_ATTR)); @@ -187,7 +203,6 @@ private Map buildDataPickerInputAttributes() { if (getAttribute(PRESENTATIONML_FORMAT_ATTR) != null) { presentationAttrs.put(PRESENTATIONML_FORMAT_ATTR, getAttribute(PRESENTATIONML_FORMAT_ATTR)); } - return presentationAttrs; } diff --git a/src/main/java/org/symphonyoss/symphony/messageml/elements/GroupedElement.java b/src/main/java/org/symphonyoss/symphony/messageml/elements/GroupedElement.java index 92b6a33a..34e5b64f 100644 --- a/src/main/java/org/symphonyoss/symphony/messageml/elements/GroupedElement.java +++ b/src/main/java/org/symphonyoss/symphony/messageml/elements/GroupedElement.java @@ -29,6 +29,9 @@ public abstract class GroupedElement extends FormElement { protected static final String VALUE_ATTR = "value"; protected static final String CHECKED_ATTR = "checked"; protected static final String FOR_ATTR = "for"; + protected static final String DISABLED_ATTR = "disabled"; + protected static final String READONLY_ATTR = "readonly"; + public GroupedElement(Element parent, String messageMLTag, FormatEnum format) { @@ -188,6 +191,15 @@ protected Map buildGroupedElementInputAttributes(String id) { } else { presentationAttrs.put(VALUE_ATTR, PRESENTATIONML_DEFAULT_VALUE); } + + if (getAttribute(DISABLED_ATTR) != null) { + presentationAttrs.put(DISABLED_ATTR, getAttribute(DISABLED_ATTR)); + } + + if (getAttribute(READONLY_ATTR) != null) { + presentationAttrs.put(READONLY_ATTR, getAttribute(READONLY_ATTR)); + } + return presentationAttrs; } diff --git a/src/main/java/org/symphonyoss/symphony/messageml/elements/Radio.java b/src/main/java/org/symphonyoss/symphony/messageml/elements/Radio.java index 80421d8a..e3d49e67 100644 --- a/src/main/java/org/symphonyoss/symphony/messageml/elements/Radio.java +++ b/src/main/java/org/symphonyoss/symphony/messageml/elements/Radio.java @@ -67,6 +67,16 @@ public void validate() throws InvalidInputException { assertAttributeValue(CHECKED_ATTR, Arrays.asList(Boolean.TRUE.toString(), Boolean.FALSE.toString())); } + if (getAttribute(DISABLED_ATTR) != null) { + assertAttributeValue(DISABLED_ATTR, + Arrays.asList(Boolean.TRUE.toString(), Boolean.FALSE.toString())); + } + + if (getAttribute(READONLY_ATTR) != null) { + assertAttributeValue(READONLY_ATTR, + Arrays.asList(Boolean.TRUE.toString(), Boolean.FALSE.toString())); + } + if (!getChildren().isEmpty()) { assertContentModel(Arrays.asList(TextNode.class, Bold.class, Italic.class)); } @@ -80,6 +90,8 @@ protected void buildAttribute(MessageMLParser parser, case NAME_ATTR: case VALUE_ATTR: case LABEL: + case DISABLED_ATTR: + case READONLY_ATTR: setAttribute(item.getNodeName(), getStringAttribute(item)); break; case ID_ATTR: diff --git a/src/main/java/org/symphonyoss/symphony/messageml/elements/Select.java b/src/main/java/org/symphonyoss/symphony/messageml/elements/Select.java index a3efd33a..e87b062e 100644 --- a/src/main/java/org/symphonyoss/symphony/messageml/elements/Select.java +++ b/src/main/java/org/symphonyoss/symphony/messageml/elements/Select.java @@ -16,8 +16,7 @@ package org.symphonyoss.symphony.messageml.elements; -import org.apache.commons.lang3.BooleanUtils; -import org.apache.commons.lang3.StringUtils; + import org.symphonyoss.symphony.messageml.MessageMLParser; import org.symphonyoss.symphony.messageml.bi.BiContext; import org.symphonyoss.symphony.messageml.bi.BiFields; @@ -62,9 +61,10 @@ public class Select extends FormElement implements LabelableElement, Tooltipable private static final String MIN_ATTR = "data-min"; private static final String MML_MAX_ATTR = "max"; private static final String MAX_ATTR = "data-max"; - private static final String MML_AUTO_SUBMIT_ATTR = "auto-submit"; + protected static final String DISABLED_ATTR = "disabled"; + protected static final String READONLY_ATTR = "readonly"; private static final String AUTO_SUBMIT_ATTR = "data-auto-submit"; - + private static final String MML_AUTO_SUBMIT_ATTR = "auto-submit"; public Select(Element parent) { super(parent, MESSAGEML_TAG); @@ -95,6 +95,17 @@ public void validate() throws InvalidInputException { assertAttributeValue(MULTIPLE_ATTR, Arrays.asList(Boolean.TRUE.toString(), Boolean.FALSE.toString())); } + if (getAttribute(DISABLED_ATTR) != null) { + assertAttributeValue(DISABLED_ATTR, + Arrays.asList(Boolean.TRUE.toString(), Boolean.FALSE.toString())); + } + + if (getAttribute(READONLY_ATTR) != null) { + assertAttributeValue(READONLY_ATTR, + + Arrays.asList(Boolean.TRUE.toString(), Boolean.FALSE.toString())); + } + if (getAttribute(AUTO_SUBMIT_ATTR) != null) { assertAttributeValue(AUTO_SUBMIT_ATTR, Arrays.asList(Boolean.TRUE.toString(), Boolean.FALSE.toString())); @@ -135,6 +146,8 @@ protected void buildAttribute(MessageMLParser parser, Node item) throws InvalidI case LABEL: case TITLE: case MULTIPLE_ATTR: + case DISABLED_ATTR: + case READONLY_ATTR: setAttribute(item.getNodeName(), getStringAttribute(item)); break; case MML_MIN_ATTR: diff --git a/src/main/java/org/symphonyoss/symphony/messageml/elements/TextArea.java b/src/main/java/org/symphonyoss/symphony/messageml/elements/TextArea.java index 6db085bd..a75a0e3b 100644 --- a/src/main/java/org/symphonyoss/symphony/messageml/elements/TextArea.java +++ b/src/main/java/org/symphonyoss/symphony/messageml/elements/TextArea.java @@ -28,6 +28,8 @@ public class TextArea extends FormElement implements RegexElement, LabelableElem private static final String PLACEHOLDER_ATTR = "placeholder"; private static final String REQUIRED_ATTR = "required"; + private static final String DISABLED_ATTR = "disabled"; + private static final String READONLY_ATTR = "readonly"; private static final String ROWS = "rows"; private static final String COLS = "cols"; private static final List VALID_VALUES_FOR_REQUIRED_ATTR = Arrays.asList("true", "false"); @@ -48,6 +50,14 @@ public void validate() throws InvalidInputException { assertAttributeValue(REQUIRED_ATTR, VALID_VALUES_FOR_REQUIRED_ATTR); } + + if (getAttribute(DISABLED_ATTR) != null) { + assertAttributeValue(DISABLED_ATTR, VALID_VALUES_FOR_REQUIRED_ATTR); + } + + if (getAttribute(READONLY_ATTR) != null) { + assertAttributeValue(READONLY_ATTR, VALID_VALUES_FOR_REQUIRED_ATTR); + } if (getAttribute(ROWS) != null) { checkIntegerAttribute(ROWS, 0, "Attribute \"rows\" is not valid, it must be an integer >= 0"); } @@ -74,6 +84,8 @@ protected void buildAttribute(MessageMLParser parser, case PATTERN_ATTR: case LABEL: case TITLE: + case DISABLED_ATTR: + case READONLY_ATTR: case ROWS: case COLS: setAttribute(item.getNodeName(), getStringAttribute(item)); diff --git a/src/main/java/org/symphonyoss/symphony/messageml/elements/TextField.java b/src/main/java/org/symphonyoss/symphony/messageml/elements/TextField.java old mode 100755 new mode 100644 index 196e3c1e..81c6c234 --- a/src/main/java/org/symphonyoss/symphony/messageml/elements/TextField.java +++ b/src/main/java/org/symphonyoss/symphony/messageml/elements/TextField.java @@ -35,9 +35,9 @@ public class TextField extends FormElement implements RegexElement, LabelableEle private static final String MASKED_ATTR = "masked"; private static final String PLACEHOLDER_ATTR = "placeholder"; private static final String VALUE_ATTR = "value"; - + private static final String DISABLED_ATTR = "disabled"; + private static final String READONLY_ATTR = "readonly"; private static final String PRESENTATIONML_MASKED_ATTR = "data-masked"; - private static final String MML_AUTO_SUBMIT_ATTR = "auto-submit"; private static final String AUTO_SUBMIT_ATTR = "data-auto-submit"; @@ -67,6 +67,14 @@ public void validate() throws InvalidInputException { assertAttributeValue(MASKED_ATTR, VALID_BOOLEAN_VALUES); } + if (getAttribute(DISABLED_ATTR) != null) { + assertAttributeValue(DISABLED_ATTR, VALID_BOOLEAN_VALUES); + } + + if (getAttribute(READONLY_ATTR) != null) { + assertAttributeValue(READONLY_ATTR, VALID_BOOLEAN_VALUES); + } + if (getAttribute(AUTO_SUBMIT_ATTR) != null) { assertAttributeValue(AUTO_SUBMIT_ATTR, VALID_BOOLEAN_VALUES); } @@ -109,6 +117,8 @@ protected void buildAttribute(MessageMLParser parser, case PATTERN_ERROR_MESSAGE_ATTR: case LABEL: case TITLE: + case DISABLED_ATTR: + case READONLY_ATTR: setAttribute(item.getNodeName(), getStringAttribute(item)); break; case ID_ATTR: @@ -194,6 +204,13 @@ public Map getOtherAttributes() { presentationAttrs.put(MAXLENGTH_ATTR, getAttribute(MAXLENGTH_ATTR)); } + if (getAttribute(DISABLED_ATTR) != null) { + presentationAttrs.put(DISABLED_ATTR, getAttribute(DISABLED_ATTR)); + } + + if (getAttribute(READONLY_ATTR) != null) { + presentationAttrs.put(READONLY_ATTR, getAttribute(READONLY_ATTR)); + } if (getAttribute(AUTO_SUBMIT_ATTR) != null) { presentationAttrs.put(AUTO_SUBMIT_ATTR, getAttribute(AUTO_SUBMIT_ATTR)); } diff --git a/src/main/java/org/symphonyoss/symphony/messageml/elements/TimePicker.java b/src/main/java/org/symphonyoss/symphony/messageml/elements/TimePicker.java index 01c976dd..74e4322b 100644 --- a/src/main/java/org/symphonyoss/symphony/messageml/elements/TimePicker.java +++ b/src/main/java/org/symphonyoss/symphony/messageml/elements/TimePicker.java @@ -34,6 +34,8 @@ public class TimePicker extends FormElement implements LabelableElement, Tooltip private static final String STEP_ATTR = "step"; private static final String STRICT_ATTR = "strict"; private static final String FORMAT_ATTR = "format"; + private static final String DISABLED_ATTR = "disabled"; + private static final String READONLY_ATTR = "readonly"; // PresentationML specific attributes private static final String PRESENTATIONML_FORMAT_ATTR = "data-format"; @@ -67,6 +69,8 @@ protected void buildAttribute(MessageMLParser parser, case MIN_ATTR: case MAX_ATTR: case STEP_ATTR: + case DISABLED_ATTR: + case READONLY_ATTR: setAttribute(item.getNodeName(), getStringAttribute(item)); break; case DISABLED_TIME_ATTR: @@ -115,6 +119,13 @@ public void validate() throws InvalidInputException { if (getAttribute(STRICT_ATTR) != null) { assertAttributeValue(STRICT_ATTR, Arrays.asList("true", "false")); } + + if (getAttribute(DISABLED_ATTR) != null) { + assertAttributeValue(DISABLED_ATTR, Arrays.asList("true", "false")); + } + if (getAttribute(READONLY_ATTR) != null) { + assertAttributeValue(READONLY_ATTR, Arrays.asList("true", "false")); + } } @Override @@ -295,6 +306,12 @@ private Map buildTimePickerInputAttributes() { if (getAttribute(PRESENTATIONML_DISABLED_TIME_ATTR) != null) { presentationAttrs.put(PRESENTATIONML_DISABLED_TIME_ATTR, getAttribute(PRESENTATIONML_DISABLED_TIME_ATTR)); } + if (getAttribute(DISABLED_ATTR) != null) { + presentationAttrs.put(DISABLED_ATTR, getAttribute(DISABLED_ATTR)); + } + if (getAttribute(READONLY_ATTR) != null) { + presentationAttrs.put(READONLY_ATTR, getAttribute(READONLY_ATTR)); + } return presentationAttrs; } diff --git a/src/test/java/org/symphonyoss/symphony/messageml/elements/form/CheckboxTest.java b/src/test/java/org/symphonyoss/symphony/messageml/elements/form/CheckboxTest.java index 2dbbc20c..a31c1cce 100644 --- a/src/test/java/org/symphonyoss/symphony/messageml/elements/form/CheckboxTest.java +++ b/src/test/java/org/symphonyoss/symphony/messageml/elements/form/CheckboxTest.java @@ -368,6 +368,58 @@ public void testMoreThanFiftyCheckboxesAsTableSelectWithinForm() throws Exceptio context.parseMessageML(input, null, MessageML.MESSAGEML_VERSION); } + @Test + public void testCheckboxWithReadyOnlyAndDisabledAttributes() throws Exception { + String input = + "
Red
"; + context.parseMessageML(input, null, MessageML.MESSAGEML_VERSION); + String presentationML = context.getPresentationML(); + int startId = presentationML.indexOf("label for=\""); + int endId = presentationML.indexOf('"', startId + "label for=\"".length()); + String id = presentationML.substring(startId + "label for=\"".length(), endId); + + String expectedPresentationML = + String.format( + "
", id, id); + + assertEquals(expectedPresentationML, context.getPresentationML()); + } + + @Test + public void testCheckboxWithInvalidReadyOnlyAttribute() throws Exception { + String input = + "
Red
"; + expectedException.expect(InvalidInputException.class); + expectedException.expectMessage( + "Attribute \"readonly\" of element \"checkbox\" can only be one of the following values: " + + "[true, false]."); + context.parseMessageML(input, null, MessageML.MESSAGEML_VERSION); + } + + @Test + public void testCheckboxWithInvalidDisabledAttribute() throws Exception { + String input = + "
Red
"; + expectedException.expect(InvalidInputException.class); + expectedException.expectMessage( + "Attribute \"disabled\" of element \"checkbox\" can only be one of the following values: " + + "[true, false]."); + context.parseMessageML(input, null, MessageML.MESSAGEML_VERSION); + } + + + private static Stream messageMlStream() { return Stream.of( Arguments.of( diff --git a/src/test/java/org/symphonyoss/symphony/messageml/elements/form/DatePickerTest.java b/src/test/java/org/symphonyoss/symphony/messageml/elements/form/DatePickerTest.java index e2f79f81..1122ee11 100644 --- a/src/test/java/org/symphonyoss/symphony/messageml/elements/form/DatePickerTest.java +++ b/src/test/java/org/symphonyoss/symphony/messageml/elements/form/DatePickerTest.java @@ -519,5 +519,54 @@ void testBiContextDatePicker_withValidations(String dataPickerML, Map
"; + String expectedPresentationML = + "
"; + + context.parseMessageML(input, null, MessageML.MESSAGEML_VERSION); + + assertEquals(expectedPresentationML, context.getPresentationML()); + } + + @Test + public void testDatePickerWithInvalidReadyOnlyAttribute() throws Exception { + String input = + "
"; + expectedException.expect(InvalidInputException.class); + expectedException.expectMessage( + "Attribute \"readonly\" of element \"date-picker\" can only be one of the following " + + "values: " + + "[true, false]."); + + context.parseMessageML(input, null, MessageML.MESSAGEML_VERSION); + } + + @Test + public void testDatePickerWithInvalidDisabledAttribute() throws Exception { + String input = + "
"; + expectedException.expect(InvalidInputException.class); + expectedException.expectMessage( + "Attribute \"disabled\" of element \"date-picker\" can only be one of the following " + + "values: " + + "[true, false]."); + + context.parseMessageML(input, null, MessageML.MESSAGEML_VERSION); + } + + + } diff --git a/src/test/java/org/symphonyoss/symphony/messageml/elements/form/RadioTest.java b/src/test/java/org/symphonyoss/symphony/messageml/elements/form/RadioTest.java index a3d7cb10..e4812d6a 100644 --- a/src/test/java/org/symphonyoss/symphony/messageml/elements/form/RadioTest.java +++ b/src/test/java/org/symphonyoss/symphony/messageml/elements/form/RadioTest.java @@ -604,6 +604,58 @@ void testBiContextRadio_checked(String radioML, Map expectedAttr assertMessageLengthBiItem(items.get(4), input.length()); } + @Test + public void testRadioWithReadyOnlyAndDisabledAttributes() throws Exception { + String input = + "
Red
"; + context.parseMessageML(input, null, MessageML.MESSAGEML_VERSION); + String presentationML = context.getPresentationML(); + String id = getInputId(context.getPresentationML()); + + String expectedPresentationML = + String.format( + "
", + id, id); + + assertEquals(expectedPresentationML, context.getPresentationML()); + } + + @Test + public void testRadioWithInvalidReadyOnlyAttribute() throws Exception { + String input = + "
Red
"; + expectedException.expect(InvalidInputException.class); + expectedException.expectMessage( + "Attribute \"readonly\" of element \"radio\" can only be one of the following values: " + + "[true, false]."); + context.parseMessageML(input, null, MessageML.MESSAGEML_VERSION); + } + + @Test + public void testRadioWithInvalidDisabledAttribute() throws Exception { + String input = + "
Red
"; + expectedException.expect(InvalidInputException.class); + expectedException.expectMessage( + "Attribute \"disabled\" of element \"radio\" can only be one of the following values: " + + "[true, false]."); + context.parseMessageML(input, null, MessageML.MESSAGEML_VERSION); + } + static String getInputId(String presentationML) { int startId = presentationML.indexOf("label for=\""); int endId = presentationML.indexOf('"', startId + "label for=\"".length()); diff --git a/src/test/java/org/symphonyoss/symphony/messageml/elements/form/SelectOptionTest.java b/src/test/java/org/symphonyoss/symphony/messageml/elements/form/SelectOptionTest.java index 348f2509..1212dcbd 100644 --- a/src/test/java/org/symphonyoss/symphony/messageml/elements/form/SelectOptionTest.java +++ b/src/test/java/org/symphonyoss/symphony/messageml/elements/form/SelectOptionTest.java @@ -688,6 +688,57 @@ public void testMultiSelectMultipleInvalid() throws Exception { } @Test + public void testSelectWithReadyOnlyAndDisabledAttributes() throws Exception { + String input = + "
"; + + String expectedPresentationML = + "
"; + + context.parseMessageML(input, null, MessageML.MESSAGEML_VERSION); + + assertEquals(expectedPresentationML, context.getPresentationML()); + } + + @Test + public void testSelectWithInvalidReadyOnlyAttribute() throws Exception { + String input = + "
"; + expectedException.expect(InvalidInputException.class); + expectedException.expectMessage( + "Attribute \"readonly\" of element \"select\" can only be one of the following values: " + + "[true, false]."); + context.parseMessageML(input, null, MessageML.MESSAGEML_VERSION); + } + + @Test + public void testSelectWithInvalidDisabledAttribute() throws Exception { + String input = + "
"; + expectedException.expect(InvalidInputException.class); + expectedException.expectMessage( + "Attribute \"disabled\" of element \"select\" can only be one of the following values: " + + "[true, false]."); + context.parseMessageML(input, null, MessageML.MESSAGEML_VERSION); + } + public void testAutoSubmitSelect() throws Exception { //language=XML String input = diff --git a/src/test/java/org/symphonyoss/symphony/messageml/elements/form/TextAreaTest.java b/src/test/java/org/symphonyoss/symphony/messageml/elements/form/TextAreaTest.java index 5b6977f6..a53357c3 100755 --- a/src/test/java/org/symphonyoss/symphony/messageml/elements/form/TextAreaTest.java +++ b/src/test/java/org/symphonyoss/symphony/messageml/elements/form/TextAreaTest.java @@ -400,6 +400,47 @@ public void testTextAreaMessageMLWithValueSmallerThanMaxLength() throws Exceptio context.parseMessageML(input, null, MessageML.MESSAGEML_VERSION); } + @Test + public void testTextAreaWithReadyOnlyAndDisabledAttributes() throws Exception { + String input = + "
"; + context.parseMessageML(input, null, MessageML.MESSAGEML_VERSION); + String expectedPresentationML = + "
"; + assertEquals(expectedPresentationML, context.getPresentationML()); + } + + @Test + public void testTextAreaWithInvalidReadyOnlyAttribute() throws Exception { + String input = + "
"; + expectedException.expect(InvalidInputException.class); + expectedException.expectMessage( + "Attribute \"readonly\" of element \"textarea\" can only be one of the following values: " + + "[true, false]."); + context.parseMessageML(input, null, MessageML.MESSAGEML_VERSION); + } + + @Test + public void testTextAreaWithInvalidDisabledAttribute() throws Exception { + String input = + "
"; + expectedException.expect(InvalidInputException.class); + expectedException.expectMessage( + "Attribute \"disabled\" of element \"textarea\" can only be one of the following values: " + + "[true, false]."); + context.parseMessageML(input, null, MessageML.MESSAGEML_VERSION); + } + private static Stream messageMlStream() { return Stream.of( Arguments.of( diff --git a/src/test/java/org/symphonyoss/symphony/messageml/elements/form/TextFieldTest.java b/src/test/java/org/symphonyoss/symphony/messageml/elements/form/TextFieldTest.java index 9889a59b..121d9945 100644 --- a/src/test/java/org/symphonyoss/symphony/messageml/elements/form/TextFieldTest.java +++ b/src/test/java/org/symphonyoss/symphony/messageml/elements/form/TextFieldTest.java @@ -812,6 +812,47 @@ void testBiContextTextField_masked_withValidation(String textFieldML, Map
With initial value
"; + context.parseMessageML(input, null, MessageML.MESSAGEML_VERSION); + String expectedPresentationML = + "
"; + assertEquals(expectedPresentationML, context.getPresentationML()); + } + + @Test + public void testTextFieldWithInvalidReadyOnlyAttribute() throws Exception { + String input = + "
With " + + "initial value
"; + expectedException.expect(InvalidInputException.class); + expectedException.expectMessage( + "Attribute \"readonly\" of element \"text-field\" can only be one of the following values: " + + "[true, false]."); + context.parseMessageML(input, null, MessageML.MESSAGEML_VERSION); + } + + @Test + public void testTextFieldWithInvalidDisabledAttribute() throws Exception { + String input = + "
With " + + "initial value
"; + expectedException.expect(InvalidInputException.class); + expectedException.expectMessage( + "Attribute \"disabled\" of element \"text-field\" can only be one of the following values: " + + "[true, false]."); + context.parseMessageML(input, null, MessageML.MESSAGEML_VERSION); + } + private String getLabelId(String presentationML) { String textFieldRegex = ".*(\"textfield-(.*?)\").*"; diff --git a/src/test/java/org/symphonyoss/symphony/messageml/elements/form/TimePickerTest.java b/src/test/java/org/symphonyoss/symphony/messageml/elements/form/TimePickerTest.java index 66092847..2967f7d3 100644 --- a/src/test/java/org/symphonyoss/symphony/messageml/elements/form/TimePickerTest.java +++ b/src/test/java/org/symphonyoss/symphony/messageml/elements/form/TimePickerTest.java @@ -463,4 +463,57 @@ public void testBiContextTimePicker_BadAttribute() { 0, items.size()); } + @Test + public void testTextFieldWithReadyOnlyAndDisabledAttributes() throws Exception { + String input = + "
"; + context.parseMessageML(input, null, MessageML.MESSAGEML_VERSION); + + String presentationML = context.getPresentationML(); + String timePickerRegex = ".*(\"time-picker-(.*?)\").*"; + Pattern pattern = Pattern.compile(timePickerRegex); + Matcher matcher = pattern.matcher(presentationML); + String uniqueLabelId = matcher.matches() ? matcher.group(2) : null; + + String expectedPresentationML = String.format( + "
", uniqueLabelId, uniqueLabelId); + assertEquals(expectedPresentationML, context.getPresentationML()); + } + + @Test + public void testTimePickerWithInvalidReadyOnlyAttribute() throws Exception { + String input = + "
"; + expectedException.expect(InvalidInputException.class); + expectedException.expectMessage( + "Attribute \"readonly\" of element \"time-picker\" can only be one of the following " + + "values: [true, false]."); + context.parseMessageML(input, null, MessageML.MESSAGEML_VERSION); + } + + @Test + public void testTimePickerWithInvalidDisabledAttribute() throws Exception { + String input = + "
"; + expectedException.expect(InvalidInputException.class); + expectedException.expectMessage( + "Attribute \"disabled\" of element \"time-picker\" can only be one of the following " + + "values: " + + "[true, false]."); + context.parseMessageML(input, null, MessageML.MESSAGEML_VERSION); + } + + + }