diff options
author | Henrik Paul <henrik@vaadin.com> | 2015-03-10 17:02:02 +0200 |
---|---|---|
committer | Pekka Hyvönen <pekka@vaadin.com> | 2015-03-17 21:53:20 +0000 |
commit | a1619ee73dc18eecda22056541826a3c8bb65a5c (patch) | |
tree | 398476a7cd0192faed7393cbc1a9e65ac4df87c9 /uitest | |
parent | 84c143dd76ed1d27d03c0d695e7218b477d008fe (diff) | |
download | vaadin-framework-a1619ee73dc18eecda22056541826a3c8bb65a5c.tar.gz vaadin-framework-a1619ee73dc18eecda22056541826a3c8bb65a5c.zip |
Grid's Details can now be Components (#16644)
Change-Id: If67dd2e86cf41c57f208a3691e2cb7a5a29c133c
Diffstat (limited to 'uitest')
-rw-r--r-- | uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java | 74 | ||||
-rw-r--r-- | uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridDetailsServerTest.java | 100 |
2 files changed, 170 insertions, 4 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 f0c4b3d9c0..08f0d7d5d2 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java @@ -46,6 +46,7 @@ import com.vaadin.tests.components.AbstractComponentTest; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.Component; import com.vaadin.ui.Grid; import com.vaadin.ui.Grid.CellReference; import com.vaadin.ui.Grid.CellStyleGenerator; @@ -58,6 +59,8 @@ import com.vaadin.ui.Grid.RowReference; import com.vaadin.ui.Grid.RowStyleGenerator; import com.vaadin.ui.Grid.SelectionMode; import com.vaadin.ui.Grid.SelectionModel; +import com.vaadin.ui.Label; +import com.vaadin.ui.Panel; import com.vaadin.ui.renderers.DateRenderer; import com.vaadin.ui.renderers.HtmlRenderer; import com.vaadin.ui.renderers.NumberRenderer; @@ -109,6 +112,8 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> { } }; + private Panel detailsPanel; + @Override @SuppressWarnings("unchecked") protected Grid constructComponent() { @@ -1054,6 +1059,64 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> { } private void createDetailsActions() { + createClickAction("custom details generator", "Details", + new Command<Grid, Void>() { + @Override + public void execute(Grid c, Void value, Object data) { + grid.setDetailsGenerator(new Grid.DetailsGenerator() { + private int seq = 0; + + @Override + public Component getDetails( + RowReference rowReference) { + return new Label("You are watching item id " + + rowReference.getItemId() + " (" + + (seq++) + ")"); + } + }); + } + }, null); + createClickAction("hierarchy details generator", "Details", + new Command<Grid, Void>() { + @Override + public void execute(Grid c, Void value, Object data) { + grid.setDetailsGenerator(new Grid.DetailsGenerator() { + @Override + public Component getDetails( + RowReference rowReference) { + detailsPanel = new Panel(); + detailsPanel.setContent(new Label("One")); + return detailsPanel; + } + }); + } + }, null); + + createClickAction("change hierarchy in generator", "Details", + 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")); + } + } + }, null); + + createClickAction("toggle firstItemId", "Details", + new Command<Grid, Void>() { + @Override + public void execute(Grid g, Void value, Object data) { + Object firstItemId = g.getContainerDataSource() + .firstItemId(); + boolean toggle = g.isDetailsVisible(firstItemId); + g.setDetailsVisible(firstItemId, !toggle); + g.setDetailsVisible(firstItemId, toggle); + } + }, null); + createBooleanAction("firstItemId", "Details", false, new Command<Grid, Boolean>() { @Override @@ -1063,6 +1126,17 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> { .firstItemId(), visible); } }); + + createBooleanAction("lastItemId-5", "Details", false, + new Command<Grid, Boolean>() { + @Override + @SuppressWarnings("boxing") + public void execute(Grid g, Boolean visible, Object data) { + Object fifthLastItemId = g.getContainerDataSource() + .getItemIds(ROWS - 6, 1).get(0); + g.setDetailsVisible(fifthLastItemId, visible); + } + }); } @Override 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 01d2ba55eb..e9e32cb1ca 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 @@ -15,21 +15,43 @@ */ package com.vaadin.tests.components.grid.basicfeatures.server; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; +import org.openqa.selenium.By; import org.openqa.selenium.NoSuchElementException; -import com.vaadin.testbench.annotations.RunLocally; -import com.vaadin.testbench.parallel.Browser; +import com.vaadin.testbench.TestBenchElement; +import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeatures; import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest; -@RunLocally(Browser.PHANTOMJS) public class GridDetailsServerTest extends GridBasicFeaturesTest { + /** + * The reason to why last item details wasn't selected is that since it will + * exist only after the viewport has been scrolled into view, we wouldn't be + * able to scroll that particular details row into view, making tests + * awkward with two scroll commands back to back. + */ + private static final int ALMOST_LAST_ITEM_INDEX = GridBasicFeatures.ROWS - 5; + private static final String[] ALMOST_LAST_ITEM_DETAILS = new String[] { + "Component", "Details", "lastItemId-5" }; + private static final String[] FIRST_ITEM_DETAILS = new String[] { "Component", "Details", "firstItemId" }; + private static final String[] TOGGLE_FIRST_ITEM_DETAILS = new String[] { + "Component", "Details", "toggle firstItemId" }; + private static final String[] CUSTOM_DETAILS_GENERATOR = new String[] { + "Component", "Details", "custom details generator" }; + private static final String[] HIERARCHY_DETAILS_GENERATOR = new String[] { + "Component", "Details", "hierarchy details generator" }; + private static final String[] CHANGE_HIERARCHY = new String[] { + "Component", "Details", "change hierarchy in generator" }; @Before public void setUp() { @@ -53,7 +75,9 @@ public class GridDetailsServerTest extends GridBasicFeaturesTest { public void closeVisibleDetails() { selectMenuPath(FIRST_ITEM_DETAILS); selectMenuPath(FIRST_ITEM_DETAILS); - getGridElement().getDetails(0); + + // this will throw before assertNull + assertNull(getGridElement().getDetails(0)); } @Test @@ -73,4 +97,72 @@ public class GridDetailsServerTest extends GridBasicFeaturesTest { getGridElement().scroll(0); getGridElement().getDetails(0); } + + @Test + public void componentIsVisibleClientSide() { + selectMenuPath(CUSTOM_DETAILS_GENERATOR); + selectMenuPath(FIRST_ITEM_DETAILS); + + TestBenchElement details = getGridElement().getDetails(0); + assertNotNull("No widget detected inside details", + details.findElement(By.className("v-widget"))); + } + + @Test + public void togglingAVisibleDetailsRowWithSeparateRoundtrips() { + selectMenuPath(CUSTOM_DETAILS_GENERATOR); + selectMenuPath(FIRST_ITEM_DETAILS); // open + selectMenuPath(FIRST_ITEM_DETAILS); // close + selectMenuPath(FIRST_ITEM_DETAILS); // open + + TestBenchElement details = getGridElement().getDetails(0); + assertNotNull("No widget detected inside details", + details.findElement(By.className("v-widget"))); + } + + @Test + public void togglingAVisibleDetailsRowWithOneRoundtrip() { + selectMenuPath(CUSTOM_DETAILS_GENERATOR); + selectMenuPath(FIRST_ITEM_DETAILS); // open + + assertTrue("Unexpected generator content", + getGridElement().getDetails(0).getText().endsWith("(0)")); + selectMenuPath(TOGGLE_FIRST_ITEM_DETAILS); + assertTrue("New component was not displayed in the client", + getGridElement().getDetails(0).getText().endsWith("(1)")); + } + + @Test + @Ignore("This will be patched with https://dev.vaadin.com/review/#/c/7917/") + public void almosLastItemIdIsRendered() { + selectMenuPath(CUSTOM_DETAILS_GENERATOR); + selectMenuPath(ALMOST_LAST_ITEM_DETAILS); + scrollGridVerticallyTo(100000); + + TestBenchElement details = getGridElement().getDetails( + ALMOST_LAST_ITEM_INDEX); + assertNotNull(details); + assertTrue("Unexpected details content", + details.getText().endsWith(ALMOST_LAST_ITEM_INDEX + " (0)")); + } + + @Test + public void hierarchyChangesWorkInDetails() { + selectMenuPath(HIERARCHY_DETAILS_GENERATOR); + selectMenuPath(FIRST_ITEM_DETAILS); + assertEquals("One", getGridElement().getDetails(0).getText()); + selectMenuPath(CHANGE_HIERARCHY); + assertEquals("Two", getGridElement().getDetails(0).getText()); + } + + @Test + @Ignore("This will be patched with https://dev.vaadin.com/review/#/c/7917/") + public void hierarchyChangesWorkInDetailsWhileOutOfView() { + selectMenuPath(HIERARCHY_DETAILS_GENERATOR); + selectMenuPath(FIRST_ITEM_DETAILS); + scrollGridVerticallyTo(10000); + selectMenuPath(CHANGE_HIERARCHY); + scrollGridVerticallyTo(0); + assertEquals("Two", getGridElement().getDetails(0).getText()); + } } |