From 754caf060f1473f2367c421ecd70f3a8966f6f10 Mon Sep 17 00:00:00 2001 From: Henrik Paul Date: Mon, 23 Mar 2015 15:35:26 +0200 Subject: Adds Escalator.scrollToSpacer (#17270) Change-Id: Ib420e8da6c167fdba9d3023a73cb242643c7af67 --- .../EscalatorBasicClientFeaturesTest.java | 2 ++ .../escalator/EscalatorSpacerTest.java | 37 ++++++++++++++++++++++ .../grid/EscalatorBasicClientFeaturesWidget.java | 13 ++++++++ 3 files changed, 52 insertions(+) (limited to 'uitest/src') diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorBasicClientFeaturesTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorBasicClientFeaturesTest.java index 04c0933866..de254b4deb 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorBasicClientFeaturesTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/EscalatorBasicClientFeaturesTest.java @@ -77,11 +77,13 @@ public abstract class EscalatorBasicClientFeaturesTest extends MultiBrowserTest protected static final String COLSPAN_NONE = "Apply no colspan"; protected static final String SET_100PX = "Set 100px"; protected static final String SPACERS = "Spacers"; + protected static final String SCROLL_HERE_ANY_0PADDING = "Scroll here (ANY, 0)"; protected static final String REMOVE = "Remove"; protected static final String ROW_MINUS1 = "Row -1"; protected static final String ROW_1 = "Row 1"; protected static final String ROW_25 = "Row 25"; + protected static final String ROW_50 = "Row 50"; protected static final String ROW_75 = "Row 75"; protected static final String ROW_99 = "Row 99"; diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorSpacerTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorSpacerTest.java index 1e9771ab13..a0fa961ad2 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorSpacerTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/escalator/EscalatorSpacerTest.java @@ -30,6 +30,7 @@ import org.junit.Test; import org.openqa.selenium.WebElement; import com.vaadin.client.WidgetUtil; +import com.vaadin.shared.ui.grid.Range; import com.vaadin.testbench.elements.NotificationElement; import com.vaadin.tests.components.grid.basicfeatures.EscalatorBasicClientFeaturesTest; @@ -96,6 +97,7 @@ public class EscalatorSpacerTest extends EscalatorBasicClientFeaturesTest { @Before public void before() { openTestURL(); + selectMenuPath(COLUMNS_AND_ROWS, BODY_ROWS, "Set 20px default height"); populate(); } @@ -299,6 +301,41 @@ public class EscalatorSpacerTest extends EscalatorBasicClientFeaturesTest { } } + @Test + public void scrollToSpacerFromAbove() throws Exception { + selectMenuPath(FEATURES, SPACERS, ROW_50, SET_100PX); + selectMenuPath(FEATURES, SPACERS, ROW_50, SCROLL_HERE_ANY_0PADDING); + + // Browsers might vary with a few pixels. + Range allowableScrollRange = Range.between(765, 780); + int scrollTop = (int) getScrollTop(); + assertTrue("Scroll position was not " + allowableScrollRange + ", but " + + scrollTop, allowableScrollRange.contains(scrollTop)); + } + + @Test + public void scrollToSpacerFromBelow() throws Exception { + selectMenuPath(FEATURES, SPACERS, ROW_50, SET_100PX); + scrollVerticallyTo(999999); + selectMenuPath(FEATURES, SPACERS, ROW_50, SCROLL_HERE_ANY_0PADDING); + + // Browsers might vary with a few pixels. + Range allowableScrollRange = Range.between(1015, 1025); + int scrollTop = (int) getScrollTop(); + assertTrue("Scroll position was not " + allowableScrollRange + ", but " + + scrollTop, allowableScrollRange.contains(scrollTop)); + } + + @Test + public void scrollToSpacerAlreadyInViewport() throws Exception { + selectMenuPath(FEATURES, SPACERS, ROW_50, SET_100PX); + scrollVerticallyTo(1000); + selectMenuPath(FEATURES, SPACERS, ROW_50, SCROLL_HERE_ANY_0PADDING); + + // Browsers might vary with a few pixels. + assertEquals(getScrollTop(), 1000); + } + private static double[] getElementDimensions(WebElement element) { /* * we need to parse the style attribute, since using getCssValue gets a diff --git a/uitest/src/com/vaadin/tests/widgetset/client/grid/EscalatorBasicClientFeaturesWidget.java b/uitest/src/com/vaadin/tests/widgetset/client/grid/EscalatorBasicClientFeaturesWidget.java index 0d4aa305d9..4cf4726c28 100644 --- a/uitest/src/com/vaadin/tests/widgetset/client/grid/EscalatorBasicClientFeaturesWidget.java +++ b/uitest/src/com/vaadin/tests/widgetset/client/grid/EscalatorBasicClientFeaturesWidget.java @@ -585,6 +585,13 @@ public class EscalatorBasicClientFeaturesWidget extends } }, scrollToRowMenuPath); } + + addMenuCommand("Set 20px default height", new ScheduledCommand() { + @Override + public void execute() { + escalator.getBody().setDefaultRowHeight(20); + } + }, menupath); } private void createRowsMenu(final RowContainer container, String[] menupath) { @@ -685,6 +692,12 @@ public class EscalatorBasicClientFeaturesWidget extends escalator.getBody().setSpacer(rowIndex, -1); } }, menupath); + addMenuCommand("Scroll here (ANY, 0)", new ScheduledCommand() { + @Override + public void execute() { + escalator.scrollToSpacer(rowIndex, ScrollDestination.ANY, 0); + } + }, menupath); } private void insertRows(final RowContainer container, int offset, int number) { -- cgit v1.2.3