You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ComboBoxEmptyCaptionTest.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests.components.combobox;
  17. import java.util.ArrayList;
  18. import java.util.Arrays;
  19. import org.junit.Assert;
  20. import org.junit.Before;
  21. import org.junit.Test;
  22. import com.vaadin.testbench.elements.ButtonElement;
  23. import com.vaadin.testbench.elements.ComboBoxElement;
  24. import com.vaadin.tests.tb3.MultiBrowserTest;
  25. /**
  26. * @author Vaadin Ltd
  27. *
  28. */
  29. public class ComboBoxEmptyCaptionTest extends MultiBrowserTest {
  30. @Before
  31. public void setUp() {
  32. openTestURL();
  33. }
  34. @Test
  35. public void emptyItemCaption() {
  36. ComboBoxElement combo = $(ComboBoxElement.class).first();
  37. // empty string in caption becomes   because of #7506
  38. ensureSuggestions(combo, " ", "item1", "item2", "item3", "item4",
  39. "item5", "item6", "item7", "item8", "item9");
  40. }
  41. @Test
  42. public void hasEmptyItemCaption() {
  43. ComboBoxElement combo = $(ComboBoxElement.class).first();
  44. // set some caption for the empty selection element
  45. $(ButtonElement.class).first().click();
  46. ensureSuggestions(combo, "empty", "item1", "item2", "item3", "item4",
  47. "item5", "item6", "item7", "item8", "item9");
  48. }
  49. @Test
  50. public void resetEmptyItem() {
  51. ComboBoxElement combo = $(ComboBoxElement.class).first();
  52. // set some caption for the empty selection element
  53. $(ButtonElement.class).first().click();
  54. // set empty string back as an empty caption
  55. $(ButtonElement.class).get(1).click();
  56. ensureSuggestions(combo, " ", "item1", "item2", "item3", "item4",
  57. "item5", "item6", "item7", "item8", "item9");
  58. }
  59. @Test
  60. public void disableEmptyItem() {
  61. ComboBoxElement combo = $(ComboBoxElement.class).first();
  62. // set some caption for the empty selection element
  63. $(ButtonElement.class).get(2).click();
  64. ensureSuggestions(combo, "item1", "item2", "item3", "item4", "item5",
  65. "item6", "item7", "item8", "item9", "item10");
  66. }
  67. private void ensureSuggestions(ComboBoxElement element,
  68. String... suggestions) {
  69. element.openPopup();
  70. System.out.println(element.getPopupSuggestions());
  71. Assert.assertEquals(Arrays.asList(suggestions),
  72. new ArrayList<>(element.getPopupSuggestions()));
  73. }
  74. }