123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- 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.testbench.parallel.BrowserUtil;
- 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<WebElement> 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
- if (BrowserUtil.isChrome(getDesiredCapabilities())) {
- // Chrome 56 requires different scroll position
- scrollable.scroll(846);
- } else {
- 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<WebElement> 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");
- }
-
- }
|