diff options
author | Klaudeta <31614592+Klaudeta@users.noreply.github.com> | 2019-03-21 07:56:20 +0200 |
---|---|---|
committer | Pekka Hyvönen <pekka@vaadin.com> | 2019-03-21 07:56:20 +0200 |
commit | 15cc5d13b379d744988b169916eb1b9437cf8021 (patch) | |
tree | 725cae6e6c05b309882ef4762f3de0e3aebe15f3 /uitest | |
parent | f11ea958cce7a3b273bc041e6a20a399dd23e6ac (diff) | |
download | vaadin-framework-15cc5d13b379d744988b169916eb1b9437cf8021.tar.gz vaadin-framework-15cc5d13b379d744988b169916eb1b9437cf8021.zip |
Make improve of caching for hierarchical data optional (#11501)
Make improve of caching for hierarchical data optional
Fixes #11477
Diffstat (limited to 'uitest')
2 files changed, 174 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridIndexedContainerInsertSelect.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridIndexedContainerInsertSelect.java new file mode 100644 index 0000000000..27678aedfd --- /dev/null +++ b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridIndexedContainerInsertSelect.java @@ -0,0 +1,108 @@ +package com.vaadin.v7.tests.components.grid.basicfeatures.server; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractReindeerTestUI; +import com.vaadin.ui.Button; +import com.vaadin.v7.data.Item; +import com.vaadin.v7.data.sort.Sort; +import com.vaadin.v7.data.util.AbstractInMemoryContainer; +import com.vaadin.v7.data.util.IndexedContainer; +import com.vaadin.v7.ui.CheckBox; +import com.vaadin.v7.ui.Grid; +import com.vaadin.v7.ui.HorizontalLayout; +import com.vaadin.v7.ui.VerticalLayout; + +@Widgetset("com.vaadin.v7.Vaadin7WidgetSet") +public class GridIndexedContainerInsertSelect extends AbstractReindeerTestUI { + + private static final String INFO_COLUMN_PATTERN = "InsertedIndex: %d ItemUid: %d SelectedRowIndex: %d SelectedItemUid: %s"; + private static final String COLUMN1 = "Column1"; + private static final String COLUMN2 = "Column2"; + private int currInsertionIndex = 4; + private VerticalLayout layout; + private Grid grid; + private IndexedContainer container; + + protected void setup(VaadinRequest vaadinRequest) { + layout = new VerticalLayout(); + layout.setSizeFull(); + + initGrid(); + initData(container); + selectFirstRow(); + + CheckBox checkBox = new CheckBox("Select row after insert", true); + + Button.ClickListener clickListener = e -> { + addNewItem(); + selectOnlyLastItemIfRequested(checkBox); + currInsertionIndex++; + }; + + Button button = new Button("Add row after selected row!", + clickListener); + + HorizontalLayout inputBox = new HorizontalLayout(); + + inputBox.addComponents(checkBox, button); + + layout.addComponents(grid, inputBox); + + addComponent(layout); + } + + private void initGrid() { + grid = new Grid(); + grid.setSizeFull(); + container = new IndexedContainer(); + container.addContainerProperty(COLUMN1, String.class, null); + container.addContainerProperty(COLUMN2, String.class, null); + grid.setContainerDataSource(container); + } + + private void selectFirstRow() { + grid.select("1"); + } + + private void initData(IndexedContainer container) { + createRowItem("1", "Item 1", "ItemCol2 1", container); + createRowItem("2", "Item 2", "ItemCol2 2", container); + createRowItem("3", "Item 3", "ItemCol2 3", container); + } + + private void selectOnlyLastItemIfRequested(CheckBox checkBox) { + if (checkBox.getValue()) { + grid.select(currInsertionIndex + ""); + } + } + + private void addNewItem() { + final Object selectedRow = grid.getSelectedRow(); + int currentIndex = container.indexOfId(selectedRow); + int insertIndex = currentIndex + 1; + final Item thirdItem = container.addItemAt(insertIndex, + currInsertionIndex + ""); + setRowData(thirdItem, "Item " + currInsertionIndex, + getInfoColumnContent(selectedRow, currentIndex, insertIndex)); + } + + private void setRowData(Item thirdItem, String column1Data, + String column2Data) { + thirdItem.getItemProperty(COLUMN1).setValue(column1Data); + thirdItem.getItemProperty(COLUMN2).setValue(column2Data); + } + + private String getInfoColumnContent(Object selectedRow, int currentIndex, + int insertIndex) { + return String.format(INFO_COLUMN_PATTERN, insertIndex, + currInsertionIndex, currentIndex, selectedRow); + } + + private void createRowItem(String id, String column1, String column2, + AbstractInMemoryContainer<Object, Object, Item> container) { + Item firstRow = container.addItem(id); + setRowData(firstRow, column1, column2); + } + +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridIndexedContainerInsertSelectTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridIndexedContainerInsertSelectTest.java new file mode 100644 index 0000000000..e09fa5f560 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/basicfeatures/server/GridIndexedContainerInsertSelectTest.java @@ -0,0 +1,66 @@ +package com.vaadin.v7.tests.components.grid.basicfeatures.server; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.GridElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.SingleBrowserTest; +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; + +@TestCategory("grid") +public class GridIndexedContainerInsertSelectTest extends SingleBrowserTest { + + @Override + public void setup() throws Exception { + + super.setup(); + openTestURL(); + waitForElementPresent(By.className("v-grid")); + } + + /** + * Test asserting that issue https://github.com/vaadin/framework/issues/11477 + * is fixed. + */ + @Test + public void test_insertRowAfterSelected_newRowIsSelected() { + openTestURL(); + + // Assert that first row is already selected when ui loaded + Assert.assertTrue( + "First row should be selected to continue with the test!", + isRowSelected(0)); + + // Add new row after the selected one + $(ButtonElement.class).first().click(); + + // Assert that the new row is added correctly + Assert.assertEquals("Item 4", + $(GridElement.class).first().getRow(1).getCell(0).getText()); + + // Assert that the new added row is selected + Assert.assertTrue("Newly inserted row should be selected!", + isRowSelected(1)); + + // Select row at index 2 + $(GridElement.class).first().getRow(2).click(); + + // Add new row after the selected one + $(ButtonElement.class).first().click(); + + // Assert that the new row is added correctly + Assert.assertEquals("Item 5", + $(GridElement.class).first().getRow(3).getCell(0).getText()); + + // Assert that the new added row is selected + Assert.assertTrue("Newly inserted row should be selected!", + isRowSelected(3)); + + } + + protected boolean isRowSelected(int index) { + return $(GridElement.class).first().getRow(index).isSelected(); + } + +} |