Search in sources :

Example 16 with WCheckBox

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

the class WSubordinateControlRenderer_Test method testAndCondition.

@Test
public void testAndCondition() throws IOException, SAXException, XpathException {
    SubordinateTrigger condTrigger1 = new WCheckBox();
    SubordinateTrigger condTrigger2 = new WCheckBox();
    SubordinateTrigger condTrigger3 = new WCheckBox();
    // Create AND condition
    Condition cond1 = new Equal(condTrigger1, Boolean.TRUE);
    Condition cond2 = new Equal(condTrigger2, Boolean.TRUE);
    Condition cond3 = new Equal(condTrigger3, Boolean.TRUE);
    Condition and = new And(cond1, cond2, cond3);
    SubordinateTarget actionTarget = new WTextField();
    // Setup Rule with AND Condition
    Rule rule = new Rule();
    rule.setCondition(and);
    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(condTrigger1);
    root.add(condTrigger2);
    root.add(condTrigger3);
    root.add(actionTarget);
    root.add(control);
    // Apply the controls
    control.applyTheControls();
    // Validate Schema
    assertSchemaMatch(root);
    // Check AND
    assertXpathEvaluatesTo("1", "count(//ui:subordinate/ui:and)", root);
    assertXpathEvaluatesTo("3", "count(//ui:subordinate/ui:and/ui:condition)", root);
    assertXpathEvaluatesTo(condTrigger1.getId(), "//ui:subordinate/ui:and/ui:condition[position()=1]/@controller", root);
    assertXpathEvaluatesTo(condTrigger2.getId(), "//ui:subordinate/ui:and/ui:condition[position()=2]/@controller", root);
    assertXpathEvaluatesTo(condTrigger3.getId(), "//ui:subordinate/ui:and/ui:condition[position()=3]/@controller", root);
    // Check action target
    assertXpathEvaluatesTo("true", "//ui:textfield/@hidden", root);
}
Also used : Condition(com.github.bordertech.wcomponents.subordinate.Condition) Hide(com.github.bordertech.wcomponents.subordinate.Hide) SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) WContainer(com.github.bordertech.wcomponents.WContainer) Equal(com.github.bordertech.wcomponents.subordinate.Equal) LessThanOrEqual(com.github.bordertech.wcomponents.subordinate.LessThanOrEqual) NotEqual(com.github.bordertech.wcomponents.subordinate.NotEqual) GreaterThanOrEqual(com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual) And(com.github.bordertech.wcomponents.subordinate.And) WSubordinateControl(com.github.bordertech.wcomponents.subordinate.WSubordinateControl) SubordinateTrigger(com.github.bordertech.wcomponents.SubordinateTrigger) Show(com.github.bordertech.wcomponents.subordinate.Show) Rule(com.github.bordertech.wcomponents.subordinate.Rule) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 17 with WCheckBox

use of com.github.bordertech.wcomponents.WCheckBox 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);
}
Also used : Condition(com.github.bordertech.wcomponents.subordinate.Condition) Hide(com.github.bordertech.wcomponents.subordinate.Hide) WContainer(com.github.bordertech.wcomponents.WContainer) Or(com.github.bordertech.wcomponents.subordinate.Or) WSubordinateControl(com.github.bordertech.wcomponents.subordinate.WSubordinateControl) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) Equal(com.github.bordertech.wcomponents.subordinate.Equal) LessThanOrEqual(com.github.bordertech.wcomponents.subordinate.LessThanOrEqual) NotEqual(com.github.bordertech.wcomponents.subordinate.NotEqual) GreaterThanOrEqual(com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual) And(com.github.bordertech.wcomponents.subordinate.And) SubordinateTrigger(com.github.bordertech.wcomponents.SubordinateTrigger) Show(com.github.bordertech.wcomponents.subordinate.Show) Rule(com.github.bordertech.wcomponents.subordinate.Rule) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 18 with WCheckBox

use of com.github.bordertech.wcomponents.WCheckBox 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);
}
Also used : Hide(com.github.bordertech.wcomponents.subordinate.Hide) SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) WContainer(com.github.bordertech.wcomponents.WContainer) Equal(com.github.bordertech.wcomponents.subordinate.Equal) LessThanOrEqual(com.github.bordertech.wcomponents.subordinate.LessThanOrEqual) NotEqual(com.github.bordertech.wcomponents.subordinate.NotEqual) GreaterThanOrEqual(com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual) WSubordinateControl(com.github.bordertech.wcomponents.subordinate.WSubordinateControl) SubordinateTrigger(com.github.bordertech.wcomponents.SubordinateTrigger) Show(com.github.bordertech.wcomponents.subordinate.Show) WComponentGroup(com.github.bordertech.wcomponents.WComponentGroup) Rule(com.github.bordertech.wcomponents.subordinate.Rule) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 19 with WCheckBox

