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

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