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.java167
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorBufferedTest.java243
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorTest.java294
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorUnbufferedTest.java205
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridFocusTest.java79
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridStructureTest.java2
6 files changed, 767 insertions, 223 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 ef51cdf446..272ff1c9ae 100644
--- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java
+++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java
@@ -29,6 +29,8 @@ import java.util.Random;
import com.vaadin.data.Container.Filter;
import com.vaadin.data.Item;
import com.vaadin.data.Property;
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.data.fieldgroup.FieldGroup.CommitException;
import com.vaadin.data.sort.Sort;
import com.vaadin.data.sort.SortOrder;
@@ -48,6 +50,7 @@ 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.Field;
import com.vaadin.ui.Grid;
import com.vaadin.ui.Grid.CellReference;
import com.vaadin.ui.Grid.CellStyleGenerator;
@@ -57,6 +60,10 @@ import com.vaadin.ui.Grid.ColumnReorderListener;
import com.vaadin.ui.Grid.ColumnVisibilityChangeEvent;
import com.vaadin.ui.Grid.ColumnVisibilityChangeListener;
import com.vaadin.ui.Grid.DetailsGenerator;
+import com.vaadin.ui.Grid.EditorCloseEvent;
+import com.vaadin.ui.Grid.EditorListener;
+import com.vaadin.ui.Grid.EditorMoveEvent;
+import com.vaadin.ui.Grid.EditorOpenEvent;
import com.vaadin.ui.Grid.FooterCell;
import com.vaadin.ui.Grid.HeaderCell;
import com.vaadin.ui.Grid.HeaderRow;
@@ -123,6 +130,24 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> {
}
};
+ private ItemClickListener editorOpeningItemClickListener = new ItemClickListener() {
+
+ @Override
+ public void itemClick(ItemClickEvent event) {
+ grid.editItem(event.getItemId());
+ }
+ };
+
+ private ValueChangeListener reactiveValueChanger = new ValueChangeListener() {
+ @Override
+ @SuppressWarnings("unchecked")
+ public void valueChange(ValueChangeEvent event) {
+ Object id = grid.getEditedItemId();
+ grid.getContainerDataSource().getContainerProperty(id, "Column 2")
+ .setValue("Modified");
+ }
+ };
+
private ColumnReorderListener columnReorderListener = new ColumnReorderListener() {
@Override
@@ -362,49 +387,58 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> {
}
private void addFilterActions() {
- createClickAction("Column 1 starts with \"(23\"", "Filter",
- new Command<Grid, Void>() {
- @Override
- public void execute(Grid grid, Void value, Object data) {
- ds.addContainerFilter(new Filter() {
+ createBooleanAction("Column 1 starts with \"(23\"", "Filter", false,
+ new Command<Grid, Boolean>() {
+ Filter filter = new Filter() {
+ @Override
+ public boolean passesFilter(Object itemId, Item item) {
+ return item.getItemProperty("Column 1").getValue()
+ .toString().startsWith("(23");
+ }
- @Override
- public boolean passesFilter(Object itemId, Item item)
- throws UnsupportedOperationException {
- return item.getItemProperty("Column 1")
- .getValue().toString()
- .startsWith("(23");
- }
+ @Override
+ public boolean appliesToProperty(Object propertyId) {
+ return propertyId.equals("Column 1");
+ }
+ };
- @Override
- public boolean appliesToProperty(Object propertyId) {
- return propertyId.equals("Column 1");
- }
- });
+ @Override
+ public void execute(Grid grid, Boolean value, Object data) {
+ if (value) {
+ ds.addContainerFilter(filter);
+ } else {
+ ds.removeContainerFilter(filter);
+ }
}
- }, null);
+ });
- createClickAction("Add impassable filter", "Filter",
- new Command<Grid, Void>() {
- @Override
- public void execute(Grid c, Void value, Object data) {
- ds.addContainerFilter(new Filter() {
- @Override
- public boolean passesFilter(Object itemId, Item item)
- throws UnsupportedOperationException {
- return false;
- }
+ createBooleanAction("Impassable filter", "Filter", false,
+ new Command<Grid, Boolean>() {
+ Filter filter = new Filter() {
+ @Override
+ public boolean passesFilter(Object itemId, Item item) {
+ return false;
+ }
- @Override
- public boolean appliesToProperty(Object propertyId) {
- return true;
- }
- });
+ @Override
+ public boolean appliesToProperty(Object propertyId) {
+ return true;
+ }
+ };
+
+ @Override
+ public void execute(Grid c, Boolean value, Object data) {
+ if (value) {
+ ds.addContainerFilter(filter);
+ } else {
+ ds.removeContainerFilter(filter);
+ }
}
- }, null);
+ });
}
protected void createGridActions() {
+
LinkedHashMap<String, String> primaryStyleNames = new LinkedHashMap<String, String>();
primaryStyleNames.put("v-grid", "v-grid");
primaryStyleNames.put("v-escalator", "v-escalator");
@@ -638,6 +672,38 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> {
}
});
+ createBooleanAction("EditorOpeningItemClickListener", "State", false,
+ new Command<Grid, Boolean>() {
+
+ @Override
+ public void execute(Grid c, Boolean value, Object data) {
+ if (!value) {
+ c.removeItemClickListener(editorOpeningItemClickListener);
+ } else {
+ c.addItemClickListener(editorOpeningItemClickListener);
+ }
+ }
+
+ });
+ createBooleanAction("ReactiveValueChanger", "State", false,
+ new Command<Grid, Boolean>() {
+
+ @Override
+ public void execute(Grid c, Boolean value, Object data) {
+ Field<?> targetField = grid.getEditorFieldGroup()
+ .getField("Column 0");
+ if (targetField != null) {
+ if (!value) {
+ targetField
+ .removeValueChangeListener(reactiveValueChanger);
+ } else {
+ targetField
+ .addValueChangeListener(reactiveValueChanger);
+ }
+ }
+ }
+
+ });
createBooleanAction("ColumnReorderListener", "State", false,
new Command<Grid, Boolean>() {
@@ -661,7 +727,6 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> {
}
}
});
-
createBooleanAction("Single select allow deselect", "State",
singleSelectAllowDeselect, new Command<Grid, Boolean>() {
@Override
@@ -1218,6 +1283,14 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> {
}
});
+ createBooleanAction("Buffered mode", "Editor", true,
+ new Command<Grid, Boolean>() {
+ @Override
+ public void execute(Grid c, Boolean value, Object data) {
+ c.setEditorBuffered(value);
+ }
+ });
+
createClickAction("Edit item 5", "Editor", new Command<Grid, String>() {
@Override
public void execute(Grid c, String value, Object data) {
@@ -1265,6 +1338,30 @@ public class GridBasicFeatures extends AbstractComponentTest<Grid> {
c.setEditorCancelCaption("ʃǝɔuɐↃ");
}
}, null);
+
+ createClickAction("Add editor state listener", "Editor",
+ new Command<Grid, String>() {
+ @Override
+ public void execute(Grid grid, String value, Object data) {
+ grid.addEditorListener(new EditorListener() {
+ @Override
+ public void editorOpened(EditorOpenEvent e) {
+ log("Editor opened");
+ }
+
+ @Override
+ public void editorMoved(EditorMoveEvent e) {
+ log("Editor moved");
+ }
+
+ @Override
+ public void editorClosed(EditorCloseEvent e) {
+ log("Editor closed");
+ }
+ });
+ }
+ }, null);
+
}
@SuppressWarnings("boxing")
diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorBufferedTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorBufferedTest.java
new file mode 100644
index 0000000000..0f2fe54696
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorBufferedTest.java
@@ -0,0 +1,243 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+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.assertNotEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.Keys;
+import org.openqa.selenium.NoSuchElementException;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.interactions.Actions;
+
+import com.vaadin.shared.ui.grid.GridConstants;
+import com.vaadin.testbench.elements.GridElement.GridCellElement;
+import com.vaadin.testbench.elements.GridElement.GridEditorElement;
+import com.vaadin.testbench.elements.NotificationElement;
+
+public class GridEditorBufferedTest extends GridEditorTest {
+
+ @Override
+ @Before
+ public void setUp() {
+ super.setUp();
+ }
+
+ @Test
+ public void testSave() {
+ selectMenuPath(EDIT_ITEM_100);
+
+ WebElement textField = getEditorWidgets().get(0);
+
+ textField.click();
+
+ textField.sendKeys(" changed");
+
+ WebElement saveButton = getEditor().findElement(
+ By.className("v-grid-editor-save"));
+
+ saveButton.click();
+
+ assertEquals("(100, 0) changed", getGridElement().getCell(100, 0)
+ .getText());
+ }
+
+ @Test
+ public void testProgrammaticSave() {
+ selectMenuPath(EDIT_ITEM_100);
+
+ WebElement textField = getEditorWidgets().get(0);
+
+ textField.click();
+
+ textField.sendKeys(" changed");
+
+ selectMenuPath("Component", "Editor", "Save");
+
+ assertEquals("(100, 0) changed", getGridElement().getCell(100, 0)
+ .getText());
+ }
+
+ @Test
+ public void testInvalidEdition() {
+ selectMenuPath(EDIT_ITEM_5);
+ assertFalse(logContainsText("Exception occured, java.lang.IllegalStateException"));
+
+ GridEditorElement editor = getGridElement().getEditor();
+
+ assertFalse(
+ "Field 7 should not have been marked with an error before error",
+ editor.isFieldErrorMarked(7));
+
+ WebElement intField = editor.getField(7);
+ intField.clear();
+ intField.sendKeys("banana phone");
+ editor.save();
+
+ assertEquals("Column 7: Could not convert value to Integer",
+ editor.getErrorMessage());
+ assertTrue("Field 7 should have been marked with an error after error",
+ editor.isFieldErrorMarked(7));
+ editor.cancel();
+
+ selectMenuPath(EDIT_ITEM_100);
+ assertFalse("Exception should not exist",
+ isElementPresent(NotificationElement.class));
+ assertEquals("There should be no editor error message", null,
+ getGridElement().getEditor().getErrorMessage());
+ }
+
+ @Test
+ public void testEditorInDisabledGrid() {
+ int originalScrollPos = getGridVerticalScrollPos();
+
+ selectMenuPath(EDIT_ITEM_5);
+ assertEditorOpen();
+
+ selectMenuPath("Component", "State", "Enabled");
+ assertEditorOpen();
+
+ GridEditorElement editor = getGridElement().getEditor();
+ editor.save();
+ assertEditorOpen();
+
+ editor.cancel();
+ assertEditorOpen();
+
+ selectMenuPath("Component", "State", "Enabled");
+
+ scrollGridVerticallyTo(100);
+ assertEquals(
+ "Grid shouldn't scroll vertically while editing in buffered mode",
+ originalScrollPos, getGridVerticalScrollPos());
+ }
+
+ @Test
+ public void testCaptionChange() {
+ selectMenuPath(EDIT_ITEM_5);
+ assertEquals("Save button caption should've been \""
+ + GridConstants.DEFAULT_SAVE_CAPTION + "\" to begin with",
+ GridConstants.DEFAULT_SAVE_CAPTION, getSaveButton().getText());
+ assertEquals("Cancel button caption should've been \""
+ + GridConstants.DEFAULT_CANCEL_CAPTION + "\" to begin with",
+ GridConstants.DEFAULT_CANCEL_CAPTION, getCancelButton()
+ .getText());
+
+ selectMenuPath("Component", "Editor", "Change save caption");
+ assertNotEquals(
+ "Save button caption should've changed while editor is open",
+ GridConstants.DEFAULT_SAVE_CAPTION, getSaveButton().getText());
+
+ getCancelButton().click();
+
+ selectMenuPath("Component", "Editor", "Change cancel caption");
+ selectMenuPath(EDIT_ITEM_5);
+ assertNotEquals(
+ "Cancel button caption should've changed while editor is closed",
+ GridConstants.DEFAULT_CANCEL_CAPTION, getCancelButton()
+ .getText());
+ }
+
+ @Test(expected = NoSuchElementException.class)
+ public void testVerticalScrollLocking() {
+ selectMenuPath(EDIT_ITEM_5);
+ getGridElement().getCell(200, 0);
+ }
+
+ @Test
+ public void testNoScrollAfterEditByAPI() {
+ int originalScrollPos = getGridVerticalScrollPos();
+
+ selectMenuPath(EDIT_ITEM_5);
+
+ scrollGridVerticallyTo(100);
+ assertEquals(
+ "Grid shouldn't scroll vertically while editing in buffered mode",
+ originalScrollPos, getGridVerticalScrollPos());
+ }
+
+ @Test
+ public void testNoScrollAfterEditByMouse() {
+ int originalScrollPos = getGridVerticalScrollPos();
+
+ GridCellElement cell_5_0 = getGridElement().getCell(5, 0);
+ new Actions(getDriver()).doubleClick(cell_5_0).perform();
+
+ scrollGridVerticallyTo(100);
+ assertEquals(
+ "Grid shouldn't scroll vertically while editing in buffered mode",
+ originalScrollPos, getGridVerticalScrollPos());
+ }
+
+ @Test
+ public void testNoScrollAfterEditByKeyboard() {
+ int originalScrollPos = getGridVerticalScrollPos();
+
+ GridCellElement cell_5_0 = getGridElement().getCell(5, 0);
+ cell_5_0.click();
+ new Actions(getDriver()).sendKeys(Keys.ENTER).perform();
+
+ scrollGridVerticallyTo(100);
+ assertEquals(
+ "Grid shouldn't scroll vertically while editing in buffered mode",
+ originalScrollPos, getGridVerticalScrollPos());
+ }
+
+ @Test
+ public void testMouseOpeningClosing() {
+
+ getGridElement().getCell(4, 0).doubleClick();
+ assertEditorOpen();
+
+ getCancelButton().click();
+ assertEditorClosed();
+
+ selectMenuPath(TOGGLE_EDIT_ENABLED);
+ getGridElement().getCell(4, 0).doubleClick();
+ assertEditorClosed();
+ }
+
+ @Test
+ public void testProgrammaticOpeningWhenOpen() {
+ selectMenuPath(EDIT_ITEM_5);
+ assertEditorOpen();
+ assertEquals("Editor should edit row 5", "(5, 0)", getEditorWidgets()
+ .get(0).getAttribute("value"));
+
+ selectMenuPath(EDIT_ITEM_100);
+ boolean thrown = logContainsText("Exception occured, java.lang.IllegalStateException");
+ assertTrue("IllegalStateException thrown", thrown);
+
+ assertEditorOpen();
+ assertEquals("Editor should still edit row 5", "(5, 0)",
+ getEditorWidgets().get(0).getAttribute("value"));
+ }
+
+ @Test
+ public void testUserSortDisabled() {
+ selectMenuPath(EDIT_ITEM_5);
+
+ getGridElement().getHeaderCell(0, 0).click();
+
+ assertEditorOpen();
+ assertEquals("(2, 0)", getGridElement().getCell(2, 0).getText());
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorTest.java
index 0c39b3e509..3582038e61 100644
--- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorTest.java
+++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorTest.java
@@ -17,7 +17,6 @@ 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.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -28,24 +27,26 @@ import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
-import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
-import com.vaadin.shared.ui.grid.GridConstants;
+import com.vaadin.testbench.TestBenchElement;
import com.vaadin.testbench.elements.GridElement.GridCellElement;
import com.vaadin.testbench.elements.GridElement.GridEditorElement;
-import com.vaadin.testbench.elements.NotificationElement;
import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeatures;
import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest;
-public class GridEditorTest extends GridBasicFeaturesTest {
+public abstract class GridEditorTest extends GridBasicFeaturesTest {
- private static final String[] EDIT_ITEM_5 = new String[] { "Component",
+ protected static final By BY_EDITOR_CANCEL = By
+ .className("v-grid-editor-cancel");
+ protected static final By BY_EDITOR_SAVE = By
+ .className("v-grid-editor-save");
+ protected static final String[] EDIT_ITEM_5 = new String[] { "Component",
"Editor", "Edit item 5" };
- private static final String[] EDIT_ITEM_100 = new String[] { "Component",
+ protected static final String[] EDIT_ITEM_100 = new String[] { "Component",
"Editor", "Edit item 100" };
- private static final String[] TOGGLE_EDIT_ENABLED = new String[] {
+ protected static final String[] TOGGLE_EDIT_ENABLED = new String[] {
"Component", "Editor", "Enabled" };
@Before
@@ -88,26 +89,6 @@ public class GridEditorTest extends GridBasicFeaturesTest {
assertEditorOpen();
}
- @Test(expected = NoSuchElementException.class)
- public void testVerticalScrollLocking() {
- selectMenuPath(EDIT_ITEM_5);
- getGridElement().getCell(200, 0);
- }
-
- @Test
- public void testMouseOpeningClosing() {
-
- getGridElement().getCell(4, 0).doubleClick();
- assertEditorOpen();
-
- getCancelButton().click();
- assertEditorClosed();
-
- selectMenuPath(TOGGLE_EDIT_ENABLED);
- getGridElement().getCell(4, 0).doubleClick();
- assertEditorClosed();
- }
-
@Test
public void testKeyboardOpeningClosing() {
@@ -141,178 +122,42 @@ public class GridEditorTest extends GridBasicFeaturesTest {
assertEquals("<b>100</b>", widgets.get(8).getAttribute("value"));
}
- @Test
- public void testSave() {
- selectMenuPath(EDIT_ITEM_100);
-
- WebElement textField = getEditorWidgets().get(0);
-
- textField.click();
-
- textField.sendKeys(" changed");
-
- WebElement saveButton = getEditor().findElement(
- By.className("v-grid-editor-save"));
-
- saveButton.click();
-
- assertEquals("(100, 0) changed", getGridElement().getCell(100, 0)
- .getText());
- }
-
- @Test
- public void testProgrammaticSave() {
- selectMenuPath(EDIT_ITEM_100);
-
- WebElement textField = getEditorWidgets().get(0);
-
- textField.click();
-
- textField.sendKeys(" changed");
-
- selectMenuPath("Component", "Editor", "Save");
-
- assertEquals("(100, 0) changed", getGridElement().getCell(100, 0)
- .getText());
- }
-
- @Test
- public void testCaptionChange() {
- selectMenuPath(EDIT_ITEM_5);
- assertEquals("Save button caption should've been \""
- + GridConstants.DEFAULT_SAVE_CAPTION + "\" to begin with",
- GridConstants.DEFAULT_SAVE_CAPTION, getSaveButton().getText());
- assertEquals("Cancel button caption should've been \""
- + GridConstants.DEFAULT_CANCEL_CAPTION + "\" to begin with",
- GridConstants.DEFAULT_CANCEL_CAPTION, getCancelButton()
- .getText());
-
- selectMenuPath("Component", "Editor", "Change save caption");
- assertNotEquals(
- "Save button caption should've changed while editor is open",
- GridConstants.DEFAULT_SAVE_CAPTION, getSaveButton().getText());
-
- getCancelButton().click();
-
- selectMenuPath("Component", "Editor", "Change cancel caption");
- selectMenuPath(EDIT_ITEM_5);
- assertNotEquals(
- "Cancel button caption should've changed while editor is closed",
- GridConstants.DEFAULT_CANCEL_CAPTION, getCancelButton()
- .getText());
- }
-
- private void assertEditorOpen() {
+ protected void assertEditorOpen() {
assertNotNull("Editor is supposed to be open", getEditor());
assertEquals("Unexpected number of widgets",
GridBasicFeatures.EDITABLE_COLUMNS, getEditorWidgets().size());
}
- private void assertEditorClosed() {
+ protected void assertEditorClosed() {
assertNull("Editor is supposed to be closed", getEditor());
}
- private List<WebElement> getEditorWidgets() {
+ protected List<WebElement> getEditorWidgets() {
assertNotNull(getEditor());
return getEditor().findElements(By.className("v-textfield"));
}
@Test
- public void testInvalidEdition() {
- selectMenuPath(EDIT_ITEM_5);
- assertFalse(logContainsText("Exception occured, java.lang.IllegalStateException"));
-
- GridEditorElement editor = getGridElement().getEditor();
-
- assertFalse(
- "Field 7 should not have been marked with an error before error",
- editor.isFieldErrorMarked(7));
-
- WebElement intField = editor.getField(7);
- intField.clear();
- intField.sendKeys("banana phone");
- editor.save();
-
- assertEquals("Column 7: Could not convert value to Integer",
- editor.getErrorMessage());
- assertTrue("Field 7 should have been marked with an error after error",
- editor.isFieldErrorMarked(7));
- editor.cancel();
-
- selectMenuPath(EDIT_ITEM_100);
- assertFalse("Exception should not exist",
- isElementPresent(NotificationElement.class));
- assertEquals("There should be no editor error message", null,
- getGridElement().getEditor().getErrorMessage());
- }
-
- @Test
- public void testNoScrollAfterProgrammaticOpen() {
- int originalScrollPos = getGridVerticalScrollPos();
-
- selectMenuPath(EDIT_ITEM_5);
-
- scrollGridVerticallyTo(100);
- assertEquals("Grid shouldn't scroll vertically while editing",
- originalScrollPos, getGridVerticalScrollPos());
- }
-
- @Test
- public void testNoScrollAfterMouseOpen() {
- int originalScrollPos = getGridVerticalScrollPos();
-
- GridCellElement cell_5_0 = getGridElement().getCell(5, 0);
- new Actions(getDriver()).doubleClick(cell_5_0).perform();
-
- scrollGridVerticallyTo(100);
- assertEquals("Grid shouldn't scroll vertically while editing",
- originalScrollPos, getGridVerticalScrollPos());
- }
-
- @Test
- public void testNoScrollAfterKeyboardOpen() {
- int originalScrollPos = getGridVerticalScrollPos();
-
- GridCellElement cell_5_0 = getGridElement().getCell(5, 0);
- cell_5_0.click();
- new Actions(getDriver()).sendKeys(Keys.ENTER).perform();
-
- scrollGridVerticallyTo(100);
- assertEquals("Grid shouldn't scroll vertically while editing",
- originalScrollPos, getGridVerticalScrollPos());
- }
-
- @Test
- public void testEditorInDisabledGrid() {
- int originalScrollPos = getGridVerticalScrollPos();
-
- selectMenuPath(EDIT_ITEM_5);
- assertEditorOpen();
-
- selectMenuPath("Component", "State", "Enabled");
- assertEditorOpen();
+ public void testFocusOnMouseOpen() {
- GridEditorElement editor = getGridElement().getEditor();
- editor.save();
- assertEditorOpen();
+ GridCellElement cell = getGridElement().getCell(4, 2);
- editor.cancel();
- assertEditorOpen();
+ cell.doubleClick();
- selectMenuPath("Component", "State", "Enabled");
+ WebElement focused = getFocusedElement();
- scrollGridVerticallyTo(100);
- assertEquals("Grid shouldn't scroll vertically while editing",
- originalScrollPos, getGridVerticalScrollPos());
+ assertEquals("", "input", focused.getTagName());
+ assertEquals("", cell.getText(), focused.getAttribute("value"));
}
@Test
- public void testFocusOnMouseOpen() {
+ public void testFocusOnKeyboardOpen() {
GridCellElement cell = getGridElement().getCell(4, 2);
- cell.doubleClick();
+ cell.click();
+ new Actions(getDriver()).sendKeys(Keys.ENTER).perform();
WebElement focused = getFocusedElement();
@@ -321,12 +166,12 @@ public class GridEditorTest extends GridBasicFeaturesTest {
}
@Test
- public void testFocusOnKeyboardOpen() {
+ public void testFocusOnProgrammaticOpenOnItemClick() {
+ selectMenuPath("Component", "State", "EditorOpeningItemClickListener");
GridCellElement cell = getGridElement().getCell(4, 2);
cell.click();
- new Actions(getDriver()).sendKeys(Keys.ENTER).perform();
WebElement focused = getFocusedElement();
@@ -345,11 +190,6 @@ public class GridEditorTest extends GridBasicFeaturesTest {
focused.getAttribute("id"));
}
- @Override
- protected WebElement getFocusedElement() {
- return (WebElement) executeScript("return document.activeElement;");
- }
-
@Test
public void testUneditableColumn() {
selectMenuPath(EDIT_ITEM_5);
@@ -367,11 +207,91 @@ public class GridEditorTest extends GridBasicFeaturesTest {
}
- private WebElement getSaveButton() {
- return getDriver().findElement(By.className("v-grid-editor-save"));
+ @Test
+ public void testNoOpenFromHeaderOrFooter() {
+ selectMenuPath("Component", "Footer", "Visible");
+
+ getGridElement().getHeaderCell(0, 0).doubleClick();
+ assertEditorClosed();
+
+ new Actions(getDriver()).sendKeys(Keys.ENTER).perform();
+ assertEditorClosed();
+
+ getGridElement().getFooterCell(0, 0).doubleClick();
+ assertEditorClosed();
+
+ new Actions(getDriver()).sendKeys(Keys.ENTER).perform();
+ assertEditorClosed();
+ }
+
+ public void testEditorMoveOnResize() {
+ selectMenuPath("Component", "Size", "Height", "500px");
+ getGridElement().getCell(22, 0).doubleClick();
+ assertEditorOpen();
+
+ GridEditorElement editor = getGridElement().getEditor();
+ TestBenchElement tableWrapper = getGridElement().getTableWrapper();
+
+ int tableWrapperBottom = tableWrapper.getLocation().getY()
+ + tableWrapper.getSize().getHeight();
+ int editorBottom = editor.getLocation().getY()
+ + editor.getSize().getHeight();
+
+ assertTrue("Editor should not be initially outside grid",
+ tableWrapperBottom - editorBottom <= 2);
+
+ selectMenuPath("Component", "Size", "Height", "300px");
+ assertEditorOpen();
+
+ tableWrapperBottom = tableWrapper.getLocation().getY()
+ + tableWrapper.getSize().getHeight();
+ editorBottom = editor.getLocation().getY()
+ + editor.getSize().getHeight();
+
+ assertTrue("Editor should not be outside grid after resize",
+ tableWrapperBottom - editorBottom <= 2);
+ }
+
+ public void testEditorDoesNotMoveOnResizeIfNotNeeded() {
+ selectMenuPath("Component", "Size", "Height", "500px");
+
+ selectMenuPath(EDIT_ITEM_5);
+ assertEditorOpen();
+
+ GridEditorElement editor = getGridElement().getEditor();
+
+ int editorPos = editor.getLocation().getY();
+
+ selectMenuPath("Component", "Size", "Height", "300px");
+ assertEditorOpen();
+
+ assertTrue("Editor should not have moved due to resize",
+ editorPos == editor.getLocation().getY());
+ }
+
+ @Test
+ public void testEditorClosedOnSort() {
+ selectMenuPath(EDIT_ITEM_5);
+
+ selectMenuPath("Component", "State", "Sort by column", "Column 0, ASC");
+
+ assertEditorClosed();
+ }
+
+ @Test
+ public void testEditorClosedOnFilter() {
+ selectMenuPath(EDIT_ITEM_5);
+
+ selectMenuPath("Component", "Filter", "Column 1 starts with \"(23\"");
+
+ assertEditorClosed();
+ }
+
+ protected WebElement getSaveButton() {
+ return getDriver().findElement(BY_EDITOR_SAVE);
}
- private WebElement getCancelButton() {
- return getDriver().findElement(By.className("v-grid-editor-cancel"));
+ protected WebElement getCancelButton() {
+ return getDriver().findElement(BY_EDITOR_CANCEL);
}
}
diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorUnbufferedTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorUnbufferedTest.java
new file mode 100644
index 0000000000..1058fe2d74
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridEditorUnbufferedTest.java
@@ -0,0 +1,205 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+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.assertTrue;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.Keys;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.interactions.Actions;
+
+import com.vaadin.testbench.elements.GridElement.GridCellElement;
+
+public class GridEditorUnbufferedTest extends GridEditorTest {
+
+ private static final String[] TOGGLE_EDITOR_BUFFERED = new String[] {
+ "Component", "Editor", "Buffered mode" };
+ private static final String[] CANCEL_EDIT = new String[] { "Component",
+ "Editor", "Cancel edit" };
+
+ @Override
+ @Before
+ public void setUp() {
+ super.setUp();
+ selectMenuPath(TOGGLE_EDITOR_BUFFERED);
+ }
+
+ @Test
+ public void testEditorShowsNoButtons() {
+ selectMenuPath(EDIT_ITEM_5);
+
+ assertEditorOpen();
+
+ assertFalse("Save button should not be visible in unbuffered mode.",
+ isElementPresent(BY_EDITOR_SAVE));
+
+ assertFalse("Cancel button should not be visible in unbuffered mode.",
+ isElementPresent(BY_EDITOR_CANCEL));
+ }
+
+ @Test
+ public void testToggleEditorUnbufferedWhileOpen() {
+ selectMenuPath(EDIT_ITEM_5);
+ assertEditorOpen();
+ selectMenuPath(TOGGLE_EDITOR_BUFFERED);
+ boolean thrown = logContainsText("Exception occured, java.lang.IllegalStateException");
+ assertTrue("IllegalStateException thrown", thrown);
+ }
+
+ @Test
+ public void testEditorMove() {
+ selectMenuPath(EDIT_ITEM_5);
+
+ assertEditorOpen();
+
+ String firstFieldValue = getEditorWidgets().get(0)
+ .getAttribute("value");
+ assertTrue("Editor is not at correct row index (5)",
+ "(5, 0)".equals(firstFieldValue));
+
+ getGridElement().getCell(10, 0).click();
+ firstFieldValue = getEditorWidgets().get(0).getAttribute("value");
+
+ assertTrue("Editor is not at correct row index (10)",
+ "(10, 0)".equals(firstFieldValue));
+ }
+
+ @Test
+ public void testErrorMessageWrapperHidden() {
+ selectMenuPath(EDIT_ITEM_5);
+
+ assertEditorOpen();
+
+ WebElement editorFooter = getEditor().findElement(
+ By.className("v-grid-editor-footer"));
+
+ assertTrue("Editor footer should not be visible when there's no error",
+ editorFooter.getCssValue("display").equalsIgnoreCase("none"));
+ }
+
+ @Test
+ public void testScrollAfterEditByAPI() {
+ int originalScrollPos = getGridVerticalScrollPos();
+
+ selectMenuPath(EDIT_ITEM_5);
+
+ scrollGridVerticallyTo(100);
+ assertGreater(
+ "Grid should scroll vertically while editing in unbuffered mode",
+ getGridVerticalScrollPos(), originalScrollPos);
+ }
+
+ @Test
+ public void testScrollAfterEditByMouse() {
+ int originalScrollPos = getGridVerticalScrollPos();
+
+ GridCellElement cell_5_0 = getGridElement().getCell(5, 0);
+ new Actions(getDriver()).doubleClick(cell_5_0).perform();
+
+ scrollGridVerticallyTo(100);
+ assertGreater(
+ "Grid should scroll vertically while editing in unbuffered mode",
+ getGridVerticalScrollPos(), originalScrollPos);
+ }
+
+ @Test
+ public void testScrollAfterEditByKeyboard() {
+ int originalScrollPos = getGridVerticalScrollPos();
+
+ GridCellElement cell_5_0 = getGridElement().getCell(5, 0);
+ cell_5_0.click();
+ new Actions(getDriver()).sendKeys(Keys.ENTER).perform();
+
+ scrollGridVerticallyTo(100);
+ assertGreater(
+ "Grid should scroll vertically while editing in unbuffered mode",
+ getGridVerticalScrollPos(), originalScrollPos);
+ }
+
+ @Test
+ public void testEditorInDisabledGrid() {
+ selectMenuPath(EDIT_ITEM_5);
+
+ selectMenuPath("Component", "State", "Enabled");
+ assertEditorOpen();
+
+ assertTrue("Editor text field should be disabled",
+ null != getEditorWidgets().get(2).getAttribute("disabled"));
+
+ selectMenuPath("Component", "State", "Enabled");
+ assertEditorOpen();
+
+ assertFalse("Editor text field should not be disabled",
+ null != getEditorWidgets().get(2).getAttribute("disabled"));
+ }
+
+ @Test
+ public void testMouseOpeningClosing() {
+
+ getGridElement().getCell(4, 0).doubleClick();
+ assertEditorOpen();
+
+ selectMenuPath(CANCEL_EDIT);
+ selectMenuPath(TOGGLE_EDIT_ENABLED);
+
+ getGridElement().getCell(4, 0).doubleClick();
+ assertEditorClosed();
+ }
+
+ @Test
+ public void testProgrammaticOpeningWhenOpen() {
+ selectMenuPath(EDIT_ITEM_5);
+ assertEditorOpen();
+ assertEquals("Editor should edit row 5", "(5, 0)", getEditorWidgets()
+ .get(0).getAttribute("value"));
+
+ selectMenuPath(EDIT_ITEM_100);
+ assertEditorOpen();
+ assertEquals("Editor should edit row 100", "(100, 0)",
+ getEditorWidgets().get(0).getAttribute("value"));
+ }
+
+ @Test
+ public void testExternalValueChangePassesToEditor() {
+ selectMenuPath(EDIT_ITEM_5);
+ assertEditorOpen();
+
+ selectMenuPath("Component", "State", "ReactiveValueChanger");
+
+ getEditorWidgets().get(0).click();
+ getEditorWidgets().get(0).sendKeys("changing value");
+
+ // Focus another field to cause the value to be sent to the server
+ getEditorWidgets().get(2).click();
+
+ assertEquals("Value of Column 2 in the editor was not changed",
+ "Modified", getEditorWidgets().get(2).getAttribute("value"));
+ }
+
+ @Test
+ public void testEditorClosedOnUserSort() {
+ selectMenuPath(EDIT_ITEM_5);
+
+ getGridElement().getHeaderCell(0, 0).click();
+
+ assertEditorClosed();
+ }
+} \ No newline at end of file
diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridFocusTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridFocusTest.java
new file mode 100644
index 0000000000..ca9d78409c
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridFocusTest.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.grid.basicfeatures.server;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.vaadin.testbench.elements.MenuBarElement;
+import com.vaadin.tests.components.grid.basicfeatures.GridBasicFeaturesTest;
+
+/**
+ * Test for server-side Grid focus features.
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+public class GridFocusTest extends GridBasicFeaturesTest {
+
+ @Before
+ public void setUp() {
+ openTestURL();
+ }
+
+ @Test
+ public void testFocusListener() {
+ selectMenuPath("Component", "Listeners", "Focus listener");
+
+ getGridElement().click();
+
+ assertTrue("Focus listener should be invoked",
+ getLogRow(0).contains("FocusEvent"));
+ }
+
+ @Test
+ public void testBlurListener() {
+ selectMenuPath("Component", "Listeners", "Blur listener");
+
+ getGridElement().click();
+ $(MenuBarElement.class).first().click();
+
+ assertTrue("Blur listener should be invoked",
+ getLogRow(0).contains("BlurEvent"));
+ }
+
+ @Test
+ public void testProgrammaticFocus() {
+ selectMenuPath("Component", "State", "Set focus");
+
+ assertTrue("Grid cell (0, 0) should be focused", getGridElement()
+ .getCell(0, 0).isFocused());
+ }
+
+ @Test
+ public void testTabIndex() {
+ assertEquals(getGridElement().getAttribute("tabindex"), "0");
+
+ selectMenuPath("Component", "State", "Tab index", "-1");
+ assertEquals(getGridElement().getAttribute("tabindex"), "-1");
+
+ selectMenuPath("Component", "State", "Tab index", "10");
+ assertEquals(getGridElement().getAttribute("tabindex"), "10");
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridStructureTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridStructureTest.java
index 5d72d481c7..f44f39689c 100644
--- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridStructureTest.java
+++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridStructureTest.java
@@ -274,7 +274,7 @@ public class GridStructureTest extends GridBasicFeaturesTest {
@Test
public void testBareItemSetChangeRemovingAllRows() throws Exception {
openTestURL();
- selectMenuPath("Component", "Filter", "Add impassable filter");
+ selectMenuPath("Component", "Filter", "Impassable filter");
assertFalse("A notification shouldn't have been displayed",
$(NotificationElement.class).exists());
assertTrue("No body cells should've been found", getGridElement()