Search in sources :

Example 1 with WSuggestions

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

the class WSuggestionsRenderer_Test method testDoPaintStaticOptions.

@Test
public void testDoPaintStaticOptions() throws IOException, SAXException, XpathException {
    List<String> options = Arrays.asList("A", "B", "C");
    WSuggestions field = new WSuggestions(options);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo(field.getId(), "//ui:suggestions/@id", field);
    assertXpathNotExists("//ui:suggestions/@ajax", field);
    assertXpathNotExists("//ui:suggestions/@min", field);
    assertXpathNotExists("//ui:suggestions/@data", field);
    assertXpathExists("//ui:suggestions/ui:suggestion", field);
    assertXpathEvaluatesTo(options.get(0), "//ui:suggestions/ui:suggestion[1]/@value", field);
    assertXpathEvaluatesTo(options.get(1), "//ui:suggestions/ui:suggestion[2]/@value", field);
    assertXpathEvaluatesTo(options.get(2), "//ui:suggestions/ui:suggestion[3]/@value", field);
}
Also used : WSuggestions(com.github.bordertech.wcomponents.WSuggestions) Test(org.junit.Test)

Example 2 with WSuggestions

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

the class WSuggestionsRenderer_Test method testDoPaintAjaxOptions.

@Test
public void testDoPaintAjaxOptions() throws IOException, SAXException, XpathException {
    List<String> options = Arrays.asList("A", "B", "C");
    WSuggestions field = new WSuggestions(options);
    // Set action for AJAX refresh
    field.setRefreshAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
        // Do nothing
        }
    });
    assertSchemaMatch(field);
    assertXpathEvaluatesTo(field.getId(), "//ui:suggestions/@id", field);
    assertXpathNotExists("//ui:suggestions/@min", field);
    assertXpathNotExists("//ui:suggestions/@data", field);
    // AJAX flag should be true
    assertXpathEvaluatesTo("true", "//ui:suggestions/@ajax", field);
    // Suggestions should only be rendered when refreshed via AJAX
    assertXpathNotExists("//ui:suggestions/ui:suggestion", field);
    // Setup suggestions as the current AJAX trigger
    UIContext uic = createUIContext();
    uic.setUI(new DefaultWComponent());
    setActiveContext(uic);
    try {
        AjaxOperation operation = new AjaxOperation(field.getId(), field.getId());
        AjaxHelper.setCurrentOperationDetails(operation, null);
        assertSchemaMatch(field);
        assertXpathExists("//ui:suggestions/ui:suggestion", field);
        assertXpathEvaluatesTo(options.get(0), "//ui:suggestions/ui:suggestion[1]/@value", field);
        assertXpathEvaluatesTo(options.get(1), "//ui:suggestions/ui:suggestion[2]/@value", field);
        assertXpathEvaluatesTo(options.get(2), "//ui:suggestions/ui:suggestion[3]/@value", field);
    } finally {
        AjaxHelper.clearCurrentOperationDetails();
    }
}
Also used : Action(com.github.bordertech.wcomponents.Action) AjaxOperation(com.github.bordertech.wcomponents.AjaxOperation) UIContext(com.github.bordertech.wcomponents.UIContext) WSuggestions(com.github.bordertech.wcomponents.WSuggestions) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) DefaultWComponent(com.github.bordertech.wcomponents.DefaultWComponent) Test(org.junit.Test)

Example 3 with WSuggestions

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

the class WSuggestionsRenderer_Test method testDoPaintLookupTableOptions.

@Test
public void testDoPaintLookupTableOptions() throws IOException, SAXException, XpathException {
    WSuggestions field = new WSuggestions(TestLookupTable.CACHEABLE_DAY_OF_WEEK_TABLE);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo(field.getId(), "//ui:suggestions/@id", field);
    assertXpathNotExists("//ui:suggestions/@ajax", field);
    assertXpathNotExists("//ui:suggestions/@min", field);
    assertXpathNotExists("//ui:suggestions/suggestion", field);
    assertXpathEvaluatesTo(field.getListCacheKey(), "//ui:suggestions/@data", field);
    // If action set with a lookup table, AJAX flag should still be not set
    field.setRefreshAction(new Action() {

        @Override
        public void execute(final ActionEvent event) {
        // Do nothing
        }
    });
    assertSchemaMatch(field);
    assertXpathNotExists("//ui:suggestions/@ajax", field);
}
Also used : Action(com.github.bordertech.wcomponents.Action) WSuggestions(com.github.bordertech.wcomponents.WSuggestions) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) Test(org.junit.Test)

Example 4 with WSuggestions

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

the class WSuggestionsRenderer_Test method testDoBasicPaint.

@Test
public void testDoBasicPaint() throws IOException, SAXException, XpathException {
    WSuggestions field = new WSuggestions();
    assertSchemaMatch(field);
    assertXpathEvaluatesTo(field.getId(), "//ui:suggestions/@id", field);
    assertXpathNotExists("//ui:suggestions/@ajax", field);
    assertXpathNotExists("//ui:suggestions/@min", field);
    assertXpathNotExists("//ui:suggestions/@data", field);
    assertXpathNotExists("//ui:suggestions/@autocomplete", field);
    assertXpathNotExists("//ui:suggestions/suggestion", field);
    // Set min
    field.setMinRefresh(2);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo("2", "//ui:suggestions/@min", field);
}
Also used : WSuggestions(com.github.bordertech.wcomponents.WSuggestions) Test(org.junit.Test)

Example 5 with WSuggestions

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

the class WSuggestionsRenderer_Test method testDoPaintAutocomplete.

@Test
public void testDoPaintAutocomplete() throws IOException, SAXException, XpathException {
    List<String> options = Arrays.asList("A", "B", "C");
    WSuggestions field = new WSuggestions(options);
    assertSchemaMatch(field);
    assertXpathNotExists("//ui:suggestions/@autocomplete", field);
    field.setAutocomplete(WSuggestions.Autocomplete.LIST);
    assertXpathEvaluatesTo("list", "//ui:suggestions/@autocomplete", field);
    field.setAutocomplete(WSuggestions.Autocomplete.BOTH);
    assertXpathNotExists("//ui:suggestions/@autocomplete", field);
}
Also used : WSuggestions(com.github.bordertech.wcomponents.WSuggestions) Test(org.junit.Test)

Aggregations

WSuggestions (com.github.bordertech.wcomponents.WSuggestions)14 Test (org.junit.Test)9 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)4 WButton (com.github.bordertech.wcomponents.WButton)3 WComponent (com.github.bordertech.wcomponents.WComponent)3 WContainer (com.github.bordertech.wcomponents.WContainer)3 Action (com.github.bordertech.wcomponents.Action)2 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)2 WEmailField (com.github.bordertech.wcomponents.WEmailField)2 WPhoneNumberField (com.github.bordertech.wcomponents.WPhoneNumberField)2 WTextField (com.github.bordertech.wcomponents.WTextField)2 AjaxOperation (com.github.bordertech.wcomponents.AjaxOperation)1 DefaultWComponent (com.github.bordertech.wcomponents.DefaultWComponent)1 UIContext (com.github.bordertech.wcomponents.UIContext)1