Search in sources :

Example 41 with WContainer

use of com.github.bordertech.wcomponents.WContainer in project wcomponents by BorderTech.

the class WSubordinateControlRenderer_Test method testMandatoryOptionalActions.

@Test
public void testMandatoryOptionalActions() throws IOException, SAXException, XpathException {
    WCheckBox condTrigger = new WCheckBox();
    // Setup Group
    SubordinateTarget actionTarget = new WTextField();
    SubordinateTarget actionTarget1 = new WTextField();
    SubordinateTarget actionTarget2 = new WTextField();
    SubordinateTarget actionTarget3 = new WTextField();
    WComponentGroup<SubordinateTarget> group1 = new WComponentGroup<>();
    group1.addToGroup(actionTarget1);
    group1.addToGroup(actionTarget2);
    group1.addToGroup(actionTarget3);
    // Setup Rule with Mandatory/Optional actions
    Rule rule = new Rule();
    rule.setCondition(new Equal(condTrigger, Boolean.TRUE));
    // Single Component Target
    rule.addActionOnTrue(new Mandatory(actionTarget));
    rule.addActionOnFalse(new Optional(actionTarget));
    // Group Target
    rule.addActionOnTrue(new Mandatory(group1));
    rule.addActionOnFalse(new Optional(group1));
    // Setup Subordinate
    WSubordinateControl control = new WSubordinateControl();
    control.addRule(rule);
    WContainer root = new WContainer();
    root.add(condTrigger);
    root.add(actionTarget);
    root.add(actionTarget1);
    root.add(actionTarget2);
    root.add(actionTarget3);
    root.add(control);
    root.add(group1);
    setActiveContext(createUIContext());
    condTrigger.setSelected(true);
    // Apply the controls
    control.applyTheControls();
    // Validate Schema
    assertSchemaMatch(root);
    // Check onTrue
    assertXpathEvaluatesTo("2", "count(//ui:subordinate/ui:onTrue)", root);
    // Check onTrue - Component
    assertXpathEvaluatesTo("mandatory", "//ui:subordinate/ui:onTrue[position()=1]/@action", root);
    assertXpathEvaluatesTo(actionTarget.getId(), "//ui:subordinate/ui:onTrue[position()=1]/ui:target/@id", root);
    assertXpathEvaluatesTo("", "//ui:subordinate/ui:onTrue[position()=1]/ui:target/@groupId", root);
    // Check onTrue - Group
    assertXpathEvaluatesTo("mandatory", "//ui:subordinate/ui:onTrue[position()=2]/@action", root);
    assertXpathEvaluatesTo(group1.getId(), "//ui:subordinate/ui:onTrue[position()=2]/ui:target/@groupId", root);
    assertXpathEvaluatesTo("", "//ui:subordinate/ui:onTrue[position()=2]/ui:target/@id", root);
    // Check onFalse
    assertXpathEvaluatesTo("2", "count(//ui:subordinate/ui:onFalse)", root);
    // Check onFalse - Component
    assertXpathEvaluatesTo("optional", "//ui:subordinate/ui:onFalse[position()=1]/@action", root);
    assertXpathEvaluatesTo(actionTarget.getId(), "//ui:subordinate/ui:onFalse[position()=1]/ui:target/@id", root);
    assertXpathEvaluatesTo("", "//ui:subordinate/ui:onFalse[position()=1]/ui:target/@groupId", root);
    // Check onFalse - Group
    assertXpathEvaluatesTo("optional", "//ui:subordinate/ui:onFalse[position()=2]/@action", root);
    assertXpathEvaluatesTo(group1.getId(), "//ui:subordinate/ui:onFalse[position()=2]/ui:target/@groupId", root);
    assertXpathEvaluatesTo("", "//ui:subordinate/ui:onFalse[position()=2]/ui:target/@id", root);
    // Check action target
    assertXpathEvaluatesTo("true", "//ui:textfield[@id='" + actionTarget.getId() + "']/@required", root);
    assertXpathEvaluatesTo("true", "//ui:textfield[@id='" + actionTarget1.getId() + "']/@required", root);
    assertXpathEvaluatesTo("true", "//ui:textfield[@id='" + actionTarget2.getId() + "']/@required", root);
    assertXpathEvaluatesTo("true", "//ui:textfield[@id='" + actionTarget3.getId() + "']/@required", root);
}
Also used : SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) WContainer(com.github.bordertech.wcomponents.WContainer) Optional(com.github.bordertech.wcomponents.subordinate.Optional) Equal(com.github.bordertech.wcomponents.subordinate.Equal) LessThanOrEqual(com.github.bordertech.wcomponents.subordinate.LessThanOrEqual) NotEqual(com.github.bordertech.wcomponents.subordinate.NotEqual) GreaterThanOrEqual(com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual) WSubordinateControl(com.github.bordertech.wcomponents.subordinate.WSubordinateControl) WComponentGroup(com.github.bordertech.wcomponents.WComponentGroup) Rule(com.github.bordertech.wcomponents.subordinate.Rule) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) WTextField(com.github.bordertech.wcomponents.WTextField) Mandatory(com.github.bordertech.wcomponents.subordinate.Mandatory) Test(org.junit.Test)

