Search in sources :

Example 6 with WField

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

the class WCheckBoxExample_Test method testFindByLabelTextExact.

/**
 * Test that ByLabel works for CheckBoxes by label text exact match.
 */
@Test
public void testFindByLabelTextExact() {
    // Launch the web browser to the LDE
    WebDriver driver = getDriver();
    WContainer container = (WContainer) getUi();
    WFieldLayout layout = (WFieldLayout) container.getChildAt(0);
    WField field = (WField) layout.getChildAt(0);
    String labelText = field.getLabel().getText();
    String componentId = field.getField().getId();
    WebElement checkBox = driver.findElement(new ByLabel(labelText, false));
    Assert.assertNotNull("Unable to find checkbox by label text", checkBox);
    Assert.assertEquals("Checkbox element ID does not match expected", componentId, checkBox.getAttribute("id"));
}
Also used : WebDriver(org.openqa.selenium.WebDriver) WContainer(com.github.bordertech.wcomponents.WContainer) WField(com.github.bordertech.wcomponents.WField) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) WebElement(org.openqa.selenium.WebElement) ByLabel(com.github.bordertech.wcomponents.test.selenium.ByLabel) Test(org.junit.Test)

Example 7 with WField

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

the class WFieldRenderer method doRender.

/**
 * Paints the given WField.
 *
 * @param component the WField to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WField field = (WField) component;
    XmlStringBuilder xml = renderContext.getWriter();
    int inputWidth = field.getInputWidth();
    xml.appendTagOpen("ui:field");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("hidden", field.isHidden(), "true");
    xml.appendOptionalAttribute("inputWidth", inputWidth > 0, inputWidth);
    xml.appendClose();
    // Label
    WLabel label = field.getLabel();
    if (label != null) {
        label.paint(renderContext);
    }
    // Field
    if (field.getField() != null) {
        xml.appendTag("ui:input");
        field.getField().paint(renderContext);
        if (field.getErrorIndicator() != null) {
            field.getErrorIndicator().paint(renderContext);
        }
        if (field.getWarningIndicator() != null) {
            field.getWarningIndicator().paint(renderContext);
        }
        xml.appendEndTag("ui:input");
    }
    xml.appendEndTag("ui:field");
}
Also used : WField(com.github.bordertech.wcomponents.WField) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) WLabel(com.github.bordertech.wcomponents.WLabel)

Example 8 with WField

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

the class WFieldRenderer_Test method testWithValidationMessages.

@Test
public void testWithValidationMessages() throws IOException, SAXException, XpathException {
    WTextField text = new WTextField();
    text.setText("text1");
    WFieldLayout test = new WFieldLayout();
    WField field = test.addField("label1", text);
    setActiveContext(createUIContext());
    assertXpathEvaluatesTo("text1", "//ui:field/ui:input/ui:textfield/text()", field);
    // Simulate Error Message
    List<Diagnostic> diags = new ArrayList<>();
    diags.add(new DiagnosticImpl(Diagnostic.ERROR, text, "Test Error"));
    diags.add(new DiagnosticImpl(Diagnostic.WARNING, text, "Test Warning"));
    field.showErrorIndicators(diags);
    field.showWarningIndicators(diags);
    // Validate Schema
    assertSchemaMatch(test);
    // Check Attributes
    assertXpathEvaluatesTo(field.getId(), "//ui:field/@id", field);
    // Check Label
    assertXpathEvaluatesTo("label1", "//ui:field/ui:label", field);
    // Check Input
    assertXpathEvaluatesTo("text1", "//ui:field/ui:input/ui:textfield/text()", field);
    assertXpathExists("//ui:field/ui:input/ui:textfield/ui:fieldindicator", field);
    assertXpathExists("//ui:field/ui:input/ui:textfield/ui:fieldindicator[@type='error']", field);
    assertXpathExists("//ui:field/ui:input/ui:textfield/ui:fieldindicator[@type='warn']", field);
    assertXpathEvaluatesTo("Test Error", "//ui:field/ui:input/ui:textfield/ui:fieldindicator[@type='error']/ui:message", field);
    assertXpathEvaluatesTo("Test Warning", "//ui:field/ui:input/ui:textfield/ui:fieldindicator[@type='warn']/ui:message", field);
}
Also used : WField(com.github.bordertech.wcomponents.WField) DiagnosticImpl(com.github.bordertech.wcomponents.validation.DiagnosticImpl) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) ArrayList(java.util.ArrayList) Diagnostic(com.github.bordertech.wcomponents.validation.Diagnostic) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 9 with WField

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

the class WFieldRenderer_Test method testDoPaintBasic.

@Test
public void testDoPaintBasic() throws IOException, SAXException, XpathException {
    WTextField text = new WTextField();
    WFieldLayout test = new WFieldLayout();
    WField field = test.addField("label1", text);
    text.setText("text1");
    // Validate Schema
    assertSchemaMatch(test);
    // Check Attributes
    assertXpathEvaluatesTo(field.getId(), "//ui:field/@id", field);
    assertXpathEvaluatesTo("", "//ui:field/@hidden", field);
    assertXpathEvaluatesTo("", "//ui:field/@inputWidth", field);
    // Check Label
    assertXpathEvaluatesTo("label1", "//ui:field/ui:label", field);
    // Check Input
    assertXpathEvaluatesTo("text1", "//ui:field/ui:input/ui:textfield", field);
    // Test Hidden
    setFlag(field, ComponentModel.HIDE_FLAG, true);
    assertSchemaMatch(test);
    assertXpathEvaluatesTo("true", "//ui:field/@hidden", field);
    // Test Width - 1
    field.setInputWidth(1);
    assertSchemaMatch(test);
    assertXpathEvaluatesTo("1", "//ui:field/@inputWidth", field);
    // Test Width - 100
    field.setInputWidth(100);
    assertSchemaMatch(test);
    assertXpathEvaluatesTo("100", "//ui:field/@inputWidth", field);
}
Also used : WField(com.github.bordertech.wcomponents.WField) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 10 with WField

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

the class WFieldRenderer_Test method testNoInputField.

@Test
public void testNoInputField() throws IOException, SAXException, XpathException {
    // No Input field, so label created by WTextWithColon.
    WText text = new WText("text1");
    WFieldLayout test = new WFieldLayout();
    WField field = test.addField("label1", text);
    // Validate Schema
    assertSchemaMatch(test);
    // Check Attributes
    assertXpathEvaluatesTo(field.getId(), "//ui:field/@id", field);
    // Check Label
    assertXpathEvaluatesTo("label1", "//ui:field/ui:label", field);
    // Check Input
    assertXpathEvaluatesTo("text1", "//ui:field/ui:input", field);
}
Also used : WField(com.github.bordertech.wcomponents.WField) WText(com.github.bordertech.wcomponents.WText) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) Test(org.junit.Test)

Aggregations

WField (com.github.bordertech.wcomponents.WField)11 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)10 Test (org.junit.Test)7 WTextField (com.github.bordertech.wcomponents.WTextField)4 WFieldSet (com.github.bordertech.wcomponents.WFieldSet)3 Action (com.github.bordertech.wcomponents.Action)2 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)2 WContainer (com.github.bordertech.wcomponents.WContainer)2 WTextArea (com.github.bordertech.wcomponents.WTextArea)2 ByLabel (com.github.bordertech.wcomponents.test.selenium.ByLabel)2 WebDriver (org.openqa.selenium.WebDriver)2 WebElement (org.openqa.selenium.WebElement)2 Input (com.github.bordertech.wcomponents.Input)1 SubordinateTarget (com.github.bordertech.wcomponents.SubordinateTarget)1 WButton (com.github.bordertech.wcomponents.WButton)1 WDropdown (com.github.bordertech.wcomponents.WDropdown)1 WHeading (com.github.bordertech.wcomponents.WHeading)1 WHorizontalRule (com.github.bordertech.wcomponents.WHorizontalRule)1 WLabel (com.github.bordertech.wcomponents.WLabel)1 WMessageBox (com.github.bordertech.wcomponents.WMessageBox)1