From 06f758e3916ccbd783d3277b0d17b099724dc44c Mon Sep 17 00:00:00 2001 From: Anna Koskinen Date: Thu, 14 Aug 2014 16:08:38 +0300 Subject: TreeTablePartialUpdates test upgrade (#14292) Change-Id: I32029461c7a4eeec1b54ce8a3f0b730f22deca1b --- .../treetable/TreeTableNegativeArraySize.html | 59 ------- .../TreeTablePartialUpdates-LongScroll.html | 52 ------ .../treetable/TreeTablePartialUpdates.java | 13 +- .../treetable/TreeTablePartialUpdatesTest.java | 196 +++++++++++++++++++++ 4 files changed, 204 insertions(+), 116 deletions(-) delete mode 100644 uitest/src/com/vaadin/tests/components/treetable/TreeTableNegativeArraySize.html delete mode 100644 uitest/src/com/vaadin/tests/components/treetable/TreeTablePartialUpdates-LongScroll.html create mode 100644 uitest/src/com/vaadin/tests/components/treetable/TreeTablePartialUpdatesTest.java diff --git a/uitest/src/com/vaadin/tests/components/treetable/TreeTableNegativeArraySize.html b/uitest/src/com/vaadin/tests/components/treetable/TreeTableNegativeArraySize.html deleted file mode 100644 index b57c5f978e..0000000000 --- a/uitest/src/com/vaadin/tests/components/treetable/TreeTableNegativeArraySize.html +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - -New Test - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
New Test
open/run/com.vaadin.tests.components.treetable.TreeTablePartialUpdates?restartApplication
mouseClickvaadin=runcomvaadintestscomponentstreetableTreeTablePartialUpdates::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTreeTable[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]12,4
scrollvaadin=runcomvaadintestscomponentstreetableTreeTablePartialUpdates::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTreeTable[0]/domChild[1]3969
pause300
mouseClickvaadin=runcomvaadintestscomponentstreetableTreeTablePartialUpdates::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTreeTable[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[42]/domChild[0]/domChild[0]/domChild[0]9,-183
pause1000
mouseClickvaadin=runcomvaadintestscomponentstreetableTreeTablePartialUpdates::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTreeTable[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[42]/domChild[0]/domChild[0]/domChild[0]11,-182
screenCaptureroot1-expanded-scrolled-to-end
- - diff --git a/uitest/src/com/vaadin/tests/components/treetable/TreeTablePartialUpdates-LongScroll.html b/uitest/src/com/vaadin/tests/components/treetable/TreeTablePartialUpdates-LongScroll.html deleted file mode 100644 index 276725e6bd..0000000000 --- a/uitest/src/com/vaadin/tests/components/treetable/TreeTablePartialUpdates-LongScroll.html +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - -New Test - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
New Test
open/run/com.vaadin.tests.components.treetable.TreeTablePartialUpdates?restartApplication
mouseClickvaadin=runcomvaadintestscomponentstreetableTreeTablePartialUpdates::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTreeTable[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]12,6
scrollvaadin=runcomvaadintestscomponentstreetableTreeTablePartialUpdates::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTreeTable[0]/domChild[1]1692
pause300
scrollvaadin=runcomvaadintestscomponentstreetableTreeTablePartialUpdates::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTreeTable[0]/domChild[1]6000
pause300
screenCapturetreetable-long-scroll
- - diff --git a/uitest/src/com/vaadin/tests/components/treetable/TreeTablePartialUpdates.java b/uitest/src/com/vaadin/tests/components/treetable/TreeTablePartialUpdates.java index 23eaa5dfea..78d67ee090 100644 --- a/uitest/src/com/vaadin/tests/components/treetable/TreeTablePartialUpdates.java +++ b/uitest/src/com/vaadin/tests/components/treetable/TreeTablePartialUpdates.java @@ -2,19 +2,21 @@ package com.vaadin.tests.components.treetable; import com.vaadin.data.Container.Hierarchical; import com.vaadin.data.util.HierarchicalContainer; -import com.vaadin.tests.components.TestBase; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; import com.vaadin.ui.TreeTable; -public class TreeTablePartialUpdates extends TestBase { +public class TreeTablePartialUpdates extends AbstractTestUI { @Override - protected void setup() { + protected void setup(VaadinRequest request) { TreeTable tt = new TreeTable(); tt.setContainerDataSource(makeHierarchicalContainer()); tt.setWidth("300px"); addComponent(tt); } + @SuppressWarnings("unchecked") private Hierarchical makeHierarchicalContainer() { HierarchicalContainer hc = new HierarchicalContainer(); hc.addContainerProperty("p1", String.class, ""); @@ -42,6 +44,7 @@ public class TreeTablePartialUpdates extends TestBase { return hc; } + @SuppressWarnings("unchecked") private void addNodesToRoot(HierarchicalContainer hc, Object root, int count) { for (int ix = 0; ix < count; ix++) { Object id = hc.addItem(); @@ -51,8 +54,8 @@ public class TreeTablePartialUpdates extends TestBase { } @Override - protected String getDescription() { - return ""; + protected String getTestDescription() { + return "Tests partial updates and how they affect cached rows and scroll position."; } @Override diff --git a/uitest/src/com/vaadin/tests/components/treetable/TreeTablePartialUpdatesTest.java b/uitest/src/com/vaadin/tests/components/treetable/TreeTablePartialUpdatesTest.java new file mode 100644 index 0000000000..5a55df581c --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/treetable/TreeTablePartialUpdatesTest.java @@ -0,0 +1,196 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.treetable; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + +import java.io.IOException; +import java.util.List; + +import org.junit.Test; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.commands.TestBenchElementCommands; +import com.vaadin.testbench.elements.TreeTableElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * Tests partial updates of a TreeTable. + * + * @author Vaadin Ltd + */ +public class TreeTablePartialUpdatesTest extends MultiBrowserTest { + + @Test + public void testLongScroll() throws IOException, InterruptedException { + openTestURL(); + + TreeTableElement treeTable = $(TreeTableElement.class).first(); + List rows = treeTable.findElement( + By.className("v-table-body")).findElements(By.tagName("tr")); + assertEquals("unexpected row count", 4, rows.size()); + + // expand the first root element + treeTable.getCell(0, 0) + .findElement(By.className("v-treetable-treespacer")).click(); + treeTable = $(TreeTableElement.class).first(); + + // wait for the scrollposition element to disappear + waitUntilNot(ExpectedConditions.visibilityOfElementLocated(By + .className("v-table-scrollposition"))); + + rows = treeTable.findElement(By.className("v-table-body")) + .findElements(By.tagName("tr")); + assertEquals("unexpected cached row count", 46, rows.size()); + + // TODO: replace these with just treeTable.scroll(int) when #13826 has + // been fixed + TestBenchElementCommands scrollable = testBenchElement(treeTable + .findElement(By.className("v-scrollable"))); + + // scroll far enough down to drop the first row from the cache + // but not far enough to reach the last row + scrollable.scroll(1692); + + // wait for the scrollposition element to disappear + waitUntilNot(ExpectedConditions.visibilityOfElementLocated(By + .className("v-table-scrollposition"))); + + assertEquals("elements found where there should be none", 0, treeTable + .findElements(By.vaadin("#row[0]/col[0]")).size()); + assertEquals("elements found where there should be none", 0, treeTable + .findElements(By.vaadin("#row[203]/col[0]")).size()); + + // scroll 6000 to make sure to actually hit bottom + scrollable.scroll(6000); + + // wait for the scrollposition element to disappear + waitUntilNot(ExpectedConditions.visibilityOfElementLocated(By + .className("v-table-scrollposition"))); + + // check the contents + treeTable = $(TreeTableElement.class).first(); + rows = treeTable.findElement(By.className("v-table-body")) + .findElements(By.tagName("tr")); + assertEquals("unexpected cached row count", 45, rows.size()); + assertEquals("unexpected cell contents (final row expected)", "END", + treeTable.getCell(203, 0).getText()); + assertEquals("unexpected cell contents (first visible row expected)", + "188", treeTable.getCell(189, 0).getText()); + assertEquals("unexpected cell contents (first cached row expected)", + "158", treeTable.getCell(159, 0).getText()); + + assertEquals("elements found where there should be none", 0, treeTable + .findElements(By.vaadin("#row[158]/col[0]")).size()); + assertEquals("elements found where there should be none", 0, treeTable + .findElements(By.vaadin("#row[204]/col[0]")).size()); + + // check the actual visibility + compareScreen("bottom"); + } + + @Test + public void testNegativeArraySize() throws IOException, + InterruptedException { + openTestURL(); + + TreeTableElement treeTable = $(TreeTableElement.class).first(); + List rows = treeTable.findElement( + By.className("v-table-body")).findElements(By.tagName("tr")); + assertEquals("unexpected row count", 4, rows.size()); + + // expand the first root element + treeTable.getCell(0, 0) + .findElement(By.className("v-treetable-treespacer")).click(); + + // wait for the scrollposition element to disappear + waitUntilNot(ExpectedConditions.visibilityOfElementLocated(By + .className("v-table-scrollposition"))); + + treeTable = $(TreeTableElement.class).first(); + rows = treeTable.findElement(By.className("v-table-body")) + .findElements(By.tagName("tr")); + assertEquals("unexpected cached row count", 46, rows.size()); + + // TODO: replace these with just treeTable.scroll(int) when #13826 has + // been fixed + TestBenchElementCommands scrollable = testBenchElement(treeTable + .findElement(By.className("v-scrollable"))); + + // scroll far enough down to reach the second root item again + scrollable.scroll(3969); + + // wait for the scrollposition element to disappear + waitUntilNot(ExpectedConditions.visibilityOfElementLocated(By + .className("v-table-scrollposition"))); + + assertEquals("elements found where there should be none", 0, treeTable + .findElements(By.vaadin("#row[0]/col[0]")).size()); + assertEquals("unexpected cell contents", "root2", + treeTable.getCell(201, 0).getText()); + assertEquals("unexpected cell contents", "END", + treeTable.getCell(203, 0).getText()); + + // expand the second root element + treeTable.getCell(201, 0) + .findElement(By.className("v-treetable-treespacer")).click(); + + // wait for the scrollposition element to disappear + waitUntilNot(ExpectedConditions.visibilityOfElementLocated(By + .className("v-table-scrollposition"))); + + // ensure the last cached row isn't the final row + treeTable = $(TreeTableElement.class).first(); + rows = treeTable.findElement(By.className("v-table-body")) + .findElements(By.tagName("tr")); + String elementText = rows.get(rows.size() - 1) + .findElement(By.className("v-table-cell-wrapper")).getText(); + assertFalse("final row found when it should be beyond cache", + elementText.contains("END")); + + // collapse the second root element + treeTable.getCell(201, 0) + .findElement(By.className("v-treetable-treespacer")).click(); + + // wait for the scrollposition element to disappear + waitUntilNot(ExpectedConditions.visibilityOfElementLocated(By + .className("v-table-scrollposition"))); + + // check the contents + treeTable = $(TreeTableElement.class).first(); + rows = treeTable.findElement(By.className("v-table-body")) + .findElements(By.tagName("tr")); + assertEquals("unexpected cached row count", 45, rows.size()); + assertEquals("unexpected cell contents (final row expected)", "END", + treeTable.getCell(203, 0).getText()); + assertEquals("unexpected cell contents (first visible row expected)", + "188", treeTable.getCell(189, 0).getText()); + assertEquals("unexpected cell contents (first cached row expected)", + "158", treeTable.getCell(159, 0).getText()); + + assertEquals("elements found where there should be none", 0, treeTable + .findElements(By.vaadin("#row[158]/col[0]")).size()); + assertEquals("elements found where there should be none", 0, treeTable + .findElements(By.vaadin("#row[204]/col[0]")).size()); + + // check the actual visibility + compareScreen("bottom"); + } + +} -- cgit v1.2.3