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.

GridAriaRowcountTest.java 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright 2000-2017 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 com.vaadin.testbench.elements.ButtonElement;
  18. import com.vaadin.testbench.elements.GridElement;
  19. import com.vaadin.tests.tb3.SingleBrowserTest;
  20. import org.junit.Test;
  21. import static org.junit.Assert.assertEquals;
  22. import static org.junit.Assert.assertTrue;
  23. /**
  24. * @author Vaadin Ltd
  25. */
  26. public class GridAriaRowcountTest extends SingleBrowserTest {
  27. private GridElement grid;
  28. @Test
  29. public void checkGridAriaRowcount() {
  30. openTestURL();
  31. grid = $(GridElement.class).first();
  32. // default grid should contain at least one of each role
  33. String gridHtml = grid.getHTML();
  34. assertTrue("Grid should contain a role=\"rowheader\"", gridHtml.contains("role=\"rowheader\""));
  35. assertTrue("Grid should contain a role=\"columnheader\"", gridHtml.contains("role=\"columnheader\""));
  36. assertTrue("Grid should contain a role=\"row\"", gridHtml.contains("role=\"row\""));
  37. assertTrue("Grid should contain a role=\"gridcell\"", gridHtml.contains("role=\"gridcell\""));
  38. assertTrue("Grid should contain a role=\"rowgroup\"", gridHtml.contains("role=\"rowgroup\""));
  39. // default with 1 header row and 2 body rows.
  40. assertTrue("Grid should have 3 rows", containsRows(3));
  41. $(ButtonElement.class).caption("addFooter").first().click();
  42. // 1 header row, 2 body rows and 1 footer row.
  43. assertTrue("Grid should have 4 rows", containsRows(4));
  44. $(ButtonElement.class).caption("removeFooter").first().click();
  45. // 1 header row and 2 body rows.
  46. assertTrue("Grid should have 3 rows", containsRows(3));
  47. $(ButtonElement.class).caption("addHeader").first().click();
  48. // 2 header row and 2 body rows.
  49. assertTrue("Grid should have 4 rows", containsRows(4));
  50. $(ButtonElement.class).caption("removeHeader").first().click();
  51. // 1 header row and 2 body rows.
  52. assertTrue("Grid should have 3 rows", containsRows(3));
  53. $(ButtonElement.class).caption("setItemsTo3").first().click();
  54. // 1 header row and 3 body rows.
  55. assertTrue("Grid should have 4 rows", containsRows(4));
  56. $(ButtonElement.class).caption("setItemsTo6").first().click();
  57. // 1 header row and 6 body rows.
  58. assertTrue("Grid should have 7 rows", containsRows(7));
  59. $(ButtonElement.class).caption("updateAll").first().click();
  60. // 2 header rows, 4 body rows and 1 footer row.
  61. assertTrue("Grid should have 7 rows", containsRows(7));
  62. }
  63. private boolean containsRows(int rowcount) {
  64. return grid.getHTML().contains("aria-rowcount=\"" + String.valueOf(rowcount) + "\"");
  65. }
  66. }