Search in sources :

Example 1 with WShuffler

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

the class WShufflerRenderer_Test method testRendererCorrectlyConfigured.

@Test
public void testRendererCorrectlyConfigured() {
    WShuffler component = new WShuffler();
    Assert.assertTrue("Incorrect renderer supplied", getWebXmlRenderer(component) instanceof WShufflerRenderer);
}
Also used : WShuffler(com.github.bordertech.wcomponents.WShuffler) Test(org.junit.Test)

Example 2 with WShuffler

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

the class WShufflerRenderer_Test method testReadOnly.

@Test
public void testReadOnly() throws IOException, SAXException, XpathException {
    String optionA = "A";
    String optionB = "B";
    String optionC = "C";
    // No options.
    WShuffler shuffler = new WShuffler();
    // Default options
    shuffler.setOptions(Arrays.asList(new String[] { optionA, optionB, optionC }));
    // Check optional attributes
    shuffler.setReadOnly(true);
    assertSchemaMatch(shuffler);
    assertXpathEvaluatesTo("true", "//ui:shuffler/@readOnly", shuffler);
}
Also used : WShuffler(com.github.bordertech.wcomponents.WShuffler) Test(org.junit.Test)

Example 3 with WShuffler

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

the class WShufflerRenderer method doRender.

/**
 * Paints the given WShuffler.
 *
 * @param component the WShuffler to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WShuffler shuffler = (WShuffler) component;
    XmlStringBuilder xml = renderContext.getWriter();
    boolean readOnly = shuffler.isReadOnly();
    // Start tag
    xml.appendTagOpen("ui:shuffler");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("hidden", shuffler.isHidden(), "true");
    if (readOnly) {
        xml.appendAttribute("readOnly", "true");
    } else {
        xml.appendOptionalAttribute("disabled", shuffler.isDisabled(), "true");
        xml.appendOptionalAttribute("toolTip", shuffler.getToolTip());
        xml.appendOptionalAttribute("accessibleText", shuffler.getAccessibleText());
        int rows = shuffler.getRows();
        xml.appendOptionalAttribute("rows", rows > 0, rows);
    }
    xml.appendClose();
    // Options
    List<?> options = shuffler.getOptions();
    if (options != null && !options.isEmpty()) {
        for (int i = 0; i < options.size(); i++) {
            String stringOption = String.valueOf(options.get(i));
            xml.appendTagOpen("ui:option");
            xml.appendAttribute("value", stringOption);
            xml.appendClose();
            xml.appendEscaped(stringOption);
            xml.appendEndTag("ui:option");
        }
    }
    if (!readOnly) {
        DiagnosticRenderUtil.renderDiagnostics(shuffler, renderContext);
    }
    // End tag
    xml.appendEndTag("ui:shuffler");
}
Also used : XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) WShuffler(com.github.bordertech.wcomponents.WShuffler)

Example 4 with WShuffler

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

the class WShufflerRenderer_Test method testDoPaint.

@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
    String optionA = "A";
    String optionB = "B";
    String optionC = "C";
    String optionX = "X";
    // No options.
    WShuffler shuffler = new WShuffler();
    assertSchemaMatch(shuffler);
    assertXpathEvaluatesTo("0", "count(//ui:shuffler/ui:option)", shuffler);
    // Default options
    shuffler.setOptions(Arrays.asList(new String[] { optionA, optionB, optionC }));
    assertSchemaMatch(shuffler);
    assertXpathEvaluatesTo("3", "count(//ui:shuffler/ui:option)", shuffler);
    assertXpathEvaluatesTo(optionA, "//ui:shuffler/ui:option[1]", shuffler);
    assertXpathEvaluatesTo(optionB, "//ui:shuffler/ui:option[2]", shuffler);
    assertXpathEvaluatesTo(optionC, "//ui:shuffler/ui:option[3]", shuffler);
    assertXpathEvaluatesTo(optionA, "//ui:shuffler/ui:option[1]/@value", shuffler);
    assertXpathEvaluatesTo(optionB, "//ui:shuffler/ui:option[2]/@value", shuffler);
    assertXpathEvaluatesTo(optionC, "//ui:shuffler/ui:option[3]/@value", shuffler);
    assertXpathEvaluatesTo("", "//ui:shuffler/@readOnly", shuffler);
    assertXpathEvaluatesTo("", "//ui:shuffler/@disabled", shuffler);
    assertXpathEvaluatesTo("", "//ui:shuffler/@toolTip", shuffler);
    assertXpathEvaluatesTo("", "//ui:shuffler/@rows", shuffler);
    // Check with user context
    assertSchemaMatch(shuffler);
    assertXpathEvaluatesTo("3", "count(//ui:shuffler/ui:option)", shuffler);
    assertXpathEvaluatesTo(optionA, "//ui:shuffler/ui:option[1]", shuffler);
    assertXpathEvaluatesTo(optionB, "//ui:shuffler/ui:option[2]", shuffler);
    assertXpathEvaluatesTo(optionC, "//ui:shuffler/ui:option[3]", shuffler);
    assertXpathEvaluatesTo(optionA, "//ui:shuffler/ui:option[1]/@value", shuffler);
    assertXpathEvaluatesTo(optionB, "//ui:shuffler/ui:option[2]/@value", shuffler);
    assertXpathEvaluatesTo(optionC, "//ui:shuffler/ui:option[3]/@value", shuffler);
    // User specific options
    shuffler.setOptions(Arrays.asList(new String[] { optionX }));
    assertXpathEvaluatesTo("1", "count(//ui:shuffler/ui:option)", shuffler);
    assertXpathEvaluatesTo(optionX, "//ui:shuffler/ui:option[1]", shuffler);
    assertXpathEvaluatesTo(optionX, "//ui:shuffler/ui:option[1]/@value", shuffler);
    // Check optional attributes
    shuffler.setDisabled(true);
    shuffler.setToolTip("TITLE");
    shuffler.setRows(2);
    assertSchemaMatch(shuffler);
    assertXpathEvaluatesTo("true", "//ui:shuffler/@disabled", shuffler);
    assertXpathEvaluatesTo("TITLE", "//ui:shuffler/@toolTip", shuffler);
    assertXpathEvaluatesTo("2", "//ui:shuffler/@rows", shuffler);
}
Also used : WShuffler(com.github.bordertech.wcomponents.WShuffler) Test(org.junit.Test)

Example 5 with WShuffler

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

the class WShufflerRenderer_Test method testXssEscaping.

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

Aggregations

WShuffler (com.github.bordertech.wcomponents.WShuffler)6 Test (org.junit.Test)5 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)1