Search in sources :

Example 6 with WSuggestions

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

the class WTextFieldRenderer_Test method testDoPaint.

@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
    WTextField textField = new WTextField();
    WButton button = new WButton();
    WSuggestions suggestions = new WSuggestions();
    WContainer root = new WContainer();
    root.add(textField);
    root.add(button);
    root.add(suggestions);
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo(textField.getId(), "//ui:textfield/@id", textField);
    assertXpathNotExists("//ui:textfield/@disabled", textField);
    assertXpathNotExists("//ui:textfield/@hidden", textField);
    assertXpathNotExists("//ui:textfield/@required", textField);
    assertXpathNotExists("//ui:textfield/@readOnly", textField);
    assertXpathNotExists("//ui:textfield/@minLength", textField);
    assertXpathNotExists("//ui:textfield/@maxLength", textField);
    assertXpathNotExists("//ui:textfield/@toolTip", textField);
    assertXpathNotExists("//ui:textfield/@accessibleText", textField);
    assertXpathNotExists("//ui:textfield/@size", textField);
    assertXpathNotExists("//ui:textfield/@buttonId", textField);
    assertXpathNotExists("//ui:textfield/@pattern", textField);
    assertXpathNotExists("//ui:textfield/@list", textField);
    assertXpathNotExists("//ui:textfield/@autocomplete", textField);
    textField.setDisabled(true);
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo("true", "//ui:textfield/@disabled", textField);
    setFlag(textField, ComponentModel.HIDE_FLAG, true);
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo("true", "//ui:textfield/@hidden", textField);
    textField.setMandatory(true);
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo("true", "//ui:textfield/@required", textField);
    textField.setMinLength(45);
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo("45", "//ui:textfield/@minLength", textField);
    textField.setMaxLength(50);
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo("50", "//ui:textfield/@maxLength", textField);
    textField.setToolTip("tooltip");
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo(textField.getToolTip(), "//ui:textfield/@toolTip", textField);
    textField.setAccessibleText("accessible");
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo(textField.getAccessibleText(), "//ui:textfield/@accessibleText", textField);
    textField.setColumns(40);
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo("40", "//ui:textfield/@size", textField);
    textField.setDefaultSubmitButton(button);
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo(button.getId(), "//ui:textfield/@buttonId", textField);
    textField.setPattern("");
    assertSchemaMatch(textField);
    assertXpathNotExists("//ui:textfield/@pattern", textField);
    textField.setPattern("test[123]");
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo(textField.getPattern(), "//ui:textfield/@pattern", textField);
    textField.setText("Hello");
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo(textField.getText(), "normalize-space(//ui:textfield)", textField);
    textField.setSuggestions(suggestions);
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo(suggestions.getId(), "//ui:textfield/@list", textField);
    textField.setPlaceholder("enter stuff here");
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo("enter stuff here", "//ui:textfield/@placeholder", textField);
    textField.setAutocomplete(Person.GIVEN);
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo(textField.getAutocomplete(), "//ui:textfield/@autocomplete", textField);
    textField.setAutocompleteOff();
    assertSchemaMatch(textField);
    assertXpathEvaluatesTo(AutocompleteUtil.getOff(), "//ui:textfield/@autocomplete", textField);
}
Also used : WContainer(com.github.bordertech.wcomponents.WContainer) WSuggestions(com.github.bordertech.wcomponents.WSuggestions) WTextField(com.github.bordertech.wcomponents.WTextField) WButton(com.github.bordertech.wcomponents.WButton) Test(org.junit.Test)

Example 7 with WSuggestions

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

the class WPhoneNumberFieldRenderer_Test method testDoPaint.

@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
    WPhoneNumberField field = new WPhoneNumberField();
    WButton button = new WButton();
    WSuggestions suggestions = new WSuggestions();
    WContainer root = new WContainer();
    root.add(field);
    root.add(button);
    root.add(suggestions);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo(field.getId(), "//ui:phonenumberfield/@id", field);
    assertXpathNotExists("//ui:phonenumberfield/@disabled", field);
    assertXpathNotExists("//ui:phonenumberfield/@hidden", field);
    assertXpathNotExists("//ui:phonenumberfield/@required", field);
    assertXpathNotExists("//ui:phonenumberfield/@readOnly", field);
    assertXpathNotExists("//ui:phonenumberfield/@minLength", field);
    assertXpathNotExists("//ui:phonenumberfield/@maxLength", field);
    assertXpathNotExists("//ui:phonenumberfield/@toolTip", field);
    assertXpathNotExists("//ui:phonenumberfield/@accessibleText", field);
    assertXpathNotExists("//ui:phonenumberfield/@size", field);
    assertXpathNotExists("//ui:phonenumberfield/@buttonId", field);
    assertXpathNotExists("//ui:phonenumberfield/@pattern", field);
    assertXpathNotExists("//ui:phonenumberfield/@list", field);
    assertXpathNotExists("//ui:phonenumberfield/@autocomplete", field);
    field.setDisabled(true);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo("true", "//ui:phonenumberfield/@disabled", field);
    setFlag(field, ComponentModel.HIDE_FLAG, true);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo("true", "//ui:phonenumberfield/@hidden", field);
    field.setMandatory(true);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo("true", "//ui:phonenumberfield/@required", field);
    field.setMinLength(45);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo("45", "//ui:phonenumberfield/@minLength", field);
    field.setMaxLength(50);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo("50", "//ui:phonenumberfield/@maxLength", field);
    field.setToolTip("tooltip");
    assertSchemaMatch(field);
    assertXpathEvaluatesTo(field.getToolTip(), "//ui:phonenumberfield/@toolTip", field);
    field.setAccessibleText("accessible");
    assertSchemaMatch(field);
    assertXpathEvaluatesTo(field.getAccessibleText(), "//ui:phonenumberfield/@accessibleText", field);
    field.setColumns(40);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo("40", "//ui:phonenumberfield/@size", field);
    field.setDefaultSubmitButton(button);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo(button.getId(), "//ui:phonenumberfield/@buttonId", field);
    field.setPattern("");
    assertSchemaMatch(field);
    assertXpathNotExists("//ui:phonenumberfield/@pattern", field);
    field.setPattern("test[123]");
    assertSchemaMatch(field);
    assertXpathEvaluatesTo(field.getPattern(), "//ui:phonenumberfield/@pattern", field);
    field.setText("(12) 3456 7890");
    assertSchemaMatch(field);
    assertXpathEvaluatesTo(field.getText(), "normalize-space(//ui:phonenumberfield)", field);
    field.setSuggestions(suggestions);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo(suggestions.getId(), "//ui:phonenumberfield/@list", field);
    field.setPlaceholder("enter stuff here");
    assertSchemaMatch(field);
    assertXpathEvaluatesTo("enter stuff here", "//ui:phonenumberfield/@placeholder", field);
}
Also used : WContainer(com.github.bordertech.wcomponents.WContainer) WPhoneNumberField(com.github.bordertech.wcomponents.WPhoneNumberField) WSuggestions(com.github.bordertech.wcomponents.WSuggestions) WButton(com.github.bordertech.wcomponents.WButton) Test(org.junit.Test)

