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.

GridGeneratedPropertiesTest.java 3.3KB

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;
  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.GridElement.GridCellElement;
  23. import com.vaadin.testbench.elements.NotificationElement;
  24. import com.vaadin.testbench.parallel.TestCategory;
  25. import com.vaadin.tests.tb3.MultiBrowserTest;
  26. @TestCategory("grid")
  27. public class GridGeneratedPropertiesTest extends MultiBrowserTest {
  28. @Test
  29. public void testMilesColumnExists() {
  30. openTestURL();
  31. GridElement grid = $(GridElement.class).first();
  32. assertEquals("Miles header wasn't present.", "miles", grid
  33. .getHeaderCell(0, 2).getText().toLowerCase());
  34. }
  35. @Test
  36. public void testUnsortableGeneratedProperty() {
  37. openTestURL();
  38. GridElement grid = $(GridElement.class).first();
  39. // Overwritten foo property should not be sortable
  40. GridCellElement fooHeader = grid.getHeaderCell(0, 0);
  41. fooHeader.click();
  42. assertFalse("Column foo was unexpectedly sorted.", fooHeader
  43. .getAttribute("class").contains("sort"));
  44. // Generated property miles is not sortable
  45. GridCellElement milesHeader = grid.getHeaderCell(0, 2);
  46. milesHeader.click();
  47. assertFalse("Column miles was unexpectedly sorted.", milesHeader
  48. .getAttribute("class").contains("sort"));
  49. }
  50. @Test
  51. public void testSortableGeneratedProperty() {
  52. openTestURL();
  53. GridElement grid = $(GridElement.class).first();
  54. // Generated property baz is sortable
  55. GridCellElement bazHeader = grid.getHeaderCell(0, 3);
  56. bazHeader.click();
  57. assertTrue("Column baz was not sorted ascending", bazHeader
  58. .getAttribute("class").contains("sort-asc"));
  59. bazHeader.click();
  60. assertTrue("Column baz was not sorted descending", bazHeader
  61. .getAttribute("class").contains("sort-desc"));
  62. }
  63. @Test
  64. public void testInitialSorting() {
  65. // Grid is sorted in this case by one visible and one nonexistent
  66. // column. There should be no sort indicator.
  67. setDebug(true);
  68. openTestURL();
  69. GridElement grid = $(GridElement.class).first();
  70. GridCellElement kmHeader = grid.getHeaderCell(0, 1);
  71. assertFalse("Column km was unexpectedly sorted",
  72. kmHeader.getAttribute("class").contains("sort-asc")
  73. || kmHeader.getAttribute("class").contains("sort-desc"));
  74. assertFalse("Unexpected client-side exception was visible",
  75. isElementPresent(NotificationElement.class));
  76. }
  77. }