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.

GridDetailsWidthTest.java 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright 2000-2014 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 java.util.List;
  18. import org.junit.Assert;
  19. import org.junit.Test;
  20. import org.openqa.selenium.By;
  21. import org.openqa.selenium.WebElement;
  22. import com.vaadin.testbench.elements.GridElement;
  23. import com.vaadin.testbench.elements.GridElement.GridCellElement;
  24. import com.vaadin.testbench.parallel.TestCategory;
  25. import com.vaadin.tests.tb3.SingleBrowserTest;
  26. @TestCategory("grid")
  27. public class GridDetailsWidthTest extends SingleBrowserTest {
  28. @Test
  29. public void testSpacerTDsHaveNoWidth() {
  30. openTestURL();
  31. GridElement grid = $(GridElement.class).first();
  32. // Open all details rows
  33. grid.getCell(0, 0).click();
  34. checkSpacersHaveNoWidths(1);
  35. grid.getCell(1, 0).click();
  36. checkSpacersHaveNoWidths(2);
  37. grid.getCell(2, 0).click();
  38. checkSpacersHaveNoWidths(3);
  39. // Close all details rows
  40. grid.getCell(2, 0).click();
  41. checkSpacersHaveNoWidths(2);
  42. grid.getCell(1, 0).click();
  43. checkSpacersHaveNoWidths(1);
  44. grid.getCell(0, 0).click();
  45. checkSpacersHaveNoWidths(0);
  46. }
  47. private void checkSpacersHaveNoWidths(int expectedCount) {
  48. List<WebElement> spacers = findElements(By.className("v-grid-spacer"));
  49. Assert.assertEquals("Wrong amount of spacers visible.", expectedCount,
  50. spacers.size());
  51. for (WebElement spacer : spacers) {
  52. Assert.assertFalse("Spacer element had an unexpected width set.",
  53. spacer.findElement(By.tagName("td")).getAttribute("style")
  54. .contains("width"));
  55. }
  56. }
  57. @Test
  58. public void testDetailsOnSort() {
  59. openTestURL();
  60. GridElement grid = $(GridElement.class).first();
  61. // Open a details rows
  62. grid.getCell(0, 0).click();
  63. GridCellElement cell = grid.getHeaderCell(0, 0);
  64. cell.click();
  65. cell.click();
  66. cell = grid.getCell(2, 0);
  67. WebElement spacer = findElement(By.className("v-grid-spacer"));
  68. Assert.assertEquals("Grid was not sorted correctly", "Hello 0",
  69. cell.getText());
  70. Assert.assertEquals("Details row was not in correct location", cell
  71. .getLocation().getY() + cell.getSize().getHeight(), spacer
  72. .getLocation().getY());
  73. }
  74. }