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.

TableToggleColumnVisibilityTest.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright 2000-2013 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.table;
  17. import static org.junit.Assert.assertEquals;
  18. import static org.junit.Assert.assertFalse;
  19. import static org.junit.Assert.assertTrue;
  20. import org.junit.Test;
  21. import org.openqa.selenium.By;
  22. import com.vaadin.testbench.elements.ButtonElement;
  23. import com.vaadin.testbench.elements.TableElement;
  24. import com.vaadin.testbench.elements.TableHeaderElement;
  25. import com.vaadin.tests.tb3.MultiBrowserTest;
  26. /**
  27. * Tests that column keeps its header, icon, alignment after toggling visibility
  28. * (#6245, #12303).
  29. *
  30. * @author Vaadin Ltd
  31. */
  32. public class TableToggleColumnVisibilityTest extends MultiBrowserTest {
  33. @Test
  34. public void testColumnWidthRestoredAfterTogglingVisibility() {
  35. openTestURL();
  36. ButtonElement toggleVisibilityButton = $(ButtonElement.class)
  37. .id("visib-toggler");
  38. ButtonElement changeOrderButton = $(ButtonElement.class)
  39. .id("order-toggler");
  40. checkHeaderAttributes(1);
  41. toggleVisibilityButton.click(); // hide column #1
  42. assertEquals("One column should be visible",
  43. findElements(By.className("v-table-header-cell")).size(), 1);
  44. toggleVisibilityButton.click(); // restore column #1
  45. assertEquals("Two columns should be visible",
  46. findElements(By.className("v-table-header-cell")).size(), 2);
  47. checkHeaderAttributes(1);
  48. // change column order, column #1 now becomes column #0
  49. changeOrderButton.click();
  50. checkHeaderAttributes(0);
  51. }
  52. /*
  53. * Checks column header with number columnNumber.
  54. */
  55. private void checkHeaderAttributes(int columnNumber) {
  56. TableHeaderElement headerCell = $(TableElement.class).first()
  57. .getHeaderCell(columnNumber);
  58. assertTrue("Column header text should be custom",
  59. headerCell.getText().equalsIgnoreCase("Hello World"));
  60. assertFalse("Column should have an icon",
  61. headerCell.findElements(By.className("v-icon")).isEmpty());
  62. assertFalse("Column should have alignment to the right", headerCell
  63. .findElements(
  64. By.className("v-table-caption-container-align-right"))
  65. .isEmpty());
  66. }
  67. }