Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

EscalatorColspanTest.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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.basicfeatures.escalator;
  17. import static org.junit.Assert.assertEquals;
  18. import org.junit.Test;
  19. import org.openqa.selenium.WebElement;
  20. import com.vaadin.tests.components.grid.basicfeatures.EscalatorBasicClientFeaturesTest;
  21. public class EscalatorColspanTest extends EscalatorBasicClientFeaturesTest {
  22. private static final int NO_COLSPAN = 1;
  23. @Test
  24. public void testNoColspan() {
  25. openTestURL();
  26. populate();
  27. assertEquals(NO_COLSPAN, getColSpan(getHeaderCell(0, 0)));
  28. assertEquals(NO_COLSPAN, getColSpan(getBodyCell(0, 0)));
  29. assertEquals(NO_COLSPAN, getColSpan(getFooterCell(0, 0)));
  30. }
  31. @Test
  32. public void testColspan() {
  33. openTestURL();
  34. populate();
  35. int firstCellWidth = getWidth(getBodyCell(0, 0));
  36. int secondCellWidth = getWidth(getBodyCell(0, 1));
  37. int doubleCellWidth = firstCellWidth + secondCellWidth;
  38. selectMenuPath(FEATURES, COLUMN_SPANNING, COLSPAN_NORMAL);
  39. WebElement bodyCell = getBodyCell(0, 0);
  40. assertEquals(2, getColSpan(bodyCell));
  41. assertEquals(doubleCellWidth, getWidth(bodyCell));
  42. }
  43. @Test
  44. public void testColspanToggle() {
  45. openTestURL();
  46. populate();
  47. int singleCellWidth = getWidth(getBodyCell(0, 0));
  48. selectMenuPath(FEATURES, COLUMN_SPANNING, COLSPAN_NORMAL);
  49. selectMenuPath(FEATURES, COLUMN_SPANNING, COLSPAN_NONE);
  50. WebElement bodyCell = getBodyCell(0, 0);
  51. assertEquals(NO_COLSPAN, getColSpan(bodyCell));
  52. assertEquals(singleCellWidth, getWidth(bodyCell));
  53. }
  54. private static int getWidth(WebElement element) {
  55. String widthString = element.getCssValue("width"); // e.g. 100px
  56. if ("0".equals(widthString)) {
  57. return 0;
  58. } else if (widthString.endsWith("px")) {
  59. return Integer.parseInt(widthString.substring(0,
  60. widthString.length() - 2));
  61. } else {
  62. throw new IllegalStateException("Element width expressed "
  63. + "in an unsupported format: " + widthString);
  64. }
  65. }
  66. private static int getColSpan(WebElement cell) {
  67. String attribute = cell.getAttribute("colspan");
  68. if (attribute == null) {
  69. return NO_COLSPAN;
  70. } else {
  71. return Integer.parseInt(attribute);
  72. }
  73. }
  74. }