Search in sources :

Example 26 with WCheckBox

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

the class Rule_Test method testExecuteRuleWithRequest.

@Test
public void testExecuteRuleWithRequest() {
    WCheckBox box = new WCheckBox();
    WTextField target = new WTextField();
    // Create Rule
    Rule rule = new Rule();
    rule.setCondition(new Equal(box, Boolean.TRUE));
    rule.addActionOnTrue(new Hide(target));
    rule.addActionOnFalse(new Show(target));
    // Test TRUE Action (Hide target)
    setActiveContext(createUIContext());
    MockRequest request = new MockRequest();
    setFlag(target, ComponentModel.HIDE_FLAG, false);
    // CheckBox selected in Request
    setupCheckBoxRequest(box, request, true);
    rule.execute(request);
    Assert.assertTrue("True condition should Hide Target", target.isHidden());
    // Test FALSE Action (Show target)
    setActiveContext(createUIContext());
    request = new MockRequest();
    setFlag(target, ComponentModel.HIDE_FLAG, true);
    // CheckBox not selected in Request
    setupCheckBoxRequest(box, request, false);
    rule.execute(request);
    Assert.assertFalse("False condition should Show Target", target.isHidden());
}
Also used : MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 27 with WCheckBox

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

the class Rule_Test method testConstructors.

@Test
public void testConstructors() {
    Condition cond = new Equal(new WCheckBox(), null);
    Action onTrue = new Hide(new WTextField());
    Action onFalse = new Hide(new WTextField());
    // Constructor - 1
    Rule rule = new Rule();
    Assert.assertNull("Constructor 1: Condition should be null", rule.getCondition());
    Assert.assertTrue("Constructor 1: onTrue actions should be empty", rule.getOnTrue().isEmpty());
    Assert.assertTrue("Constructor 1: onFalse actions should be empty", rule.getOnFalse().isEmpty());
    // Constructor - 2
    rule = new Rule(cond);
    Assert.assertEquals("Constructor 2: Incorrect condition returned", cond, rule.getCondition());
    Assert.assertTrue("Constructor 2: onTrue actions should be empty", rule.getOnTrue().isEmpty());
    Assert.assertTrue("Constructor 2: onFalse actions should be empty", rule.getOnFalse().isEmpty());
    // Constructor - 3
    rule = new Rule(cond, onTrue);
    Assert.assertEquals("Constructor 3: Incorrect condition returned", cond, rule.getCondition());
    Assert.assertEquals("Constructor 3: onTrue actions list should have 1 item", 1, rule.getOnTrue().size());
    Assert.assertEquals("Constructor 3: Item 1 in onTrue actions list is incorrect", onTrue, rule.getOnTrue().get(0));
    Assert.assertTrue("Constructor 3: onFalse actions should be empty", rule.getOnFalse().isEmpty());
    // Constructor - 4
    rule = new Rule(cond, onTrue, onFalse);
    Assert.assertEquals("Constructor 4: Incorrect condition returned", cond, rule.getCondition());
    Assert.assertEquals("Constructor 4: onTrue actions list should have 1 item", 1, rule.getOnTrue().size());
    Assert.assertEquals("Constructor 4: Item 1 in onTrue actions list is incorrect", onTrue, rule.getOnTrue().get(0));
    Assert.assertEquals("Constructor 4: onFalse actions list should have 1 item", 1, rule.getOnFalse().size());
    Assert.assertEquals("Constructor 4: Item 1 in onFalse actions list is incorrect", onFalse, rule.getOnFalse().get(0));
}
Also used : WCheckBox(com.github.bordertech.wcomponents.WCheckBox) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 28 with WCheckBox

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

the class Rule_Test method testAccessors.