use of com.github.bordertech.wcomponents.WCheckBox 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);
}
Also used : Hide(com.github.bordertech.wcomponents.subordinate.Hide) SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) WContainer(com.github.bordertech.wcomponents.WContainer) Equal(com.github.bordertech.wcomponents.subordinate.Equal) LessThanOrEqual(com.github.bordertech.wcomponents.subordinate.LessThanOrEqual) NotEqual(com.github.bordertech.wcomponents.subordinate.NotEqual) GreaterThanOrEqual(com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual) WSubordinateControl(com.github.bordertech.wcomponents.subordinate.WSubordinateControl) SubordinateTrigger(com.github.bordertech.wcomponents.SubordinateTrigger) Show(com.github.bordertech.wcomponents.subordinate.Show) WComponentGroup(com.github.bordertech.wcomponents.WComponentGroup) Rule(com.github.bordertech.wcomponents.subordinate.Rule) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 20 with WCheckBox

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

the class WSelectToggleRenderer_Test method testDoPaint.

@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
    // Client-side
    WCheckBox target = new WCheckBox();
    WSelectToggle toggle = new WSelectToggle(true);
    toggle.setTarget(target);
    WContainer root = new WContainer();
    root.add(toggle);
    root.add(target);
    assertSchemaMatch(toggle);
    assertXpathNotExists("//ui:selecttoggle/@roundTrip", toggle);
    assertXpathEvaluatesTo(toggle.getId(), "//ui:selecttoggle/@id", toggle);
    assertXpathEvaluatesTo(toggle.getTarget().getId(), "//ui:selecttoggle/@target", toggle);
    assertXpathEvaluatesTo("control", "//ui:selecttoggle/@renderAs", toggle);
    assertXpathEvaluatesTo("none", "//ui:selecttoggle/@selected", toggle);
    // Test Server-side
    toggle.setClientSide(false);
    assertSchemaMatch(toggle);
    assertXpathEvaluatesTo("true", "//ui:selecttoggle/@roundTrip", toggle);
    // Test when selected
    toggle.setState(WSelectToggle.State.ALL);
    assertSchemaMatch(toggle);
    assertXpathEvaluatesTo("all", "//ui:selecttoggle/@selected", toggle);
    // Test when partially selected
    toggle.setState(WSelectToggle.State.SOME);
    assertSchemaMatch(toggle);
    assertXpathEvaluatesTo("some", "//ui:selecttoggle/@selected", toggle);
}
Also used : WContainer(com.github.bordertech.wcomponents.WContainer) WSelectToggle(com.github.bordertech.wcomponents.WSelectToggle) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) Test(org.junit.Test)

Aggregations

WCheckBox (com.github.bordertech.wcomponents.WCheckBox)42 Test (org.junit.Test)35 WTextField (com.github.bordertech.wcomponents.WTextField)21 SubordinateTarget (com.github.bordertech.wcomponents.SubordinateTarget)18 WContainer (com.github.bordertech.wcomponents.WContainer)17 Equal (com.github.bordertech.wcomponents.subordinate.Equal)13 Rule (com.github.bordertech.wcomponents.subordinate.Rule)13 WSubordinateControl (com.github.bordertech.wcomponents.subordinate.WSubordinateControl)13 WComponentGroup (com.github.bordertech.wcomponents.WComponentGroup)12 GreaterThanOrEqual (com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual)11 LessThanOrEqual (com.github.bordertech.wcomponents.subordinate.LessThanOrEqual)11 NotEqual (com.github.bordertech.wcomponents.subordinate.NotEqual)11 SubordinateTrigger (com.github.bordertech.wcomponents.SubordinateTrigger)10 Hide (com.github.bordertech.wcomponents.subordinate.Hide)7 Show (com.github.bordertech.wcomponents.subordinate.Show)7 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)5 WHeading (com.github.bordertech.wcomponents.WHeading)3 WLabel (com.github.bordertech.wcomponents.WLabel)3 Condition (com.github.bordertech.wcomponents.subordinate.Condition)3 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)3