diff options
author | Anna Koskinen <Ansku@users.noreply.github.com> | 2020-01-09 15:09:49 +0200 |
---|---|---|
committer | Olli Tietäväinen <ollit@vaadin.com> | 2020-01-09 15:09:49 +0200 |
commit | 376131e16b10d07eea707fcacfa9b14b71fd971a (patch) | |
tree | 5fae66ce2793a5e4ed0f0eb0880435cfaa0ad4c0 /uitest | |
parent | 458de861053d7c69c04f31260f847576c2feab01 (diff) | |
download | vaadin-framework-376131e16b10d07eea707fcacfa9b14b71fd971a.tar.gz vaadin-framework-376131e16b10d07eea707fcacfa9b14b71fd971a.zip |
Removed outdated spacer height update from removal process. (#11861)
* Removed outdated spacer height update from removal process.
Fixes #11856
Diffstat (limited to 'uitest')
2 files changed, 115 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridDetailsAndUndefinedHeight.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridDetailsAndUndefinedHeight.java new file mode 100644 index 0000000000..b30211412e --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridDetailsAndUndefinedHeight.java @@ -0,0 +1,76 @@ +package com.vaadin.tests.components.grid; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Set; +import java.util.stream.IntStream; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.ui.grid.HeightMode; +import com.vaadin.tests.components.AbstractReindeerTestUI; +import com.vaadin.tests.data.bean.Person; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Grid.SelectionMode; +import com.vaadin.ui.Label; +import com.vaadin.ui.VerticalLayout; + +public class GridDetailsAndUndefinedHeight extends AbstractReindeerTestUI { + + @Override + protected void setup(VaadinRequest request) { + ArrayList<Person> itemsCollection = new ArrayList<>(); + + final Grid<Person> grid = new Grid<Person>() { + @Override + public void setItems(Collection<Person> items) { + itemsCollection.clear(); + itemsCollection.addAll(items); + super.setItems(items); + } + }; + addComponent(grid); + + grid.addColumn(Person::getFirstName); + grid.addColumn(Person::getLastName); + grid.addColumn(Person::getEmail); + + grid.setItems(IntStream.range(0, 5).mapToObj(this::createPerson)); + + grid.setWidthFull(); + grid.setHeightMode(HeightMode.UNDEFINED); + + grid.setSelectionMode(SelectionMode.SINGLE); + + grid.addSelectionListener(event -> { + itemsCollection + .forEach(item -> grid.setDetailsVisible(item, false)); + final Set<Person> selections = event.getAllSelectedItems(); + if (!selections.isEmpty()) { + Person selection = selections.iterator().next(); + grid.setDetailsVisible(selection, true); + grid.scrollTo(itemsCollection.indexOf(selection)); + } + }); + grid.setDetailsGenerator(person -> new VerticalLayout( + new Label("Details " + itemsCollection.indexOf(person)))); + } + + private Person createPerson(int index) { + Person person = new Person(); + person.setFirstName("cell " + index + " 0"); + person.setLastName("cell " + index + " 1"); + person.setEmail("cell " + index + " 2"); + return person; + } + + @Override + protected String getTestDescription() { + return "Second selection should successfully close " + + "the details row from the first selection."; + } + + @Override + protected Integer getTicketNumber() { + return 11856; + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridDetailsAndUndefinedHeightTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridDetailsAndUndefinedHeightTest.java new file mode 100644 index 0000000000..c167049eb9 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridDetailsAndUndefinedHeightTest.java @@ -0,0 +1,39 @@ +package com.vaadin.tests.components.grid; + +import static org.junit.Assert.assertEquals; + +import java.util.List; + +import org.junit.Test; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.GridElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class GridDetailsAndUndefinedHeightTest extends MultiBrowserTest { + + @Test + public void changingSelectionClosesOldDetails() { + openTestURL(); + GridElement grid = $(GridElement.class).first(); + grid.getCell(4, 0).click(); + waitForElementPresent(By.className("v-grid-spacer")); + + List<WebElement> spacers = grid + .findElements(By.className("v-grid-spacer")); + assertEquals("Unexpected amount of details rows", 1, spacers.size()); + assertEquals("Unexpected details row contents", "Details 4", + spacers.get(0).findElement(By.className("v-label")).getText()); + + // change selection + grid.getCell(3, 0).click(); + + spacers = grid.findElements(By.className("v-grid-spacer")); + assertEquals("Unexpected amount of details rows", 1, spacers.size()); + assertEquals("Unexpected details row contents", "Details 3", + spacers.get(0).findElement(By.className("v-label")).getText()); + + } + +} |