diff options
Diffstat (limited to 'uitest')
2 files changed, 104 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridApplyFilterWhenScrolledDown.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridApplyFilterWhenScrolledDown.java new file mode 100644 index 0000000000..93413c102a --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridApplyFilterWhenScrolledDown.java @@ -0,0 +1,64 @@ +package com.vaadin.tests.components.grid; + +import com.vaadin.annotations.Theme; +import com.vaadin.data.Container.Filterable; +import com.vaadin.data.Item; +import com.vaadin.data.util.filter.SimpleStringFilter; +import com.vaadin.event.FieldEvents.TextChangeEvent; +import com.vaadin.event.FieldEvents.TextChangeListener; +import com.vaadin.server.VaadinRequest; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Grid.HeaderRow; +import com.vaadin.ui.TextField; +import com.vaadin.ui.UI; +import com.vaadin.ui.themes.ValoTheme; + +@Theme("valo") +public class GridApplyFilterWhenScrolledDown extends UI { + + Grid grid = new Grid(); + + @Override + protected void init(VaadinRequest vaadinRequest) { + + grid.addColumn("Name", String.class); + + HeaderRow appendHeaderRow = grid.appendHeaderRow(); + TextField filter = getColumnFilter("Name"); + appendHeaderRow.getCell("Name").setComponent(filter); + + for (int i = 0; i < 1000; i++) { + Item addItem = grid.getContainerDataSource().addItem(i); + addItem.getItemProperty("Name").setValue("Name " + i); + + } + + Item addItem = grid.getContainerDataSource().addItem(1000); + addItem.getItemProperty("Name").setValue("Test"); + + grid.scrollToStart(); + setContent(grid); + } + + private TextField getColumnFilter(final Object columnId) { + TextField filter = new TextField(); + filter.setWidth("100%"); + filter.addStyleName(ValoTheme.TEXTFIELD_TINY); + filter.addTextChangeListener(new TextChangeListener() { + SimpleStringFilter filter = null; + + @Override + public void textChange(TextChangeEvent event) { + Filterable f = (Filterable) grid.getContainerDataSource(); + if (filter != null) { + f.removeContainerFilter(filter); + } + filter = new SimpleStringFilter(columnId, event.getText(), true, + true); + f.addContainerFilter(filter); + } + }); + return filter; + } + +}
\ No newline at end of file diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridApplyFilterWhenScrolledDownTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridApplyFilterWhenScrolledDownTest.java new file mode 100644 index 0000000000..279cf8ef95 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridApplyFilterWhenScrolledDownTest.java @@ -0,0 +1,40 @@ +package com.vaadin.tests.components.grid; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedCondition; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.TestBenchElement; +import com.vaadin.testbench.elements.GridElement; +import com.vaadin.testbench.elements.TextFieldElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class GridApplyFilterWhenScrolledDownTest extends MultiBrowserTest { + + @Test + public void scrolledCorrectly() throws InterruptedException { + openTestURL(); + final GridElement grid = $(GridElement.class).first(); + grid.scrollToRow(50); + $(TextFieldElement.class).first().setValue("Test"); + final TestBenchElement gridBody = grid.getBody(); + // Can't use element API because it scrolls + waitUntil(new ExpectedCondition<Boolean>() { + + @Override + public Boolean apply(WebDriver input) { + return gridBody.findElements(By.className("v-grid-row")) + .size() == 1; + } + }); + WebElement cell = gridBody.findElements(By.className("v-grid-cell")) + .get(0); + Assert.assertEquals("Test", cell.getText()); + + Assert.assertTrue( + grid.getVerticalScroller().getSize().getHeight() < 100); + } +} |