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.

GridColumnWidthRecalculationTest.java 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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.Dimension;
  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 GridColumnWidthRecalculationTest extends SingleBrowserTest {
  28. private GridElement grid;
  29. @Before
  30. public void open() {
  31. openTestURL();
  32. grid = $(LegacyGridElement.class).first();
  33. }
  34. @Test
  35. public void columnWidthAfterSwap() {
  36. int column0Width = getColumnWidth(0);
  37. int column1Width = getColumnWidth(1);
  38. Assert.assertTrue("Column 0 should be narrower than column 1 initially",
  39. column0Width < column1Width);
  40. $(ButtonElement.class).caption("Swap content").first().click();
  41. Assert.assertEquals(
  42. "Column 0 width should not change when swapping contents only",
  43. column0Width, getColumnWidth(0));
  44. Assert.assertEquals(
  45. "Column 1 width should not change when swapping contents only",
  46. column1Width, getColumnWidth(1));
  47. }
  48. @Test
  49. public void columnWidthAfterSwapAndRecalculate() {
  50. int column0Width = getColumnWidth(0);
  51. int column1Width = getColumnWidth(1);
  52. Assert.assertTrue("Column 0 should be narrower than column 1 initially",
  53. column0Width < column1Width);
  54. $(ButtonElement.class).caption("Swap content and recalculate columns")
  55. .first().click();
  56. column0Width = getColumnWidth(0);
  57. column1Width = getColumnWidth(1);
  58. Assert.assertTrue(
  59. "Column 1 should be narrower than column 0 after resize",
  60. column1Width < column0Width);
  61. }
  62. private int getColumnWidth(int columnIndex) {
  63. GridCellElement headerColumn = grid.getHeaderCells(0).get(columnIndex);
  64. Dimension column1Size = headerColumn.getSize();
  65. int columnWidth = column1Size.getWidth();
  66. return columnWidth;
  67. }
  68. }