From: Denis Date: Thu, 5 Jan 2017 13:47:23 +0000 (+0200) Subject: Migrate Grid UI tests P4 (#8133) X-Git-Tag: 8.0.0.beta2~108 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b74e08cfe8a849a8f74e6f9f0a3d7c0475ce196d;p=vaadin-framework.git Migrate Grid UI tests P4 (#8133) Fixes vaadin/framework8-issues#592 --- diff --git a/tests/screenshots b/tests/screenshots index eec6eee661..203312a80a 160000 --- a/tests/screenshots +++ b/tests/screenshots @@ -1 +1 @@ -Subproject commit eec6eee6610e80e28736e8a27aaaa2166ea2fa7c +Subproject commit 203312a80a5f76d48fc36ef8d215f8b70b8e7545 diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridEditingWithNoScrollBars.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridEditingWithNoScrollBars.java new file mode 100644 index 0000000000..203a69b1f0 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridEditingWithNoScrollBars.java @@ -0,0 +1,60 @@ +/* + * 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.Arrays; +import java.util.stream.IntStream; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.tests.data.bean.Person; +import com.vaadin.ui.ComboBox; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Grid.Column; +import com.vaadin.ui.Grid.SelectionMode; + +public class GridEditingWithNoScrollBars extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + Grid grid = new Grid<>(); + grid.addColumn(Person::getFirstName); + Column column = grid.addColumn(Person::getLastName); + + grid.setItems(IntStream.range(0, 10).mapToObj(this::createPerson)); + + ComboBox stCombo = new ComboBox<>(); + stCombo.setItems(Arrays.asList("1", "2", "3")); + stCombo.setEmptySelectionAllowed(false); + stCombo.setSizeFull(); + + column.setEditorComponent(stCombo); + + grid.setSelectionMode(SelectionMode.SINGLE); + grid.getEditor().setEnabled(true); + grid.setSizeFull(); + + addComponent(grid); + } + + private Person createPerson(int i) { + Person person = new Person(); + person.setFirstName("foo"); + person.setLastName(String.valueOf(i % 3 + 1)); + return person; + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridEditorFrozenColumnsUI.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridEditorFrozenColumnsUI.java new file mode 100644 index 0000000000..94d5c13b50 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridEditorFrozenColumnsUI.java @@ -0,0 +1,44 @@ +/* + * 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 com.vaadin.tests.util.Person; +import com.vaadin.ui.Grid; + +public class GridEditorFrozenColumnsUI extends GridEditorUI { + + @Override + protected Grid createGrid() { + Grid grid = super.createGrid(); + + grid.setFrozenColumnCount(2); + + grid.setWidth("600px"); + grid.setHeight("100%"); + + return grid; + } + + @Override + protected Integer getTicketNumber() { + return 16727; + } + + @Override + protected String getTestDescription() { + return "Frozen columns should also freeze cells in editor."; + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridEditorMultiselect.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridEditorMultiselect.java new file mode 100644 index 0000000000..dbeb1bbc8a --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridEditorMultiselect.java @@ -0,0 +1,63 @@ +package com.vaadin.tests.components.grid; + +import java.util.stream.IntStream; + +import com.vaadin.data.Binder; +import com.vaadin.data.converter.StringToIntegerConverter; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.tests.data.bean.Person; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Grid.Column; +import com.vaadin.ui.TextField; +import com.vaadin.ui.renderers.NumberRenderer; + +public class GridEditorMultiselect extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + Grid grid = new Grid<>(); + + Column nameColumn = grid.addColumn(Person::getFirstName) + .setCaption("name"); + Column ageColumn = grid + .addColumn(Person::getAge, new NumberRenderer()) + .setCaption("age"); + + Binder binder = new Binder<>(); + grid.getEditor().setBinder(binder); + + TextField name = new TextField(); + nameColumn.setEditorComponent(name); + binder.bind(name, Person::getFirstName, Person::setFirstName); + + TextField age = new TextField(); + ageColumn.setEditorComponent(age); + binder.forField(age).withConverter(new StringToIntegerConverter("")) + .bind(Person::getAge, Person::setAge); + + grid.setItems(IntStream.range(0, 30).mapToObj(this::createPerson)); + + grid.getEditor().setEnabled(true); + grid.setSelectionMode(Grid.SelectionMode.MULTI); + + addComponent(grid); + } + + @Override + protected Integer getTicketNumber() { + return 17132; + } + + @Override + protected String getTestDescription() { + return "Grid Multiselect: Edit mode allows invalid selection"; + } + + private Person createPerson(int i) { + Person person = new Person(); + person.setFirstName("name" + i); + person.setAge(i); + return person; + } +} diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridEditorUI.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridEditorUI.java new file mode 100644 index 0000000000..bf8b997f80 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridEditorUI.java @@ -0,0 +1,108 @@ +/* + * 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.ArrayList; +import java.util.Collection; +import java.util.Random; + +import com.vaadin.data.Binder; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.tests.util.Person; +import com.vaadin.tests.util.TestDataGenerator; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Grid.Column; +import com.vaadin.ui.PasswordField; +import com.vaadin.ui.TextField; +import com.vaadin.ui.renderers.NumberRenderer; + +public class GridEditorUI extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + Grid grid = createGrid(); + grid.setItems(createTestData()); + addComponent(grid); + } + + protected Collection createTestData() { + return createTestData(100); + } + + protected Collection createTestData(int size) { + Random r = new Random(0); + ArrayList testData = new ArrayList<>(); + for (int i = 0; i < size; i++) { + Person person = new Person(); + person.setFirstName(TestDataGenerator.getFirstName(r)); + person.setLastName(TestDataGenerator.getLastName(r)); + person.getAddress().setCity(TestDataGenerator.getCity(r)); + person.setEmail(person.getFirstName().toLowerCase() + "." + + person.getLastName().toLowerCase() + "@vaadin.com"); + person.setPhoneNumber(TestDataGenerator.getPhoneNumber(r)); + + person.getAddress() + .setPostalCode(TestDataGenerator.getPostalCode(r)); + person.getAddress() + .setStreetAddress(TestDataGenerator.getStreetAddress(r)); + testData.add(person); + } + return testData; + } + + protected Grid createGrid() { + Grid grid = new Grid<>(); + + Binder binder = new Binder<>(); + grid.getEditor().setBinder(binder); + + grid.addColumn(Person::getEmail).setCaption("Email"); + Column fistNameColumn = grid + .addColumn(Person::getFirstName).setCaption("First Name"); + Column lastNameColumn = grid + .addColumn(Person::getLastName).setCaption("Last Name"); + + Column phoneColumn = grid + .addColumn(Person::getPhoneNumber).setCaption("Phone Number"); + grid.addColumn(person -> person.getAddress().getStreetAddress()) + .setCaption("Street Address"); + grid.addColumn(person -> person.getAddress().getPostalCode(), + new NumberRenderer()).setCaption("Postal Code"); + grid.addColumn(person -> person.getAddress().getCity()) + .setCaption("City"); + + grid.getEditor().setEnabled(true); + + PasswordField passwordField = new PasswordField(); + fistNameColumn.setEditorComponent(passwordField); + binder.bind(passwordField, Person::getFirstName, Person::setFirstName); + + TextField lastNameEditor = new TextField(); + lastNameColumn.setEditorComponent(lastNameEditor); + lastNameEditor.setMaxLength(50); + binder.bind(lastNameEditor, Person::getLastName, Person::setLastName); + + TextField phoneEditor = new TextField(); + phoneEditor.setReadOnly(true); + phoneColumn.setEditorComponent(phoneEditor); + binder.bind(phoneEditor, Person::getPhoneNumber, + Person::setPhoneNumber); + + return grid; + } + +} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridDragAndDrop.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridDragAndDrop.java deleted file mode 100644 index 5a29717239..0000000000 --- a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridDragAndDrop.java +++ /dev/null @@ -1,62 +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.Arrays; -import java.util.List; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractReindeerTestUI; -import com.vaadin.v7.ui.Grid; - -@SuppressWarnings("serial") -public class GridDragAndDrop extends AbstractReindeerTestUI { - - @Override - protected void setup(VaadinRequest request) { - - List columnIds = Arrays.asList("Hello", "this", "are", - "multiple", "columns", "plus", "these", "resemble", "a", - "group", "here", "no", "more"); - - Grid grid = new Grid(); - - for (String columnId : columnIds) { - grid.addColumn(columnId); - } - - for (int i = 0; i < 100; i++) { - grid.addRow(columnIds.toArray()); - } - - grid.setColumnReorderingAllowed(true); - - grid.setFrozenColumnCount(1); - grid.setSelectionMode(Grid.SelectionMode.MULTI); - - addComponent(grid); - } - - @Override - protected String getTestDescription() { - return "Start dragging a column header and move left and right.
The drop indicator should appear exactly on the lines between column headers."; - } - - @Override - protected Integer getTicketNumber() { - return 18925; - } -} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridEditingWithNoScrollBars.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridEditingWithNoScrollBars.java deleted file mode 100644 index 78523f362c..0000000000 --- a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridEditingWithNoScrollBars.java +++ /dev/null @@ -1,53 +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 com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractReindeerTestUI; -import com.vaadin.v7.ui.ComboBox; -import com.vaadin.v7.ui.Grid; -import com.vaadin.v7.ui.Grid.Column; -import com.vaadin.v7.ui.Grid.SelectionMode; - -public class GridEditingWithNoScrollBars extends AbstractReindeerTestUI { - - @Override - protected void setup(VaadinRequest request) { - Grid grid = new Grid(); - grid.addColumn("foo", String.class); - grid.addColumn("bar", String.class); - for (int i = 0; i < 10; ++i) { - grid.addRow("foo", "" + (i % 3 + 1)); - } - - ComboBox stCombo = new ComboBox(); - stCombo.addItem("" + 1); - stCombo.addItem("" + 2); - stCombo.addItem("" + 3); - stCombo.setNullSelectionAllowed(false); - stCombo.setSizeFull(); - - Column stCol = grid.getColumn("bar"); - stCol.setEditorField(stCombo); - - grid.setSelectionMode(SelectionMode.SINGLE); - grid.setEditorEnabled(true); - grid.setSizeFull(); - - addComponent(grid); - } - -} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridEditorConverterNotFound.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridEditorConverterNotFound.java deleted file mode 100644 index d224583c26..0000000000 --- a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridEditorConverterNotFound.java +++ /dev/null @@ -1,56 +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 com.vaadin.server.ErrorHandler; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUIWithLog; -import com.vaadin.v7.ui.Grid; - -public class GridEditorConverterNotFound extends AbstractTestUIWithLog { - - class Foo { - } - - @Override - protected void setup(VaadinRequest request) { - - Grid grid = new Grid(); - - grid.addColumn("foo", Foo.class); - grid.addRow(new Foo()); - grid.setEditorEnabled(true); - grid.setErrorHandler(new ErrorHandler() { - - @Override - public void error(com.vaadin.server.ErrorEvent event) { - log(event.getThrowable().toString()); - } - }); - - addComponent(grid); - } - - @Override - protected Integer getTicketNumber() { - return 17935; - } - - @Override - protected String getTestDescription() { - return "Grid should gracefully handle bind failures when opening editor"; - } -} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridEditorFrozenColumnsUI.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridEditorFrozenColumnsUI.java deleted file mode 100644 index 3732e70a6f..0000000000 --- a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridEditorFrozenColumnsUI.java +++ /dev/null @@ -1,43 +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 com.vaadin.tests.util.PersonContainer; -import com.vaadin.v7.ui.Grid; - -public class GridEditorFrozenColumnsUI extends GridEditorUI { - - @Override - protected Grid createGrid(PersonContainer container) { - Grid grid = super.createGrid(container); - - grid.setFrozenColumnCount(2); - - grid.setWidth("600px"); - - return grid; - } - - @Override - protected Integer getTicketNumber() { - return 16727; - } - - @Override - protected String getTestDescription() { - return "Frozen columns should also freeze cells in editor."; - } -} diff --git a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridEditorMultiselect.java b/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridEditorMultiselect.java deleted file mode 100644 index 086aa8dd9f..0000000000 --- a/uitest/src/main/java/com/vaadin/v7/tests/components/grid/GridEditorMultiselect.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.vaadin.v7.tests.components.grid; - -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractReindeerTestUI; -import com.vaadin.v7.ui.Grid; - -public class GridEditorMultiselect extends AbstractReindeerTestUI { - - @Override - protected void setup(VaadinRequest request) { - Grid grid = new Grid(); - - grid.addColumn("name"); - grid.addColumn("age", Integer.class); - - for (int i = 0; i < 30; i++) { - grid.addRow("name " + i, i); - } - - grid.setEditorEnabled(true); - grid.setSelectionMode(Grid.SelectionMode.MULTI); - - addComponent(grid); - } - - @Override - protected Integer getTicketNumber() { - return 17132; - } - - @Override - protected String getTestDescription() { - return "Grid Multiselect: Edit mode allows invalid selection"; - } -} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditingWithNoScrollBarsTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditingWithNoScrollBarsTest.java new file mode 100644 index 0000000000..c0db4f0d35 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditingWithNoScrollBarsTest.java @@ -0,0 +1,38 @@ +/* + * 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 static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import com.vaadin.testbench.customelements.GridElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; + +@TestCategory("grid") +public class GridEditingWithNoScrollBarsTest extends MultiBrowserTest { + + @Test + public void testEditorWideEnough() { + openTestURL(); + + GridElement grid = $(GridElement.class).first(); + grid.getCell(1, 1).doubleClick(); + assertEquals(grid.getEditor().getSize().width, + grid.getTableWrapper().getSize().width); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorFrozenColumnsUITest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorFrozenColumnsUITest.java new file mode 100644 index 0000000000..e2a932f452 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorFrozenColumnsUITest.java @@ -0,0 +1,77 @@ +/* + * 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.io.IOException; + +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.interactions.Actions; + +import com.vaadin.testbench.customelements.GridElement; +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; + +@TestCategory("grid") +public class GridEditorFrozenColumnsUITest extends MultiBrowserTest { + + @Test + public void testEditorWithFrozenColumns() throws IOException { + openTestURL(); + + openEditor(10); + + compareScreen("noscroll"); + + scrollGridHorizontallyTo(100); + + compareScreen("scrolled"); + } + + private void openEditor(int rowIndex) { + GridElement grid = $(GridElement.class).first(); + + GridCellElement cell = grid.getCell(rowIndex, 1); + + new Actions(driver).moveToElement(cell).doubleClick().build().perform(); + } + + private void scrollGridHorizontallyTo(double px) { + executeScript("arguments[0].scrollLeft = " + px, + getGridHorizontalScrollbar()); + } + + private Object executeScript(String script, WebElement element) { + final WebDriver driver = getDriver(); + if (driver instanceof JavascriptExecutor) { + final JavascriptExecutor je = (JavascriptExecutor) driver; + return je.executeScript(script, element); + } else { + throw new IllegalStateException("current driver " + + getDriver().getClass().getName() + " is not a " + + JavascriptExecutor.class.getSimpleName()); + } + } + + private WebElement getGridHorizontalScrollbar() { + return getDriver().findElement(By.xpath( + "//div[contains(@class, \"v-grid-scroller-horizontal\")]")); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorMultiselectTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorMultiselectTest.java new file mode 100644 index 0000000000..1034012311 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridEditorMultiselectTest.java @@ -0,0 +1,59 @@ +package com.vaadin.tests.components.grid; + +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.customelements.GridElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; + +@TestCategory("grid") +public class GridEditorMultiselectTest extends MultiBrowserTest { + + @Test + public void testSelectCheckboxesDisabled() { + openTestURL(); + GridElement grid = openEditor(); + assertCheckboxesEnabled(grid, false); + } + + @Test + public void testSelectCheckboxesEnabledBackOnSave() { + openTestURL(); + GridElement grid = openEditor(); + grid.getEditor().save(); + waitForElementNotPresent(By.className("v-grid-editor-cells")); + assertCheckboxesEnabled(grid, true); + } + + @Test + public void testSelectCheckboxesEnabledBackOnCancel() { + openTestURL(); + GridElement grid = openEditor(); + grid.getEditor().cancel(); + assertCheckboxesEnabled(grid, true); + } + + private GridElement openEditor() { + GridElement grid = $(GridElement.class).first(); + grid.getRow(0).doubleClick(); + Assert.assertTrue("Grid editor should be displayed.", + grid.getEditor().isDisplayed()); + return grid; + } + + private void assertCheckboxesEnabled(GridElement grid, boolean isEnabled) { + List checkboxes = grid + .findElements(By.xpath("//input[@type='checkbox']")); + for (WebElement checkbox : checkboxes) { + Assert.assertEquals( + "Select checkboxes should be " + + (isEnabled ? "enabled" : "disabled"), + isEnabled, checkbox.isEnabled()); + } + } +} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridEditingWithNoScrollBarsTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridEditingWithNoScrollBarsTest.java deleted file mode 100644 index d7d59552eb..0000000000 --- a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridEditingWithNoScrollBarsTest.java +++ /dev/null @@ -1,38 +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 static org.junit.Assert.assertEquals; - -import org.junit.Test; - -import com.vaadin.testbench.customelements.GridElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; - -@TestCategory("grid") -public class GridEditingWithNoScrollBarsTest extends MultiBrowserTest { - - @Test - public void testEditorWideEnough() { - openTestURL(); - - GridElement grid = $(GridElement.class).first(); - grid.getCell(1, 1).doubleClick(); - assertEquals(grid.getEditor().getSize().width, - grid.getTableWrapper().getSize().width); - } -} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridEditorConverterNotFoundTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridEditorConverterNotFoundTest.java deleted file mode 100644 index c0d2a83558..0000000000 --- a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridEditorConverterNotFoundTest.java +++ /dev/null @@ -1,42 +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 static org.junit.Assert.assertEquals; - -import org.junit.Test; - -import com.vaadin.testbench.customelements.GridElement; -import com.vaadin.v7.tests.components.grid.basicfeatures.GridBasicFeaturesTest; - -public class GridEditorConverterNotFoundTest extends GridBasicFeaturesTest { - - @Override - protected Class getUIClass() { - // Use the correct UI with helpers from GridBasicFeatures - return GridEditorConverterNotFound.class; - } - - @Test - public void testConverterNotFound() { - openTestURL(); - - $(GridElement.class).first().getCell(0, 0).doubleClick(); - - assertEquals("1. com.vaadin.v7.data.Buffered$SourceException", - getLogRow(0)); - } -} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridEditorFrozenColumnsUITest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridEditorFrozenColumnsUITest.java deleted file mode 100644 index 9a451362fd..0000000000 --- a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridEditorFrozenColumnsUITest.java +++ /dev/null @@ -1,77 +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.io.IOException; - -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.JavascriptExecutor; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.interactions.Actions; - -import com.vaadin.testbench.customelements.GridElement; -import com.vaadin.testbench.elements.GridElement.GridCellElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; - -@TestCategory("grid") -public class GridEditorFrozenColumnsUITest extends MultiBrowserTest { - - @Test - public void testEditorWithFrozenColumns() throws IOException { - openTestURL(); - - openEditor(10); - - compareScreen("noscroll"); - - scrollGridHorizontallyTo(100); - - compareScreen("scrolled"); - } - - private void openEditor(int rowIndex) { - GridElement grid = $(GridElement.class).first(); - - GridCellElement cell = grid.getCell(rowIndex, 1); - - new Actions(driver).moveToElement(cell).doubleClick().build().perform(); - } - - private void scrollGridHorizontallyTo(double px) { - executeScript("arguments[0].scrollLeft = " + px, - getGridHorizontalScrollbar()); - } - - private Object executeScript(String script, WebElement element) { - final WebDriver driver = getDriver(); - if (driver instanceof JavascriptExecutor) { - final JavascriptExecutor je = (JavascriptExecutor) driver; - return je.executeScript(script, element); - } else { - throw new IllegalStateException("current driver " - + getDriver().getClass().getName() + " is not a " - + JavascriptExecutor.class.getSimpleName()); - } - } - - private WebElement getGridHorizontalScrollbar() { - return getDriver().findElement(By.xpath( - "//div[contains(@class, \"v-grid-scroller-horizontal\")]")); - } -} diff --git a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridEditorMultiselectTest.java b/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridEditorMultiselectTest.java deleted file mode 100644 index ec15e0368c..0000000000 --- a/uitest/src/test/java/com/vaadin/v7/tests/components/grid/GridEditorMultiselectTest.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.vaadin.v7.tests.components.grid; - -import java.util.List; - -import org.junit.Assert; -import org.junit.Test; -import org.openqa.selenium.WebElement; - -import com.vaadin.testbench.By; -import com.vaadin.testbench.customelements.GridElement; -import com.vaadin.testbench.parallel.TestCategory; -import com.vaadin.tests.tb3.MultiBrowserTest; - -@TestCategory("grid") -public class GridEditorMultiselectTest extends MultiBrowserTest { - - @Test - public void testSelectCheckboxesDisabled() { - openTestURL(); - GridElement grid = openEditor(); - assertCheckboxesEnabled(grid, false); - } - - @Test - public void testSelectCheckboxesEnabledBackOnSave() { - openTestURL(); - GridElement grid = openEditor(); - grid.getEditor().save(); - assertCheckboxesEnabled(grid, true); - } - - @Test - public void testSelectCheckboxesEnabledBackOnCancel() { - openTestURL(); - GridElement grid = openEditor(); - grid.getEditor().cancel(); - assertCheckboxesEnabled(grid, true); - } - - private GridElement openEditor() { - GridElement grid = $(GridElement.class).first(); - grid.getRow(0).doubleClick(); - Assert.assertTrue("Grid editor should be displayed.", - grid.getEditor().isDisplayed()); - return grid; - } - - private void assertCheckboxesEnabled(GridElement grid, boolean isEnabled) { - List checkboxes = grid - .findElements(By.xpath("//input[@type='checkbox']")); - for (WebElement checkbox : checkboxes) { - Assert.assertEquals( - "Select checkboxes should be " - + (isEnabled ? "enabled" : "disabled"), - isEnabled, checkbox.isEnabled()); - } - } -}