Search in sources :

Example 16 with WContainer

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

the class WSubordinateControlRenderer_Test method testBasicConditionWithGroup.

@Test
public void testBasicConditionWithGroup() throws IOException, SAXException, XpathException {
    SubordinateTrigger condTrigger = new WCheckBox();
    // Setup Group
    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);
    // Basic Condition
    Rule rule = new Rule();
    rule.setCondition(new Equal(condTrigger, Boolean.TRUE));
    rule.addActionOnTrue(new Show(group1));
    rule.addActionOnFalse(new Hide(group1));
    // Setup Subordinate
    WSubordinateControl control = new WSubordinateControl();
    control.addRule(rule);
    WContainer root = new WContainer();
    root.add(condTrigger);
    root.add(actionTarget1);
    root.add(actionTarget2);
    root.add(actionTarget3);
    root.add(control);
    root.add(group1);
    setActiveContext(createUIContext());
    // Apply the controls
    control.applyTheControls();
    // Validate Schema
    assertSchemaMatch(root);
    // Check for basic elements
    assertXpathEvaluatesTo("1", "count(//ui:subordinate)", root);
    assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:condition)", root);
    assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:onTrue)", root);
    assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:onFalse)", root);
    assertXpathEvaluatesTo("1", "count(//ui:componentGroup)", root);
    assertXpathEvaluatesTo("3", "count(//ui:componentGroup/ui:component)", root);
    // Check id
    assertXpathEvaluatesTo(control.getId() + "-c0", "//ui:subordinate/@id", root);
    // Check condition
    assertXpathEvaluatesTo(condTrigger.getId(), "//ui:subordinate/ui:condition/@controller", root);
    assertXpathEvaluatesTo("true", "//ui:subordinate/ui:condition/@value", root);
    // Check onTrue
    assertXpathEvaluatesTo("show", "//ui:subordinate/ui:onTrue/@action", root);
    assertXpathEvaluatesTo(group1.getId(), "//ui:subordinate/ui:onTrue/ui:target/@groupId", root);
    assertXpathEvaluatesTo("", "//ui:subordinate/ui:onTrue/ui:target/@id", root);
    // Check onFalse
    assertXpathEvaluatesTo("hide", "//ui:subordinate/ui:onFalse/@action", root);
    assertXpathEvaluatesTo(group1.getId(), "//ui:subordinate/ui:onFalse/ui:target/@groupId", root);
    assertXpathEvaluatesTo("", "//ui:subordinate/ui:onFalse/ui:target/@id", root);
    // Check group
    assertXpathEvaluatesTo(group1.getId(), "//ui:componentGroup/@id", root);
    assertXpathEvaluatesTo(actionTarget1.getId(), "//ui:componentGroup/ui:component[position()=1]/@id", root);
    assertXpathEvaluatesTo(actionTarget2.getId(), "//ui:componentGroup/ui:component[position()=2]/@id", root);
    assertXpathEvaluatesTo(actionTarget3.getId(), "//ui:componentGroup/ui:component[position()=3]/@id", root);
    // Check action target
    assertXpathEvaluatesTo("true", "//ui:textfield[@id='" + actionTarget1.getId() + "']/@hidden", root);
    assertXpathEvaluatesTo("true", "//ui:textfield[@id='" + actionTarget2.getId() + "']/@hidden", root);
    assertXpathEvaluatesTo("true", "//ui:textfield[@id='" + actionTarget3.getId() + "']/@hidden", root);
}
Also used : Hide(com.github.bordertech.wcomponents.subordinate.Hide) SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) WContainer(com.github.bordertech.wcomponents.WContainer) 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) SubordinateTrigger(com.github.bordertech.wcomponents.SubordinateTrigger) Show(com.github.bordertech.wcomponents.subordinate.Show) 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) Test(org.junit.Test)

Example 17 with WContainer

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

the class WTextFieldRenderer_Test method testDoPaint.