@Test
public void testAccessors() {
    Condition cond = new Equal(new WCheckBox(), null);
    Action onTrue1 = new Hide(new WTextField());
    Action onTrue2 = new Hide(new WTextField());
    Action onFalse1 = new Hide(new WTextField());
    Action onFalse2 = new Hide(new WTextField());
    Rule rule = new Rule();
    // Condition
    Assert.assertNull("Condition should be null", rule.getCondition());
    rule.setCondition(cond);
    Assert.assertEquals("Incorrect condition returned", cond, rule.getCondition());
    // OnTrue Actions
    Assert.assertTrue("onTrue actions should be empty", rule.getOnTrue().isEmpty());
    rule.addActionOnTrue(onTrue1);
    Assert.assertEquals("onTrue actions list should have 1 item", 1, rule.getOnTrue().size());
    Assert.assertEquals("Item 1 in onTrue actions list is incorrect", onTrue1, rule.getOnTrue().get(0));
    rule.addActionOnTrue(onTrue2);
    Assert.assertEquals("onTrue actions list should have 2 items", 2, rule.getOnTrue().size());
    Assert.assertEquals("Item 1 in onTrue actions list is incorrect", onTrue1, rule.getOnTrue().get(0));
    Assert.assertEquals("Item 2 in onTrue actions list is incorrect", onTrue2, rule.getOnTrue().get(1));
    try {
        rule.addActionOnTrue(null);
        Assert.fail("Should not be able to add a null action.");
    } catch (IllegalArgumentException e) {
        Assert.assertNotNull("Invalid exception message for adding null action", e.getMessage());
    }
    // OnFalse Actions
    Assert.assertTrue("onFalse actions should be empty", rule.getOnFalse().isEmpty());
    rule.addActionOnFalse(onFalse1);
    Assert.assertEquals("onFalse actions list should have 1 item", 1, rule.getOnFalse().size());
    Assert.assertEquals("Item 1 in onFalse actions list is incorrect", onFalse1, rule.getOnFalse().get(0));
    rule.addActionOnFalse(onFalse2);
    Assert.assertEquals("onFalse actions list should have 2 item", 2, rule.getOnFalse().size());
    Assert.assertEquals("Item 1 in onFalse actions list is incorrect", onFalse1, rule.getOnFalse().get(0));
    Assert.assertEquals("Item 2 in onFalse actions list is incorrect", onFalse2, rule.getOnFalse().get(1));
    try {
        rule.addActionOnFalse(null);
        Assert.fail("Should not be able to add a null action.");
    } catch (IllegalArgumentException e) {
        Assert.assertNotNull("Invalid exception message for adding null action", e.getMessage());
    }
}
Also used : WCheckBox(com.github.bordertech.wcomponents.WCheckBox) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 29 with WCheckBox

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

the class SubordinateBuilder_Test method testShowIn.

@Test
public void testShowIn() {
    SubordinateBuilder builder = new SubordinateBuilder();
    WCheckBox input1 = new WCheckBox();
    WCheckBox input2 = new WCheckBox();
    WCheckBox input3 = new WCheckBox();
    WComponentGroup<SubordinateTarget> group = new WComponentGroup<>();
    group.addToGroup(input1);
    group.addToGroup(input2);
    group.addToGroup(input3);
    // True Condition
    builder.condition().equals(new WCheckBox(), "false");
    // ShowIn Action
    builder.whenTrue().showIn(input2, group);
    setActiveContext(createUIContext());
    // Set initial states (opposite to end state)
    setFlag(input1, ComponentModel.HIDE_FLAG, false);
    setFlag(input2, ComponentModel.HIDE_FLAG, true);
    setFlag(input3, ComponentModel.HIDE_FLAG, false);
    Assert.assertFalse("showIn - Input1 Component should not be hidden", input1.isHidden());
    Assert.assertTrue("showIn - Input2 Component should be initially hidden", input2.isHidden());
    Assert.assertFalse("showIn - Input3 Component should not be hidden", input3.isHidden());
    builder.build().applyTheControls();
    Assert.assertTrue("showIn - Input1 Component should be hidden", input1.isHidden());
    Assert.assertFalse("showIn - Input2 Component should not be hidden", input2.isHidden());
    Assert.assertTrue("showIn - Input3 Component should be hidden", input3.isHidden());
}
Also used : SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) WComponentGroup(com.github.bordertech.wcomponents.WComponentGroup) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) Test(org.junit.Test)

Example 30 with WCheckBox

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

the class SubordinateBuilder_Test method testEnableIn.

@Test
public void testEnableIn() {
    SubordinateBuilder builder = new SubordinateBuilder();
    WCheckBox input1 = new WCheckBox();
    WCheckBox input2 = new WCheckBox();
    WCheckBox input3 = new WCheckBox();
    WComponentGroup<SubordinateTarget> group = new WComponentGroup<>();
    group.addToGroup(input1);
    group.addToGroup(input2);
    group.addToGroup(input3);
    // True Condition
    builder.condition().equals(new WCheckBox(), "false");
    // EnableIn Action
    builder.whenTrue().enableIn(input2, group);
    setActiveContext(createUIContext());
    // Set initial states (opposite to end state)
    input1.setDisabled(false);
    input2.setDisabled(true);
    input3.setDisabled(false);
    Assert.assertFalse("enableIn - Input1 Component should be enabled", input1.isDisabled());
    Assert.assertTrue("enableIn - Input2 Component should be disabled", input2.isDisabled());
    Assert.assertFalse("enableIn - Input3 Component should be enabled", input3.isDisabled());
    builder.build().applyTheControls();
    Assert.assertTrue("enableIn - Input1 Component should be disabled", input1.isDisabled());
    Assert.assertFalse("enableIn - Input2 Component should be enabled", input2.isDisabled());
    Assert.assertTrue("enableIn - Input3 Component should be disabled", input3.isDisabled());
}
Also used : SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) WComponentGroup(com.github.bordertech.wcomponents.WComponentGroup) 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