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"));
}
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");
}
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);
}
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);
}
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);
}
Aggregations