@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
    WTextField textField = new WTextField();
    WButton button = new WButton();
    WSuggestions suggestions = new WSuggestions();
    WContainer root = new WContainer();
    root.add(textField);
    root.add(button);
    root.add(suggestions);
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo(textField.getId(), "//ui:textfield/@id", textField);
    assertXpathNotExists("//ui:textfield/@disabled", textField);
    assertXpathNotExists("//ui:textfield/@hidden", textField);
    assertXpathNotExists("//ui:textfield/@required", textField);
    assertXpathNotExists("//ui:textfield/@readOnly", textField);
    assertXpathNotExists("//ui:textfield/@minLength", textField);
    assertXpathNotExists("//ui:textfield/@maxLength", textField);
    assertXpathNotExists("//ui:textfield/@toolTip", textField);
    assertXpathNotExists("//ui:textfield/@accessibleText", textField);
    assertXpathNotExists("//ui:textfield/@size", textField);
    assertXpathNotExists("//ui:textfield/@buttonId", textField);
    assertXpathNotExists("//ui:textfield/@pattern", textField);
    assertXpathNotExists("//ui:textfield/@list", textField);
    textField.setDisabled(true);
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo("true", "//ui:textfield/@disabled", textField);
    setFlag(textField, ComponentModel.HIDE_FLAG, true);
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo("true", "//ui:textfield/@hidden", textField);
    textField.setMandatory(true);
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo("true", "//ui:textfield/@required", textField);
    textField.setMinLength(45);
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo("45", "//ui:textfield/@minLength", textField);
    textField.setMaxLength(50);
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo("50", "//ui:textfield/@maxLength", textField);
    textField.setToolTip("tooltip");
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo(textField.getToolTip(), "//ui:textfield/@toolTip", textField);
    textField.setAccessibleText("accessible");
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo(textField.getAccessibleText(), "//ui:textfield/@accessibleText", textField);
    textField.setColumns(40);
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo("40", "//ui:textfield/@size", textField);
    textField.setDefaultSubmitButton(button);
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo(button.getId(), "//ui:textfield/@buttonId", textField);
    textField.setPattern("");
    assertSchemaMatch(textField);
    assertXpathNotExists("//ui:textfield/@pattern", textField);
    textField.setPattern("test[123]");
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo(textField.getPattern(), "//ui:textfield/@pattern", textField);
    textField.setText("Hello");
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo(textField.getText(), "normalize-space(//ui:textfield)", textField);
    textField.setSuggestions(suggestions);
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo(suggestions.getId(), "//ui:textfield/@list", textField);
    textField.setPlaceholder("enter stuff here");
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo("enter stuff here", "//ui:textfield/@placeholder", textField);
}
Also used : WContainer(com.github.bordertech.wcomponents.WContainer) WSuggestions(com.github.bordertech.wcomponents.WSuggestions) WTextField(com.github.bordertech.wcomponents.WTextField) WButton(com.github.bordertech.wcomponents.WButton) Test(org.junit.Test)

Example 18 with WContainer

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

the class WButtonRenderer_Test method testAllOptions.

