aboutsummaryrefslogtreecommitdiffstats
path: root/uitest/src/com/vaadin/tests/components/grid
diff options
context:
space:
mode:
Diffstat (limited to 'uitest/src/com/vaadin/tests/components/grid')
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java131
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridDetailsServerTest.java162
2 files changed, 199 insertions, 94 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 08f0d7d5d2..63fb903f53 100644
--- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java
+++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java
@@ -47,10 +47,12 @@ 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.CssLayout;
import com.vaadin.ui.Grid;
import com.vaadin.ui.Grid.CellReference;
import com.vaadin.ui.Grid.CellStyleGenerator;
import com.vaadin.ui.Grid.Column;
+import com.vaadin.ui.Grid.DetailsGenerator;
import com.vaadin.ui.Grid.FooterCell;
import com.vaadin.ui.Grid.HeaderCell;
import com.vaadin.ui.Grid.HeaderRow;
@@ -60,6 +62,7 @@ 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.Notification;
import com.vaadin.ui.Panel;
import com.vaadin.ui.renderers.DateRenderer;
import com.vaadin.ui.renderers.HtmlRenderer;
@@ -114,6 +117,53 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> {
private Panel detailsPanel;
+ private final DetailsGenerator detailedDetailsGenerator = new DetailsGenerator() {
+ @Override
+ public Component getDetails(final RowReference rowReference) {
+ CssLayout cssLayout = new CssLayout();
+ cssLayout.setHeight("200px");
+ cssLayout.setWidth("100%");
+
+ Item item = rowReference.getItem();
+ for (Object propertyId : item.getItemPropertyIds()) {
+ Property<?> prop = item.getItemProperty(propertyId);
+ String string = prop.getValue().toString();
+ cssLayout.addComponent(new Label(string));
+ }
+
+ final int rowIndex = grid.getContainerDataSource().indexOfId(
+ rowReference.getItemId());
+ ClickListener clickListener = new ClickListener() {
+ @Override
+ public void buttonClick(ClickEvent event) {
+ Notification.show("You clicked on the "
+ + "button in the details for " + "row " + rowIndex);
+ }
+ };
+ cssLayout.addComponent(new Button("Press me", clickListener));
+ return cssLayout;
+ }
+ };
+
+ private final DetailsGenerator watchingDetailsGenerator = new DetailsGenerator() {
+ private int id = 0;
+
+ @Override
+ public Component getDetails(RowReference rowReference) {
+ return new Label("You are watching item id "
+ + rowReference.getItemId() + " (" + (id++) + ")");
+ }
+ };
+
+ private final DetailsGenerator hierarchicalDetailsGenerator = new DetailsGenerator() {
+ @Override
+ public Component getDetails(RowReference rowReference) {
+ detailsPanel = new Panel();
+ detailsPanel.setContent(new Label("One"));
+ return detailsPanel;
+ }
+ };
+
@Override
@SuppressWarnings("unchecked")
protected Grid constructComponent() {
@@ -1059,40 +1109,32 @@ 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;
+ Command<Grid, DetailsGenerator> swapDetailsGenerator = new Command<Grid, DetailsGenerator>() {
+ @Override
+ public void execute(Grid c, DetailsGenerator generator, Object data) {
+ grid.setDetailsGenerator(generator);
+ }
+ };
- @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);
+ Command<Grid, Boolean> openOrCloseItemId = new Command<Grid, Boolean>() {
+ @Override
+ @SuppressWarnings("boxing")
+ public void execute(Grid g, Boolean visible, Object itemId) {
+ g.setDetailsVisible(itemId, visible);
+ }
+ };
- createClickAction("change hierarchy in generator", "Details",
+ createCategory("Generators", "Details");
+ createClickAction("NULL", "Generators", swapDetailsGenerator,
+ DetailsGenerator.NULL);
+ createClickAction("\"Watching\"", "Generators", swapDetailsGenerator,
+ watchingDetailsGenerator);
+ createClickAction("Detailed", "Generators", swapDetailsGenerator,
+ detailedDetailsGenerator);
+ createClickAction("Hierarchical", "Generators", swapDetailsGenerator,
+ hierarchicalDetailsGenerator);
+
+ createClickAction("- Change Component", "Generators",
new Command<Grid, Void>() {
@Override
public void execute(Grid c, Void value, Object data) {
@@ -1105,7 +1147,7 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> {
}
}, null);
- createClickAction("toggle firstItemId", "Details",
+ createClickAction("Toggle firstItemId", "Details",
new Command<Grid, Void>() {
@Override
public void execute(Grid g, Void value, Object data) {
@@ -1117,26 +1159,11 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> {
}
}, null);
- createBooleanAction("firstItemId", "Details", false,
- new Command<Grid, Boolean>() {
- @Override
- @SuppressWarnings("boxing")
- public void execute(Grid g, Boolean visible, Object data) {
- g.setDetailsVisible(g.getContainerDataSource()
- .firstItemId(), visible);
- }
- });
+ createBooleanAction("Open firstItemId", "Details", false,
+ openOrCloseItemId, ds.firstItemId());
- 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);
- }
- });
+ createBooleanAction("Open 995", "Details", false, openOrCloseItemId,
+ ds.getIdByIndex(995));
}
@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 e9b5b688d1..f3f58b002e 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
@@ -16,6 +16,7 @@
package com.vaadin.tests.components.grid.basicfeatures.server;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -27,7 +28,7 @@ import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import com.vaadin.testbench.TestBenchElement;
-import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeatures;
+import com.vaadin.testbench.elements.NotificationElement;
import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest;
public class GridDetailsServerTest extends GridBasicFeaturesTest {
@@ -37,20 +38,21 @@ public class GridDetailsServerTest extends GridBasicFeaturesTest {
* 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 int ALMOST_LAST_INDEX = 995;
+ private static final String[] OPEN_ALMOST_LAST_ITEM_DETAILS = new String[] {
+ "Component", "Details", "Open " + ALMOST_LAST_INDEX };
+ private static final String[] OPEN_FIRST_ITEM_DETAILS = new String[] {
+ "Component", "Details", "Open 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" };
+ "Component", "Details", "Toggle firstItemId" };
+ private static final String[] DETAILS_GENERATOR_NULL = new String[] {
+ "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[] CHANGE_HIERARCHY = new String[] {
- "Component", "Details", "change hierarchy in generator" };
+ "Component", "Details", "Generators", "- Change Component" };
@Before
public void setUp() {
@@ -65,41 +67,42 @@ public class GridDetailsServerTest extends GridBasicFeaturesTest {
} catch (NoSuchElementException ignore) {
// expected
}
- selectMenuPath(FIRST_ITEM_DETAILS);
+ selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
assertNotNull("details should've opened", getGridElement()
.getDetails(0));
}
@Test(expected = NoSuchElementException.class)
public void closeVisibleDetails() {
- selectMenuPath(FIRST_ITEM_DETAILS);
- selectMenuPath(FIRST_ITEM_DETAILS);
+ selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
+ selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
getGridElement().getDetails(0);
}
@Test
- public void openDetailsOutsideOfActiveRange() {
+ public void openDetailsOutsideOfActiveRange() throws InterruptedException {
getGridElement().scroll(10000);
- selectMenuPath(FIRST_ITEM_DETAILS);
+ selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
getGridElement().scroll(0);
+ Thread.sleep(50);
assertNotNull("details should've been opened", getGridElement()
.getDetails(0));
}
@Test(expected = NoSuchElementException.class)
public void closeDetailsOutsideOfActiveRange() {
- selectMenuPath(FIRST_ITEM_DETAILS);
+ selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
getGridElement().scroll(10000);
- selectMenuPath(FIRST_ITEM_DETAILS);
+ selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
getGridElement().scroll(0);
getGridElement().getDetails(0);
}
@Test
public void componentIsVisibleClientSide() {
- selectMenuPath(CUSTOM_DETAILS_GENERATOR);
- selectMenuPath(FIRST_ITEM_DETAILS);
+ selectMenuPath(DETAILS_GENERATOR_WATCHING);
+ selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
TestBenchElement details = getGridElement().getDetails(0);
assertNotNull("No widget detected inside details",
@@ -107,11 +110,11 @@ public class GridDetailsServerTest extends GridBasicFeaturesTest {
}
@Test
- public void togglingAVisibleDetailsRowWithSeparateRoundtrips() {
- selectMenuPath(CUSTOM_DETAILS_GENERATOR);
- selectMenuPath(FIRST_ITEM_DETAILS); // open
- selectMenuPath(FIRST_ITEM_DETAILS); // close
- selectMenuPath(FIRST_ITEM_DETAILS); // open
+ public void openingDetailsTwice() {
+ selectMenuPath(DETAILS_GENERATOR_WATCHING);
+ selectMenuPath(OPEN_FIRST_ITEM_DETAILS); // open
+ selectMenuPath(OPEN_FIRST_ITEM_DETAILS); // close
+ selectMenuPath(OPEN_FIRST_ITEM_DETAILS); // open
TestBenchElement details = getGridElement().getDetails(0);
assertNotNull("No widget detected inside details",
@@ -120,7 +123,7 @@ public class GridDetailsServerTest extends GridBasicFeaturesTest {
@Test(expected = NoSuchElementException.class)
public void scrollingDoesNotCreateAFloodOfDetailsRows() {
- selectMenuPath(CUSTOM_DETAILS_GENERATOR);
+ selectMenuPath(DETAILS_GENERATOR_WATCHING);
// scroll somewhere to hit uncached rows
getGridElement().scrollToRow(101);
@@ -133,8 +136,8 @@ public class GridDetailsServerTest extends GridBasicFeaturesTest {
public void openingDetailsOutOfView() {
getGridElement().scrollToRow(500);
- selectMenuPath(CUSTOM_DETAILS_GENERATOR);
- selectMenuPath(FIRST_ITEM_DETAILS);
+ selectMenuPath(DETAILS_GENERATOR_WATCHING);
+ selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
getGridElement().scrollToRow(0);
@@ -145,8 +148,8 @@ public class GridDetailsServerTest extends GridBasicFeaturesTest {
@Test
public void togglingAVisibleDetailsRowWithOneRoundtrip() {
- selectMenuPath(CUSTOM_DETAILS_GENERATOR);
- selectMenuPath(FIRST_ITEM_DETAILS); // open
+ selectMenuPath(DETAILS_GENERATOR_WATCHING);
+ selectMenuPath(OPEN_FIRST_ITEM_DETAILS); // open
assertTrue("Unexpected generator content",
getGridElement().getDetails(0).getText().endsWith("(0)"));
@@ -156,36 +159,111 @@ public class GridDetailsServerTest extends GridBasicFeaturesTest {
}
@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);
+ selectMenuPath(DETAILS_GENERATOR_WATCHING);
+ selectMenuPath(OPEN_ALMOST_LAST_ITEM_DETAILS);
scrollGridVerticallyTo(100000);
TestBenchElement details = getGridElement().getDetails(
- ALMOST_LAST_ITEM_INDEX);
+ ALMOST_LAST_INDEX);
assertNotNull(details);
assertTrue("Unexpected details content",
- details.getText().endsWith(ALMOST_LAST_ITEM_INDEX + " (0)"));
+ details.getText().endsWith(ALMOST_LAST_INDEX + " (0)"));
}
@Test
public void hierarchyChangesWorkInDetails() {
- selectMenuPath(HIERARCHY_DETAILS_GENERATOR);
- selectMenuPath(FIRST_ITEM_DETAILS);
+ selectMenuPath(DETAILS_GENERATOR_HIERARCHICAL);
+ selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
assertEquals("One", getGridElement().getDetails(0).getText());
selectMenuPath(CHANGE_HIERARCHY);
assertEquals("Two", getGridElement().getDetails(0).getText());
}
+ @Ignore("This use case is not currently supported by Grid. If the detail "
+ + "is out of view, the component is detached from the UI and a "
+ + "new instance is generated when scrolled back. Support will "
+ + "maybe be incorporated at a later time")
@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);
+ selectMenuPath(DETAILS_GENERATOR_HIERARCHICAL);
+ selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
scrollGridVerticallyTo(10000);
selectMenuPath(CHANGE_HIERARCHY);
scrollGridVerticallyTo(0);
assertEquals("Two", getGridElement().getDetails(0).getText());
}
+
+ @Test
+ public void swappingDetailsGenerators_noDetailsShown() {
+ selectMenuPath(DETAILS_GENERATOR_WATCHING);
+ selectMenuPath(DETAILS_GENERATOR_NULL);
+ assertFalse("Got some errors", $(NotificationElement.class).exists());
+ }
+
+ @Test
+ public void swappingDetailsGenerators_shownDetails() {
+ selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
+ assertTrue("Details should be empty at the start", getGridElement()
+ .getDetails(0).getText().isEmpty());
+
+ selectMenuPath(DETAILS_GENERATOR_WATCHING);
+ assertFalse("Details should not be empty after swapping generator",
+ getGridElement().getDetails(0).getText().isEmpty());
+ }
+
+ @Test
+ public void swappingDetailsGenerators_whileDetailsScrolledOut_showNever() {
+ scrollGridVerticallyTo(1000);
+ selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
+ selectMenuPath(DETAILS_GENERATOR_WATCHING);
+ assertFalse("Got some errors", $(NotificationElement.class).exists());
+ }
+
+ @Test
+ public void swappingDetailsGenerators_whileDetailsScrolledOut_showAfter() {
+ scrollGridVerticallyTo(1000);
+ selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
+ selectMenuPath(DETAILS_GENERATOR_WATCHING);
+ scrollGridVerticallyTo(0);
+
+ assertFalse("Got some errors", $(NotificationElement.class).exists());
+ assertNotNull("Could not find a details", getGridElement()
+ .getDetails(0));
+ }
+
+ @Test
+ public void swappingDetailsGenerators_whileDetailsScrolledOut_showBefore() {
+ selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
+ selectMenuPath(DETAILS_GENERATOR_WATCHING);
+ scrollGridVerticallyTo(1000);
+
+ assertFalse("Got some errors", $(NotificationElement.class).exists());
+ assertNotNull("Could not find a details", getGridElement()
+ .getDetails(0));
+ }
+
+ @Test
+ public void swappingDetailsGenerators_whileDetailsScrolledOut_showBeforeAndAfter() {
+ selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
+ selectMenuPath(DETAILS_GENERATOR_WATCHING);
+ scrollGridVerticallyTo(1000);
+ scrollGridVerticallyTo(0);
+
+ assertFalse("Got some errors", $(NotificationElement.class).exists());
+ assertNotNull("Could not find a details", getGridElement()
+ .getDetails(0));
+ }
+
+ @Test
+ public void nullDetailComponentToggling() {
+ selectMenuPath(OPEN_FIRST_ITEM_DETAILS);
+ selectMenuPath(DETAILS_GENERATOR_WATCHING);
+ selectMenuPath(DETAILS_GENERATOR_NULL);
+ assertTrue("Details should be empty with null component",
+ getGridElement().getDetails(0).getText().isEmpty());
+ selectMenuPath(DETAILS_GENERATOR_WATCHING);
+ assertFalse("Details should be not empty with details component",
+ getGridElement().getDetails(0).getText().isEmpty());
+ }
}