123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870 |
- package com.vaadin.tests.components.treegrid;
-
- import static org.hamcrest.Matchers.greaterThanOrEqualTo;
- import static org.hamcrest.Matchers.not;
- import static org.hamcrest.number.IsCloseTo.closeTo;
- import static org.junit.Assert.assertEquals;
- import static org.junit.Assert.assertNotEquals;
- import static org.junit.Assert.assertNotNull;
- import static org.junit.Assert.assertThat;
-
- import java.util.List;
-
- import org.junit.Before;
- import org.junit.Test;
- import org.openqa.selenium.StaleElementReferenceException;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.WebElement;
- import org.openqa.selenium.support.ui.ExpectedCondition;
- import org.openqa.selenium.support.ui.ExpectedConditions;
-
- import com.vaadin.testbench.By;
- import com.vaadin.testbench.TestBenchElement;
- import com.vaadin.testbench.elements.ButtonElement;
- import com.vaadin.testbench.elements.TreeGridElement;
- import com.vaadin.tests.tb3.MultiBrowserTest;
-
- public class TreeGridBigDetailsManagerTest extends MultiBrowserTest {
-
- private static final String CLASSNAME_ERROR = "v-Notification-error";
- private static final String CLASSNAME_LABEL = "v-label";
- private static final String CLASSNAME_LEAF = "v-treegrid-row-depth-1";
- private static final String CLASSNAME_SPACER = "v-treegrid-spacer";
- private static final String CLASSNAME_TREEGRID = "v-treegrid";
-
- private static final String EXPAND_ALL = "expandAll";
- private static final String COLLAPSE_ALL = "collapseAll";
- private static final String SHOW_DETAILS = "showDetails";
- private static final String HIDE_DETAILS = "hideDetails";
- private static final String ADD_GRID = "addGrid";
- private static final String SCROLL_TO_55 = "scrollTo55";
- private static final String SCROLL_TO_3055 = "scrollTo3055";
- private static final String SCROLL_TO_END = "scrollToEnd";
- private static final String SCROLL_TO_START = "scrollToStart";
- private static final String TOGGLE_15 = "toggle15";
- private static final String TOGGLE_3000 = "toggle3000";
-
- private TreeGridElement treeGrid;
- private int expectedSpacerHeight = 0;
- private int expectedRowHeight = 0;
-
- private ExpectedCondition<Boolean> expectedConditionDetails(final int root,
- final Integer branch, final Integer leaf) {
- return new ExpectedCondition<Boolean>() {
- @Override
- public Boolean apply(WebDriver arg0) {
- return getSpacer(root, branch, leaf) != null;
- }
-
- @Override
- public String toString() {
- // waiting for...
- if (leaf != null) {
- return String.format(
- "Leaf %s/%s/%s details row contents to be found",
- root, branch, leaf);
- }
- return String.format(
- "Branch %s/%s details row contents to be found", root,
- branch);
- }
- };
- }
-
- private WebElement getSpacer(final int root, final Integer branch,
- final Integer leaf) {
- String text;
- if (leaf == null) {
- if (branch == null) {
- text = "details for Root %s";
- } else {
- text = "details for Branch %s/%s";
- }
- } else {
- text = "details for Leaf %s/%s/%s";
- }
- try {
- List<WebElement> spacers = treeGrid
- .findElements(By.className(CLASSNAME_SPACER));
- for (WebElement spacer : spacers) {
- List<WebElement> labels = spacer
- .findElements(By.className(CLASSNAME_LABEL));
- for (WebElement label : labels) {
- if (String.format(text, root, branch, leaf)
- .equals(label.getText())) {
- return spacer;
- }
- }
- }
- } catch (StaleElementReferenceException e) {
- treeGrid = $(TreeGridElement.class).first();
- }
- return null;
- }
-
- private WebElement getRow(int index) {
- return treeGrid.getBody().findElements(By.className("v-treegrid-row"))
- .get(index);
- }
-
- private void ensureExpectedSpacerHeightSet() {
- if (expectedSpacerHeight == 0) {
- expectedSpacerHeight = treeGrid
- .findElement(By.className(CLASSNAME_SPACER)).getSize()
- .getHeight();
- assertThat((double) expectedSpacerHeight, closeTo(27d, 2d));
- }
- }
-
- private void assertSpacerCount(int expectedSpacerCount) {
- assertEquals("Unexpected amount of spacers.", expectedSpacerCount,
- treeGrid.findElements(By.className(CLASSNAME_SPACER)).size());
- }
-
- /**
- * Asserts that every spacer has the same height.
- */
- private void assertSpacerHeights() {
- List<WebElement> spacers = treeGrid
- .findElements(By.className(CLASSNAME_SPACER));
- for (WebElement spacer : spacers) {
- assertEquals("Unexpected spacer height.", expectedSpacerHeight,
- spacer.getSize().getHeight());
- }
- }
-
- /**
- * Asserts that every spacer is at least a row height from the previous one.
- * Doesn't check that the spacers are in correct order or rendered properly.
- */
- private void assertSpacerPositions() {
- List<WebElement> spacers = treeGrid
- .findElements(By.className(CLASSNAME_SPACER));
- WebElement previousSpacer = null;
- for (WebElement spacer : spacers) {
- if (previousSpacer == null) {
- previousSpacer = spacer;
- continue;
- }
- // -1 should be enough, but increased tolerance to -3 for FireFox
- // and IE11 since a few pixels' discrepancy isn't relevant for this
- // fix
- assertThat("Unexpected spacer position.", spacer.getLocation().y,
- greaterThanOrEqualTo(previousSpacer.getLocation().y
- + expectedSpacerHeight + expectedRowHeight - 3));
- previousSpacer = spacer;
- }
- }
-
- private void assertNoErrors() {
- assertEquals("Error notification detected.", 0,
- treeGrid.findElements(By.className(CLASSNAME_ERROR)).size());
- }
-
- private void addGrid() {
- $(ButtonElement.class).id(ADD_GRID).click();
- waitForElementPresent(By.className(CLASSNAME_TREEGRID));
-
- treeGrid = $(TreeGridElement.class).first();
- expectedRowHeight = treeGrid.getRow(0).getSize().getHeight();
- }
-
- @Before
- public void before() {
- openTestURL();
- }
-
- @Test
- public void expandAllOpenAllInitialDetails_toggleOneTwice_hideAll() {
- $(ButtonElement.class).id(EXPAND_ALL).click();
- $(ButtonElement.class).id(SHOW_DETAILS).click();
- addGrid();
-
- waitUntil(expectedConditionDetails(0, 0, 0));
- ensureExpectedSpacerHeightSet();
- int spacerCount = treeGrid.findElements(By.className(CLASSNAME_SPACER))
- .size();
- assertSpacerPositions();
-
- treeGrid.collapseWithClick(0);
-
- // collapsing one shouldn't affect spacer count, just update the cache
- waitUntil(ExpectedConditions.not(expectedConditionDetails(0, 0, 0)));
- assertSpacerHeights();
- assertSpacerPositions();
- assertSpacerCount(spacerCount);
-
- treeGrid.expandWithClick(0);
-
- // expanding back shouldn't affect spacer count, just update the cache
- waitUntil(expectedConditionDetails(0, 0, 0));
- assertSpacerHeights();
- assertSpacerPositions();
- assertSpacerCount(spacerCount);
-
- // test that repeating the toggle still doesn't change anything
- treeGrid.collapseWithClick(0);
-
- waitUntil(ExpectedConditions.not(expectedConditionDetails(0, 0, 0)));
- assertSpacerHeights();
- assertSpacerPositions();
- assertSpacerCount(spacerCount);
-
- treeGrid.expandWithClick(0);
-
- waitUntil(expectedConditionDetails(0, 0, 0));
- assertSpacerHeights();
- assertSpacerPositions();
- assertSpacerCount(spacerCount);
-
- // test that hiding all still won't break things
- $(ButtonElement.class).id(HIDE_DETAILS).click();
- waitForElementNotPresent(By.className(CLASSNAME_SPACER));
-
- assertNoErrors();
- }
-
- @Test
- public void expandAllOpenAllInitialDetails_toggleAll() {
- $(ButtonElement.class).id(EXPAND_ALL).click();
- $(ButtonElement.class).id(SHOW_DETAILS).click();
- addGrid();
-
- waitUntil(expectedConditionDetails(0, 0, 0));
- ensureExpectedSpacerHeightSet();
-
- int spacerCount = treeGrid.findElements(By.className(CLASSNAME_SPACER))
- .size();
- assertSpacerPositions();
-
- $(ButtonElement.class).id(COLLAPSE_ALL).click();
-
- // There should still be a full cache's worth of details rows open,
- // just not the same rows than before collapsing all.
- waitForElementNotPresent(By.className(CLASSNAME_LEAF));
- assertSpacerCount(spacerCount);
- assertSpacerHeights();
- assertSpacerPositions();
-
- // FIXME: TreeGrid fails to update cache correctly when you expand all
- // and triggers client-side exceptions for rows that fall outside of the
- // cache because they try to extend the cache with a range that isn't
- // connected to the cached range
- if (true) {// remove this block after fixed
- return;
- }
-
- $(ButtonElement.class).id(EXPAND_ALL).click();
-
- // State should have returned to what it was before collapsing.
- waitUntil(expectedConditionDetails(0, 0, 0), 15);
- assertSpacerCount(spacerCount);
- assertSpacerHeights();
- assertSpacerPositions();
-
- assertNoErrors();
- }
-
- @Test
- public void expandAllOpenNoInitialDetails_showSeveral_toggleOneByOne() {
- $(ButtonElement.class).id(EXPAND_ALL).click();
- addGrid();
-
- // open details for several rows, leave one out from the hierarchy that
- // is to be collapsed
- treeGrid.getCell(0, 0).click();
- treeGrid.getCell(1, 0).click();
- treeGrid.getCell(2, 0).click();
- // no click for cell (3, 0)
- treeGrid.getCell(4, 0).click();
- treeGrid.getCell(5, 0).click();
- treeGrid.getCell(6, 0).click();
- treeGrid.getCell(7, 0).click();
- treeGrid.getCell(8, 0).click();
- int spacerCount = 8;
-
- waitUntil(expectedConditionDetails(0, 0, 0));
- assertSpacerCount(spacerCount);
- ensureExpectedSpacerHeightSet();
- assertSpacerPositions();
-
- // toggle the root with open details rows
- treeGrid.collapseWithClick(0);
-
- waitUntil(ExpectedConditions.not(expectedConditionDetails(0, 0, 0)));
- assertSpacerCount(1);
- assertSpacerHeights();
-
- treeGrid.expandWithClick(0);
-
- waitUntil(expectedConditionDetails(0, 0, 0));
- assertSpacerCount(spacerCount);
- assertSpacerHeights();
- assertSpacerPositions();
-
- // toggle one of the branches with open details rows
- treeGrid.collapseWithClick(5);
-
- waitUntil(ExpectedConditions.not(expectedConditionDetails(0, 1, 0)));
- assertSpacerCount(spacerCount - 3);
- assertSpacerHeights();
- assertSpacerPositions();
-
- treeGrid.expandWithClick(5);
-
- waitUntil(expectedConditionDetails(0, 1, 0));
- assertSpacerCount(spacerCount);
- assertSpacerHeights();
- assertSpacerPositions();
-
- assertNoErrors();
- }
-
- @Test
- public void expandAllOpenAllInitialDetails_hideOne() {
- $(ButtonElement.class).id(EXPAND_ALL).click();
- $(ButtonElement.class).id(SHOW_DETAILS).click();
- addGrid();
-
- // check the position of a row
- int oldY = treeGrid.getCell(2, 0).getLocation().getY();
-
- // hide the spacer from previous row
- treeGrid.getCell(1, 0).click();
-
- // ensure the investigated row moved
- assertNotEquals(oldY, treeGrid.getCell(2, 0).getLocation().getY());
- }
-
- @Test
- public void expandAllOpenAllInitialDetailsScrolled_toggleOne_hideAll() {
- $(ButtonElement.class).id(EXPAND_ALL).click();
- $(ButtonElement.class).id(SHOW_DETAILS).click();
- addGrid();
-
- $(ButtonElement.class).id(SCROLL_TO_55).click();
-
- waitUntil(expectedConditionDetails(1, 2, 0));
- ensureExpectedSpacerHeightSet();
- int spacerCount = treeGrid.findElements(By.className(CLASSNAME_SPACER))
- .size();
- assertSpacerPositions();
-
- treeGrid.collapseWithClick(50);
-
- // collapsing one shouldn't affect spacer count, just update the cache
- waitUntil(ExpectedConditions.not(expectedConditionDetails(1, 2, 0)));
- assertSpacerHeights();
- assertSpacerPositions();
- assertSpacerCount(spacerCount);
-
- treeGrid.expandWithClick(50);
-
- // expanding back shouldn't affect spacer count, just update the cache
- waitUntil(expectedConditionDetails(1, 2, 0));
- assertSpacerHeights();
- assertSpacerPositions();
- assertSpacerCount(spacerCount);
-
- // test that repeating the toggle still doesn't change anything
-
- treeGrid.collapseWithClick(50);
-
- waitUntil(ExpectedConditions.not(expectedConditionDetails(1, 2, 0)));
- assertSpacerHeights();
- assertSpacerPositions();
- assertSpacerCount(spacerCount);
-
- treeGrid.expandWithClick(50);
-
- waitUntil(expectedConditionDetails(1, 2, 0));
- assertSpacerHeights();
- assertSpacerPositions();
- assertSpacerCount(spacerCount);
-
- // test that hiding all still won't break things
-
- $(ButtonElement.class).id(HIDE_DETAILS).click();
- waitForElementNotPresent(By.className(CLASSNAME_SPACER));
-
- assertNoErrors();
- }
-
- @Test
- public void expandAllOpenAllInitialDetailsScrolled_toggleAll() {
- $(ButtonElement.class).id(EXPAND_ALL).click();
- $(ButtonElement.class).id(SHOW_DETAILS).click();
- addGrid();
-
- $(ButtonElement.class).id(SCROLL_TO_55).click();
-
- waitUntil(expectedConditionDetails(1, 3, 0));
- ensureExpectedSpacerHeightSet();
-
- int spacerCount = treeGrid.findElements(By.className(CLASSNAME_SPACER))
- .size();
- assertSpacerPositions();
-
- $(ButtonElement.class).id(COLLAPSE_ALL).click();
-
- waitForElementNotPresent(By.className(CLASSNAME_LEAF));
-
- // There should still be a full cache's worth of details rows open,
- // just not the same rows than before collapsing all.
- assertSpacerCount(spacerCount);
- assertSpacerHeights();
- assertSpacerPositions();
-
- // FIXME: collapsing and expanding too many rows after scrolling still
- // fails to reset to the same state
- if (true) { // remove this block after fixed
- return;
- }
-
- $(ButtonElement.class).id(EXPAND_ALL).click();
-
- // State should have returned to what it was before collapsing.
- waitUntil(expectedConditionDetails(1, 3, 0));
- assertSpacerCount(spacerCount);
- assertSpacerHeights();
- assertSpacerPositions();
-
- assertNoErrors();
- }
-
- @Test
- public void expandAllOpenNoInitialDetailsScrolled_showSeveral_toggleOneByOne() {
- $(ButtonElement.class).id(EXPAND_ALL).click();
- addGrid();
-
- $(ButtonElement.class).id(SCROLL_TO_55).click();
-
- assertSpacerCount(0);
-
- // open details for several rows, leave one out from the hierarchy that
- // is to be collapsed
- treeGrid.getCell(50, 0).click(); // Branch 1/2
- treeGrid.getCell(51, 0).click(); // Leaf 1/2/0
- treeGrid.getCell(52, 0).click(); // Leaf 1/2/1
- // no click for cell (53, 0) // Leaf 1/2/2
- treeGrid.getCell(54, 0).click(); // Branch 1/3
- treeGrid.getCell(55, 0).click(); // Leaf 1/3/0
- treeGrid.getCell(56, 0).click(); // Leaf 1/3/1
- treeGrid.getCell(57, 0).click(); // Leaf 1/3/2
- treeGrid.getCell(58, 0).click(); // Branch 1/4
- int spacerCount = 8;
-
- waitUntil(expectedConditionDetails(1, 2, 0));
- assertSpacerCount(spacerCount);
- ensureExpectedSpacerHeightSet();
- assertSpacerPositions();
-
- // toggle the branch with partially open details rows
- treeGrid.collapseWithClick(50);
-
- waitUntil(ExpectedConditions.not(expectedConditionDetails(1, 2, 0)));
- assertSpacerCount(spacerCount - 2);
- assertSpacerHeights();
- assertSpacerPositions();
-
- treeGrid.expandWithClick(50);
-
- waitUntil(expectedConditionDetails(1, 2, 0));
- assertSpacerCount(spacerCount);
- assertSpacerHeights();
- assertSpacerPositions();
-
- // toggle the branch with fully open details rows
- treeGrid.collapseWithClick(54);
-
- waitUntil(ExpectedConditions.not(expectedConditionDetails(1, 3, 0)));
- assertSpacerCount(spacerCount - 3);
- assertSpacerHeights();
- assertSpacerPositions();
-
- treeGrid.expandWithClick(54);
-
- waitUntil(expectedConditionDetails(1, 3, 0));
- assertSpacerCount(spacerCount);
- assertSpacerHeights();
- assertSpacerPositions();
-
- // repeat both toggles to ensure still no errors
- treeGrid.collapseWithClick(50);
-
- waitUntil(ExpectedConditions.not(expectedConditionDetails(1, 2, 0)));
- assertSpacerCount(spacerCount - 2);
- assertSpacerHeights();
- assertSpacerPositions();
-
- treeGrid.expandWithClick(50);
-
- waitUntil(expectedConditionDetails(1, 2, 0));
- assertSpacerCount(spacerCount);
- assertSpacerHeights();
- assertSpacerPositions();
- treeGrid.collapseWithClick(54);
-
- waitUntil(ExpectedConditions.not(expectedConditionDetails(1, 3, 0)));
- assertSpacerCount(spacerCount - 3);
- assertSpacerHeights();
- assertSpacerPositions();
-
- treeGrid.expandWithClick(54);
-
- waitUntil(expectedConditionDetails(1, 3, 0));
- assertSpacerCount(spacerCount);
- assertSpacerHeights();
- assertSpacerPositions();
-
- assertNoErrors();
- }
-
- @Test
- public void expandAllOpenAllInitialDetailsScrolled_hideOne() {
- $(ButtonElement.class).id(EXPAND_ALL).click();
- $(ButtonElement.class).id(SHOW_DETAILS).click();
- addGrid();
-
- $(ButtonElement.class).id(SCROLL_TO_55).click();
-
- // check the position of a row
- int oldY = treeGrid.getCell(52, 0).getLocation().getY();
-
- // hide the spacer from previous row
- treeGrid.getCell(51, 0).click();
-
- // ensure the investigated row moved
- assertNotEquals(oldY, treeGrid.getCell(52, 0).getLocation().getY());
- }
-
- @Test
- public void expandAllOpenAllInitialDetailsScrolledFar_toggleOne_hideAll() {
- $(ButtonElement.class).id(EXPAND_ALL).click();
- $(ButtonElement.class).id(SHOW_DETAILS).click();
- addGrid();
-
- $(ButtonElement.class).id(SCROLL_TO_3055).click();
-
- waitUntil(expectedConditionDetails(74, 4, 0));
- ensureExpectedSpacerHeightSet();
- int spacerCount = treeGrid.findElements(By.className(CLASSNAME_SPACER))
- .size();
- assertSpacerPositions();
-
- treeGrid.collapseWithClick(3051);
-
- // collapsing one shouldn't affect spacer count, just update the cache
- waitUntil(ExpectedConditions.not(expectedConditionDetails(1, 2, 0)));
- assertSpacerHeights();
- assertSpacerPositions();
- assertSpacerCount(spacerCount);
-
- treeGrid.expandWithClick(3051);
-
- // expanding back shouldn't affect spacer count, just update the cache
- waitUntil(expectedConditionDetails(74, 4, 0));
- assertSpacerHeights();
- assertSpacerPositions();
- assertSpacerCount(spacerCount);
-
- // test that repeating the toggle still doesn't change anything
-
- treeGrid.collapseWithClick(3051);
-
- waitUntil(ExpectedConditions.not(expectedConditionDetails(74, 4, 0)));
- assertSpacerHeights();
- assertSpacerPositions();
- assertSpacerCount(spacerCount);
-
- treeGrid.expandWithClick(3051);
-
- waitUntil(expectedConditionDetails(74, 4, 0));
- assertSpacerHeights();
- assertSpacerPositions();
- assertSpacerCount(spacerCount);
-
- // test that hiding all still won't break things
-
- $(ButtonElement.class).id(HIDE_DETAILS).click();
- waitForElementNotPresent(By.className(CLASSNAME_SPACER));
-
- assertNoErrors();
- }
-
- @Test
- public void expandAllOpenAllInitialDetailsScrolledFar_toggleAll() {
- $(ButtonElement.class).id(EXPAND_ALL).click();
- $(ButtonElement.class).id(SHOW_DETAILS).click();
- addGrid();
-
- $(ButtonElement.class).id(SCROLL_TO_3055).click();
-
- waitUntil(expectedConditionDetails(74, 4, 0));
- ensureExpectedSpacerHeightSet();
-
- int spacerCount = treeGrid.findElements(By.className(CLASSNAME_SPACER))
- .size();
- assertSpacerPositions();
-
- $(ButtonElement.class).id(COLLAPSE_ALL).click();
-
- waitForElementNotPresent(By.className(CLASSNAME_LEAF));
-
- // There should still be a full cache's worth of details rows open,
- // just not the same rows than before collapsing all.
- assertSpacerCount(spacerCount);
- assertSpacerHeights();
- assertSpacerPositions();
-
- // FIXME: collapsing and expanding too many rows after scrolling still
- // fails to reset to the same state
- if (true) { // remove this block after fixed
- return;
- }
-
- $(ButtonElement.class).id(EXPAND_ALL).click();
-
- // State should have returned to what it was before collapsing.
- waitUntil(expectedConditionDetails(74, 4, 0));
- assertSpacerCount(spacerCount);
- assertSpacerHeights();
- assertSpacerPositions();
-
- assertNoErrors();
- }
-
- @Test
- public void expandAllOpenNoInitialDetailsScrolledFar_showSeveral_toggleOneByOne() {
- $(ButtonElement.class).id(EXPAND_ALL).click();
- addGrid();
-
- $(ButtonElement.class).id(SCROLL_TO_3055).click();
-
- assertSpacerCount(0);
-
- // open details for several rows, leave one out from the hierarchy that
- // is to be collapsed
- treeGrid.getCell(3051, 0).click(); // Branch 74/4
- treeGrid.getCell(3052, 0).click(); // Leaf 74/4/0
- treeGrid.getCell(3053, 0).click(); // Leaf 74/4/1
- // no click for cell (3054, 0) // Leaf 74/4/2
- treeGrid.getCell(3055, 0).click(); // Branch 74/5
- treeGrid.getCell(3056, 0).click(); // Leaf 74/5/0
- treeGrid.getCell(3057, 0).click(); // Leaf 74/5/1
- treeGrid.getCell(3058, 0).click(); // Leaf 74/5/2
- treeGrid.getCell(3059, 0).click(); // Branch 74/6
- int spacerCount = 8;
-
- waitUntil(expectedConditionDetails(74, 4, 0));
- assertSpacerCount(spacerCount);
- ensureExpectedSpacerHeightSet();
- assertSpacerPositions();
-
- // toggle the branch with partially open details rows
- treeGrid.collapseWithClick(3051);
-
- waitUntil(ExpectedConditions.not(expectedConditionDetails(74, 4, 0)));
- assertSpacerCount(spacerCount - 2);
- assertSpacerHeights();
- assertSpacerPositions();
-
- treeGrid.expandWithClick(3051);
-
- waitUntil(expectedConditionDetails(74, 4, 0));
- assertSpacerCount(spacerCount);
- assertSpacerHeights();
- assertSpacerPositions();
-
- // toggle the branch with fully open details rows
- treeGrid.collapseWithClick(3055);
-
- waitUntil(ExpectedConditions.not(expectedConditionDetails(74, 5, 0)));
- assertSpacerCount(spacerCount - 3);
- assertSpacerHeights();
- assertSpacerPositions();
-
- treeGrid.expandWithClick(3055);
-
- waitUntil(expectedConditionDetails(74, 5, 0));
- assertSpacerCount(spacerCount);
- assertSpacerHeights();
- assertSpacerPositions();
-
- // repeat both toggles to ensure still no errors
- treeGrid.collapseWithClick(3051);
-
- waitUntil(ExpectedConditions.not(expectedConditionDetails(74, 4, 0)));
- assertSpacerCount(spacerCount - 2);
- assertSpacerHeights();
- assertSpacerPositions();
-
- treeGrid.expandWithClick(3051);
-
- waitUntil(expectedConditionDetails(74, 4, 0));
- assertSpacerCount(spacerCount);
- assertSpacerHeights();
- assertSpacerPositions();
- treeGrid.collapseWithClick(3055);
-
- waitUntil(ExpectedConditions.not(expectedConditionDetails(74, 5, 0)));
- assertSpacerCount(spacerCount - 3);
- assertSpacerHeights();
- assertSpacerPositions();
-
- treeGrid.expandWithClick(3055);
-
- waitUntil(expectedConditionDetails(74, 5, 0));
- assertSpacerCount(spacerCount);
- assertSpacerHeights();
- assertSpacerPositions();
-
- assertNoErrors();
- }
-
- @Test
- public void expandAllOpenAllInitialDetailsScrolledFar_hideOne() {
- $(ButtonElement.class).id(EXPAND_ALL).click();
- $(ButtonElement.class).id(SHOW_DETAILS).click();
- addGrid();
-
- $(ButtonElement.class).id(SCROLL_TO_3055).click();
-
- // check the position of a row
- int oldY = treeGrid.getCell(3052, 0).getLocation().getY();
-
- // hide the spacer from previous row
- treeGrid.getCell(3051, 0).click();
-
- // ensure the investigated row moved
- assertNotEquals(oldY, treeGrid.getCell(52, 0).getLocation().getY());
- }
-
- @Test
- public void expandAllOpenAllInitialDetails_checkScrollPositions() {
- $(ButtonElement.class).id(EXPAND_ALL).click();
- $(ButtonElement.class).id(SHOW_DETAILS).click();
- addGrid();
-
- TestBenchElement tableWrapper = treeGrid.getTableWrapper();
-
- $(ButtonElement.class).id(SCROLL_TO_55).click();
- waitUntil(expectedConditionDetails(1, 3, 0));
-
- WebElement detailsRow = getSpacer(1, 3, 0);
- assertNotNull("Spacer for row 55 not found", detailsRow);
-
- int wrapperY = tableWrapper.getLocation().getY();
- int wrapperHeight = tableWrapper.getSize().getHeight();
-
- int detailsY = detailsRow.getLocation().getY();
- int detailsHeight = detailsRow.getSize().getHeight();
-
- assertThat("Scroll to 55 didn't scroll as expected",
- (double) detailsY + detailsHeight,
- closeTo(wrapperY + wrapperHeight, 1d));
-
- $(ButtonElement.class).id(SCROLL_TO_3055).click();
- waitUntil(expectedConditionDetails(74, 5, null));
-
- detailsRow = getSpacer(74, 5, null);
- assertNotNull("Spacer for row 3055 not found", detailsRow);
-
- detailsY = detailsRow.getLocation().getY();
- detailsHeight = detailsRow.getSize().getHeight();
-
- assertThat("Scroll to 3055 didn't scroll as expected",
- (double) detailsY + detailsHeight,
- closeTo(wrapperY + wrapperHeight, 1d));
-
- $(ButtonElement.class).id(SCROLL_TO_END).click();
- waitUntil(expectedConditionDetails(99, 9, 2));
-
- detailsRow = getSpacer(99, 9, 2);
- assertNotNull("Spacer for last row not found", detailsRow);
-
- detailsY = detailsRow.getLocation().getY();
- detailsHeight = detailsRow.getSize().getHeight();
-
- // the layout jumps sometimes, check again
- wrapperY = tableWrapper.getLocation().getY();
- wrapperHeight = tableWrapper.getSize().getHeight();
-
- assertThat("Scroll to end didn't scroll as expected",
- (double) detailsY + detailsHeight,
- closeTo(wrapperY + wrapperHeight, 1d));
-
- $(ButtonElement.class).id(SCROLL_TO_START).click();
- waitUntil(expectedConditionDetails(0, 0, 0));
-
- WebElement firstRow = getRow(0);
- TestBenchElement header = treeGrid.getHeader();
-
- assertThat("Scroll to start didn't scroll as expected",
- (double) firstRow.getLocation().getY(),
- closeTo(wrapperY + header.getSize().getHeight(), 1d));
- }
-
- @Test
- public void expandAllOpenNoInitialDetails_testToggleScrolling() {
- $(ButtonElement.class).id(EXPAND_ALL).click();
- addGrid();
-
- TestBenchElement tableWrapper = treeGrid.getTableWrapper();
- int wrapperY = tableWrapper.getLocation().getY();
-
- WebElement firstRow = getRow(0);
- int firstRowY = firstRow.getLocation().getY();
-
- TestBenchElement header = treeGrid.getHeader();
- int headerHeight = header.getSize().getHeight();
-
- assertThat("Unexpected initial scroll position", (double) firstRowY,
- closeTo(wrapperY + headerHeight, 1d));
-
- $(ButtonElement.class).id(TOGGLE_15).click();
-
- firstRowY = firstRow.getLocation().getY();
-
- assertThat(
- "Toggling row 15's details open should have caused scrolling",
- (double) firstRowY, not(closeTo(wrapperY + headerHeight, 1d)));
-
- $(ButtonElement.class).id(SCROLL_TO_START).click();
-
- firstRowY = firstRow.getLocation().getY();
-
- assertThat("Scrolling to start failed", (double) firstRowY,
- closeTo(wrapperY + headerHeight, 1d));
-
- $(ButtonElement.class).id(TOGGLE_15).click();
-
- firstRowY = firstRow.getLocation().getY();
-
- assertThat(
- "Toggling row 15's details closed should not have caused scrolling",
- (double) firstRowY, closeTo(wrapperY + headerHeight, 1d));
-
- $(ButtonElement.class).id(TOGGLE_3000).click();
-
- firstRowY = firstRow.getLocation().getY();
-
- assertThat(
- "Toggling row 3000's details open should not have caused scrolling",
- (double) firstRowY, closeTo(wrapperY + headerHeight, 1d));
-
- $(ButtonElement.class).id(SCROLL_TO_55).click();
-
- WebElement row = getRow(0);
- assertNotEquals("First row should be out of visual range", firstRowY,
- row);
-
- $(ButtonElement.class).id(TOGGLE_15).click();
-
- assertEquals(
- "Toggling row 15's details open should not have caused scrolling "
- + "when row 15 is outside of visual range",
- row, getRow(0));
- }
-
- }
|