@Test
public void testAllOptions() throws IOException, SAXException, XpathException {
    WButton button = new WButton("All");
    button.setDisabled(true);
    setFlag(button, ComponentModel.HIDE_FLAG, true);
    button.setToolTip("Title");
    button.setAccessKey('T');
    button.setImageUrl("http://localhost/image.png");
    button.setImagePosition(ImagePosition.EAST);
    button.setRenderAsLink(true);
    button.setAjaxTarget(new WTextField());
    button.setPopupTrigger(true);
    setActiveContext(createUIContext());
    WPanel validationComponent = new WPanel();
    button.setAction(new ValidatingAction(new WValidationErrors(), validationComponent) {

        @Override
        public void executeOnValid(final ActionEvent event) {
        // Do nothing
        }
    });
    WContainer root = new WContainer();
    root.add(button);
    root.add(validationComponent);
    assertXpathExists("//html:button[@id]", button);
    assertXpathExists("//html:button[contains(@class, 'wc-linkbutton')]", button);
    assertXpathEvaluatesTo(button.getText(), "//html:button", button);
    assertXpathEvaluatesTo("disabled", "//html:button/@disabled", button);
    assertXpathEvaluatesTo("hidden", "//html:button/@hidden", button);
    assertXpathEvaluatesTo(button.getToolTip(), "//html:button/@title", button);
    assertXpathUrlEvaluatesTo(button.getImageUrl(), "//html:button//html:img/@src", button);
    assertXpathExists("//html:button/html:span[contains(@class, 'wc_btn_imge')]", button);
    assertXpathEvaluatesTo(button.getAccessKeyAsString(), "//html:button/@accesskey", button);
    assertXpathEvaluatesTo("true", "//html:button/@aria-haspopup", button);
    assertXpathEvaluatesTo(validationComponent.getId(), "//html:button/@data-wc-validate", button);
    assertXpathEvaluatesTo(button.getId(), "//ui:ajaxtrigger/@triggerId", button);
    button.setImagePosition(ImagePosition.NORTH);
    assertXpathExists("//html:button/html:span[contains(@class, 'wc_btn_imgn')]", button);
    button.setImagePosition(ImagePosition.SOUTH);
    assertXpathExists("//html:button/html:span[contains(@class, 'wc_btn_imgs')]", button);
    button.setImagePosition(ImagePosition.WEST);
    assertXpathExists("//html:button/html:span[contains(@class, 'wc_btn_imgw')]", button);
    button.setClientCommandOnly(true);
    assertXpathEvaluatesTo("button", "//html:button/@type", button);
}
Also used : WContainer(com.github.bordertech.wcomponents.WContainer) ValidatingAction(com.github.bordertech.wcomponents.validation.ValidatingAction) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WPanel(com.github.bordertech.wcomponents.WPanel) WValidationErrors(com.github.bordertech.wcomponents.validation.WValidationErrors) WButton(com.github.bordertech.wcomponents.WButton) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 19 with WContainer

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

the class WComponentGroupRenderer_Test method testDoPaint.

@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
    // Setup Group
    WComponent actionTarget1 = new WTextField();
    WComponent actionTarget2 = new WTextField();
    WComponent actionTarget3 = new WTextField();
    WComponentGroup<WComponent> group = new WComponentGroup<>();
    group.addToGroup(actionTarget1);
    group.addToGroup(actionTarget2);
    group.addToGroup(actionTarget3);
    WContainer root = new WContainer();
    root.add(actionTarget1);
    root.add(actionTarget2);
    root.add(actionTarget3);
    root.add(group);
    setActiveContext(createUIContext());
    // Validate Schema
    assertSchemaMatch(root);
    // Check group
    assertXpathEvaluatesTo("1", "count(//ui:componentGroup)", root);
    assertXpathEvaluatesTo("3", "count(//ui:componentGroup/ui:component)", root);
    assertXpathEvaluatesTo(group.getId(), "//ui:componentGroup/@id", root);
    assertXpathEvaluatesTo(actionTarget1.getId(), "//ui:componentGroup/ui:component[position()=1]/@id", root);
    assertXpathEvaluatesTo(actionTarget2.getId(), "//ui:componentGroup/ui:component[position()=2]/@id", root);
    assertXpathEvaluatesTo(actionTarget3.getId(), "//ui:componentGroup/ui:component[position()=3]/@id", root);
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WContainer(com.github.bordertech.wcomponents.WContainer) WComponentGroup(com.github.bordertech.wcomponents.WComponentGroup) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 20 with WContainer

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

the class WFieldErrorIndicatorRenderer_Test method testXssEscaping.

@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
    WContainer root = new WContainer();
    WPanel target = new WPanel();
    WFieldErrorIndicator indicator = new WFieldErrorIndicator(target);
    root.add(indicator);
    root.add(target);
    List<Diagnostic> diags = new ArrayList<>();
    diags.add(new DiagnosticImpl(Diagnostic.ERROR, target, getMaliciousContent()));
    root.showErrorIndicators(diags);
    assertSafeContent(root);
}
Also used : WFieldErrorIndicator(com.github.bordertech.wcomponents.validation.WFieldErrorIndicator) WContainer(com.github.bordertech.wcomponents.WContainer) DiagnosticImpl(com.github.bordertech.wcomponents.validation.DiagnosticImpl) WPanel(com.github.bordertech.wcomponents.WPanel) ArrayList(java.util.ArrayList) Diagnostic(com.github.bordertech.wcomponents.validation.Diagnostic) 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