Search in sources :

Example 6 with WMultiDropdown

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

the class WMultiDropdownRenderer_Test method testIsNullOption.

@Test
public void testIsNullOption() throws IOException, SAXException, XpathException {
    String[] options = new String[] { null, "", "A", "B", "C" };
    WMultiDropdown drop = new WMultiDropdown(options);
    assertSchemaMatch(drop);
    assertXpathEvaluatesTo("5", "count(//ui:multidropdown/ui:option)", drop);
    assertXpathEvaluatesTo("", "//ui:multidropdown/ui:option[@value='']/text()", drop);
    for (int i = 0; i < options.length; i++) {
        String code = drop.optionToCode(options[i]);
        String option = options[i];
        if (option == null || option.equals("")) {
            assertXpathEvaluatesTo("", "//ui:multidropdown/ui:option[@value='" + code + "']/text()", drop);
            assertXpathEvaluatesTo("true", "//ui:multidropdown/ui:option[@value='" + code + "']/@isNull", drop);
        } else {
            assertXpathEvaluatesTo(option, "//ui:multidropdown/ui:option[@value='" + code + "']/text()", drop);
            assertXpathEvaluatesTo("", "//ui:multidropdown/ui:option[@value='" + code + "']/@isNull", drop);
        }
    }
}
Also used : WMultiDropdown(com.github.bordertech.wcomponents.WMultiDropdown) Test(org.junit.Test)

Example 7 with WMultiDropdown

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

the class WMultiDropdownRenderer_Test method testDataList.

@Test
public void testDataList() throws IOException, SAXException, XpathException {
    WMultiDropdown dropdown = new WMultiDropdown(TestLookupTable.CACHEABLE_DAY_OF_WEEK_TABLE);
    setActiveContext(createUIContext());
    assertSchemaMatch(dropdown);
    // Default first option
    String code = dropdown.getCode(dropdown.getOptions().get(0), 0);
    String desc = dropdown.getDesc(dropdown.getOptions().get(0), 0);
    assertSchemaMatch(dropdown);
    assertXpathEvaluatesTo("1", "count(//ui:multidropdown/ui:option)", dropdown);
    assertXpathEvaluatesTo(desc, "//ui:multidropdown/ui:option[@value='" + code + "']/text()", dropdown);
    assertXpathEvaluatesTo(dropdown.getListCacheKey(), "//ui:multidropdown/@data", dropdown);
}
Also used : WMultiDropdown(com.github.bordertech.wcomponents.WMultiDropdown) Test(org.junit.Test)

Example 8 with WMultiDropdown

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

the class WMultiDropdownRenderer_Test method testXssEscaping.

@Test
public void testXssEscaping() throws IOException, SAXException, XpathException {
    OptionGroup optionGroup = new OptionGroup(getMaliciousAttribute("ui:optgroup"), Arrays.asList(new String[] { "dummy" }));
    WMultiDropdown drop = new WMultiDropdown(Arrays.asList(new Object[] { getInvalidCharSequence(), getMaliciousContent(), optionGroup }));
    assertSafeContent(drop);
    drop.setToolTip(getMaliciousAttribute("ui:multidropdown"));
    assertSafeContent(drop);
    drop.setAccessibleText(getMaliciousAttribute("ui:multidropdown"));
    assertSafeContent(drop);
}
Also used : OptionGroup(com.github.bordertech.wcomponents.OptionGroup) WMultiDropdown(com.github.bordertech.wcomponents.WMultiDropdown) Test(org.junit.Test)

Example 9 with WMultiDropdown

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

the class WMultiDropdownRenderer_Test method testRendererCorrectlyConfigured.

@Test
public void testRendererCorrectlyConfigured() {
    WMultiDropdown dropdown = new WMultiDropdown(new String[] { "a", "b", "c" });
    Assert.assertTrue("Incorrect renderer supplied", getWebXmlRenderer(dropdown) instanceof WMultiDropdownRenderer);
}
Also used : WMultiDropdown(com.github.bordertech.wcomponents.WMultiDropdown) Test(org.junit.Test)

Example 10 with WMultiDropdown

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

the class WMultiDropdownTestingExample method addOneSelectionExample.

/**
 * Add example with one default selection.
 * @param readOnly if {@code true} then make the example read-only.
 */
private void addOneSelectionExample(final boolean readOnly) {
    String label = readOnly ? LABEL_RO_ONE_SELECTED : LABEL_ONE_SELECTED;
    WMultiDropdown dropdown = new WMultiDropdown(DATA_LIST);
    dropdown.setSelected(DATA_ONE_SELECTED);
    dropdown.setReadOnly(readOnly);
    layout.addField(label, dropdown);
}
Also used : WMultiDropdown(com.github.bordertech.wcomponents.WMultiDropdown)

Aggregations

WMultiDropdown (com.github.bordertech.wcomponents.WMultiDropdown)15 Test (org.junit.Test)8 OptionGroup (com.github.bordertech.wcomponents.OptionGroup)2 WDropdown (com.github.bordertech.wcomponents.WDropdown)1 WLabel (com.github.bordertech.wcomponents.WLabel)1 WMultiSelect (com.github.bordertech.wcomponents.WMultiSelect)1 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)1