Search in sources :

Example 26 with WTextField

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

the class WSubordinateControl_Test method testApplyControls.

@Test
public void testApplyControls() {
    WCheckBox box = new WCheckBox();
    SubordinateTarget 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));
    WSubordinateControl control = new WSubordinateControl();
    control.addRule(rule);
    WContainer root = new WContainer();
    root.add(control);
    root.add(box);
    root.add(target);
    setActiveContext(createUIContext());
    // Setup true condition - Selected
    box.setSelected(true);
    // Apply the controls
    setFlag(box, ComponentModel.HIDE_FLAG, false);
    control.applyTheControls();
    Assert.assertTrue("After applyControls target should be hidden", target.isHidden());
    setFlag(box, ComponentModel.HIDE_FLAG, false);
    // Setup true condition - CheckBox selected in Request
    MockRequest request = new MockRequest();
    setupCheckBoxRequest(box, request, true);
    // ApplyControls with Request
    control.applyTheControls(request);
    Assert.assertTrue("Request - After applyControls target should be hidden", target.isHidden());
}
Also used : SubordinateTarget(com.github.bordertech.wcomponents.SubordinateTarget) WContainer(com.github.bordertech.wcomponents.WContainer) 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 WTextField

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

the class CompareExpression_Test method testBuild.

@Test
public void testBuild() {
    SubordinateTrigger trigger = new WTextField();
    String value = "test";
    // Build Equal
    CompareExpression expr = new CompareExpression(CompareType.EQUAL, trigger, value);
    Equal equal = (Equal) expr.build();
    Assert.assertEquals("Equal condition returned invalid trigger", trigger, equal.getTrigger());
    Assert.assertEquals("Equal condition returned invalid value", value, equal.getValue());
    // Build NotEqual
    expr = new CompareExpression(CompareType.NOT_EQUAL, trigger, value);
    NotEqual notEqual = (NotEqual) expr.build();
    Assert.assertEquals("NotEqual condition returned invalid trigger", trigger, notEqual.getTrigger());
    Assert.assertEquals("NotEqual condition returned invalid value", value, notEqual.getValue());
    // Build LessThan
    expr = new CompareExpression(CompareType.LESS_THAN, trigger, value);
    LessThan lessThan = (LessThan) expr.build();
    Assert.assertEquals("LessThan condition returned invalid trigger", trigger, lessThan.getTrigger());
    Assert.assertEquals("LessThan condition returned invalid value", value, lessThan.getValue());
    // Build LessThanOrEqual
    expr = new CompareExpression(CompareType.LESS_THAN_OR_EQUAL, trigger, value);
    LessThanOrEqual lessThanOrEqual = (LessThanOrEqual) expr.build();
    Assert.assertEquals("LessThanOrEqual condition returned invalid trigger", trigger, lessThanOrEqual.getTrigger());
    Assert.assertEquals("LessThanOrEqual condition returned invalid value", value, lessThanOrEqual.getValue());
    // Build GreaterThan
    expr = new CompareExpression(CompareType.GREATER_THAN, trigger, value);
    GreaterThan greaterThan = (GreaterThan) expr.build();
    Assert.assertEquals("GreaterThan condition returned invalid trigger", trigger, greaterThan.getTrigger());
    Assert.assertEquals("GreaterThan condition returned invalid value", value, greaterThan.getValue());
    // Build GreaterThanOrEqual
    expr = new CompareExpression(CompareType.GREATER_THAN_OR_EQUAL, trigger, value);
    GreaterThanOrEqual greaterThanOrEqual = (GreaterThanOrEqual) expr.build();
    Assert.assertEquals("GreaterThanOrEqual condition returned invalid trigger", trigger, greaterThanOrEqual.getTrigger());
    Assert.assertEquals("GreaterThanOrEqual condition returned invalid value", value, greaterThanOrEqual.getValue());
    // Build Match
    expr = new CompareExpression(CompareType.MATCH, trigger, value);
    Match match = (Match) expr.build();
    Assert.assertEquals("Match condition returned invalid trigger", trigger, match.getTrigger());
    Assert.assertEquals("Match condition returned invalid value", value, match.getValue());
}
Also used : LessThan(com.github.bordertech.wcomponents.subordinate.LessThan) NotEqual(com.github.bordertech.wcomponents.subordinate.NotEqual) LessThanOrEqual(com.github.bordertech.wcomponents.subordinate.LessThanOrEqual) LessThanOrEqual(com.github.bordertech.wcomponents.subordinate.LessThanOrEqual) Equal(com.github.bordertech.wcomponents.subordinate.Equal) NotEqual(com.github.bordertech.wcomponents.subordinate.NotEqual) GreaterThanOrEqual(com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual) GreaterThan(com.github.bordertech.wcomponents.subordinate.GreaterThan) SubordinateTrigger(com.github.bordertech.wcomponents.SubordinateTrigger) GreaterThanOrEqual(com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual) WTextField(com.github.bordertech.wcomponents.WTextField) Match(com.github.bordertech.wcomponents.subordinate.Match) Test(org.junit.Test)

