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.

GridHeaderFormatChangeTest.java 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 org.junit.Assert;
  18. import org.junit.Test;
  19. import org.openqa.selenium.By;
  20. import com.vaadin.testbench.elements.ButtonElement;
  21. import com.vaadin.testbench.elements.GridElement;
  22. import com.vaadin.testbench.parallel.TestCategory;
  23. import com.vaadin.tests.tb3.MultiBrowserTest;
  24. @TestCategory("grid")
  25. public class GridHeaderFormatChangeTest extends MultiBrowserTest {
  26. @Test
  27. public void testHeaderRetainsSelectAllForColumnRemoval() {
  28. openTestURL();
  29. GridElement grid = $(GridElement.class).first();
  30. // Assert that we do not have the select all checkbox
  31. Assert.assertTrue(
  32. "Found input in header even though none should exist.",
  33. grid.getHeader().findElements(By.tagName("input")).isEmpty());
  34. // Set grid into multiselection mode
  35. toggleSelectionMode();
  36. // Assert that we now have a select all checkbox in the header
  37. Assert.assertFalse("Expected one input field in header",
  38. grid.getHeader().findElements(By.tagName("input")).isEmpty());
  39. // Hide the firstName column from the grid.
  40. toggleFirstName();
  41. // Assert that we still have the select all checkbox in the header.
  42. Assert.assertFalse("Header was missing checkbox after hiding column",
  43. grid.getHeader().findElements(By.tagName("input")).isEmpty());
  44. // Show the firstName column.
  45. toggleFirstName();
  46. // Assert that we still have the select all checkbox in the header.
  47. Assert.assertFalse(
  48. "Header was missing checkbox after bringing back column",
  49. grid.getHeader().findElements(By.tagName("input")).isEmpty());
  50. }
  51. @Test
  52. public void testHeaderRetainsSelectAllForJoinColumnAdd() {
  53. openTestURL();
  54. GridElement grid = $(GridElement.class).first();
  55. // Assert that we do not have the select all checkbox
  56. Assert.assertTrue(
  57. "Found input in header even though none should exist.",
  58. grid.getHeader().findElements(By.tagName("input")).isEmpty());
  59. // Set grid into multiselection mode
  60. toggleSelectionMode();
  61. // Assert that we now have a select all checkbox in the header
  62. Assert.assertFalse("Expected one input field in header",
  63. grid.getHeader().findElements(By.tagName("input")).isEmpty());
  64. // Add Join columns header
  65. toggleJoin();
  66. // Assert that we still have the select all checkbox in the header.
  67. Assert.assertFalse("Header was missing checkbox after hiding column",
  68. grid.getHeader().findElements(By.tagName("input")).isEmpty());
  69. // remove Join Columns header
  70. toggleJoin();
  71. // Assert that we still have the select all checkbox in the header.
  72. Assert.assertFalse(
  73. "Header was missing checkbox after bringing back column",
  74. grid.getHeader().findElements(By.tagName("input")).isEmpty());
  75. }
  76. @Test
  77. public void selectAllShouldKeepState() {
  78. openTestURL();
  79. GridElement grid = $(GridElement.class).first();
  80. // Assert that we do not have the select all checkbox
  81. Assert.assertTrue(
  82. "Found input in header even though none should exist.",
  83. grid.getHeader().findElements(By.tagName("input")).isEmpty());
  84. // Set grid into multiselection mode
  85. toggleSelectionMode();
  86. // Assert that we now have a select all checkbox in the header
  87. Assert.assertFalse("Should not be selected after adding",
  88. grid.getHeader().findElement(By.tagName("input")).isSelected());
  89. grid.getHeader().findElement(By.tagName("input")).click();
  90. // Assert that checkbox is checked
  91. assertSelectAllChecked(
  92. "Not selected even though we just clicked selection", grid);
  93. // Hide the firstName column from the grid.
  94. toggleFirstName();
  95. // Assert that checkbox is still checked
  96. assertSelectAllChecked("Selection disappeared after removing column",
  97. grid);
  98. // Show the firstName column.
  99. toggleFirstName();
  100. // Assert that checkbox is still checked
  101. assertSelectAllChecked("Selection disappeared after adding column",
  102. grid);
  103. }
  104. private void assertSelectAllChecked(String message, GridElement grid) {
  105. Assert.assertTrue(message,
  106. grid.getHeader().findElement(By.tagName("input")).isSelected());
  107. }
  108. private void toggleSelectionMode() {
  109. $(ButtonElement.class).id("selection_mode").click();
  110. }
  111. private void toggleFirstName() {
  112. $(ButtonElement.class).id("show_hide").click();
  113. }
  114. private void toggleJoin() {
  115. $(ButtonElement.class).id("join").click();
  116. }
  117. }