Example 42 with WContainer

use of com.github.bordertech.wcomponents.WContainer in project wcomponents by BorderTech.

the class WTextAreaRenderer_Test method testDoPaint.

@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
    WTextArea field = new WTextArea();
    WButton button = new WButton();
    WContainer root = new WContainer();
    root.add(field);
    root.add(button);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo(field.getId(), "//ui:textarea/@id", field);
    assertXpathNotExists("//ui:textarea/@disabled", field);
    assertXpathNotExists("//ui:textarea/@hidden", field);
    assertXpathNotExists("//ui:textarea/@required", field);
    assertXpathNotExists("//ui:textarea/@readOnly", field);
    assertXpathNotExists("//ui:textarea/@minLength", field);
    assertXpathNotExists("//ui:textarea/@maxLength", field);
    assertXpathNotExists("//ui:textarea/@toolTip", field);
    assertXpathNotExists("//ui:textarea/@accessibleText", field);
    assertXpathNotExists("//ui:textarea/@rows", field);
    assertXpathNotExists("//ui:textarea/@cols", field);
    assertXpathNotExists("//ui:textarea/ui:rtf", field);
    field.setDisabled(true);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo("true", "//ui:textarea/@disabled", field);
    setFlag(field, ComponentModel.HIDE_FLAG, true);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo("true", "//ui:textarea/@hidden", field);
    field.setMandatory(true);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo("true", "//ui:textarea/@required", field);
    field.setMinLength(45);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo("45", "//ui:textarea/@minLength", field);
    field.setMaxLength(50);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo("50", "//ui:textarea/@maxLength", field);
    field.setToolTip("tooltip");
    assertSchemaMatch(field);
    assertXpathEvaluatesTo(field.getToolTip(), "//ui:textarea/@toolTip", field);
    field.setAccessibleText("accessible");
    assertSchemaMatch(field);
    assertXpathEvaluatesTo(field.getAccessibleText(), "//ui:textarea/@accessibleText", field);
    field.setRows(20);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo("20", "//ui:textarea/@rows", field);
    field.setColumns(40);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo("40", "//ui:textarea/@cols", field);
    field.setRichTextArea(false);
    assertSchemaMatch(field);
    assertXpathNotExists("//ui:textarea/ui:rtf", field);
    field.setRichTextArea(true);
    assertSchemaMatch(field);
    assertXpathExists("//ui:textarea/ui:rtf", field);
    field.setDefaultSubmitButton(button);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo(button.getId(), "//ui:textarea/@buttonId", field);
    field.setPattern("");
    assertSchemaMatch(field);
    assertXpathNotExists("//ui:textarea/@pattern", field);
    // Pattern is not supported on the client for TextArea, and will not be rendered
    field.setPattern("test[123]");
    assertSchemaMatch(field);
    assertXpathNotExists("//ui:textarea/@pattern", field);
    field.setText("Hello");
    assertSchemaMatch(field);
    assertXpathEvaluatesTo(field.getText(), "normalize-space(//ui:textarea)", field);
    field.setPlaceholder("enter stuff here");
    assertSchemaMatch(field);
    assertXpathEvaluatesTo("enter stuff here", "//ui:textarea/@placeholder", field);
}
Also used : WTextArea(com.github.bordertech.wcomponents.WTextArea) WContainer(com.github.bordertech.wcomponents.WContainer) WButton(com.github.bordertech.wcomponents.WButton) Test(org.junit.Test)

Example 43 with WContainer

use of com.github.bordertech.wcomponents.WContainer in project wcomponents by BorderTech.

the class WToggleButtonRenderer_Test method testDoPaint.

