use of com.github.bordertech.wcomponents.WComponentGroup in project wcomponents by BorderTech.
the class WSubordinateControlRenderer_Test method testGroupEnableInDisableInAction.
@Test
public void testGroupEnableInDisableInAction() 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);
// Setup Rule with ShowInGroup/HideInGroup actions
Rule rule = new Rule();
rule.setCondition(new Equal(condTrigger, Boolean.TRUE));
// OnTrue - EnableInGroup
rule.addActionOnTrue(new EnableInGroup(actionTarget1, group1));
// OnFalse - DisableInGroup
rule.addActionOnFalse(new DisableInGroup(actionTarget1, 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 (False conditions)
control.applyTheControls();
// Validate Schema
assertSchemaMatch(root);
// Check onTrue
assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:onTrue)", root);
assertXpathEvaluatesTo("enableIn", "//ui:subordinate/ui:onTrue/@action", root);
assertXpathEvaluatesTo(group1.getId(), "//ui:subordinate/ui:onTrue/ui:target/@groupId", root);
assertXpathEvaluatesTo(actionTarget1.getId(), "//ui:subordinate/ui:onTrue/ui:target/@id", root);
// Check onFalse
assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:onFalse)", root);
assertXpathEvaluatesTo("disableIn", "//ui:subordinate/ui:onFalse/@action", root);
assertXpathEvaluatesTo(group1.getId(), "//ui:subordinate/ui:onFalse/ui:target/@groupId", root);
assertXpathEvaluatesTo(actionTarget1.getId(), "//ui:subordinate/ui:onFalse/ui:target/@id", root);
// Check action target (Target 1 should be disabled)
assertXpathEvaluatesTo("true", "//ui:textfield[@id='" + actionTarget1.getId() + "']/@disabled", root);
assertXpathEvaluatesTo("", "//ui:textfield[@id='" + actionTarget2.getId() + "']/@disabled", root);
assertXpathEvaluatesTo("", "//ui:textfield[@id='" + actionTarget3.getId() + "']/@disabled", root);
}
use of com.github.bordertech.wcomponents.WComponentGroup in project wcomponents by BorderTech.
the class WSubordinateControlRenderer_Test method testMandatoryOptionalActions.
@Test
public void testMandatoryOptionalActions() throws IOException, SAXException, XpathException {
WCheckBox 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 Mandatory/Optional actions
Rule rule = new Rule();
rule.setCondition(new Equal(condTrigger, Boolean.TRUE));
// Single Component Target
rule.addActionOnTrue(new Mandatory(actionTarget));
rule.addActionOnFalse(new Optional(actionTarget));
// Group Target
rule.addActionOnTrue(new Mandatory(group1));
rule.addActionOnFalse(new Optional(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());
condTrigger.setSelected(true);
// Apply the controls
control.applyTheControls();
// Validate Schema
assertSchemaMatch(root);
// Check onTrue
assertXpathEvaluatesTo("2", "count(//ui:subordinate/ui:onTrue)", root);
// Check onTrue - Component
assertXpathEvaluatesTo("mandatory", "//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("mandatory", "//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("optional", "//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("optional", "//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() + "']/@required", root);
assertXpathEvaluatesTo("true", "//ui:textfield[@id='" + actionTarget1.getId() + "']/@required", root);
assertXpathEvaluatesTo("true", "//ui:textfield[@id='" + actionTarget2.getId() + "']/@required", root);
assertXpathEvaluatesTo("true", "//ui:textfield[@id='" + actionTarget3.getId() + "']/@required", root);
}
use of com.github.bordertech.wcomponents.WComponentGroup in project wcomponents by BorderTech.
the class WToggleButtonRenderer_Test method testDoPaint.
@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
WToggleButton toggle = new WToggleButton();
WComponentGroup<WToggleButton> group = new WComponentGroup<>();
WButton button = new WButton("test");
WContainer root = new WContainer();
root.add(toggle);
root.add(group);
root.add(button);
setActiveContext(createUIContext());
assertSchemaMatch(toggle);
assertXpathExists("//ui:togglebutton", toggle);
assertXpathEvaluatesTo(toggle.getId(), "//ui:togglebutton/@id", toggle);
// Check disabled
assertXpathNotExists("//ui:togglebutton/@disabled", toggle);
toggle.setDisabled(true);
assertSchemaMatch(toggle);
assertXpathEvaluatesTo("true", "//ui:togglebutton/@disabled", toggle);
// Check hidden
assertXpathNotExists("//ui:togglebutton/@hidden", toggle);
setFlag(toggle, ComponentModel.HIDE_FLAG, true);
assertSchemaMatch(toggle);
assertXpathEvaluatesTo("true", "//ui:togglebutton/@hidden", toggle);
// Check selected
assertXpathNotExists("//ui:togglebutton/@selected", toggle);
toggle.setSelected(true);
assertSchemaMatch(toggle);
assertXpathEvaluatesTo("true", "//ui:togglebutton/@selected", toggle);
// Check toolTip
assertXpathNotExists("//ui:togglebutton/@toolTip", toggle);
toggle.setToolTip("WCheckBox_Test.testRenderedFormat.title");
assertSchemaMatch(toggle);
assertXpathEvaluatesTo(toggle.getToolTip(), "//ui:togglebutton/@toolTip", toggle);
// Check accessibleText
assertXpathNotExists("//ui:togglebutton/@accessibleText", toggle);
toggle.setAccessibleText("WCheckBox_Test.testRenderedFormat.accessibleText");
assertSchemaMatch(toggle);
assertXpathEvaluatesTo(toggle.getAccessibleText(), "//ui:togglebutton/@accessibleText", toggle);
}
use of com.github.bordertech.wcomponents.WComponentGroup in project wcomponents by BorderTech.
the class WCheckBoxRenderer_Test method testDoPaint.
@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
WCheckBox wcbTest = new WCheckBox();
WComponentGroup<WCheckBox> group = new WComponentGroup<>();
WButton button = new WButton("test");
WContainer root = new WContainer();
root.add(wcbTest);
root.add(group);
root.add(button);
setActiveContext(createUIContext());
assertSchemaMatch(wcbTest);
assertXpathExists("//ui:checkbox", wcbTest);
assertXpathEvaluatesTo(wcbTest.getId(), "//ui:checkbox/@id", wcbTest);
// Check groupName
assertXpathNotExists("//ui:checkbox/@groupName", wcbTest);
wcbTest.setGroup(group);
assertSchemaMatch(wcbTest);
assertXpathEvaluatesTo(group.getId(), "//ui:checkbox/@groupName", wcbTest);
// Check disabled
assertXpathNotExists("//ui:checkbox/@disabled", wcbTest);
wcbTest.setDisabled(true);
assertSchemaMatch(wcbTest);
assertXpathEvaluatesTo("true", "//ui:checkbox/@disabled", wcbTest);
// Check hidden
assertXpathNotExists("//ui:checkbox/@hidden", wcbTest);
setFlag(wcbTest, ComponentModel.HIDE_FLAG, true);
assertSchemaMatch(wcbTest);
assertXpathEvaluatesTo("true", "//ui:checkbox/@hidden", wcbTest);
// Check required
assertXpathNotExists("//ui:checkbox/@required", wcbTest);
wcbTest.setMandatory(true);
assertSchemaMatch(wcbTest);
assertXpathEvaluatesTo("true", "//ui:checkbox/@required", wcbTest);
// Check selected
assertXpathNotExists("//ui:checkbox/@selected", wcbTest);
wcbTest.setSelected(true);
assertSchemaMatch(wcbTest);
assertXpathEvaluatesTo("true", "//ui:checkbox/@selected", wcbTest);
// Check submitOnChange
assertXpathNotExists("//ui:checkbox/@submitOnChange", wcbTest);
wcbTest.setSubmitOnChange(true);
assertSchemaMatch(wcbTest);
assertXpathEvaluatesTo("true", "//ui:checkbox/@submitOnChange", wcbTest);
// Check toolTip
assertXpathNotExists("//ui:checkbox/@toolTip", wcbTest);
wcbTest.setToolTip("WCheckBox_Test.testRenderedFormat.title");
assertSchemaMatch(wcbTest);
assertXpathEvaluatesTo(wcbTest.getToolTip(), "//ui:checkbox/@toolTip", wcbTest);
// Check accessibleText
assertXpathNotExists("//ui:checkbox/@accessibleText", wcbTest);
wcbTest.setAccessibleText("WCheckBox_Test.testRenderedFormat.accessibleText");
assertSchemaMatch(wcbTest);
assertXpathEvaluatesTo(wcbTest.getAccessibleText(), "//ui:checkbox/@accessibleText", wcbTest);
// Check button id
assertXpathNotExists("//ui:checkbox/@buttonId", wcbTest);
wcbTest.setDefaultSubmitButton(button);
assertSchemaMatch(wcbTest);
assertXpathEvaluatesTo(button.getId(), "//ui:checkbox/@buttonId", wcbTest);
}
Aggregations