Search in sources :

Example 46 with SubordinateTarget

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

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

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

the class Action_Test method testConstructor1.

@Test
public void testConstructor1() {
    SubordinateTarget target = new MyTarget();
    Action action = new Action(com.github.bordertech.wcomponents.subordinate.Action.ActionType.DISABLE, target);
    Assert.assertEquals("Incorrect type returned", com.github.bordertech.wcomponents.subordinate.Action.ActionType.DISABLE, action.getType());
    Assert.assertEquals("Incorrect target returned", target, action.getTarget());
    Assert.assertNull("Group should be null", action.getGroup());
}
Also used : SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) Test(org.junit.Test)

Example 49 with SubordinateTarget

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

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

SubordinateTarget (com.github.bordertech.wcomponents.SubordinateTarget)57 Test (org.junit.Test)53 WComponentGroup (com.github.bordertech.wcomponents.WComponentGroup)30 WTextField (com.github.bordertech.wcomponents.WTextField)21 WCheckBox (com.github.bordertech.wcomponents.WCheckBox)18 Equal (com.github.bordertech.wcomponents.subordinate.Equal)17 Rule (com.github.bordertech.wcomponents.subordinate.Rule)17 WSubordinateControl (com.github.bordertech.wcomponents.subordinate.WSubordinateControl)17 WContainer (com.github.bordertech.wcomponents.WContainer)15 GreaterThanOrEqual (com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual)15 LessThanOrEqual (com.github.bordertech.wcomponents.subordinate.LessThanOrEqual)15 NotEqual (com.github.bordertech.wcomponents.subordinate.NotEqual)15 Hide (com.github.bordertech.wcomponents.subordinate.Hide)12 SubordinateTrigger (com.github.bordertech.wcomponents.SubordinateTrigger)11 Show (com.github.bordertech.wcomponents.subordinate.Show)11 WLabel (com.github.bordertech.wcomponents.WLabel)5 Condition (com.github.bordertech.wcomponents.subordinate.Condition)5 WHorizontalRule (com.github.bordertech.wcomponents.WHorizontalRule)3 And (com.github.bordertech.wcomponents.subordinate.And)3 Disable (com.github.bordertech.wcomponents.subordinate.Disable)3