From be25df9b752a7350c91393397389761ce652f52d Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Tue, 27 Jan 2015 14:44:24 +0200 Subject: Defer RPC calls in RpcDataProvider to avoid cache issues (#16505) This patch defers cache refresh and row adding/removing. These calls are omitted completely when making initial response to the client or updating the size with bare ItemSetChangeEvents. Change-Id: I6b350680b3e2381caf6a66c9a4ad283207d024dc --- .../tests/components/grid/GridInTabSheet.java | 30 ++++++++++++++-- .../tests/components/grid/GridInTabSheetTest.java | 41 ++++++++++++++++++++++ 2 files changed, 68 insertions(+), 3 deletions(-) (limited to 'uitest') diff --git a/uitest/src/com/vaadin/tests/components/grid/GridInTabSheet.java b/uitest/src/com/vaadin/tests/components/grid/GridInTabSheet.java index 6c7f254a0d..cddbd390f2 100644 --- a/uitest/src/com/vaadin/tests/components/grid/GridInTabSheet.java +++ b/uitest/src/com/vaadin/tests/components/grid/GridInTabSheet.java @@ -20,6 +20,8 @@ import com.vaadin.tests.components.AbstractTestUI; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Grid; +import com.vaadin.ui.Grid.CellReference; +import com.vaadin.ui.Grid.CellStyleGenerator; import com.vaadin.ui.Grid.SelectionMode; import com.vaadin.ui.Label; import com.vaadin.ui.TabSheet; @@ -36,8 +38,8 @@ public class GridInTabSheet extends AbstractTestUI { grid.addRow(i); } - sheet.addTab(grid); - sheet.addTab(new Label("Hidden")); + sheet.addTab(grid, "Grid"); + sheet.addTab(new Label("Hidden"), "Label"); addComponent(sheet); addComponent(new Button("Add row to Grid", new Button.ClickListener() { @@ -64,6 +66,28 @@ public class GridInTabSheet extends AbstractTestUI { } } })); - } + addComponent(new Button("Add CellStyleGenerator", + new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + grid.setCellStyleGenerator(new CellStyleGenerator() { + @Override + public String getStyle(CellReference cellReference) { + int rowIndex = ((Integer) cellReference + .getItemId()).intValue(); + Object propertyId = cellReference + .getPropertyId(); + if (rowIndex % 4 == 1) { + return null; + } else if (rowIndex % 4 == 3 + && "Column 1".equals(propertyId)) { + return null; + } + return propertyId.toString().replace(' ', '_'); + } + }); + } + })); + } } diff --git a/uitest/src/com/vaadin/tests/components/grid/GridInTabSheetTest.java b/uitest/src/com/vaadin/tests/components/grid/GridInTabSheetTest.java index cd165e4678..168496e9df 100644 --- a/uitest/src/com/vaadin/tests/components/grid/GridInTabSheetTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/GridInTabSheetTest.java @@ -23,6 +23,7 @@ import org.junit.Test; import com.vaadin.testbench.elements.ButtonElement; import com.vaadin.testbench.elements.GridElement; import com.vaadin.testbench.elements.NotificationElement; +import com.vaadin.testbench.elements.TabSheetElement; import com.vaadin.tests.annotations.TestCategory; import com.vaadin.tests.tb3.MultiBrowserTest; @@ -43,10 +44,45 @@ public class GridInTabSheetTest extends MultiBrowserTest { assertEquals("" + (100 + i), getGridElement().getCell(i, 1) .getText()); } + + assertNoNotification(); + } + + private void assertNoNotification() { assertFalse("There was an unexpected error notification", isElementPresent(NotificationElement.class)); } + @Test + public void testAddManyRowsWhenGridIsHidden() { + setDebug(true); + openTestURL(); + + TabSheetElement tabsheet = $(TabSheetElement.class).first(); + tabsheet.openTab("Label"); + for (int i = 0; i < 50; ++i) { + addGridRow(); + } + + tabsheet.openTab("Grid"); + + assertNoNotification(); + } + + @Test + public void testAddCellStyleGeneratorWhenGridIsHidden() { + setDebug(true); + openTestURL(); + + TabSheetElement tabsheet = $(TabSheetElement.class).first(); + tabsheet.openTab("Label"); + addCellStyleGenerator(); + + tabsheet.openTab("Grid"); + + assertNoNotification(); + } + private void removeGridRow() { $(ButtonElement.class).caption("Remove row from Grid").first().click(); } @@ -55,6 +91,11 @@ public class GridInTabSheetTest extends MultiBrowserTest { $(ButtonElement.class).caption("Add row to Grid").first().click(); } + private void addCellStyleGenerator() { + $(ButtonElement.class).caption("Add CellStyleGenerator").first() + .click(); + } + private GridElement getGridElement() { return $(GridElement.class).first(); } -- cgit v1.2.3