Search in sources :

Example 31 with WDropdown

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

the class WDropdownRenderer_Test method testCrtEntryExpiration.

@Test
public void testCrtEntryExpiration() throws IOException, SAXException, XpathException {
    UIContext uic1 = new UIContextImpl();
    UIContext uic2 = new UIContextImpl() {

        @Override
        public long getCreationTime() {
            // 01 jan 1970 - should have no options
            return 0;
        }
    };
    // Test getOptions accessor
    WDropdown drop = new WDropdown(TestLookupTable.YesNoTable.class);
    // Test rendered format
    setActiveContext(uic1);
    assertSchemaMatch(drop);
    assertXpathEvaluatesTo("2", "count(//ui:dropdown/ui:option)", drop);
    setActiveContext(uic2);
    assertSchemaMatch(drop);
    assertXpathEvaluatesTo("0", "count(//ui:dropdown/ui:option)", drop);
}
Also used : WDropdown(com.github.bordertech.wcomponents.WDropdown) TestLookupTable(com.github.bordertech.wcomponents.TestLookupTable) UIContext(com.github.bordertech.wcomponents.UIContext) UIContextImpl(com.github.bordertech.wcomponents.UIContextImpl) Test(org.junit.Test)

Example 32 with WDropdown

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

the class WDropdownRenderer_Test method testOptionGroups.

@Test
public void testOptionGroups() throws IOException, SAXException, XpathException {
    OptionGroup optionGroup = new OptionGroup("B", Arrays.asList(new String[] { "B.1", "B.2", "B.3", "B.4" }));
    Object[] options = new Object[] { "A", optionGroup, "C" };
    WDropdown drop = new WDropdown(options);
    assertSchemaMatch(drop);
    assertXpathEvaluatesTo("2", "count(//ui:dropdown/ui:option)", drop);
    assertXpathEvaluatesTo("1", "count(//ui:dropdown/ui:optgroup)", drop);
    assertXpathEvaluatesTo("4", "count(//ui:dropdown/ui:optgroup/ui:option)", drop);
    // Check grouped options
    assertXpathEvaluatesTo(optionGroup.getDesc(), "//ui:dropdown/ui:optgroup/@label", drop);
    assertXpathEvaluatesTo((String) optionGroup.getOptions().get(0), "//ui:dropdown/ui:optgroup/ui:option[1]", drop);
    assertXpathEvaluatesTo((String) optionGroup.getOptions().get(1), "//ui:dropdown/ui:optgroup/ui:option[2]", drop);
    assertXpathEvaluatesTo((String) optionGroup.getOptions().get(2), "//ui:dropdown/ui:optgroup/ui:option[3]", drop);
    assertXpathEvaluatesTo((String) optionGroup.getOptions().get(3), "//ui:dropdown/ui:optgroup/ui:option[4]", drop);
    // Check values
    assertXpathEvaluatesTo("1", "//ui:dropdown/ui:option[1]/@value", drop);
    assertXpathEvaluatesTo("2", "//ui:dropdown/ui:optgroup/ui:option[1]/@value", drop);
    assertXpathEvaluatesTo("3", "//ui:dropdown/ui:optgroup/ui:option[2]/@value", drop);
    assertXpathEvaluatesTo("4", "//ui:dropdown/ui:optgroup/ui:option[3]/@value", drop);
    assertXpathEvaluatesTo("5", "//ui:dropdown/ui:optgroup/ui:option[4]/@value", drop);
    assertXpathEvaluatesTo("6", "//ui:dropdown/ui:option[2]/@value", drop);
    // Check selection
    drop.setSelected("B.3");
    assertXpathEvaluatesTo("1", "count(//ui:option[@selected='true'])", drop);
    assertXpathExists("//ui:dropdown/ui:optgroup/ui:option[text()='B.3'][@selected='true']", drop);
}
Also used : OptionGroup(com.github.bordertech.wcomponents.OptionGroup) WDropdown(com.github.bordertech.wcomponents.WDropdown) Test(org.junit.Test)

Example 33 with WDropdown

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

the class WDropdownRenderer_Test method testDoPaint.

@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
    // Shared options.
    WDropdown drop = new WDropdown();
    drop.setLocked(true);
    assertSchemaMatch(drop);
    assertXpathEvaluatesTo("0", "count(//ui:dropdown/ui:option)", drop);
    drop.setOptions(new String[] { "A", "B", "C" });
    assertSchemaMatch(drop);
    assertXpathEvaluatesTo("3", "count(//ui:dropdown/ui:option)", drop);
    drop.setSubmitOnChange(true);
    assertSchemaMatch(drop);
    // User specific options.
    drop.setLocked(true);
    setActiveContext(createUIContext());
    resetContext();
    drop = new WDropdown(new String[] { "A", "B" });
    assertXpathEvaluatesTo("2", "count(//ui:dropdown/ui:option)", drop);
    assertXpathEvaluatesTo(drop.getId(), "//ui:dropdown/@id", drop);
    assertXpathExists("//ui:dropdown[ui:option='A']", drop);
    assertXpathExists("//ui:dropdown[ui:option='B']", drop);
    Assert.assertTrue("Dropdown should be in default state", drop.isDefaultState());
    setActiveContext(createUIContext());
    drop.setOptions(new String[] { "X" });
    assertXpathEvaluatesTo("1", "count(//ui:dropdown/ui:option)", drop);
    assertXpathExists("//ui:dropdown[ui:option='X']", drop);
}
Also used : WDropdown(com.github.bordertech.wcomponents.WDropdown) Test(org.junit.Test)

Aggregations

WDropdown (com.github.bordertech.wcomponents.WDropdown)33 Test (org.junit.Test)28 WTextField (com.github.bordertech.wcomponents.WTextField)12 WTextArea (com.github.bordertech.wcomponents.WTextArea)10 UIContext (com.github.bordertech.wcomponents.UIContext)7 WMultiSelect (com.github.bordertech.wcomponents.WMultiSelect)6 SeleniumWComponentsWebDriver (com.github.bordertech.wcomponents.test.selenium.driver.SeleniumWComponentsWebDriver)6 OptionGroup (com.github.bordertech.wcomponents.OptionGroup)3 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)3 SubordinateTarget (com.github.bordertech.wcomponents.SubordinateTarget)2 WComponent (com.github.bordertech.wcomponents.WComponent)2 WFieldSet (com.github.bordertech.wcomponents.WFieldSet)2 Equal (com.github.bordertech.wcomponents.subordinate.Equal)2 Hide (com.github.bordertech.wcomponents.subordinate.Hide)2 Rule (com.github.bordertech.wcomponents.subordinate.Rule)2 WSubordinateControl (com.github.bordertech.wcomponents.subordinate.WSubordinateControl)2 Action (com.github.bordertech.wcomponents.Action)1 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)1 RadioButtonGroup (com.github.bordertech.wcomponents.RadioButtonGroup)1 TestLookupTable (com.github.bordertech.wcomponents.TestLookupTable)1