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.

GridClientColumnPropertiesTest.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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.client;
  17. import static org.junit.Assert.assertEquals;
  18. import static org.junit.Assert.assertFalse;
  19. import static org.junit.Assert.assertTrue;
  20. import org.junit.Test;
  21. import com.vaadin.testbench.elements.GridElement;
  22. import com.vaadin.testbench.elements.NotificationElement;
  23. import com.vaadin.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest;
  24. import com.vaadin.tests.widgetset.client.grid.GridBasicClientFeaturesWidget;
  25. public class GridClientColumnPropertiesTest extends GridBasicClientFeaturesTest {
  26. @Test
  27. public void initialColumnWidths() {
  28. openTestURL();
  29. for (int col = 0; col < GridBasicClientFeaturesWidget.COLUMNS; col++) {
  30. int width = getGridElement().getCell(0, col).getSize().getWidth();
  31. if (col <= 6) {
  32. // Growing column widths
  33. int expectedWidth = 50 + col * 25;
  34. assertEquals("column " + col + " has incorrect width",
  35. expectedWidth, width);
  36. }
  37. }
  38. }
  39. @Test
  40. public void testChangingColumnWidth() {
  41. openTestURL();
  42. selectMenuPath("Component", "Columns", "Column 0", "Width", "50px");
  43. int width = getGridElement().getCell(0, 0).getSize().getWidth();
  44. assertEquals(50, width);
  45. selectMenuPath("Component", "Columns", "Column 0", "Width", "200px");
  46. width = getGridElement().getCell(0, 0).getSize().getWidth();
  47. assertEquals(200, width);
  48. selectMenuPath("Component", "Columns", "Column 0", "Width", "auto");
  49. int autoWidth = getGridElement().getCell(0, 0).getSize().getWidth();
  50. assertLessThan("Automatic sizing should've shrunk the column",
  51. autoWidth, width);
  52. }
  53. @Test
  54. public void testFrozenColumns() {
  55. openTestURL();
  56. assertFalse(cellIsFrozen(0, 0));
  57. assertFalse(cellIsFrozen(0, 1));
  58. selectMenuPath("Component", "State", "Frozen column count", "1 columns");
  59. assertTrue(cellIsFrozen(1, 0));
  60. assertFalse(cellIsFrozen(1, 1));
  61. selectMenuPath("Component", "State", "Selection mode", "multi");
  62. assertTrue(cellIsFrozen(1, 1));
  63. assertFalse(cellIsFrozen(1, 2));
  64. selectMenuPath("Component", "State", "Frozen column count", "0 columns");
  65. assertTrue(cellIsFrozen(1, 0));
  66. assertFalse(cellIsFrozen(1, 1));
  67. selectMenuPath("Component", "State", "Frozen column count",
  68. "-1 columns");
  69. assertFalse(cellIsFrozen(1, 0));
  70. }
  71. @Test
  72. public void testBrokenRenderer() {
  73. setDebug(true);
  74. openTestURL();
  75. GridElement gridElement = getGridElement();
  76. // Scroll first row out of view
  77. gridElement.getRow(50);
  78. // Enable broken renderer for the first row
  79. selectMenuPath("Component", "Columns", "Column 0", "Broken renderer");
  80. // Shouldn't have an error notification yet
  81. assertFalse("Notification was present",
  82. isElementPresent(NotificationElement.class));
  83. // Scroll broken row into view and enjoy the chaos
  84. gridElement.getRow(0);
  85. assertTrue("Notification was not present",
  86. isElementPresent(NotificationElement.class));
  87. assertFalse("Text in broken cell should have old value",
  88. "(0, 0)".equals(gridElement.getCell(0, 0).getText()));
  89. assertEquals("Neighbour cell should be updated", "(0, 1)", gridElement
  90. .getCell(0, 1).getText());
  91. assertEquals("Neighbour cell should be updated", "(1, 0)", gridElement
  92. .getCell(1, 0).getText());
  93. }
  94. private boolean cellIsFrozen(int row, int col) {
  95. return getGridElement().getCell(row, col).isFrozen();
  96. }
  97. }