updateUI(new RequestHandler() {
@SuppressWarnings("unchecked")
@Override
public void onRequest() {
final PSuggestBox suggestBox1 = new PSuggestBox();
suggestBox1.getSuggestOracle().add("Suggest 1");
suggestBox1.getSuggestOracle().add("Suggest 2");
suggestBox1.getSuggestOracle().add("Suggest 3");
suggestBox1.getSuggestOracle().add("Suggest 4");
suggestBox1.ensureDebugId("suggestBox1");
suggestBox1.addSelectionHandler(eventsListener);
PRootPanel.get().add(suggestBox1);
register(suggestBox1);
}
});
WebElement element = findElementById("suggestBox1");
final PSuggestBox pSuggestBox1 = get("suggestBox1");
element.sendKeys("su");
final WebElement popup = findElementById("suggestBox1-popup");
final List<WebElement> items = popup.findElements(By.className("item"));
Assert.assertEquals(4, items.size());
Assert.assertEquals("Suggest 1", items.get(0).getText());
Assert.assertEquals("Suggest 2", items.get(1).getText());
Assert.assertEquals("Suggest 3", items.get(2).getText());
Assert.assertEquals("Suggest 4", items.get(3).getText());
items.get(2).click();
final PSelectionEvent<PSuggestion> selection1 = eventsListener.poll();
Assert.assertEquals("Suggest 3", selection1.getSelectedItem().getReplacementString());
Assert.assertEquals("Suggest 3", pSuggestBox1.getText());
Assert.assertEquals("Suggest 3", pSuggestBox1.getTextBox().getText());
// set text
updateUI(new RequestHandler() {
@Override
public void onRequest() {
final PSuggestBox suggestBox1 = get("suggestBox1");
suggestBox1.setText("Custom text");
}
});
element = findElementById("suggestBox1");
Assert.assertEquals("Custom text", element.getAttribute("value"));
Assert.assertEquals(true, element.isEnabled());
// disable
updateUI(new RequestHandler() {
@Override
public void onRequest() {
final PSuggestBox suggestBox1 = get("suggestBox1");
suggestBox1.getTextBox().setEnabled(false);
}
});
element = findElementById("suggestBox1");
Assert.assertEquals(false, element.isEnabled());