summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorPekka Hyvönen <pekka@vaadin.com>2016-12-15 13:46:05 +0200
committerAleksi Hietanen <aleksi@vaadin.com>2016-12-15 13:46:05 +0200
commit04f30c6892c8ddf8794ed8561fa6f00beefeec28 (patch)
tree335763bd648d44da995b7a8d0495f07a8c610270 /uitest
parent10d4d70b5e2ee7879eec67f1ce91fea01929b5a1 (diff)
downloadvaadin-framework-04f30c6892c8ddf8794ed8561fa6f00beefeec28.tar.gz
vaadin-framework-04f30c6892c8ddf8794ed8561fa6f00beefeec28.zip
Allow defining a focus delegate component for CustomField (#20336)
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/grid/GridEditorCustomField.java144
-rw-r--r--uitest/src/main/java/com/vaadin/tests/fieldgroup/ComplexPerson.java20
-rw-r--r--uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridEditorCustomField.java100
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorCustomFieldTest.java (renamed from uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridEditorCustomFieldTest.java)19
4 files changed, 181 insertions, 102 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridEditorCustomField.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridEditorCustomField.java
new file mode 100644
index 0000000000..409147ff9b
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridEditorCustomField.java
@@ -0,0 +1,144 @@
+/*
+ * Copyright 2000-2016 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;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import com.vaadin.annotations.Theme;
+import com.vaadin.data.Binder;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.server.data.ListDataProvider;
+import com.vaadin.server.data.Query;
+import com.vaadin.tests.components.AbstractTestUIWithLog;
+import com.vaadin.tests.fieldgroup.ComplexPerson;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.ComboBox;
+import com.vaadin.ui.Component;
+import com.vaadin.ui.CustomField;
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.TextField;
+
+@Theme("tests-valo-disabled-animations")
+public class GridEditorCustomField extends AbstractTestUIWithLog {
+
+ private static final String LAST_NAME_IDENTIFIER = "lastName";
+ private static final String FIRST_NAME_IDENTIFIER = "firstName";
+ private static final String ADDRESS_CITY_IDENTIFIER = "address.city";
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ Grid<ComplexPerson> grid = createGrid();
+
+ ListDataProvider<ComplexPerson> dataProvider = ComplexPerson
+ .createDataProvider(100);
+
+ grid.setDataProvider(dataProvider);
+
+ Set<String> cities = new HashSet<>();
+ dataProvider.fetch(new Query<>()).forEach(person -> {
+ cities.add(person.getAddress().getCity());
+ });
+ CustomCitySelect cityEditor = new CustomCitySelect(
+ cities.toArray(new String[cities.size()]));
+
+ TextField firstNameField = new TextField();
+ TextField lastNameField = new TextField();
+ Binder<ComplexPerson> binder = new Binder<>();
+
+ binder.bind(firstNameField, ComplexPerson::getFirstName,
+ ComplexPerson::setFirstName);
+ binder.bind(lastNameField, ComplexPerson::getLastName,
+ ComplexPerson::setLastName);
+ binder.bind(cityEditor, person -> person.getAddress().getCity(),
+ (person, city) -> person.getAddress().setCity(city));
+
+ grid.getEditor().setBinder(binder);
+ grid.getColumn(ADDRESS_CITY_IDENTIFIER).setEditorComponent(cityEditor);
+ grid.getColumn(FIRST_NAME_IDENTIFIER)
+ .setEditorComponent(firstNameField);
+ grid.getColumn(LAST_NAME_IDENTIFIER).setEditorComponent(lastNameField);
+
+ addComponent(grid);
+ }
+
+ private Grid<ComplexPerson> createGrid() {
+ Grid<ComplexPerson> grid = new Grid<>();
+ grid.setWidth("800px");
+ grid.addColumn(FIRST_NAME_IDENTIFIER, person -> person.getFirstName())
+ .setCaption("First Name");
+ grid.addColumn(LAST_NAME_IDENTIFIER, person -> person.getLastName())
+ .setCaption("Last Name");
+ grid.addColumn(ADDRESS_CITY_IDENTIFIER,
+ person -> person.getAddress().getCity())
+ .setCaption("City Name");
+ grid.getEditor().setEnabled(true);
+
+ return grid;
+ }
+
+ public static class CustomCitySelect extends CustomField<String> {
+ private HorizontalLayout fieldLayout;
+ private String[] values;
+ private ComboBox<String> cityComboBox;
+ private String cachedValue;
+
+ public CustomCitySelect(String... values) {
+ this.values = values;
+ }
+
+ @Override
+ protected Component initContent() {
+ fieldLayout = new HorizontalLayout();
+ fieldLayout.setWidth("100%");
+
+ cityComboBox = new ComboBox<>();
+ cityComboBox.setItems(values);
+ if (cachedValue != null) {
+ cityComboBox.setValue(cachedValue);
+ cachedValue = null;
+ }
+
+ fieldLayout.addComponent(cityComboBox);
+ fieldLayout.setExpandRatio(cityComboBox, 1.0f);
+
+ Button addCountryButton = new Button("New");
+ fieldLayout.addComponent(addCountryButton);
+
+ setFocusDelegate(cityComboBox);
+
+ return fieldLayout;
+ }
+
+ @Override
+ public String getValue() {
+ if (cityComboBox == null) {
+ return null;
+ }
+ return cityComboBox.getValue();
+ }
+
+ @Override
+ protected void doSetValue(String value) {
+ if (cityComboBox == null) {
+ getContent();
+ }
+ cityComboBox.setValue(value);
+ }
+ }
+
+}
diff --git a/uitest/src/main/java/com/vaadin/tests/fieldgroup/ComplexPerson.java b/uitest/src/main/java/com/vaadin/tests/fieldgroup/ComplexPerson.java
index c2aeb51bab..8e355484b9 100644
--- a/uitest/src/main/java/com/vaadin/tests/fieldgroup/ComplexPerson.java
+++ b/uitest/src/main/java/com/vaadin/tests/fieldgroup/ComplexPerson.java
@@ -1,9 +1,13 @@
package com.vaadin.tests.fieldgroup;
import java.math.BigDecimal;
+import java.util.ArrayList;
import java.util.Date;
+import java.util.List;
import java.util.Random;
+import com.vaadin.server.data.DataProvider;
+import com.vaadin.server.data.ListDataProvider;
import com.vaadin.tests.util.TestDataGenerator;
import com.vaadin.v7.data.util.BeanItemContainer;
@@ -25,6 +29,10 @@ public class ComplexPerson {
this.firstName = firstName;
}
+ public void setLastName(String firstName) {
+ this.firstName = firstName;
+ }
+
public String getLastName() {
return lastName;
}
@@ -90,6 +98,18 @@ public class ComplexPerson {
return bic;
}
+ public static ListDataProvider<ComplexPerson> createDataProvider(int size) {
+ List<ComplexPerson> list = new ArrayList<>();
+ Random r = new Random(size);
+
+ for (int i = 0; i < size; i++) {
+ ComplexPerson cp = ComplexPerson.create(r);
+ list.add(cp);
+ }
+
+ return DataProvider.create(list);
+ }
+
public static ComplexPerson create(Random r) {
ComplexPerson cp = new ComplexPerson();
cp.setFirstName(TestDataGenerator.getFirstName(r));
diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridEditorCustomField.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridEditorCustomField.java
deleted file mode 100644
index 22efd2b6c6..0000000000
--- a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridEditorCustomField.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Copyright 2000-2016 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.v7.tests.components.grid;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import com.vaadin.server.VaadinRequest;
-import com.vaadin.tests.components.AbstractTestUIWithLog;
-import com.vaadin.tests.fieldgroup.ComplexPerson;
-import com.vaadin.ui.Button;
-import com.vaadin.ui.Component;
-import com.vaadin.ui.HorizontalLayout;
-import com.vaadin.v7.ui.ComboBox;
-import com.vaadin.v7.ui.CustomField;
-import com.vaadin.v7.ui.Grid;
-
-public class GridEditorCustomField extends AbstractTestUIWithLog {
-
- @Override
- protected void setup(VaadinRequest request) {
- Grid grid = new PersonTestGrid(100);
- grid.setWidth("800px");
- grid.setColumns("firstName", "lastName", "address.city");
- grid.setEditorEnabled(true);
- Set<String> cities = new HashSet<>();
- for (Object o : grid.getContainerDataSource().getItemIds()) {
- ComplexPerson p = (ComplexPerson) o;
- cities.add(p.getAddress().getCity());
- }
- CustomCitySelect cityEditor = new CustomCitySelect(
- cities.toArray(new String[cities.size()]));
- grid.getColumn("address.city").setEditorField(cityEditor);
- addComponent(grid);
- }
-
- public static class CustomCitySelect extends CustomField<String> {
- private HorizontalLayout fieldLayout;
- private String[] values;
- private ComboBox cityComboBox;
-
- public CustomCitySelect(String... values) {
- this.values = values;
- }
-
- @Override
- protected Component initContent() {
- fieldLayout = new HorizontalLayout();
- fieldLayout.setWidth("100%");
-
- cityComboBox = new ComboBox();
- for (String value : values) {
- cityComboBox.addItem(value);
- }
- fieldLayout.addComponent(cityComboBox);
- fieldLayout.setExpandRatio(cityComboBox, 1.0f);
-
- Button addCountryButton = new Button("New");
- fieldLayout.addComponent(addCountryButton);
-
- return fieldLayout;
- }
-
- @Override
- public Class<String> getType() {
- return String.class;
- }
-
- @Override
- protected void setInternalValue(String newValue) {
- super.setInternalValue(newValue);
- if (cityComboBox == null) {
- return;
- }
- cityComboBox.setValue(newValue);
- }
-
- @Override
- public String getInternalValue() {
- if (cityComboBox == null) {
- return null;
- }
- return (String) cityComboBox.getValue();
- }
- }
-
-}
diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridEditorCustomFieldTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorCustomFieldTest.java
index f7b56f53d6..77d54dd93b 100644
--- a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridEditorCustomFieldTest.java
+++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorCustomFieldTest.java
@@ -13,17 +13,18 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
-package com.vaadin.v7.tests.components.grid;
+package com.vaadin.tests.components.grid;
import org.junit.Assert;
import org.junit.Test;
+import org.openqa.selenium.Keys;
import com.vaadin.testbench.TestBenchElement;
import com.vaadin.testbench.customelements.ComboBoxElement;
+import com.vaadin.testbench.customelements.GridElement;
import com.vaadin.testbench.elements.GridElement.GridEditorElement;
import com.vaadin.testbench.parallel.TestCategory;
import com.vaadin.tests.tb3.MultiBrowserTest;
-import com.vaadin.testbench.customelements.GridElement;
@TestCategory("grid")
public class GridEditorCustomFieldTest extends MultiBrowserTest {
@@ -43,4 +44,18 @@ public class GridEditorCustomFieldTest extends MultiBrowserTest {
Assert.assertEquals("Oslo", grid.getCell(0, 2).getText());
}
+
+ @Test
+ public void tabReachesCustomField() {
+ openTestURL();
+ GridElement grid = $(GridElement.class).first();
+ grid.getCell(0, 1).doubleClick();
+ GridEditorElement editor = grid.getEditor();
+ editor.getField(0).sendKeys(Keys.TAB, Keys.TAB);
+
+ ComboBoxElement comboBoxInCustomField = editor.getField(2)
+ .$(ComboBoxElement.class).first();
+ assertElementsEquals(comboBoxInCustomField.getInputField(),
+ getActiveElement());
+ }
}