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.

GridHeaderFooterComponentsTest.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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.grid;
  17. import static org.junit.Assert.assertFalse;
  18. import java.util.List;
  19. import org.junit.Assert;
  20. import org.junit.Before;
  21. import org.junit.Test;
  22. import com.vaadin.testbench.By;
  23. import com.vaadin.testbench.elements.ButtonElement;
  24. import com.vaadin.testbench.elements.GridElement;
  25. import com.vaadin.testbench.elements.GridElement.GridCellElement;
  26. import com.vaadin.testbench.elements.TextFieldElement;
  27. import com.vaadin.tests.tb3.SingleBrowserTest;
  28. public class GridHeaderFooterComponentsTest extends SingleBrowserTest {
  29. @Before
  30. public void setUp() {
  31. setDebug(true);
  32. openTestURL();
  33. }
  34. @Test
  35. public void hideAndShowComponentsInHeader() {
  36. GridElement grid = $(LegacyGridElement.class).first();
  37. int filterRow = 2;
  38. Assert.assertNull(getHeaderElement(grid, filterRow, 1));
  39. Assert.assertNotNull(getHeaderElement(grid, filterRow, 2));
  40. Assert.assertNotNull(getHeaderElement(grid, filterRow, 3));
  41. // Show (1,2)
  42. grid.getHeaderCell(1, 1).$(ButtonElement.class).first().click();
  43. TextFieldElement textfield = getHeaderElement(grid, filterRow, 1);
  44. Assert.assertNotNull(textfield);
  45. Assert.assertEquals("Filter: string", textfield.getValue());
  46. textfield.setValue("foo");
  47. Assert.assertEquals("1. value change for field in string to foo",
  48. getLogRow(0));
  49. assertNoErrorNotifications();
  50. }
  51. private TextFieldElement getHeaderElement(GridElement grid, int row,
  52. int col) {
  53. GridCellElement cell = grid.getHeaderCell(row, col);
  54. List<TextFieldElement> all = cell.$(TextFieldElement.class).all();
  55. if (all.size() == 0) {
  56. return null;
  57. } else if (all.size() == 1) {
  58. return all.get(0);
  59. } else {
  60. throw new RuntimeException(
  61. "Multiple elements found in the header cell at " + row + ","
  62. + col);
  63. }
  64. }
  65. @Test
  66. public void hideAndShowComponentsInFooter() {
  67. GridElement grid = $(LegacyGridElement.class).first();
  68. int filterRow = 0;
  69. Assert.assertNull(getFooterElement(grid, filterRow, 1));
  70. Assert.assertNotNull(getFooterElement(grid, filterRow, 2));
  71. Assert.assertNotNull(getFooterElement(grid, filterRow, 3));
  72. // Show (1,2)
  73. grid.getFooterCell(1, 1).$(ButtonElement.class).first().click();
  74. TextFieldElement textfield = getFooterElement(grid, filterRow, 1);
  75. Assert.assertNotNull(textfield);
  76. Assert.assertEquals("Filter: string", textfield.getValue());
  77. textfield.setValue("foo");
  78. Assert.assertEquals("1. value change for field in string to foo",
  79. getLogRow(0));
  80. assertNoErrorNotifications();
  81. }
  82. private TextFieldElement getFooterElement(GridElement grid, int row,
  83. int col) {
  84. GridCellElement cell = grid.getFooterCell(row, col);
  85. List<TextFieldElement> all = cell.$(TextFieldElement.class).all();
  86. if (all.size() == 0) {
  87. return null;
  88. } else if (all.size() == 1) {
  89. return all.get(0);
  90. } else {
  91. throw new RuntimeException(
  92. "Multiple elements found in the footer cell at " + row + ","
  93. + col);
  94. }
  95. }
  96. @Test
  97. public void testRemoveAllHeadersAndFooters() {
  98. openTestURL();
  99. for (int i = 2; i >= 0; --i) {
  100. // Remove Header
  101. $(LegacyGridElement.class).first().getHeaderCell(i, 0)
  102. .$(ButtonElement.class).first().click();
  103. assertFalse("Header " + i + " should not be present.",
  104. $(LegacyGridElement.class).first()
  105. .isElementPresent(By.vaadin("#header[" + i + "]")));
  106. // Remove Footer
  107. $(LegacyGridElement.class).first().getFooterCell(i, 0)
  108. .$(ButtonElement.class).first().click();
  109. assertFalse("Footer " + i + " should not be present.",
  110. $(LegacyGridElement.class).first()
  111. .isElementPresent(By.vaadin("#footer[" + i + "]")));
  112. }
  113. assertNoErrorNotifications();
  114. }
  115. }