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.

TableMoveFocusWithSelectionTest.java 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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.table;
  17. import static org.junit.Assert.assertTrue;
  18. import org.junit.Test;
  19. import org.openqa.selenium.WebElement;
  20. import com.vaadin.testbench.By;
  21. import com.vaadin.tests.tb3.MultiBrowserTest;
  22. /**
  23. * Tests if table focus is moved correctly to the selected item
  24. *
  25. * @since
  26. * @author Vaadin Ltd
  27. */
  28. public class TableMoveFocusWithSelectionTest extends MultiBrowserTest {
  29. @Test
  30. public void selectUnfocusedTableAndAssumeSelectionGetsFocus() {
  31. openTestURL();
  32. // Click on row 5
  33. getDriver().findElement(By.id("row-5")).click();
  34. // Ensure row 5 gets focused
  35. WebElement row5TableRow = getDriver().findElement(
  36. By.xpath("//div[@id='row-5']/../../.."));
  37. String row5StyleName = row5TableRow.getAttribute("class");
  38. assertTrue(row5StyleName.contains("v-table-focus"));
  39. }
  40. @Test
  41. public void focusShouldStayOnUserSelectedRowIfSelectionChangesServerSide() {
  42. openTestURL();
  43. // Select multiselect
  44. getDriver().findElement(By.id("toggle-mode")).click();
  45. // Click on row 7
  46. getDriver().findElement(By.id("row-7")).click();
  47. // Clicking a row should get the row focus
  48. WebElement row7TableRow = getDriver().findElement(
  49. By.xpath("//div[@id='row-7']/../../.."));
  50. String row7StyleName = row7TableRow.getAttribute("class");
  51. assertTrue(row7StyleName.contains("v-table-focus"));
  52. // Select row 5-10 server side
  53. getDriver().findElement(By.id("select-510")).click();
  54. /*
  55. * Focus the table again (some browsers steal focus when performing
  56. * button click, other don't)
  57. */
  58. getDriver().findElement(By.id("test-table")).click();
  59. // Ensure row 7 is still focused
  60. row7TableRow = getDriver().findElement(
  61. By.xpath("//div[@id='row-7']/../../.."));
  62. row7StyleName = row7TableRow.getAttribute("class");
  63. assertTrue(row7StyleName.contains("v-table-focus"));
  64. }
  65. }