Example 28 with WTextField

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

the class CompareExpression_Test method testToString.

@Test
public void testToString() {
    SubordinateTrigger trigger = new WTextField();
    String value = "test";
    // Equal
    CompareExpression expr = new CompareExpression(CompareType.EQUAL, trigger, value);
    Assert.assertEquals("Incorrect toString for equals compare", "WTextField=\"test\"", expr.toString());
    // NotEqual
    expr = new CompareExpression(CompareType.NOT_EQUAL, trigger, value);
    Assert.assertEquals("Incorrect toString for not equals compare", "WTextField!=\"test\"", expr.toString());
    // LessThan
    expr = new CompareExpression(CompareType.LESS_THAN, trigger, value);
    Assert.assertEquals("Incorrect toString for less than compare", "WTextField<\"test\"", expr.toString());
    // LessThanOrEqual
    expr = new CompareExpression(CompareType.LESS_THAN_OR_EQUAL, trigger, value);
    Assert.assertEquals("Incorrect toString for less than or equal compare", "WTextField<=\"test\"", expr.toString());
    // GreaterThan
    expr = new CompareExpression(CompareType.GREATER_THAN, trigger, value);
    Assert.assertEquals("Incorrect toString for greater than compare", "WTextField>\"test\"", expr.toString());
    // GreaterThanOrEqual
    expr = new CompareExpression(CompareType.GREATER_THAN_OR_EQUAL, trigger, value);
    Assert.assertEquals("Incorrect toString for greater thanor equal compare", "WTextField>=\"test\"", expr.toString());
    // Match
    expr = new CompareExpression(CompareType.MATCH, trigger, value);
    Assert.assertEquals("Incorrect toString for match compare", "WTextField matches \"test\"", expr.toString());
    // Test when a label is associated with the field
    expr = new CompareExpression(CompareType.EQUAL, trigger, value);
    new WLabel("My test field", trigger);
    Assert.assertEquals("Incorrect toString for equals compare with label", "My test field=\"test\"", expr.toString());
}
Also used : SubordinateTrigger(com.github.bordertech.wcomponents.SubordinateTrigger) WTextField(com.github.bordertech.wcomponents.WTextField) WLabel(com.github.bordertech.wcomponents.WLabel) Test(org.junit.Test)

Example 29 with WTextField

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

the class ExpressionBuilder_Test method testBuildNotEquals.

@Test
public void testBuildNotEquals() {
    builder.notEquals(new WTextField(), "1");
    Assert.assertEquals("Incorrect condition", "WTextField!=\"1\"", builder.build().toString());
}
Also used : WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 30 with WTextField

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

the class ExpressionBuilder_Test method testBuildGreaterThan.

@Test
public void testBuildGreaterThan() {
    builder.greaterThan(new WTextField(), "1");
    Assert.assertEquals("Incorrect condition", "WTextField>\"1\"", builder.build().toString());
}
Also used : 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