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.

GridInitiallyHiddenColumnsTest.java 3.0KB

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.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.parallel.TestCategory;
  24. import com.vaadin.tests.tb3.SingleBrowserTest;
  25. @TestCategory("grid")
  26. public class GridInitiallyHiddenColumnsTest extends SingleBrowserTest {
  27. @Test
  28. public void ensureCorrectlyRendered() {
  29. openTestURL("debug");
  30. GridElement grid = $(LegacyGridElement.class).first();
  31. Assert.assertEquals("Rowling", grid.getCell(0, 0).getText());
  32. Assert.assertEquals("Scott", grid.getCell(1, 0).getText());
  33. getSidebarOpenButton(grid).click();
  34. getColumnHidingToggle(grid, "First Name").click();
  35. getColumnHidingToggle(grid, "Age").click();
  36. getSidebarOpenButton(grid).click();
  37. Assert.assertEquals("Umberto", grid.getCell(0, 0).getText());
  38. Assert.assertEquals("Rowling", grid.getCell(0, 1).getText());
  39. Assert.assertEquals("25", grid.getCell(0, 2).getText());
  40. Assert.assertEquals("Dan", grid.getCell(1, 0).getText());
  41. Assert.assertEquals("Scott", grid.getCell(1, 1).getText());
  42. Assert.assertEquals("54", grid.getCell(1, 2).getText());
  43. }
  44. // TODO: as to the getX methods reuse ones from GridBasicFeaturesTest?
  45. protected WebElement getSidebarOpenButton(GridElement grid) {
  46. List<WebElement> elements = grid
  47. .findElements(By.className("v-grid-sidebar-button"));
  48. return elements.isEmpty() ? null : elements.get(0);
  49. }
  50. /**
  51. * Returns the toggle inside the sidebar for hiding the column at the given
  52. * index, or null if not found.
  53. */
  54. protected WebElement getColumnHidingToggle(GridElement grid,
  55. String caption) {
  56. WebElement sidebar = getSidebar(grid);
  57. List<WebElement> elements = sidebar
  58. .findElements(By.className("column-hiding-toggle"));
  59. for (WebElement e : elements) {
  60. if (caption.equalsIgnoreCase(e.getText())) {
  61. return e;
  62. }
  63. }
  64. return null;
  65. }
  66. protected WebElement getSidebar(GridElement grid) {
  67. List<WebElement> elements = findElements(
  68. By.className("v-grid-sidebar-popup"));
  69. return elements.isEmpty() ? null : elements.get(0);
  70. }
  71. }