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.

GridHeaderStyleNamesTest.java 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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.Before;
  19. import org.junit.Test;
  20. import org.openqa.selenium.By;
  21. import org.openqa.selenium.WebElement;
  22. import com.vaadin.testbench.elements.ButtonElement;
  23. import com.vaadin.testbench.elements.GridElement;
  24. import com.vaadin.testbench.elements.GridElement.GridCellElement;
  25. import com.vaadin.testbench.parallel.TestCategory;
  26. import com.vaadin.tests.tb3.SingleBrowserTest;
  27. @TestCategory("grid")
  28. public class GridHeaderStyleNamesTest extends SingleBrowserTest {
  29. private GridElement grid;
  30. @Before
  31. public void findGridCells() {
  32. openTestURL();
  33. grid = $(LegacyGridElement.class).first();
  34. }
  35. private GridCellElement getMergedHeaderCell() {
  36. return grid.getHeaderCell(0, 3);
  37. }
  38. private WebElement getMergedHeaderCellContent() {
  39. return getMergedHeaderCell().findElement(
  40. By.cssSelector("div.v-grid-column-header-content"));
  41. }
  42. private GridCellElement getAgeFooterCell() {
  43. return grid.getFooterCell(0, 2);
  44. }
  45. private WebElement getAgeFooterCellContent() {
  46. return getAgeFooterCell().findElement(
  47. By.cssSelector("div.v-grid-column-footer-content"));
  48. }
  49. @Test
  50. public void cellStyleNamesCanBeAddedAndRemoved() {
  51. ButtonElement toggleStyles = $(ButtonElement.class)
  52. .caption("Toggle styles").first();
  53. assertStylesSet(true);
  54. toggleStyles.click();
  55. assertStylesSet(false);
  56. toggleStyles.click();
  57. assertStylesSet(true);
  58. }
  59. @Test
  60. public void rowStyleNamesCanBeAddedAndRemoved() {
  61. ButtonElement toggleStyles = $(ButtonElement.class)
  62. .caption("Toggle styles").first();
  63. assertRowStylesSet(true);
  64. toggleStyles.click();
  65. assertRowStylesSet(false);
  66. toggleStyles.click();
  67. assertRowStylesSet(true);
  68. }
  69. private void assertStylesSet(boolean set) {
  70. if (set) {
  71. assertHasStyleName(
  72. "Footer cell should have the assigned 'age-footer' class name",
  73. getAgeFooterCell(), "age-footer");
  74. assertHasStyleName(
  75. "Header cell should have the assigned 'age' class name",
  76. getAgeHeaderCell(), "age");
  77. assertHasStyleName(
  78. "The merged header cell should have the assigned 'city-country' class name",
  79. getMergedHeaderCell(), "city-country");
  80. } else {
  81. assertHasNotStyleName(
  82. "Footer cell should not have the removed 'age-footer' class name",
  83. getAgeFooterCell(), "age-footer");
  84. assertHasNotStyleName(
  85. "Header cell should not have the removed 'age' class name",
  86. getAgeHeaderCell(), "age");
  87. assertHasNotStyleName(
  88. "Ther merged header cell should not have the removed 'city-country' class name",
  89. getMergedHeaderCell(), "city-country");
  90. }
  91. assertHasStyleName(
  92. "The default v-grid-cell style name should not be removed from the header cell",
  93. getAgeHeaderCell(), "v-grid-cell");
  94. assertHasStyleName(
  95. "The default v-grid-cell style name should not be removed from the footer cell",
  96. getAgeFooterCell(), "v-grid-cell");
  97. assertHasStyleName(
  98. "The default v-grid-cell style name should not be removed from the merged header cell",
  99. getMergedHeaderCell(), "v-grid-cell");
  100. }
  101. private void assertRowStylesSet(boolean set) {
  102. if (set) {
  103. assertHasStyleName(
  104. "Footer row should have the assigned 'custom-row' class name",
  105. getFooterRow(), "custom-row");
  106. assertHasStyleName(
  107. "Header row should have the assigned 'custom-row' class name",
  108. getHeaderRow(), "custom-row");
  109. } else {
  110. assertHasNotStyleName(
  111. "Footer row should not have the removed 'custom-row' class name",
  112. getFooterRow(), "custom-row");
  113. assertHasNotStyleName(
  114. "Header row should not have the removed 'custom-row' class name",
  115. getHeaderRow(), "custom-row");
  116. }
  117. assertHasStyleName(
  118. "The default v-grid-row style name should not be removed from the header row",
  119. getHeaderRow(), "v-grid-row");
  120. assertHasStyleName(
  121. "The default v-grid-row style name should not be removed from the footer row",
  122. getFooterRow(), "v-grid-row");
  123. }
  124. private WebElement getAgeHeaderCell() {
  125. return grid.getHeaderCell(1, 2);
  126. }
  127. private WebElement getAgeHeaderCellContent() {
  128. return getAgeHeaderCell().findElement(
  129. By.cssSelector("div.v-grid-column-header-content"));
  130. }
  131. private WebElement getFooterRow() {
  132. return grid.getFooterRow(0);
  133. }
  134. private WebElement getHeaderRow() {
  135. return grid.getHeaderRow(0);
  136. }
  137. private void assertHasStyleName(String message, WebElement element,
  138. String stylename) {
  139. if (!hasCssClass(element, stylename)) {
  140. Assert.fail(message);
  141. }
  142. }
  143. private void assertHasNotStyleName(String message, WebElement element,
  144. String stylename) {
  145. if (hasCssClass(element, stylename)) {
  146. Assert.fail(message);
  147. }
  148. }
  149. }