@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
    WToggleButton toggle = new WToggleButton();
    WComponentGroup<WToggleButton> group = new WComponentGroup<>();
    WButton button = new WButton("test");
    WContainer root = new WContainer();
    root.add(toggle);
    root.add(group);
    root.add(button);
    setActiveContext(createUIContext());
    assertSchemaMatch(toggle);
    assertXpathExists("//ui:togglebutton", toggle);
    assertXpathEvaluatesTo(toggle.getId(), "//ui:togglebutton/@id", toggle);
    // Check disabled
    assertXpathNotExists("//ui:togglebutton/@disabled", toggle);
    toggle.setDisabled(true);
    assertSchemaMatch(toggle);
    assertXpathEvaluatesTo("true", "//ui:togglebutton/@disabled", toggle);
    // Check hidden
    assertXpathNotExists("//ui:togglebutton/@hidden", toggle);
    setFlag(toggle, ComponentModel.HIDE_FLAG, true);
    assertSchemaMatch(toggle);
    assertXpathEvaluatesTo("true", "//ui:togglebutton/@hidden", toggle);
    // Check selected
    assertXpathNotExists("//ui:togglebutton/@selected", toggle);
    toggle.setSelected(true);
    assertSchemaMatch(toggle);
    assertXpathEvaluatesTo("true", "//ui:togglebutton/@selected", toggle);
    // Check toolTip
    assertXpathNotExists("//ui:togglebutton/@toolTip", toggle);
    toggle.setToolTip("WCheckBox_Test.testRenderedFormat.title");
    assertSchemaMatch(toggle);
    assertXpathEvaluatesTo(toggle.getToolTip(), "//ui:togglebutton/@toolTip", toggle);
    // Check accessibleText
    assertXpathNotExists("//ui:togglebutton/@accessibleText", toggle);
    toggle.setAccessibleText("WCheckBox_Test.testRenderedFormat.accessibleText");
    assertSchemaMatch(toggle);
    assertXpathEvaluatesTo(toggle.getAccessibleText(), "//ui:togglebutton/@accessibleText", toggle);
}
Also used : WContainer(com.github.bordertech.wcomponents.WContainer) WToggleButton(com.github.bordertech.wcomponents.WToggleButton) WComponentGroup(com.github.bordertech.wcomponents.WComponentGroup) WButton(com.github.bordertech.wcomponents.WButton) Test(org.junit.Test)

Example 44 with WContainer

use of com.github.bordertech.wcomponents.WContainer in project wcomponents by BorderTech.

the class WValidationErrorsRenderer_Test method testDoPaintBasic.

@Test
public void testDoPaintBasic() throws IOException, SAXException, XpathException {
    WValidationErrors errors = new WValidationErrors();
    WTextArea text1 = new WTextArea();
    text1.setText("text1");
    WContainer root = new WContainer();
    root.add(errors);
    root.add(text1);
    root.setLocked(true);
    // Validate Schema with no errors
    assertSchemaMatch(root);
    // Simulate Error Message
    setActiveContext(createUIContext());
    List<Diagnostic> diags = new ArrayList<>();
    diags.add(new DiagnosticImpl(Diagnostic.ERROR, text1, "Test Error1"));
    root.showErrorIndicators(diags);
    errors.setErrors(diags);
    assertSchemaMatch(root);
    assertXpathEvaluatesTo(text1.getId(), "//ui:validationerrors/ui:error/@for", root);
    assertXpathEvaluatesTo("Test Error1", "//ui:validationerrors/ui:error", root);
    String title = "WValidationErrorsTitle";
    errors.setTitleText(title);
    assertSchemaMatch(root);
    assertXpathEvaluatesTo(title, "//ui:validationerrors/@title", root);
    // Check for error message with no associated component
    setActiveContext(createUIContext());
    diags.clear();
    diags.add(new DiagnosticImpl(Diagnostic.ERROR, null, "Test Error1"));
    errors.setErrors(diags);
    assertSchemaMatch(root);
    assertXpathNotExists("//ui:validationerrors/ui:error/@for", root);
    assertXpathEvaluatesTo("Test Error1", "//ui:validationerrors/ui:error", root);
}
Also used : WTextArea(com.github.bordertech.wcomponents.WTextArea) WContainer(com.github.bordertech.wcomponents.WContainer) DiagnosticImpl(com.github.bordertech.wcomponents.validation.DiagnosticImpl) WValidationErrors(com.github.bordertech.wcomponents.validation.WValidationErrors) ArrayList(java.util.ArrayList) Diagnostic(com.github.bordertech.wcomponents.validation.Diagnostic) Test(org.junit.Test)

Example 45 with WContainer

use of com.github.bordertech.wcomponents.WContainer in project wcomponents by BorderTech.

the class WCheckBoxRenderer_Test method testDoPaint.

