Search in sources :

Example 26 with WComponentGroup

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

the class ShowInGroup_Test method testToString.

@Test
public void testToString() {
    SubordinateTarget target1 = new MyTarget();
    SubordinateTarget target2 = new MyTarget();
    SubordinateTarget target3 = new MyTarget();
    WComponentGroup<SubordinateTarget> group = new WComponentGroup<>();
    group.addToGroup(target1);
    group.addToGroup(target2);
    group.addToGroup(target3);
    ShowInGroup action = new ShowInGroup(target2, group);
    Assert.assertEquals("Incorrect toString for action", "show MyTarget in WComponentGroup([MyTarget, MyTarget, MyTarget])", action.toString());
    new WLabel("test label", target2);
    Assert.assertEquals("Incorrect toString for action with a label", "show test label in WComponentGroup([MyTarget, MyTarget, MyTarget])", action.toString());
}
Also used : SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) WComponentGroup(com.github.bordertech.wcomponents.WComponentGroup) WLabel(com.github.bordertech.wcomponents.WLabel) Test(org.junit.Test)

Example 27 with WComponentGroup

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

the class Action_Test method testToString.

/**
 * Since the string representation is relied upon by other tests, it's worth testing specifically.
 */
@Test
public void testToString() {
    SubordinateTarget target = new MyTarget();
    Action action = new Action(com.github.bordertech.wcomponents.subordinate.Action.ActionType.DISABLE, target);
    Assert.assertEquals("Incorrect toString for disable action", "disable MyTarget", action.toString());
    action = new Action(com.github.bordertech.wcomponents.subordinate.Action.ActionType.ENABLE, target);
    Assert.assertEquals("Incorrect toString for enable action", "enable MyTarget", action.toString());
    action = new Action(com.github.bordertech.wcomponents.subordinate.Action.ActionType.HIDE, target);
    Assert.assertEquals("Incorrect toString for hide action", "hide MyTarget", action.toString());
    action = new Action(com.github.bordertech.wcomponents.subordinate.Action.ActionType.MANDATORY, target);
    Assert.assertEquals("Incorrect toString for set mandatory action", "set MyTarget mandatory", action.toString());
    action = new Action(com.github.bordertech.wcomponents.subordinate.Action.ActionType.OPTIONAL, target);
    Assert.assertEquals("Incorrect toString for set optional action", "set MyTarget optional", action.toString());
    action = new Action(com.github.bordertech.wcomponents.subordinate.Action.ActionType.SHOW, target);
    Assert.assertEquals("Incorrect toString for show action", "show MyTarget", action.toString());
    action = new Action(com.github.bordertech.wcomponents.subordinate.Action.ActionType.SHOWIN, target, new WComponentGroup<SubordinateTarget>());
    Assert.assertEquals("Incorrect toString for showIn action", "show MyTarget in WComponentGroup([])", action.toString());
    action = new Action(com.github.bordertech.wcomponents.subordinate.Action.ActionType.HIDEIN, target, new WComponentGroup<SubordinateTarget>());
    Assert.assertEquals("Incorrect toString for hideIn action", "hide MyTarget in WComponentGroup([])", action.toString());
    action = new Action(com.github.bordertech.wcomponents.subordinate.Action.ActionType.ENABLEIN, target, new WComponentGroup<SubordinateTarget>());
    Assert.assertEquals("Incorrect toString for enableIn action", "enable MyTarget in WComponentGroup([])", action.toString());
    action = new Action(com.github.bordertech.wcomponents.subordinate.Action.ActionType.DISABLEIN, target, new WComponentGroup<SubordinateTarget>());
    Assert.assertEquals("Incorrect toString for disableIn action", "disable MyTarget in WComponentGroup([])", action.toString());
    // Test when a label is associated with the field
    action = new Action(com.github.bordertech.wcomponents.subordinate.Action.ActionType.SHOW, target);
    new WLabel("My test field", target);
    Assert.assertEquals("Incorrect toString for show action with label", "show My test field", action.toString());
}
Also used : SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) WComponentGroup(com.github.bordertech.wcomponents.WComponentGroup) WLabel(com.github.bordertech.wcomponents.WLabel) Test(org.junit.Test)

Example 28 with WComponentGroup

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

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

Example 30 with WComponentGroup

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

the class SubordinateBuilder_Test method testDisableIn.

@Test
public void testDisableIn() {
    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");
    // DisableIn Action
    builder.whenTrue().disableIn(input2, group);
    setActiveContext(createUIContext());
    // Set initial states (opposite to end state)
    input1.setDisabled(true);
    input2.setDisabled(false);
    input3.setDisabled(true);
    Assert.assertTrue("disableIn - Input1 Component should be disabled", input1.isDisabled());
    Assert.assertFalse("disableIn - Input2 Component should be enabled", input2.isDisabled());
    Assert.assertTrue("disableIn - Input3 Component should be disabled", input3.isDisabled());
    builder.build().applyTheControls();
    Assert.assertFalse("disableIn - Input1 Component should be enabled", input1.isDisabled());
    Assert.assertTrue("disableIn - Input2 Component should be disabled", input2.isDisabled());
    Assert.assertFalse("disableIn - Input3 Component should be enabled", 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

WComponentGroup (com.github.bordertech.wcomponents.WComponentGroup)34 SubordinateTarget (com.github.bordertech.wcomponents.SubordinateTarget)30 Test (org.junit.Test)30 WCheckBox (com.github.bordertech.wcomponents.WCheckBox)12 WTextField (com.github.bordertech.wcomponents.WTextField)12 WContainer (com.github.bordertech.wcomponents.WContainer)10 Equal (com.github.bordertech.wcomponents.subordinate.Equal)9 Rule (com.github.bordertech.wcomponents.subordinate.Rule)9 WSubordinateControl (com.github.bordertech.wcomponents.subordinate.WSubordinateControl)9 GreaterThanOrEqual (com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual)7 LessThanOrEqual (com.github.bordertech.wcomponents.subordinate.LessThanOrEqual)7 NotEqual (com.github.bordertech.wcomponents.subordinate.NotEqual)7 SubordinateTrigger (com.github.bordertech.wcomponents.SubordinateTrigger)6 WLabel (com.github.bordertech.wcomponents.WLabel)5 Hide (com.github.bordertech.wcomponents.subordinate.Hide)4 WButton (com.github.bordertech.wcomponents.WButton)3 Show (com.github.bordertech.wcomponents.subordinate.Show)3 WComponent (com.github.bordertech.wcomponents.WComponent)2 WHorizontalRule (com.github.bordertech.wcomponents.WHorizontalRule)2 Disable (com.github.bordertech.wcomponents.subordinate.Disable)2