diff options
author | Teemu Suo-Anttila <teemusa@vaadin.com> | 2015-10-05 16:41:56 +0300 |
---|---|---|
committer | Teemu Suo-Anttila <teemusa@vaadin.com> | 2015-10-06 12:23:07 +0300 |
commit | 1d3fc17f38e8dbf3ee2328be221202e1774bd56b (patch) | |
tree | bc6c31972fcf2bccd02a9536404c9e49daa56e7f /uitest | |
parent | 5097095625403405d030575fcc1102f02aa3e327 (diff) | |
download | vaadin-framework-1d3fc17f38e8dbf3ee2328be221202e1774bd56b.tar.gz vaadin-framework-1d3fc17f38e8dbf3ee2328be221202e1774bd56b.zip |
Add API for data destruction to DataGenerator interface (#19038)
This patch provides destroyData implementation for all default data
generators.
Change-Id: I1458080ee0203a27b52e604d3a30c9e5240c0383
Diffstat (limited to 'uitest')
-rw-r--r-- | uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java | 35 | ||||
-rw-r--r-- | uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridDetailsServerTest.java | 39 |
2 files changed, 50 insertions, 24 deletions
diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java index 479ece71ca..598ac420fc 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java @@ -20,10 +20,12 @@ import java.text.DecimalFormatSymbols; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.Random; import com.vaadin.data.Container.Filter; @@ -190,8 +192,6 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> { } }; - private Panel detailsPanel; - private final DetailsGenerator detailedDetailsGenerator = new DetailsGenerator() { @Override public Component getDetails(final RowReference rowReference) { @@ -230,12 +230,18 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> { } }; - private final DetailsGenerator hierarchicalDetailsGenerator = new DetailsGenerator() { + private Map<Object, Panel> detailsMap = new HashMap<Object, Panel>(); + + private final DetailsGenerator persistingDetailsGenerator = new DetailsGenerator() { @Override public Component getDetails(RowReference rowReference) { - detailsPanel = new Panel(); - detailsPanel.setContent(new Label("One")); - return detailsPanel; + Object itemId = rowReference.getItemId(); + if (!detailsMap.containsKey(itemId)) { + Panel panel = new Panel(); + panel.setContent(new Label("One")); + detailsMap.put(itemId, panel); + } + return detailsMap.get(itemId); } }; @@ -1514,18 +1520,21 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> { watchingDetailsGenerator); createClickAction("Detailed", "Generators", swapDetailsGenerator, detailedDetailsGenerator); - createClickAction("Hierarchical", "Generators", swapDetailsGenerator, - hierarchicalDetailsGenerator); + createClickAction("Persisting", "Generators", swapDetailsGenerator, + persistingDetailsGenerator); createClickAction("- Change Component", "Generators", new Command<Grid, Void>() { @Override public void execute(Grid c, Void value, Object data) { - Label label = (Label) detailsPanel.getContent(); - if (label.getValue().equals("One")) { - detailsPanel.setContent(new Label("Two")); - } else { - detailsPanel.setContent(new Label("One")); + for (Object id : detailsMap.keySet()) { + Panel panel = detailsMap.get(id); + Label label = (Label) panel.getContent(); + if (label.getValue().equals("One")) { + panel.setContent(new Label("Two")); + } else { + panel.setContent(new Label("One")); + } } } }, null); diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridDetailsServerTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridDetailsServerTest.java index a9ab7027db..f13ea9c073 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridDetailsServerTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridDetailsServerTest.java @@ -23,9 +23,9 @@ import static org.junit.Assert.fail; import org.junit.Before; import org.junit.Test; -import org.openqa.selenium.By; import org.openqa.selenium.NoSuchElementException; +import com.vaadin.testbench.By; import com.vaadin.testbench.TestBenchElement; import com.vaadin.testbench.elements.NotificationElement; import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest; @@ -48,8 +48,8 @@ public class GridDetailsServerTest extends GridBasicFeaturesTest { "Component", "Details", "Generators", "NULL" }; private static final String[] DETAILS_GENERATOR_WATCHING = new String[] { "Component", "Details", "Generators", "\"Watching\"" }; - private static final String[] DETAILS_GENERATOR_HIERARCHICAL = new String[] { - "Component", "Details", "Generators", "Hierarchical" }; + private static final String[] DETAILS_GENERATOR_PERSISTING = new String[] { + "Component", "Details", "Generators", "Persisting" }; private static final String[] CHANGE_HIERARCHY = new String[] { "Component", "Details", "Generators", "- Change Component" }; @@ -187,8 +187,8 @@ public class GridDetailsServerTest extends GridBasicFeaturesTest { } @Test - public void hierarchyChangesWorkInDetails() { - selectMenuPath(DETAILS_GENERATOR_HIERARCHICAL); + public void persistingChangesWorkInDetails() { + selectMenuPath(DETAILS_GENERATOR_PERSISTING); selectMenuPath(OPEN_FIRST_ITEM_DETAILS); assertEquals("One", getGridElement().getDetails(0).getText()); selectMenuPath(CHANGE_HIERARCHY); @@ -196,8 +196,8 @@ public class GridDetailsServerTest extends GridBasicFeaturesTest { } @Test - public void hierarchyChangesWorkInDetailsWhileOutOfView() { - selectMenuPath(DETAILS_GENERATOR_HIERARCHICAL); + public void persistingChangesWorkInDetailsWhileOutOfView() { + selectMenuPath(DETAILS_GENERATOR_PERSISTING); selectMenuPath(OPEN_FIRST_ITEM_DETAILS); assertEquals("One", getGridElement().getDetails(0).getText()); scrollGridVerticallyTo(10000); @@ -207,6 +207,23 @@ public class GridDetailsServerTest extends GridBasicFeaturesTest { } @Test + public void persistingChangesWorkInDetailsWhenNotAttached() { + selectMenuPath(DETAILS_GENERATOR_PERSISTING); + selectMenuPath(OPEN_FIRST_ITEM_DETAILS); + assertEquals("One", getGridElement().getDetails(0).getText()); + + selectMenuPath(OPEN_FIRST_ITEM_DETAILS); + assertFalse("Details should be detached", getGridElement() + .isElementPresent(By.vaadin("#details[0]"))); + + selectMenuPath(CHANGE_HIERARCHY); + selectMenuPath(OPEN_FIRST_ITEM_DETAILS); + + assertEquals("Two", getGridElement().getDetails(0).getText()); + + } + + @Test public void swappingDetailsGenerators_noDetailsShown() { selectMenuPath(DETAILS_GENERATOR_WATCHING); selectMenuPath(DETAILS_GENERATOR_NULL); @@ -215,7 +232,7 @@ public class GridDetailsServerTest extends GridBasicFeaturesTest { @Test public void swappingDetailsGenerators_shownDetails() { - selectMenuPath(DETAILS_GENERATOR_HIERARCHICAL); + selectMenuPath(DETAILS_GENERATOR_PERSISTING); selectMenuPath(OPEN_FIRST_ITEM_DETAILS); assertTrue("Details should contain 'One' at first", getGridElement() .getDetails(0).getText().contains("One")); @@ -237,7 +254,7 @@ public class GridDetailsServerTest extends GridBasicFeaturesTest { @Test public void swappingDetailsGenerators_whileDetailsScrolledOut_showAfter() { scrollGridVerticallyTo(1000); - selectMenuPath(DETAILS_GENERATOR_HIERARCHICAL); + selectMenuPath(DETAILS_GENERATOR_PERSISTING); selectMenuPath(OPEN_FIRST_ITEM_DETAILS); selectMenuPath(DETAILS_GENERATOR_WATCHING); scrollGridVerticallyTo(0); @@ -249,7 +266,7 @@ public class GridDetailsServerTest extends GridBasicFeaturesTest { @Test public void swappingDetailsGenerators_whileDetailsScrolledOut_showBefore() { - selectMenuPath(DETAILS_GENERATOR_HIERARCHICAL); + selectMenuPath(DETAILS_GENERATOR_PERSISTING); selectMenuPath(OPEN_FIRST_ITEM_DETAILS); selectMenuPath(DETAILS_GENERATOR_WATCHING); scrollGridVerticallyTo(1000); @@ -261,7 +278,7 @@ public class GridDetailsServerTest extends GridBasicFeaturesTest { @Test public void swappingDetailsGenerators_whileDetailsScrolledOut_showBeforeAndAfter() { - selectMenuPath(DETAILS_GENERATOR_HIERARCHICAL); + selectMenuPath(DETAILS_GENERATOR_PERSISTING); selectMenuPath(OPEN_FIRST_ITEM_DETAILS); selectMenuPath(DETAILS_GENERATOR_WATCHING); scrollGridVerticallyTo(1000); |