Search in sources :

Example 11 with WMultiSelect

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

the class WMultiSelectRenderer_Test method testDataList.

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

Example 12 with WMultiSelect

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

the class WMultiSelectRenderer_Test method testXssEscaping.

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

Example 13 with WMultiSelect

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

the class WMultiSelectRenderer_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" };
    WMultiSelect multi = new WMultiSelect(options);
    assertSchemaMatch(multi);
    assertXpathEvaluatesTo("2", "count(//ui:listbox/ui:option)", multi);
    assertXpathEvaluatesTo("1", "count(//ui:listbox/ui:optgroup)", multi);
    assertXpathEvaluatesTo("4", "count(//ui:listbox/ui:optgroup/ui:option)", multi);
    // Check grouped options
    assertXpathEvaluatesTo(optionGroup.getDesc(), "//ui:listbox/ui:optgroup/@label", multi);
    assertXpathEvaluatesTo((String) optionGroup.getOptions().get(0), "//ui:listbox/ui:optgroup/ui:option[1]", multi);
    assertXpathEvaluatesTo((String) optionGroup.getOptions().get(1), "//ui:listbox/ui:optgroup/ui:option[2]", multi);
    assertXpathEvaluatesTo((String) optionGroup.getOptions().get(2), "//ui:listbox/ui:optgroup/ui:option[3]", multi);
    assertXpathEvaluatesTo((String) optionGroup.getOptions().get(3), "//ui:listbox/ui:optgroup/ui:option[4]", multi);
    // Check values
    assertXpathEvaluatesTo("1", "//ui:listbox/ui:option[1]/@value", multi);
    assertXpathEvaluatesTo("2", "//ui:listbox/ui:optgroup/ui:option[1]/@value", multi);
    assertXpathEvaluatesTo("3", "//ui:listbox/ui:optgroup/ui:option[2]/@value", multi);
    assertXpathEvaluatesTo("4", "//ui:listbox/ui:optgroup/ui:option[3]/@value", multi);
    assertXpathEvaluatesTo("5", "//ui:listbox/ui:optgroup/ui:option[4]/@value", multi);
    assertXpathEvaluatesTo("6", "//ui:listbox/ui:option[2]/@value", multi);
    // Check selection
    multi.setSelected(Arrays.asList(new String[] { "A", "B.3" }));
    assertXpathEvaluatesTo("2", "count(//ui:option[@selected='true'])", multi);
    assertXpathExists("//ui:listbox/ui:option[text()='A'][@selected='true']", multi);
    assertXpathExists("//ui:listbox/ui:optgroup/ui:option[text()='B.3'][@selected='true']", multi);
}
Also used : OptionGroup(com.github.bordertech.wcomponents.OptionGroup) WMultiSelect(com.github.bordertech.wcomponents.WMultiSelect) Test(org.junit.Test)

Example 14 with WMultiSelect

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

the class WMultiSelectRenderer_Test method testDoPaint.

@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
    WMultiSelect multi = new WMultiSelect(new String[] { "a", "b", "c" });
    assertSchemaMatch(multi);
    assertXpathEvaluatesTo("3", "count(//ui:listbox/ui:option)", multi);
    assertXpathNotExists("//ui:listbox/@rows", multi);
    assertXpathNotExists("//ui:listbox/@single", multi);
    // Check selected
    assertXpathNotExists("//ui:listbox/ui:option[@selected='true']", multi);
    setActiveContext(createUIContext());
    multi.setSelected(Arrays.asList(new String[] { "b" }));
    assertSchemaMatch(multi);
    assertXpathEvaluatesTo("3", "count(//ui:listbox/ui:option)", multi);
    assertXpathEvaluatesTo("b", "normalize-space(//ui:listbox/ui:option[@selected='true'])", multi);
    // Check rows
    multi.setRows(123);
    assertSchemaMatch(multi);
    assertXpathEvaluatesTo("123", "//ui:listbox/@rows", multi);
}
Also used : WMultiSelect(com.github.bordertech.wcomponents.WMultiSelect) Test(org.junit.Test)

Aggregations

WMultiSelect (com.github.bordertech.wcomponents.WMultiSelect)14 Test (org.junit.Test)11 WDropdown (com.github.bordertech.wcomponents.WDropdown)6 WTextArea (com.github.bordertech.wcomponents.WTextArea)5 WTextField (com.github.bordertech.wcomponents.WTextField)5 OptionGroup (com.github.bordertech.wcomponents.OptionGroup)3 RadioButtonGroup (com.github.bordertech.wcomponents.RadioButtonGroup)1 WCheckBox (com.github.bordertech.wcomponents.WCheckBox)1 WCheckBoxSelect (com.github.bordertech.wcomponents.WCheckBoxSelect)1 WDateField (com.github.bordertech.wcomponents.WDateField)1 WEmailField (com.github.bordertech.wcomponents.WEmailField)1 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)1 WFieldSet (com.github.bordertech.wcomponents.WFieldSet)1 WLabel (com.github.bordertech.wcomponents.WLabel)1 WMultiDropdown (com.github.bordertech.wcomponents.WMultiDropdown)1 WMultiSelectPair (com.github.bordertech.wcomponents.WMultiSelectPair)1 WNumberField (com.github.bordertech.wcomponents.WNumberField)1 WPartialDateField (com.github.bordertech.wcomponents.WPartialDateField)1 WPasswordField (com.github.bordertech.wcomponents.WPasswordField)1 WPhoneNumberField (com.github.bordertech.wcomponents.WPhoneNumberField)1