use of com.github.bordertech.wcomponents.WTextField in project wcomponents by BorderTech.
the class WSubordinateControlRenderer_Test method testNestedConditions.
@Test
public void testNestedConditions() throws IOException, SAXException, XpathException {
SubordinateTrigger condTrigger = new WCheckBox();
// Create Nested Condition
Condition cond1 = new Equal(condTrigger, Boolean.TRUE);
Condition cond2 = new Equal(condTrigger, Boolean.TRUE);
Condition cond3 = new Equal(condTrigger, Boolean.TRUE);
Condition cond4 = new Equal(condTrigger, Boolean.TRUE);
Condition orTest = new Or(cond1, cond2);
Condition and1 = new And(cond3, orTest);
Condition and2 = new And(cond4, and1);
SubordinateTarget actionTarget = new WTextField();
// Setup rule with Nested Condition
Rule rule = new Rule();
rule.setCondition(and2);
rule.addActionOnTrue(new Show(actionTarget));
rule.addActionOnFalse(new Hide(actionTarget));
// Setup Subordinate
WSubordinateControl control = new WSubordinateControl();
control.addRule(rule);
WContainer root = new WContainer();
root.add(condTrigger);
root.add(actionTarget);
root.add(control);
// Apply the controls
control.applyTheControls();
// Validate Schema
assertSchemaMatch(root);
// Check Nested
assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:and)", root);
assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:and/ui:condition)", root);
assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:and/ui:and)", root);
assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:and/ui:and/ui:condition)", root);
assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:and/ui:and/ui:or)", root);
assertXpathEvaluatesTo("2", "count(//ui:subordinate/ui:and/ui:and/ui:or/ui:condition)", root);
// Check action target
assertXpathEvaluatesTo("true", "//ui:textfield/@hidden", root);
}
use of com.github.bordertech.wcomponents.WTextField in project wcomponents by BorderTech.
the class WSubordinateControlRenderer_Test method testShowHideActions.
@Test
public void testShowHideActions() throws IOException, SAXException, XpathException {
SubordinateTrigger 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 Show/Hide actions
Rule rule = new Rule();
rule.setCondition(new Equal(condTrigger, Boolean.TRUE));
// Single Component Target
rule.addActionOnTrue(new Show(actionTarget));
rule.addActionOnFalse(new Hide(actionTarget));
// Group Target
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(actionTarget);
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 onTrue
assertXpathEvaluatesTo("2", "count(//ui:subordinate/ui:onTrue)", root);
// Check onTrue - Component
assertXpathEvaluatesTo("show", "//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("show", "//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("hide", "//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("hide", "//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() + "']/@hidden", root);
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);
}
use of com.github.bordertech.wcomponents.WTextField 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);
}
use of com.github.bordertech.wcomponents.WTextField in project wcomponents by BorderTech.
the class WTextFieldRenderer_Test method testReadOnly.
@Test
public void testReadOnly() throws IOException, SAXException, XpathException {
WTextField field = new WTextField();
field.setReadOnly(true);
assertSchemaMatch(field);
assertXpathEvaluatesTo("true", "//ui:textfield/@readOnly", field);
}
use of com.github.bordertech.wcomponents.WTextField 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);
}
Aggregations