@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
    WCheckBox wcbTest = new WCheckBox();
    WComponentGroup<WCheckBox> group = new WComponentGroup<>();
    WButton button = new WButton("test");
    WContainer root = new WContainer();
    root.add(wcbTest);
    root.add(group);
    root.add(button);
    setActiveContext(createUIContext());
    assertSchemaMatch(wcbTest);
    assertXpathExists("//ui:checkbox", wcbTest);
    assertXpathEvaluatesTo(wcbTest.getId(), "//ui:checkbox/@id", wcbTest);
    // Check groupName
    assertXpathNotExists("//ui:checkbox/@groupName", wcbTest);
    wcbTest.setGroup(group);
    assertSchemaMatch(wcbTest);
    assertXpathEvaluatesTo(group.getId(), "//ui:checkbox/@groupName", wcbTest);
    // Check disabled
    assertXpathNotExists("//ui:checkbox/@disabled", wcbTest);
    wcbTest.setDisabled(true);
    assertSchemaMatch(wcbTest);
    assertXpathEvaluatesTo("true", "//ui:checkbox/@disabled", wcbTest);
    // Check hidden
    assertXpathNotExists("//ui:checkbox/@hidden", wcbTest);
    setFlag(wcbTest, ComponentModel.HIDE_FLAG, true);
    assertSchemaMatch(wcbTest);
    assertXpathEvaluatesTo("true", "//ui:checkbox/@hidden", wcbTest);
    // Check required
    assertXpathNotExists("//ui:checkbox/@required", wcbTest);
    wcbTest.setMandatory(true);
    assertSchemaMatch(wcbTest);
    assertXpathEvaluatesTo("true", "//ui:checkbox/@required", wcbTest);
    // Check selected
    assertXpathNotExists("//ui:checkbox/@selected", wcbTest);
    wcbTest.setSelected(true);
    assertSchemaMatch(wcbTest);
    assertXpathEvaluatesTo("true", "//ui:checkbox/@selected", wcbTest);
    // Check submitOnChange
    assertXpathNotExists("//ui:checkbox/@submitOnChange", wcbTest);
    wcbTest.setSubmitOnChange(true);
    assertSchemaMatch(wcbTest);
    assertXpathEvaluatesTo("true", "//ui:checkbox/@submitOnChange", wcbTest);
    // Check toolTip
    assertXpathNotExists("//ui:checkbox/@toolTip", wcbTest);
    wcbTest.setToolTip("WCheckBox_Test.testRenderedFormat.title");
    assertSchemaMatch(wcbTest);
    assertXpathEvaluatesTo(wcbTest.getToolTip(), "//ui:checkbox/@toolTip", wcbTest);
    // Check accessibleText
    assertXpathNotExists("//ui:checkbox/@accessibleText", wcbTest);
    wcbTest.setAccessibleText("WCheckBox_Test.testRenderedFormat.accessibleText");
    assertSchemaMatch(wcbTest);
    assertXpathEvaluatesTo(wcbTest.getAccessibleText(), "//ui:checkbox/@accessibleText", wcbTest);
    // Check button id
    assertXpathNotExists("//ui:checkbox/@buttonId", wcbTest);
    wcbTest.setDefaultSubmitButton(button);
    assertSchemaMatch(wcbTest);
    assertXpathEvaluatesTo(button.getId(), "//ui:checkbox/@buttonId", wcbTest);
}
Also used : WContainer(com.github.bordertech.wcomponents.WContainer) WComponentGroup(com.github.bordertech.wcomponents.WComponentGroup) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) WButton(com.github.bordertech.wcomponents.WButton) Test(org.junit.Test)

Aggregations

WContainer (com.github.bordertech.wcomponents.WContainer)49 Test (org.junit.Test)41 WTextField (com.github.bordertech.wcomponents.WTextField)21 WCheckBox (com.github.bordertech.wcomponents.WCheckBox)17 Equal (com.github.bordertech.wcomponents.subordinate.Equal)16 Rule (com.github.bordertech.wcomponents.subordinate.Rule)16 WSubordinateControl (com.github.bordertech.wcomponents.subordinate.WSubordinateControl)16 SubordinateTarget (com.github.bordertech.wcomponents.SubordinateTarget)15 WButton (com.github.bordertech.wcomponents.WButton)14 GreaterThanOrEqual (com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual)14 LessThanOrEqual (com.github.bordertech.wcomponents.subordinate.LessThanOrEqual)14 NotEqual (com.github.bordertech.wcomponents.subordinate.NotEqual)14 SubordinateTrigger (com.github.bordertech.wcomponents.SubordinateTrigger)11 WComponentGroup (com.github.bordertech.wcomponents.WComponentGroup)10 Hide (com.github.bordertech.wcomponents.subordinate.Hide)10 Show (com.github.bordertech.wcomponents.subordinate.Show)10 WPanel (com.github.bordertech.wcomponents.WPanel)9 Diagnostic (com.github.bordertech.wcomponents.validation.Diagnostic)6 DiagnosticImpl (com.github.bordertech.wcomponents.validation.DiagnosticImpl)6 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)5