Skip to content

Commit 75e8410

Browse files
committed
Provided JUnit Test for Pull Request 222
1 parent 7169fc2 commit 75e8410

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

src/main/java/gwt/material/design/addins/client/autocomplete/MaterialAutoComplete.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public class MaterialAutoComplete extends AbstractValueWidget<List<? extends Sug
176176
private UnorderedList list = new UnorderedList();
177177
private SuggestOracle suggestions;
178178
private TextBox itemBox = new TextBox();
179-
private SuggestBox box;
179+
private SuggestBox suggestBox;
180180
private int limit = 0;
181181
private MaterialLabel errorLabel = new MaterialLabel();
182182
private final ProgressMixin<MaterialAutoComplete> progressMixin = new ProgressMixin<>(this);
@@ -231,16 +231,16 @@ protected void build(SuggestOracle suggestions) {
231231
final ListItem item = new ListItem();
232232

233233
item.setStyleName(AddinsCssName.MULTIVALUESUGGESTBOX_INPUT_TOKEN);
234-
box = new SuggestBox(suggestions, itemBox);
234+
suggestBox = new SuggestBox(suggestions, itemBox);
235235
setLimit(this.limit);
236236
String autocompleteId = DOM.createUniqueId();
237237
itemBox.getElement().setId(autocompleteId);
238238

239-
item.add(box);
239+
item.add(suggestBox);
240240
item.add(placeholderLabel);
241241
list.add(item);
242242

243-
list.addDomHandler(event -> box.showSuggestionList(), ClickEvent.getType());
243+
list.addDomHandler(event -> suggestBox.showSuggestionList(), ClickEvent.getType());
244244

245245
itemBox.addBlurHandler(blurEvent -> {
246246
if (getValue().size() > 0) {
@@ -301,9 +301,9 @@ protected void build(SuggestOracle suggestions) {
301301
}
302302
});
303303

304-
itemBox.addClickHandler(event -> box.showSuggestionList());
304+
itemBox.addClickHandler(event -> suggestBox.showSuggestionList());
305305

306-
box.addSelectionHandler(selectionEvent -> {
306+
suggestBox.addSelectionHandler(selectionEvent -> {
307307
Suggestion selectedItem = selectionEvent.getSelectedItem();
308308
itemBox.setValue("");
309309
if (addItem(selectedItem)) {
@@ -316,7 +316,7 @@ protected void build(SuggestOracle suggestions) {
316316
panel.getElement().setAttribute("onclick",
317317
"document.getElementById('" + autocompleteId + "').focus()");
318318
panel.add(errorLabel);
319-
box.setFocus(true);
319+
suggestBox.setFocus(true);
320320
}
321321

322322
protected boolean tryRemoveSuggestion(Widget widget) {
@@ -379,7 +379,7 @@ protected boolean addItem(final Suggestion suggestion) {
379379
list.remove(displayItem);
380380
itemsHighlighted.remove(displayItem);
381381
ValueChangeEvent.fire(MaterialAutoComplete.this, getValue());
382-
box.showSuggestionList();
382+
suggestBox.showSuggestionList();
383383
}
384384
});
385385
}
@@ -503,8 +503,8 @@ public int getLimit() {
503503

504504
public void setLimit(int limit) {
505505
this.limit = limit;
506-
if (this.box != null) {
507-
this.box.setLimit(limit);
506+
if (this.suggestBox != null) {
507+
this.suggestBox.setLimit(limit);
508508
}
509509
}
510510

@@ -515,8 +515,8 @@ public void setLimit(int limit) {
515515
* @param limit
516516
*/
517517
public void setAutoSuggestLimit(int limit) {
518-
if (this.box != null) {
519-
this.box.setLimit(limit);
518+
if (this.suggestBox != null) {
519+
this.suggestBox.setLimit(limit);
520520
}
521521
}
522522

@@ -823,4 +823,8 @@ public TextBox getItemBox() {
823823
public MaterialLabel getErrorLabel() {
824824
return errorLabel;
825825
}
826+
827+
public SuggestBox getSuggestBox() {
828+
return suggestBox;
829+
}
826830
}

src/test/java/gwt/material/design/addins/client/MaterialAutocompleteTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ public void init() {
4242
checkWidget(autoComplete);
4343
checkPlaceholder(autoComplete);
4444
checkValue(autoComplete);
45+
checkLimit(autoComplete);
46+
}
47+
48+
protected void checkLimit(MaterialAutoComplete autocomplete) {
49+
final int LIMIT = 2;
50+
autocomplete.setLimit(LIMIT);
51+
assertEquals(autocomplete.getLimit() , LIMIT);
52+
53+
autocomplete.setAutoSuggestLimit(LIMIT);
54+
assertEquals(autocomplete.getSuggestBox().getLimit(), LIMIT);
4555
}
4656

4757
@Override

0 commit comments

Comments
 (0)