Search in sources :

Example 6 with WMultiSelectPair

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

the class WLabelRenderer_Test method testWhatForGroup4.

@Test
public void testWhatForGroup4() throws IOException, SAXException, XpathException {
    WMultiSelectPair comp = new WMultiSelectPair();
    WLabel label = new WLabel("label", comp);
    assertSchemaMatch(label);
    assertXpathEvaluatesTo("group", "//ui:label/@what", label);
}
Also used : WMultiSelectPair(com.github.bordertech.wcomponents.WMultiSelectPair) WLabel(com.github.bordertech.wcomponents.WLabel) Test(org.junit.Test)

Example 7 with WMultiSelectPair

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

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

Example 8 with WMultiSelectPair

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

the class WMultiSelectPairRenderer_Test method testReadOnlyOption.

@Test
public void testReadOnlyOption() throws IOException, SAXException, XpathException {
    final String option1 = "WMultiSelectPairRenderer_Test.testDoPaint.option1";
    final String option2 = "WMultiSelectPairRenderer_Test.testDoPaint.option2";
    final String option3 = "WMultiSelectPairRenderer_Test.testDoPaint.option3";
    // Empty list
    WMultiSelectPair select = new WMultiSelectPair();
    setActiveContext(createUIContext());
    select.setOptions(new String[] { option1, option2, option3 });
    select.setSelected(Arrays.asList(new String[] { option2 }));
    assertSchemaMatch(select);
    // Check Readonly - only render selected option
    select.setReadOnly(true);
    assertSchemaMatch(select);
    assertXpathEvaluatesTo("true", "//ui:multiselectpair/@readOnly", select);
    assertXpathEvaluatesTo("1", "count(//ui:multiselectpair/ui:option)", select);
    assertXpathEvaluatesTo(option2, "//ui:multiselectpair/ui:option[@selected='true']", select);
}
Also used : WMultiSelectPair(com.github.bordertech.wcomponents.WMultiSelectPair) Test(org.junit.Test)

Example 9 with WMultiSelectPair

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

the class WMultiSelectPairRenderer_Test method testXssEscaping.

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

Example 10 with WMultiSelectPair

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

the class WMultiSelectPairRenderer_Test method testOptionGroupsWithShuffle.

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

Aggregations

WMultiSelectPair (com.github.bordertech.wcomponents.WMultiSelectPair)10 Test (org.junit.Test)8 OptionGroup (com.github.bordertech.wcomponents.OptionGroup)3 WLabel (com.github.bordertech.wcomponents.WLabel)2 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 WDropdown (com.github.bordertech.wcomponents.WDropdown)1 WEmailField (com.github.bordertech.wcomponents.WEmailField)1 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)1 WFieldSet (com.github.bordertech.wcomponents.WFieldSet)1 WMultiSelect (com.github.bordertech.wcomponents.WMultiSelect)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 WRadioButton (com.github.bordertech.wcomponents.WRadioButton)1 WRadioButtonSelect (com.github.bordertech.wcomponents.WRadioButtonSelect)1 WSingleSelect (com.github.bordertech.wcomponents.WSingleSelect)1