Example 8 with WSuggestions

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

the class WSuggestionsRenderer_Test method testRendererCorrectlyConfigured.

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

Example 9 with WSuggestions

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

the class WEmailFieldRenderer_Test method testDoPaint.

@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
    WEmailField field = new WEmailField();
    WButton button = new WButton();
    WSuggestions suggestions = new WSuggestions();
    WContainer root = new WContainer();
    root.add(field);
    root.add(button);
    root.add(suggestions);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo(field.getId(), "//ui:emailfield/@id", field);
    assertXpathNotExists("//ui:emailfield/@disabled", field);
    assertXpathNotExists("//ui:emailfield/@hidden", field);
    assertXpathNotExists("//ui:emailfield/@required", field);
    assertXpathNotExists("//ui:emailfield/@readOnly", field);
    assertXpathNotExists("//ui:emailfield/@maxLength", field);
    assertXpathNotExists("//ui:emailfield/@toolTip", field);
    assertXpathNotExists("//ui:emailfield/@accessibleText", field);
    assertXpathNotExists("//ui:emailfield/@size", field);
    assertXpathNotExists("//ui:emailfield/@buttonId", field);
    assertXpathNotExists("//ui:emailfield/@list", field);
    assertXpathNotExists("//ui:emailfield/@autocomplete", field);
    field.setDisabled(true);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo("true", "//ui:emailfield/@disabled", field);
    setFlag(field, ComponentModel.HIDE_FLAG, true);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo("true", "//ui:emailfield/@hidden", field);
    field.setMandatory(true);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo("true", "//ui:emailfield/@required", field);
    field.setMaxLength(50);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo("50", "//ui:emailfield/@maxLength", field);
    field.setToolTip("tooltip");
    assertSchemaMatch(field);
    assertXpathEvaluatesTo(field.getToolTip(), "//ui:emailfield/@toolTip", field);
    field.setAccessibleText("accessible");
    assertSchemaMatch(field);
    assertXpathEvaluatesTo(field.getAccessibleText(), "//ui:emailfield/@accessibleText", field);
    field.setColumns(40);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo("40", "//ui:emailfield/@size", field);
    field.setDefaultSubmitButton(button);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo(button.getId(), "//ui:emailfield/@buttonId", field);
    // RFC 2606
    field.setText("nobody@wc.test");
    assertSchemaMatch(field);
    assertXpathEvaluatesTo(field.getText(), "normalize-space(//ui:emailfield)", field);
    field.setSuggestions(suggestions);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo(suggestions.getId(), "//ui:emailfield/@list", field);
    field.setPlaceholder("enter stuff here");
    assertSchemaMatch(field);
    assertXpathEvaluatesTo("enter stuff here", "//ui:emailfield/@placeholder", field);
}
Also used : WContainer(com.github.bordertech.wcomponents.WContainer) WSuggestions(com.github.bordertech.wcomponents.WSuggestions) WEmailField(com.github.bordertech.wcomponents.WEmailField) WButton(com.github.bordertech.wcomponents.WButton) Test(org.junit.Test)

Example 10 with WSuggestions

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

the class WSuggestionsExample method preparePaintComponent.

@Override
protected void preparePaintComponent(final Request request) {
    // To change body of generated methods, choose Tools | Templates.
    super.preparePaintComponent(request);
    if (!isInitialised()) {
        setInitialised(true);
        WSuggestions suggestions = textRO.getSuggestions();
        if (suggestions != null) {
            List<String> suggestionList = suggestions.getSuggestions();
            if (suggestionList != null && suggestionList.size() > 0) {
                textRO.setText(suggestionList.get((int) Math.floor(suggestionList.size() / 2)));
            }
        }
    }
}
Also used : WSuggestions(com.github.bordertech.wcomponents.WSuggestions)

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