Search in sources :

Example 46 with WContainer

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

the class WDecoratedLabelRenderer_Test method testDoPaint.

@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
    final String bodyText = "WDecoratedLabelRenderer_Test.testDoPaint.bodyText";
    final String headText = "WDecoratedLabelRenderer_Test.testDoPaint.headText";
    final String tailText = "WDecoratedLabelRenderer_Test.testDoPaint.tailText";
    // Test minimal text content
    WDecoratedLabel decoratedLabel = new WDecoratedLabel(bodyText);
    assertSchemaMatch(decoratedLabel);
    assertXpathEvaluatesTo(bodyText, "normalize-space(//ui:decoratedlabel/ui:labelbody)", decoratedLabel);
    assertXpathNotExists("//ui:decoratedlabel/@labelFocus", decoratedLabel);
    decoratedLabel.setHead(new WText(headText));
    decoratedLabel.setTail(new WText(tailText));
    // Test all text content
    assertSchemaMatch(decoratedLabel);
    assertXpathEvaluatesTo(headText, "normalize-space(//ui:decoratedlabel/ui:labelhead)", decoratedLabel);
    assertXpathEvaluatesTo(bodyText, "normalize-space(//ui:decoratedlabel/ui:labelbody)", decoratedLabel);
    assertXpathEvaluatesTo(tailText, "normalize-space(//ui:decoratedlabel/ui:labeltail)", decoratedLabel);
    assertXpathNotExists("//ui:decoratedlabel/@labelFocus", decoratedLabel);
    // Test complex content
    WContainer complexContent = new WContainer();
    complexContent.add(new WLabel("Select"));
    complexContent.add(new WCheckBox());
    decoratedLabel.setBody(complexContent);
    assertXpathExists("//ui:decoratedlabel/ui:labelbody/ui:label/following-sibling::ui:checkbox", decoratedLabel);
}
Also used : WContainer(com.github.bordertech.wcomponents.WContainer) WText(com.github.bordertech.wcomponents.WText) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) WDecoratedLabel(com.github.bordertech.wcomponents.WDecoratedLabel) WLabel(com.github.bordertech.wcomponents.WLabel) Test(org.junit.Test)

Example 47 with WContainer

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

the class WEmailFieldRenderer_Test method testDoPaint.

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

Example 48 with WContainer

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

the class WFieldErrorIndicatorRenderer_Test method testDoPaint.

@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
    WContainer root = new WContainer();
    WPanel target = new WPanel();
    WFieldErrorIndicator indicator = new WFieldErrorIndicator(target);
    root.add(target);
    root.add(indicator);
    // Simulate Error Message
    setActiveContext(createUIContext());
    List<Diagnostic> diags = new ArrayList<>();
    diags.add(new DiagnosticImpl(Diagnostic.ERROR, target, "Test Error"));
    root.showErrorIndicators(diags);
    // Validate Schema
    assertSchemaMatch(root);
    // Check Attributes
    assertXpathEvaluatesTo(indicator.getId(), "//ui:fieldindicator/@id", root);
    assertXpathEvaluatesTo("error", "//ui:fieldindicator/@type", root);
    assertXpathEvaluatesTo(target.getId(), "//ui:fieldindicator/@for", root);
    // Check Message
    assertXpathEvaluatesTo("Test Error", "//ui:fieldindicator/ui:message", 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)

Example 49 with WContainer

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

the class WFieldWarningIndicatorRenderer_Test method testXssEscaping.

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