Search in sources :

Example 76 with WTextField

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

the class EnableInGroup_Test method testActionType.

@Test
public void testActionType() {
    SubordinateTarget target = new WTextField();
    WComponentGroup<SubordinateTarget> group = new WComponentGroup<>();
    group.addToGroup(target);
    EnableInGroup action = new EnableInGroup(target, group);
    Assert.assertEquals("Incorrect Action Type", action.getActionType(), AbstractAction.ActionType.ENABLEIN);
}
Also used : SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) WComponentGroup(com.github.bordertech.wcomponents.WComponentGroup) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 77 with WTextField

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

the class Rule_Test method testToString.

@Test
public void testToString() {
    WCheckBox box = new WCheckBox();
    SubordinateTarget target = new WTextField();
    Rule rule = new Rule();
    // No condition and actions
    Assert.assertEquals("Incorrect toString for RULE with no conditions and actions", "if (null)\nthen\n   []\nelse\n   []\n", rule.toString());
    // With Conditions and actions;
    rule.setCondition(new Equal(box, Boolean.TRUE));
    rule.addActionOnTrue(new Hide(target));
    rule.addActionOnFalse(new Show(target));
    Assert.assertEquals("Incorrect toString for RULE", "if (WCheckBox=\"true\")\nthen\n   [hide WTextField]\nelse\n   [show WTextField]\n", rule.toString());
}
Also used : SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 78 with WTextField

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

the class Rule_Test method testExecuteRule.

@Test
public void testExecuteRule() {
    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)
    setFlag(target, ComponentModel.HIDE_FLAG, false);
    box.setSelected(true);
    rule.execute();
    Assert.assertTrue("True condition should Hide Target", target.isHidden());
    // Test FALSE Action (Show target)
    setFlag(target, ComponentModel.HIDE_FLAG, true);
    box.setSelected(false);
    rule.execute();
    Assert.assertFalse("False condition should Show Target", target.isHidden());
}
Also used : WCheckBox(com.github.bordertech.wcomponents.WCheckBox) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 79 with WTextField

use of com.github.bordertech.wcomponents.WTextField 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 80 with WTextField

use of com.github.bordertech.wcomponents.WTextField 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)

Aggregations

WTextField (com.github.bordertech.wcomponents.WTextField)117 Test (org.junit.Test)90 SubordinateTarget (com.github.bordertech.wcomponents.SubordinateTarget)21 WCheckBox (com.github.bordertech.wcomponents.WCheckBox)21 WContainer (com.github.bordertech.wcomponents.WContainer)21 Equal (com.github.bordertech.wcomponents.subordinate.Equal)16 GreaterThanOrEqual (com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual)15 LessThanOrEqual (com.github.bordertech.wcomponents.subordinate.LessThanOrEqual)15 NotEqual (com.github.bordertech.wcomponents.subordinate.NotEqual)15 Rule (com.github.bordertech.wcomponents.subordinate.Rule)15 WSubordinateControl (com.github.bordertech.wcomponents.subordinate.WSubordinateControl)15 SubordinateTrigger (com.github.bordertech.wcomponents.SubordinateTrigger)14 WTextArea (com.github.bordertech.wcomponents.WTextArea)14 WComponentGroup (com.github.bordertech.wcomponents.WComponentGroup)12 WDropdown (com.github.bordertech.wcomponents.WDropdown)12 WButton (com.github.bordertech.wcomponents.WButton)11 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)11 WHeading (com.github.bordertech.wcomponents.WHeading)10 WLabel (com.github.bordertech.wcomponents.WLabel)10 Hide (com.github.bordertech.wcomponents.subordinate.Hide)10