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 5.5KB

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