diff options
author | Teemu Suo-Anttila <teemusa@vaadin.com> | 2015-07-13 15:46:31 +0300 |
---|---|---|
committer | Teemu Suo-Anttila <teemusa@vaadin.com> | 2015-07-13 15:46:31 +0300 |
commit | ae5793ae460cab22612c134cbec4b8ae6ed4175b (patch) | |
tree | e24c1924cc4882a273707661d16d9a67c875aa31 /uitest/src/com/vaadin/tests/components/grid | |
parent | 40dcbc3cfaa438c9b879720c9012331dd85ca694 (diff) | |
parent | 96e10ed8be9ec1e694001098584361e43eb35af2 (diff) | |
download | vaadin-framework-ae5793ae460cab22612c134cbec4b8ae6ed4175b.tar.gz vaadin-framework-ae5793ae460cab22612c134cbec4b8ae6ed4175b.zip |
Merge remote-tracking branch 'origin/master' into grid-unbuffered-editor
Change-Id: Id630861d5089b0deabbccffe66d971252c44f46b
Diffstat (limited to 'uitest/src/com/vaadin/tests/components/grid')
8 files changed, 451 insertions, 12 deletions
diff --git a/uitest/src/com/vaadin/tests/components/grid/GridCheckBoxDisplay.java b/uitest/src/com/vaadin/tests/components/grid/GridCheckBoxDisplay.java new file mode 100644 index 0000000000..e6aff73532 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/GridCheckBoxDisplay.java @@ -0,0 +1,91 @@ +/* + * 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; + +import java.io.Serializable; + +import com.vaadin.data.util.BeanItemContainer; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Grid; + +public class GridCheckBoxDisplay extends AbstractTestUI { + + private static final long serialVersionUID = -5575892909354637168L; + private BeanItemContainer<Todo> todoContainer = new BeanItemContainer<Todo>( + Todo.class); + + @Override + protected void setup(VaadinRequest request) { + todoContainer.addBean(new Todo("Done task", true)); + todoContainer.addBean(new Todo("Not done", false)); + + Grid grid = new Grid(todoContainer); + grid.setSizeFull(); + + grid.setColumnOrder("done", "task"); + grid.getColumn("done").setWidth(75); + grid.getColumn("task").setExpandRatio(1); + + grid.setSelectionMode(Grid.SelectionMode.SINGLE); + + grid.setEditorEnabled(true); + grid.setImmediate(true); + + getLayout().addComponent(grid); + getLayout().setExpandRatio(grid, 1); + + } + + @Override + protected Integer getTicketNumber() { + return 16976; + } + + @Override + public String getDescription() { + return "Verify that checkbox state is correct for all items in editor"; + } + + public class Todo implements Serializable { + private static final long serialVersionUID = -5961103142478316018L; + + private boolean done; + private String task = ""; + + public Todo(String task, boolean done) { + this.task = task; + this.done = done; + } + + public boolean isDone() { + return done; + } + + public void setDone(boolean done) { + this.done = done; + } + + public String getTask() { + return task; + } + + public void setTask(String task) { + this.task = task; + } + } + +} diff --git a/uitest/src/com/vaadin/tests/components/grid/GridCheckBoxDisplayTest.java b/uitest/src/com/vaadin/tests/components/grid/GridCheckBoxDisplayTest.java new file mode 100644 index 0000000000..c430821534 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/GridCheckBoxDisplayTest.java @@ -0,0 +1,72 @@ +/* + * 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; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; + +import com.vaadin.testbench.elements.CheckBoxElement; +import com.vaadin.testbench.elements.GridElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.SingleBrowserTest; + +@TestCategory("grid") +public class GridCheckBoxDisplayTest extends SingleBrowserTest { + @Test + public void testAddRow() { + openTestURL(); + + GridElement grid = $(GridElement.class).first(); + + Assert.assertEquals("First item had wrong value", "true", + grid.getCell(0, 0).getText()); + Assert.assertEquals("Second item had wrong value", "false", grid + .getCell(1, 0).getText()); + + // First edit false item and see that the CheckBox is unchecked + grid.getCell(1, 0).doubleClick(); + + CheckBoxElement checkbox = $(CheckBoxElement.class).first(); + Assert.assertEquals("CheckBox was checked", "unchecked", + checkbox.getValue()); + + closeEditor(); + + // Edit true item and see that the CheckBox is checked + grid.getCell(0, 0).doubleClick(); + + checkbox = $(CheckBoxElement.class).first(); + Assert.assertEquals("CheckBox was not checked.", "checked", + checkbox.getValue()); + + closeEditor(); + + // Edit false item and confirm that the CheckBox is unchecked again + grid.getCell(1, 0).doubleClick(); + + checkbox = $(CheckBoxElement.class).first(); + Assert.assertEquals("CheckBox was checked", "unchecked", + checkbox.getValue()); + } + + /** + * Closes the grids editor using the cancel button + */ + private void closeEditor() { + findElement(By.className("v-grid-editor-cancel")).click(); + } +} diff --git a/uitest/src/com/vaadin/tests/components/grid/GridDetailsDetach.java b/uitest/src/com/vaadin/tests/components/grid/GridDetailsDetach.java new file mode 100644 index 0000000000..1032378a2d --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/GridDetailsDetach.java @@ -0,0 +1,149 @@ +/* + * 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; + +import com.vaadin.data.util.BeanItemContainer; +import com.vaadin.event.ItemClickEvent; +import com.vaadin.event.ItemClickEvent.ItemClickListener; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Component; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Grid.DetailsGenerator; +import com.vaadin.ui.Grid.RowReference; +import com.vaadin.ui.Label; +import com.vaadin.ui.VerticalLayout; + +public class GridDetailsDetach extends AbstractTestUI { + + private Grid currentGrid; + + @Override + protected void setup(VaadinRequest request) { + VerticalLayout layout = new VerticalLayout(); + layout.setSizeFull(); + + Button button = new Button("Test"); + layout.addComponent(button); + layout.setExpandRatio(button, 0f); + + currentGrid = generateGrid(); + final VerticalLayout gridContainer = new VerticalLayout(); + gridContainer.addComponent(currentGrid); + + button.addClickListener(new Button.ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + gridContainer.replaceComponent(currentGrid, new Label("Foo")); + } + }); + + layout.addComponent(new Button("Reattach Grid", + new Button.ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + gridContainer.removeAllComponents(); + gridContainer.addComponent(currentGrid); + } + })); + + layout.addComponent(gridContainer); + layout.setExpandRatio(gridContainer, 1f); + + addComponent(layout); + } + + private Grid generateGrid() { + BeanItemContainer<GridExampleBean> container = new BeanItemContainer<GridExampleBean>( + GridExampleBean.class); + for (int i = 0; i < 1000; i++) { + container.addItem(new GridExampleBean("Bean " + i, i * i, i / 10d)); + } + + final Grid grid = new Grid(container); + grid.setColumnOrder("name", "amount", "count"); + grid.setSizeFull(); + + grid.setDetailsGenerator(new DetailsGenerator() { + @Override + public Component getDetails(RowReference rowReference) { + final GridExampleBean bean = (GridExampleBean) rowReference + .getItemId(); + VerticalLayout layout = new VerticalLayout(new Label( + "Extra data for " + bean.getName())); + layout.setMargin(true); + return layout; + } + }); + + grid.addItemClickListener(new ItemClickListener() { + @Override + public void itemClick(ItemClickEvent event) { + Object itemId = event.getItemId(); + grid.setDetailsVisible(itemId, !grid.isDetailsVisible(itemId)); + } + }); + return grid; + } + + public class GridExampleBean { + + private String name; + + private int count; + + private double amount; + + public GridExampleBean() { + } + + public GridExampleBean(String name, int count, double amount) { + this.name = name; + this.count = count; + this.amount = amount; + } + + public String getName() { + return name; + } + + public int getCount() { + return count; + } + + public double getAmount() { + return amount; + } + + public void setName(String name) { + this.name = name; + } + + public void setCount(int count) { + this.count = count; + } + + public void setAmount(double amount) { + this.amount = amount; + } + + } + +} diff --git a/uitest/src/com/vaadin/tests/components/grid/GridDetailsDetachTest.java b/uitest/src/com/vaadin/tests/components/grid/GridDetailsDetachTest.java new file mode 100644 index 0000000000..fc79fd1b68 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/GridDetailsDetachTest.java @@ -0,0 +1,73 @@ +/* + * 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; + +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.GridElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.MultiBrowserTest; + +@TestCategory("grid") +public class GridDetailsDetachTest extends MultiBrowserTest { + + @Test + public void testDetachGridWithDetailsOpen() { + setDebug(true); + openTestURL(); + + $(GridElement.class).first().getCell(3, 0).click(); + $(GridElement.class).first().getCell(5, 0).click(); + + assertNoErrorNotifications(); + + $(ButtonElement.class).first().click(); + + assertNoErrorNotifications(); + } + + @Test + public void testDetachAndReattachGridWithDetailsOpen() { + setDebug(true); + openTestURL(); + + $(GridElement.class).first().getCell(3, 0).click(); + $(GridElement.class).first().getCell(5, 0).click(); + + assertNoErrorNotifications(); + + $(ButtonElement.class).first().click(); + + assertNoErrorNotifications(); + + $(ButtonElement.class).get(1).click(); + + assertNoErrorNotifications(); + + List<WebElement> spacers = findElements(By.className("v-grid-spacer")); + Assert.assertEquals("Not enough spacers in DOM", 2, spacers.size()); + Assert.assertEquals("Spacer content not visible", + "Extra data for Bean 3", spacers.get(0).getText()); + Assert.assertEquals("Spacer content not visible", + "Extra data for Bean 5", spacers.get(1).getText()); + } +} diff --git a/uitest/src/com/vaadin/tests/components/grid/GridDetailsWidthTest.java b/uitest/src/com/vaadin/tests/components/grid/GridDetailsWidthTest.java index 41838b427b..2def2d0279 100644 --- a/uitest/src/com/vaadin/tests/components/grid/GridDetailsWidthTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/GridDetailsWidthTest.java @@ -23,6 +23,7 @@ import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import com.vaadin.testbench.elements.GridElement; +import com.vaadin.testbench.elements.GridElement.GridCellElement; import com.vaadin.testbench.parallel.TestCategory; import com.vaadin.tests.tb3.SingleBrowserTest; @@ -66,4 +67,26 @@ public class GridDetailsWidthTest extends SingleBrowserTest { } } + @Test + public void testDetailsOnSort() { + openTestURL(); + GridElement grid = $(GridElement.class).first(); + + // Open a details rows + grid.getCell(0, 0).click(); + + GridCellElement cell = grid.getHeaderCell(0, 0); + cell.click(); + cell.click(); + + cell = grid.getCell(2, 0); + WebElement spacer = findElement(By.className("v-grid-spacer")); + Assert.assertEquals("Grid was not sorted correctly", "Hello 0", + cell.getText()); + Assert.assertEquals("Details row was not in correct location", cell + .getLocation().getY() + cell.getSize().getHeight(), spacer + .getLocation().getY()); + + } + } diff --git a/uitest/src/com/vaadin/tests/components/grid/GridSubPixelProblemWrappingTest.java b/uitest/src/com/vaadin/tests/components/grid/GridSubPixelProblemWrappingTest.java index 319cf3b8b8..4368fda158 100644 --- a/uitest/src/com/vaadin/tests/components/grid/GridSubPixelProblemWrappingTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/GridSubPixelProblemWrappingTest.java @@ -15,30 +15,18 @@ */ package com.vaadin.tests.components.grid; -import java.util.List; - import org.junit.Assert; import org.junit.Test; -import org.openqa.selenium.remote.DesiredCapabilities; import com.vaadin.testbench.elements.ButtonElement; import com.vaadin.testbench.elements.GridElement; import com.vaadin.testbench.elements.GridElement.GridRowElement; -import com.vaadin.testbench.parallel.Browser; import com.vaadin.testbench.parallel.TestCategory; import com.vaadin.tests.tb3.MultiBrowserTest; @TestCategory("grid") public class GridSubPixelProblemWrappingTest extends MultiBrowserTest { - @Override - public List<DesiredCapabilities> getBrowsersToTest() { - List<DesiredCapabilities> l = super.getBrowsersToTest(); - // Currently broken because of #18214 - l.remove(Browser.IE9.getDesiredCapabilities()); - return l; - } - @Test public void addedRowShouldNotWrap() { openTestURL(); diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridClientSelectionTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridClientSelectionTest.java index a341e39b74..d1d7b21e11 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridClientSelectionTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/client/GridClientSelectionTest.java @@ -195,4 +195,17 @@ public class GridClientSelectionTest extends GridBasicClientFeaturesTest { isRowSelected(1)); } + @Test + public void testChangeSelectionModelUpdatesUI() { + openTestURL(); + + setSelectionModelSingle(true); + getGridElement().getCell(5, 1).click(); + assertTrue("Row 5 should be selected after clicking", isRowSelected(5)); + setSelectionModelNone(); + assertFalse( + "Row 5 should not be selected after changing selection model", + isRowSelected(5)); + + } } diff --git a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridSelectionTest.java b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridSelectionTest.java index b4eb473d4b..9953bbcae0 100644 --- a/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridSelectionTest.java +++ b/uitest/src/com/vaadin/tests/components/grid/basicfeatures/server/GridSelectionTest.java @@ -271,6 +271,20 @@ public class GridSelectionTest extends GridBasicFeaturesTest { } @Test + public void testSelectAllCheckboxWithHeaderOperations() { + openTestURL(); + + setSelectionModelMulti(); + selectMenuPath("Component", "Header", "Prepend row"); + selectMenuPath("Component", "Header", "Append row"); + + GridCellElement header = getGridElement().getHeaderCell(1, 0); + assertTrue("Multi Selection Model should have select all checkbox", + header.isElementPresent(By.tagName("input"))); + + } + + @Test public void testToggleDeselectAllowed() { openTestURL(); @@ -305,6 +319,22 @@ public class GridSelectionTest extends GridBasicFeaturesTest { .isSelected()); } + @Test + public void testChangeSelectionModelUpdatesUI() { + openTestURL(); + + setSelectionModelSingle(); + + getGridElement().getCell(5, 1).click(); + assertTrue("Row should be selected after clicking", getRow(5) + .isSelected()); + + setSelectionModelNone(); + assertFalse( + "Row should not be selected after changing selection model", + getRow(5).isSelected()); + } + private void setSelectionModelMulti() { selectMenuPath("Component", "State", "Selection mode", "multi"); } |