diff options
author | Ilia Motornyi <elmot@vaadin.com> | 2017-04-05 14:14:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-05 14:14:03 +0200 |
commit | 535b879cb8180983c2da6444ec275e588fb4125f (patch) | |
tree | b92535ccbc9bd9f43b1000a73fcf2d5bf9223a30 /uitest | |
parent | 1a30320913e8b9ea851af3ed4a659f969aa92ee6 (diff) | |
download | vaadin-framework-535b879cb8180983c2da6444ec275e588fb4125f.tar.gz vaadin-framework-535b879cb8180983c2da6444ec275e588fb4125f.zip |
TreeGrid keyboard navigation
Fixes #8758
Diffstat (limited to 'uitest')
3 files changed, 300 insertions, 31 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/treegrid/TreeGridHugeTreeNavigation.java b/uitest/src/main/java/com/vaadin/tests/components/treegrid/TreeGridHugeTreeNavigation.java new file mode 100644 index 0000000000..fc550a9570 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/treegrid/TreeGridHugeTreeNavigation.java @@ -0,0 +1,59 @@ +package com.vaadin.tests.components.treegrid; + +import com.vaadin.annotations.Theme; +import com.vaadin.annotations.Widgetset; +import com.vaadin.data.HierarchyData; +import com.vaadin.data.provider.InMemoryHierarchicalDataProvider; +import com.vaadin.tests.components.AbstractComponentTest; +import com.vaadin.ui.TreeGrid; + +@Theme("valo") +@Widgetset("com.vaadin.DefaultWidgetSet") +public class TreeGridHugeTreeNavigation extends AbstractComponentTest<TreeGrid> { + + private TreeGrid<String> treeGrid; + private InMemoryHierarchicalDataProvider<String> inMemoryDataProvider; + + @Override + public TreeGrid getComponent() { + return treeGrid; + } + + @Override + protected Class<TreeGrid> getTestClass() { + return TreeGrid.class; + } + + @Override + protected void initializeComponents() { + initializeDataProvider(); + treeGrid = new TreeGrid<>(); + treeGrid.setDataProvider(inMemoryDataProvider); + treeGrid.setSizeFull(); + treeGrid.addColumn(String::toString).setCaption("String") + .setId("string"); + treeGrid.addColumn((i) -> "--").setCaption("Nothing"); + treeGrid.setHierarchyColumn("string"); + treeGrid.setId("testComponent"); + treeGrid.setItemCollapseAllowedProvider(s -> !"Dad 2/1".equals(s)); + addTestComponent(treeGrid); + } + + private void initializeDataProvider() { + HierarchyData<String> data = new HierarchyData<>(); + for (int i = 0; i < 3; i++) { + String granddad = "Granddad " + i; + data.addItem(null, granddad); + for (int j = 0; j < 3; j++) { + String dad = "Dad " + i + "/" + j; + data.addItem(granddad, dad); + for (int k = 0; k < 300; k++) { + String son = "Son " + i + "/" + j + "/" + k; + data.addItem(dad, son); + } + } + } + inMemoryDataProvider = new InMemoryHierarchicalDataProvider<>(data); + } + +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/treegrid/TreeGridBasicFeaturesTest.java b/uitest/src/test/java/com/vaadin/tests/components/treegrid/TreeGridBasicFeaturesTest.java index 8f8a224049..7fb7ddf3f3 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/treegrid/TreeGridBasicFeaturesTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/treegrid/TreeGridBasicFeaturesTest.java @@ -2,8 +2,9 @@ package com.vaadin.tests.components.treegrid; import java.util.Arrays; import java.util.Collection; +import java.util.List; -import org.junit.Assert; +import com.vaadin.testbench.parallel.Browser; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; @@ -17,6 +18,10 @@ import com.vaadin.testbench.elements.TreeGridElement; import com.vaadin.tests.tb3.MultiBrowserTest; import com.vaadin.tests.tb3.ParameterizedTB3Runner; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + @RunWith(ParameterizedTB3Runner.class) public class TreeGridBasicFeaturesTest extends MultiBrowserTest { @@ -35,6 +40,7 @@ public class TreeGridBasicFeaturesTest extends MultiBrowserTest { @Before public void before() { + setDebug(true); openTestURL("theme=valo"); grid = $(TreeGridElement.class).first(); } @@ -43,79 +49,114 @@ public class TreeGridBasicFeaturesTest extends MultiBrowserTest { @Ignore // currently no implementation exists for toggling from the server // side public void toggle_collapse_server_side() { - Assert.assertEquals(3, grid.getRowCount()); + assertEquals(3, grid.getRowCount()); assertCellTexts(0, 0, new String[] { "0 | 0", "0 | 1", "0 | 2" }); selectMenuPath("Component", "Features", "Toggle expand", "0 | 0"); - Assert.assertEquals(6, grid.getRowCount()); + assertEquals(6, grid.getRowCount()); assertCellTexts(1, 0, new String[] { "1 | 0", "1 | 1", "1 | 2" }); selectMenuPath("Component", "Features", "Toggle expand", "0 | 0"); - Assert.assertEquals(3, grid.getRowCount()); + assertEquals(3, grid.getRowCount()); assertCellTexts(0, 0, new String[] { "0 | 0", "0 | 1", "0 | 2" }); // collapsing a leaf should have no effect selectMenuPath("Component", "Features", "Toggle expand", "1 | 0"); - Assert.assertEquals(3, grid.getRowCount()); + assertEquals(3, grid.getRowCount()); } @Test public void non_leaf_collapse_on_click() { - Assert.assertEquals(3, grid.getRowCount()); + assertEquals(3, grid.getRowCount()); assertCellTexts(0, 0, new String[] { "0 | 0", "0 | 1", "0 | 2" }); // Should expand "0 | 0" grid.getRow(0).getCell(0) .findElement(By.className("v-tree-grid-expander")).click(); - Assert.assertEquals(6, grid.getRowCount()); + assertEquals(6, grid.getRowCount()); assertCellTexts(1, 0, new String[] { "1 | 0", "1 | 1", "1 | 2" }); // Should collapse "0 | 0" grid.getRow(0).getCell(0) .findElement(By.className("v-tree-grid-expander")).click(); - Assert.assertEquals(3, grid.getRowCount()); + assertEquals(3, grid.getRowCount()); assertCellTexts(0, 0, new String[] { "0 | 0", "0 | 1", "0 | 2" }); } @Test - @Ignore // FIXME: remove ignore annotation once #8758 is done public void keyboard_navigation() { grid.getRow(0).getCell(0).click(); - // Should expand "0 | 0" - new Actions(getDriver()).keyDown(Keys.ALT).sendKeys(Keys.RIGHT) - .keyUp(Keys.ALT).perform(); - Assert.assertEquals(6, grid.getRowCount()); + // Should expand "0 | 0" without moving focus + new Actions(getDriver()).sendKeys(Keys.RIGHT).perform(); + assertEquals(6, grid.getRowCount()); + assertCellTexts(1, 0, new String[] { "1 | 0", "1 | 1", "1 | 2" }); + assertTrue(grid.getRow(0).hasClassName("v-grid-rowmode-row-focused")); + assertFalse(grid.getRow(1).hasClassName("v-grid-rowmode-row-focused")); + + // Should navigate 2 times down to "1 | 1" + new Actions(getDriver()).sendKeys(Keys.DOWN, Keys.DOWN).perform(); + assertEquals(6, grid.getRowCount()); assertCellTexts(1, 0, new String[] { "1 | 0", "1 | 1", "1 | 2" }); + assertFalse(grid.getRow(0).hasClassName("v-grid-rowmode-row-focused")); + assertFalse(grid.getRow(1).hasClassName("v-grid-rowmode-row-focused")); + assertTrue(grid.getRow(2).hasClassName("v-grid-rowmode-row-focused")); + + // Should expand "1 | 1" without moving focus + new Actions(getDriver()).sendKeys(Keys.RIGHT).perform(); + assertEquals(9, grid.getRowCount()); + assertCellTexts(2, 0, new String[] { "1 | 1", "2 | 0", "2 | 1", "2 | 2", "1 | 2"}); + assertTrue(grid.getRow(2).hasClassName("v-grid-rowmode-row-focused")); + + // Should collapse "1 | 1" + new Actions(getDriver()).sendKeys(Keys.LEFT).perform(); + assertEquals(6, grid.getRowCount()); + assertCellTexts(2, 0, new String[] { "1 | 1", "1 | 2", "0 | 1"}); + assertTrue(grid.getRow(2).hasClassName("v-grid-rowmode-row-focused")); + + + // Should navigate to "0 | 0" + new Actions(getDriver()).sendKeys(Keys.LEFT).perform(); + assertEquals(6, grid.getRowCount()); + assertCellTexts(0, 0, new String[] { "0 | 0", "1 | 0", "1 | 1", "1 | 2" , "0 | 1" }); + assertTrue(grid.getRow(0).hasClassName("v-grid-rowmode-row-focused")); // Should collapse "0 | 0" - new Actions(getDriver()).keyDown(Keys.ALT).sendKeys(Keys.LEFT) - .keyUp(Keys.ALT).perform(); - Assert.assertEquals(3, grid.getRowCount()); + new Actions(getDriver()).sendKeys(Keys.LEFT).perform(); + assertEquals(3, grid.getRowCount()); assertCellTexts(0, 0, new String[] { "0 | 0", "0 | 1", "0 | 2" }); + assertTrue(grid.getRow(0).hasClassName("v-grid-rowmode-row-focused")); + + // Nothing should happen + new Actions(getDriver()).sendKeys(Keys.LEFT).perform(); + assertEquals(3, grid.getRowCount()); + assertCellTexts(0, 0, new String[] { "0 | 0", "0 | 1", "0 | 2" }); + assertTrue(grid.getRow(0).hasClassName("v-grid-rowmode-row-focused")); + + assertNoErrorNotifications(); } @Test public void changing_hierarchy_column() { - Assert.assertTrue(grid.getRow(0).getCell(0) + assertTrue(grid.getRow(0).getCell(0) .isElementPresent(By.className("v-tree-grid-expander"))); - Assert.assertFalse(grid.getRow(0).getCell(1) + assertFalse(grid.getRow(0).getCell(1) .isElementPresent(By.className("v-tree-grid-expander"))); selectMenuPath("Component", "Features", "Set hierarchy column", "depth"); - Assert.assertFalse(grid.getRow(0).getCell(0) + assertFalse(grid.getRow(0).getCell(0) .isElementPresent(By.className("v-tree-grid-expander"))); - Assert.assertTrue(grid.getRow(0).getCell(1) + assertTrue(grid.getRow(0).getCell(1) .isElementPresent(By.className("v-tree-grid-expander"))); selectMenuPath("Component", "Features", "Set hierarchy column", "string"); - Assert.assertTrue(grid.getRow(0).getCell(0) + assertTrue(grid.getRow(0).getCell(0) .isElementPresent(By.className("v-tree-grid-expander"))); - Assert.assertFalse(grid.getRow(0).getCell(1) + assertFalse(grid.getRow(0).getCell(1) .isElementPresent(By.className("v-tree-grid-expander"))); } @@ -130,18 +171,18 @@ public class TreeGridBasicFeaturesTest extends MultiBrowserTest { selectMenuPath("Component", "State", "Expand listener"); selectMenuPath("Component", "State", "Collapse listener"); - Assert.assertFalse(logContainsText("Item expanded: 0 | 0")); - Assert.assertFalse(logContainsText("Item collapsed: 0 | 0")); + assertFalse(logContainsText("Item expanded: 0 | 0")); + assertFalse(logContainsText("Item collapsed: 0 | 0")); grid.expandWithClick(0); - Assert.assertTrue(logContainsText("Item expanded: 0 | 0")); - Assert.assertFalse(logContainsText("Item collapsed: 0 | 0")); + assertTrue(logContainsText("Item expanded: 0 | 0")); + assertFalse(logContainsText("Item collapsed: 0 | 0")); grid.collapseWithClick(0); - Assert.assertTrue(logContainsText("Item expanded: 0 | 0")); - Assert.assertTrue(logContainsText("Item collapsed: 0 | 0")); + assertTrue(logContainsText("Item expanded: 0 | 0")); + assertTrue(logContainsText("Item collapsed: 0 | 0")); selectMenuPath("Component", "State", "Expand listener"); selectMenuPath("Component", "State", "Collapse listener"); @@ -149,15 +190,15 @@ public class TreeGridBasicFeaturesTest extends MultiBrowserTest { grid.expandWithClick(1); grid.collapseWithClick(1); - Assert.assertFalse(logContainsText("Item expanded: 0 | 1")); - Assert.assertFalse(logContainsText("Item collapsed: 0 | 1")); + assertFalse(logContainsText("Item expanded: 0 | 1")); + assertFalse(logContainsText("Item collapsed: 0 | 1")); } private void assertCellTexts(int startRowIndex, int cellIndex, String[] cellTexts) { int index = startRowIndex; for (String cellText : cellTexts) { - Assert.assertEquals(cellText, + assertEquals(cellText, grid.getRow(index).getCell(cellIndex).getText()); index++; } diff --git a/uitest/src/test/java/com/vaadin/tests/components/treegrid/TreeGridHugeTreeNavigationTest.java b/uitest/src/test/java/com/vaadin/tests/components/treegrid/TreeGridHugeTreeNavigationTest.java new file mode 100644 index 0000000000..f37118a24b --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/treegrid/TreeGridHugeTreeNavigationTest.java @@ -0,0 +1,169 @@ +package com.vaadin.tests.components.treegrid; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.TreeGridElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class TreeGridHugeTreeNavigationTest extends MultiBrowserTest { + + private TreeGridElement grid; + + @Before + public void before() { + setDebug(true); + openTestURL(); + grid = $(TreeGridElement.class).first(); + } + + @Test + public void keyboard_navigation() { + grid.getRow(0).getCell(0).click(); + + // Should navigate to "Granddad 1" and expand it + new Actions(getDriver()).sendKeys(Keys.DOWN, Keys.RIGHT).perform(); + assertEquals(6, grid.getRowCount()); + assertCellTexts(0, 0, "Granddad 0", "Granddad 1", + "Dad 1/0", "Dad 1/1", "Dad 1/2", "Granddad 2"); + checkRowFocused(1); + + // Should navigate to and expand "Dad 1/1" + new Actions(getDriver()).sendKeys(Keys.DOWN, Keys.DOWN, Keys.RIGHT) + .perform(); + assertCellTexts(0, 0, + "Granddad 0", "Granddad 1", "Dad 1/0", "Dad 1/1", + "Son 1/1/0", "Son 1/1/1", "Son 1/1/2", "Son 1/1/3"); + checkRowFocused(3); + + // Should navigate 100 items down + Keys downKeyArr[] = new Keys[100]; + for (int i = 0; i < 100; i++) { + downKeyArr[i] = Keys.DOWN; + } + new Actions(getDriver()).sendKeys(downKeyArr).perform(); + + WebElement son1_1_99 = findFocusedRow(); + assertEquals("Son 1/1/99 --", son1_1_99.getText()); + + // Should navigate to "Dad 1/1" back + new Actions(getDriver()) + .sendKeys(Keys.HOME, Keys.DOWN, Keys.DOWN, Keys.DOWN).perform(); + WebElement dad1_1 = findFocusedRow(); + assertEquals("Dad 1/1 --", dad1_1.getText()); + + // Should collapse "Dad 1/1" + new Actions(getDriver()).sendKeys(Keys.LEFT).perform(); + assertCellTexts(0, 0, "Granddad 0", "Granddad 1", + "Dad 1/0", "Dad 1/1", "Dad 1/2", "Granddad 2"); + checkRowFocused(3); + + // Should navigate to "Granddad 1" + new Actions(getDriver()).sendKeys(Keys.LEFT).perform(); + assertCellTexts(0, 0, "Granddad 0", "Granddad 1", + "Dad 1/0", "Dad 1/1", "Dad 1/2", "Granddad 2"); + checkRowFocused(1); + + // Should collapse "Granddad 1" + new Actions(getDriver()).sendKeys(Keys.LEFT).perform(); + assertCellTexts(0, 0, "Granddad 0", "Granddad 1", "Granddad 2"); + checkRowFocused(1); + + // Nothing should happen + new Actions(getDriver()).sendKeys(Keys.LEFT).perform(); + assertCellTexts(0, 0, "Granddad 0", "Granddad 1", "Granddad 2"); + checkRowFocused(1); + assertNoErrorNotifications(); + } + + @Test + public void no_exception_when_calling_expand_or_collapse_twice() { + + // Currently the collapsed state is updated in a round trip to the + // server, thus it is possible to trigger an expand on the same row + // multiple times through the UI. This should not cause exceptions, but + // rather ignore the redundant calls. + + grid.getRow(0).getCell(0).click(); + new Actions(getDriver()).sendKeys(Keys.RIGHT, Keys.RIGHT).perform(); + assertNoErrorNotifications(); + new Actions(getDriver()).sendKeys(Keys.LEFT, Keys.LEFT).perform(); + assertNoErrorNotifications(); + } + + @Test + public void uncollapsible_item() { + grid.getRow(0).getCell(0).click(); + new Actions(getDriver()).sendKeys(Keys.DOWN, Keys.DOWN, Keys.RIGHT).perform(); + grid.waitForVaadin(); + //expand Dad 2/1 + new Actions(getDriver()).sendKeys(Keys.DOWN, Keys.DOWN, Keys.RIGHT).perform(); + grid.waitForVaadin(); + assertNoErrorNotifications(); + assertCellTexts(5,0,"Son 2/1/0"); + new Actions(getDriver()).sendKeys(Keys.LEFT).perform(); + grid.waitForVaadin(); + assertNoErrorNotifications(); + assertCellTexts(5,0,"Son 2/1/0"); + } + @Test + public void can_toggle_collapse_on_row_that_is_no_longer_in_cache() { + grid.getRow(0).getCell(0).click(); + + // Expand 2 levels + new Actions(getDriver()).sendKeys(Keys.RIGHT).perform(); + grid.waitForVaadin(); + new Actions(getDriver()).sendKeys(Keys.DOWN, Keys.RIGHT).perform(); + grid.waitForVaadin(); + grid.scrollToRow(200); + grid.waitForVaadin(); + //Jump into view + new Actions(getDriver()).sendKeys(Keys.LEFT).perform(); + grid.waitForVaadin(); + //Collapse + new Actions(getDriver()).sendKeys(Keys.LEFT).perform(); + grid.waitForVaadin(); + assertEquals(6, grid.getRowCount()); + + // Expand + new Actions(getDriver()).sendKeys(Keys.RIGHT, Keys.UP).perform(); + grid.waitForVaadin(); + grid.scrollToRow(200); + new Actions(getDriver()).sendKeys(Keys.RIGHT).perform(); + grid.waitForVaadin(); + assertEquals(306, grid.getRowCount()); + } + + private WebElement findFocusedRow() { + return grid.findElement(By.className("v-grid-rowmode-row-focused")); + } + + private void checkRowFocused(int index) { + if (index > 0) { + assertFalse(grid.getRow(index - 1) + .hasClassName("v-grid-rowmode-row-focused")); + } + assertTrue( + grid.getRow(index).hasClassName("v-grid-rowmode-row-focused")); + assertFalse(grid.getRow(index + 1) + .hasClassName("v-grid-rowmode-row-focused")); + } + + private void assertCellTexts(int startRowIndex, int cellIndex, + String... cellTexts) { + int index = startRowIndex; + for (String cellText : cellTexts) { + assertEquals(cellText, + grid.getRow(index).getCell(cellIndex).getText()); + index++; + } + } +} |