diff options
Diffstat (limited to 'uitest')
-rw-r--r-- | uitest/src/main/java/com/vaadin/tests/components/grid/GridSelectAllFiltering.java | 71 | ||||
-rw-r--r-- | uitest/src/test/java/com/vaadin/tests/components/grid/GridSelectAllFilteringTest.java | 62 |
2 files changed, 133 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridSelectAllFiltering.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridSelectAllFiltering.java new file mode 100644 index 0000000000..3c85e9c435 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridSelectAllFiltering.java @@ -0,0 +1,71 @@ +package com.vaadin.tests.components.grid; + +import java.util.Iterator; +import java.util.Set; + +import com.vaadin.data.provider.DataProvider; +import com.vaadin.data.provider.ListDataProvider; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.data.bean.Person; +import com.vaadin.ui.Button; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Grid.SelectionMode; +import com.vaadin.ui.renderers.NumberRenderer; + +public class GridSelectAllFiltering extends SimpleGridUI { + private String filterText = "Johannes"; + + @Override + protected void setup(VaadinRequest request) { + Grid<Person> grid = new Grid<>(); + grid.setSelectionMode(SelectionMode.MULTI); + grid.setHeightByRows(3); + grid.addColumn(Person::getFirstName); + grid.addColumn(Person::getAge, new NumberRenderer()); + + ListDataProvider<Person> dataProvider = DataProvider + .ofCollection(createPersons()); + dataProvider.setFilter(person -> { + if (person.getFirstName().contains(filterText)) { + return false; + } + return true; + }); + grid.setDataProvider(dataProvider); + + Button toggleButton = new Button("Toggle filter", e -> { + if ("Johannes".equals(filterText)) { + filterText = "Galileo"; + } else { + filterText = "Johannes"; + } + dataProvider.refreshAll(); + }); + toggleButton.setId("toggle"); + + Button checkButton = new Button("Check selection", e -> { + Set<Person> selected = grid.getSelectedItems(); + Iterator<Person> i = selected.iterator(); + log("selected " + selected.size() + + (i.hasNext() ? ": " + i.next().getFirstName() : "") + + (i.hasNext() ? ", " + i.next().getFirstName() : "") + + (i.hasNext() ? ", " + i.next().getFirstName() : "") + + (i.hasNext() ? "... " : "")); + }); + checkButton.setId("check"); + + addComponents(grid, toggleButton, checkButton); + } + + @Override + protected Integer getTicketNumber() { + return 11479; + } + + @Override + protected String getTestDescription() { + return "Selecting all does not select items that have been " + + "filtered out, they should not be shown selected " + + "after the filter changes."; + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridSelectAllFilteringTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridSelectAllFilteringTest.java new file mode 100644 index 0000000000..37c7d6281c --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridSelectAllFilteringTest.java @@ -0,0 +1,62 @@ +package com.vaadin.tests.components.grid; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.GridElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class GridSelectAllFilteringTest extends MultiBrowserTest { + + @Test + public void checkSelectAll() { + openTestURL(); + + GridElement grid = $(GridElement.class).first(); + ButtonElement toggleButton = $(ButtonElement.class).id("toggle"); + ButtonElement checkButton = $(ButtonElement.class).id("check"); + + // ensure no initial selection + checkButton.click(); + assertEquals("Unexpected log entry,", "1. selected 0", getLogRow(0)); + assertEquals("Unexpected amount of visually selected rows,", 0, + grid.findElements(By.className("v-grid-row-selected")).size()); + + // select all + WebElement selectAllCheckbox = grid + .findElement(By.className("v-grid-select-all-checkbox")); + selectAllCheckbox.click(); + + // ensure only the two visible rows get selected + checkButton.click(); + assertEquals("Unexpected log entry,", + "2. selected 2: Nicolaus Copernicus, Galileo Galilei", + getLogRow(0)); + assertEquals("Unexpected amount of visually selected rows,", 2, + grid.findElements(By.className("v-grid-row-selected")).size()); + + // toggle filter + toggleButton.click(); + + // ensure selection did not change but only one selected row is visible + checkButton.click(); + assertEquals("Unexpected log entry,", + "3. selected 2: Nicolaus Copernicus, Galileo Galilei", + getLogRow(0)); + assertEquals("Unexpected amount of visually selected rows,", 1, + grid.findElements(By.className("v-grid-row-selected")).size()); + + // remove all selections + selectAllCheckbox.click(); + + // ensure all selections got removed whether they were visible or not + checkButton.click(); + assertEquals("Unexpected log entry,", "4. selected 0", getLogRow(0)); + assertEquals("Unexpected amount of visually selected rows,", 0, + grid.findElements(By.className("v-grid-row-selected")).size()); + } +} |