2 * Copyright 2000-2016 Vaadin Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
16 package com.vaadin.tests.components.grid.basicfeatures.server;
18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertFalse;
20 import static org.junit.Assert.assertTrue;
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.openqa.selenium.By;
25 import org.openqa.selenium.Keys;
26 import org.openqa.selenium.WebElement;
27 import org.openqa.selenium.interactions.Actions;
29 import com.vaadin.testbench.TestBenchElement;
30 import com.vaadin.testbench.elements.GridElement.GridCellElement;
32 public class GridEditorUnbufferedTest extends GridEditorTest {
34 private static final String[] TOGGLE_EDITOR_BUFFERED = new String[] {
35 "Component", "Editor", "Buffered mode" };
36 private static final String[] CANCEL_EDIT = new String[] { "Component",
37 "Editor", "Cancel edit" };
43 selectMenuPath(TOGGLE_EDITOR_BUFFERED);
47 public void testEditorShowsNoButtons() {
48 selectMenuPath(EDIT_ITEM_5);
52 assertFalse("Save button should not be visible in unbuffered mode.",
53 isElementPresent(BY_EDITOR_SAVE));
55 assertFalse("Cancel button should not be visible in unbuffered mode.",
56 isElementPresent(BY_EDITOR_CANCEL));
60 public void testToggleEditorUnbufferedWhileOpen() {
61 selectMenuPath(EDIT_ITEM_5);
63 selectMenuPath(TOGGLE_EDITOR_BUFFERED);
64 boolean thrown = logContainsText(
65 "Exception occured, java.lang.IllegalStateException");
66 assertTrue("IllegalStateException thrown", thrown);
70 public void testEditorMoveWithMouse() {
71 selectMenuPath(EDIT_ITEM_5);
75 String firstFieldValue = getEditorWidgets().get(0)
76 .getAttribute("value");
77 assertEquals("Editor should be at row 5", "(5, 0)", firstFieldValue);
79 getGridElement().getCell(10, 0).click();
80 firstFieldValue = getEditorWidgets().get(0).getAttribute("value");
82 assertEquals("Editor should be at row 10", "(10, 0)", firstFieldValue);
86 public void testEditorMoveWithKeyboard() throws InterruptedException {
87 selectMenuPath(EDIT_ITEM_100);
91 getEditorWidgets().get(0).click();
92 new Actions(getDriver()).sendKeys(Keys.ENTER).perform();
94 String firstFieldValue = getEditorWidgets().get(0)
95 .getAttribute("value");
96 assertEquals("Editor should move to row 101", "(101, 0)",
99 for (int i = 0; i < 10; i++) {
100 new Actions(getDriver()).keyDown(Keys.SHIFT).sendKeys(Keys.ENTER)
101 .keyUp(Keys.SHIFT).perform();
103 firstFieldValue = getEditorWidgets().get(0).getAttribute("value");
105 assertEquals("Editor should move to row " + row, "(" + row + ", 0)",
111 public void testValidationErrorPreventsMove() throws InterruptedException {
112 // Because of "out of view" issues, we need to move this for easy access
113 selectMenuPath("Component", "Columns", "Column 7", "Column 7 Width",
115 for (int i = 0; i < 6; ++i) {
116 selectMenuPath("Component", "Columns", "Column 7", "Move left");
119 selectMenuPath(EDIT_ITEM_5);
121 getEditorWidgets().get(1).click();
122 String faultyInt = "not a number";
123 getEditorWidgets().get(1).sendKeys(faultyInt);
125 getGridElement().getCell(10, 0).click();
127 assertEquals("Editor should not move from row 5", "(5, 0)",
128 getEditorWidgets().get(0).getAttribute("value"));
130 getEditorWidgets().get(1).sendKeys(Keys.chord(Keys.CONTROL, "a"));
131 getEditorWidgets().get(1).sendKeys("5");
132 // FIXME: Needs to trigger one extra validation round-trip for now
133 getGridElement().sendKeys(Keys.ENTER);
135 getGridElement().getCell(10, 0).click();
137 assertEquals("Editor should move to row 10", "(10, 0)",
138 getEditorWidgets().get(0).getAttribute("value"));
143 public void testErrorMessageWrapperHidden() {
144 selectMenuPath(EDIT_ITEM_5);
148 WebElement editorFooter = getEditor()
149 .findElement(By.className("v-grid-editor-footer"));
151 assertTrue("Editor footer should not be visible when there's no error",
152 editorFooter.getCssValue("display").equalsIgnoreCase("none"));
156 public void testScrollEnabledOnProgrammaticOpen() {
157 int originalScrollPos = getGridVerticalScrollPos();
159 selectMenuPath(EDIT_ITEM_5);
161 scrollGridVerticallyTo(100);
163 "Grid should scroll vertically while editing in unbuffered mode",
164 getGridVerticalScrollPos(), originalScrollPos);
168 public void testScrollEnabledOnMouseOpen() {
169 int originalScrollPos = getGridVerticalScrollPos();
171 GridCellElement cell_5_0 = getGridElement().getCell(5, 0);
172 new Actions(getDriver()).doubleClick(cell_5_0).perform();
174 scrollGridVerticallyTo(100);
176 "Grid should scroll vertically while editing in unbuffered mode",
177 getGridVerticalScrollPos(), originalScrollPos);
181 public void testScrollEnabledOnKeyboardOpen() {
182 int originalScrollPos = getGridVerticalScrollPos();
184 GridCellElement cell_5_0 = getGridElement().getCell(5, 0);
186 new Actions(getDriver()).sendKeys(Keys.ENTER).perform();
188 scrollGridVerticallyTo(100);
190 "Grid should scroll vertically while editing in unbuffered mode",
191 getGridVerticalScrollPos(), originalScrollPos);
195 public void testEditorInDisabledGrid() {
196 selectMenuPath(EDIT_ITEM_5);
198 selectMenuPath("Component", "State", "Enabled");
201 assertTrue("Editor text field should be disabled",
202 null != getEditorWidgets().get(2).getAttribute("disabled"));
204 selectMenuPath("Component", "State", "Enabled");
207 assertFalse("Editor text field should not be disabled",
208 null != getEditorWidgets().get(2).getAttribute("disabled"));
212 public void testMouseOpeningClosing() {
214 getGridElement().getCell(4, 0).doubleClick();
217 selectMenuPath(CANCEL_EDIT);
218 selectMenuPath(TOGGLE_EDIT_ENABLED);
220 getGridElement().getCell(4, 0).doubleClick();
221 assertEditorClosed();
225 public void testProgrammaticOpeningWhenOpen() {
226 selectMenuPath(EDIT_ITEM_5);
228 assertEquals("Editor should edit row 5", "(5, 0)",
229 getEditorWidgets().get(0).getAttribute("value"));
231 selectMenuPath(EDIT_ITEM_100);
233 assertEquals("Editor should edit row 100", "(100, 0)",
234 getEditorWidgets().get(0).getAttribute("value"));
238 public void testExternalValueChangePassesToEditor() {
239 selectMenuPath(EDIT_ITEM_5);
242 selectMenuPath("Component", "State", "ReactiveValueChanger");
244 getEditorWidgets().get(0).click();
245 getEditorWidgets().get(0).sendKeys("changing value");
247 // Focus another field to cause the value to be sent to the server
248 getEditorWidgets().get(2).click();
250 assertEquals("Value of Column 2 in the editor was not changed",
251 "Modified", getEditorWidgets().get(2).getAttribute("value"));
255 public void testEditorClosedOnUserSort() {
256 selectMenuPath(EDIT_ITEM_5);
258 getGridElement().getHeaderCell(0, 0).click();
260 assertEditorClosed();
264 public void testEditorSaveOnRowChange() {
265 // Double click sets the focus programmatically
266 getGridElement().getCell(5, 2).doubleClick();
268 TestBenchElement editor = getGridElement().getEditor().getField(2);
270 // Click to ensure IE focus...
272 editor.sendKeys("Foo", Keys.ENTER);
274 assertEquals("Editor did not move.", "(6, 0)",
275 getGridElement().getEditor().getField(0).getAttribute("value"));
276 assertEquals("Editor field value did not update from server.", "(6, 2)",
277 getGridElement().getEditor().getField(2).getAttribute("value"));
279 assertEquals("Edited value was not saved.", "Foo",
280 getGridElement().getCell(5, 2).getText());