diff options
Diffstat (limited to 'uitest')
-rw-r--r-- | uitest/src/com/vaadin/tests/components/grid/GridHeaderFooterComponents.java | 140 | ||||
-rw-r--r-- | uitest/src/com/vaadin/tests/components/grid/GridHeaderFooterComponentsTest.java | 103 |
2 files changed, 243 insertions, 0 deletions
diff --git a/uitest/src/com/vaadin/tests/components/grid/GridHeaderFooterComponents.java b/uitest/src/com/vaadin/tests/components/grid/GridHeaderFooterComponents.java new file mode 100644 index 0000000000..6c2efc9a25 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/GridHeaderFooterComponents.java @@ -0,0 +1,140 @@ +/* + * 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.annotations.Theme; +import com.vaadin.data.Property.ValueChangeEvent; +import com.vaadin.data.Property.ValueChangeListener; +import com.vaadin.data.util.IndexedContainer; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.Component; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Grid.FooterRow; +import com.vaadin.ui.Grid.HeaderRow; +import com.vaadin.ui.TextField; + +@Theme("valo") +public class GridHeaderFooterComponents extends AbstractTestUIWithLog { + + @Override + protected void setup(VaadinRequest request) { + final Grid grid = new Grid(); + grid.setWidth("800px"); + grid.setContainerDataSource(createContainer()); + grid.setFooterVisible(true); + final HeaderRow defaultRow = grid.getDefaultHeaderRow(); + final HeaderRow toggleVisibilityRow = grid.appendHeaderRow(); + final Grid.HeaderRow filterRow = grid.appendHeaderRow(); + + final FooterRow footerRow = grid.addFooterRowAt(0); + final FooterRow toggleVisibilityFooterRow = grid.addFooterRowAt(0); + final FooterRow filterFooterRow = grid.addFooterRowAt(0); + + // Set up a filter for all columns + for (final Object pid : grid.getContainerDataSource() + .getContainerPropertyIds()) { + final Grid.HeaderCell headerCell = filterRow.getCell(pid); + final Grid.FooterCell footerCell = filterFooterRow.getCell(pid); + + headerCell.setComponent(createTextField(pid)); + footerCell.setComponent(createTextField(pid)); + + toggleVisibilityRow.getCell(pid).setComponent( + new Button("Toggle field", new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + Component c = headerCell.getComponent(); + c.setVisible(!c.isVisible()); + } + })); + toggleVisibilityFooterRow.getCell(pid).setComponent( + new Button("Toggle field", new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + Component c = footerCell.getComponent(); + c.setVisible(!c.isVisible()); + } + })); + } + addComponent(grid); + + addRemoveHeaderRow(grid, defaultRow); + addRemoveHeaderRow(grid, filterRow); + addRemoveHeaderRow(grid, toggleVisibilityRow); + + addRemoveFooterRow(grid, footerRow); + addRemoveFooterRow(grid, filterFooterRow); + addRemoveFooterRow(grid, toggleVisibilityFooterRow); + + // Hide first field initially + filterRow.getCell("string").getComponent().setVisible(false); + filterFooterRow.getCell("string").getComponent().setVisible(false); + } + + private void addRemoveHeaderRow(final Grid grid, final HeaderRow row) { + row.getCell("action").setComponent( + new Button("Remove row", new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + grid.removeHeaderRow(row); + } + })); + + } + + private void addRemoveFooterRow(final Grid grid, final FooterRow row) { + row.getCell("action").setComponent( + new Button("Remove row", new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + grid.removeFooterRow(row); + } + })); + + } + + private IndexedContainer createContainer() { + IndexedContainer ic = new IndexedContainer(); + ic.addContainerProperty("action", String.class, ""); + ic.addContainerProperty("string", String.class, "Hello world"); + ic.addContainerProperty("int", int.class, 13); + ic.addContainerProperty("double", double.class, 5.2f); + + for (int i = 0; i < 5; i++) { + ic.addItem(); + } + return ic; + } + + private TextField createTextField(final Object pid) { + TextField filterField = new TextField(); + filterField.setColumns(8); + filterField.setValue("Filter: " + pid); + filterField.addValueChangeListener(new ValueChangeListener() { + @Override + public void valueChange(ValueChangeEvent event) { + log("value change for field in " + pid + " to " + + event.getProperty().getValue()); + } + }); + return filterField; + } + +} diff --git a/uitest/src/com/vaadin/tests/components/grid/GridHeaderFooterComponentsTest.java b/uitest/src/com/vaadin/tests/components/grid/GridHeaderFooterComponentsTest.java new file mode 100644 index 0000000000..977b16cebd --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/grid/GridHeaderFooterComponentsTest.java @@ -0,0 +1,103 @@ +/* + * 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 com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.GridElement; +import com.vaadin.testbench.elements.GridElement.GridCellElement; +import com.vaadin.testbench.elements.TextFieldElement; +import com.vaadin.tests.tb3.SingleBrowserTest; + +public class GridHeaderFooterComponentsTest extends SingleBrowserTest { + + @Test + public void hideAndShowComponentsInHeader() { + openTestURL(); + GridElement grid = $(GridElement.class).first(); + + int filterRow = 2; + Assert.assertNull(getHeaderElement(grid, filterRow, 1)); + Assert.assertNotNull(getHeaderElement(grid, filterRow, 2)); + Assert.assertNotNull(getHeaderElement(grid, filterRow, 3)); + + // Show (1,2) + grid.getHeaderCell(1, 1).$(ButtonElement.class).first().click(); + + TextFieldElement textfield = getHeaderElement(grid, filterRow, 1); + Assert.assertNotNull(textfield); + Assert.assertEquals("Filter: string", textfield.getValue()); + + textfield.setValue("foo"); + Assert.assertEquals("1. value change for field in string to foo", + getLogRow(0)); + } + + private TextFieldElement getHeaderElement(GridElement grid, int row, int col) { + GridCellElement cell = grid.getHeaderCell(row, col); + List<TextFieldElement> all = cell.$(TextFieldElement.class).all(); + if (all.size() == 0) { + return null; + } else if (all.size() == 1) { + return all.get(0); + } else { + throw new RuntimeException( + "Multiple elements found in the header cell at " + row + + "," + col); + } + } + + @Test + public void hideAndShowComponentsInFooter() { + openTestURL(); + GridElement grid = $(GridElement.class).first(); + + int filterRow = 0; + Assert.assertNull(getFooterElement(grid, filterRow, 1)); + Assert.assertNotNull(getFooterElement(grid, filterRow, 2)); + Assert.assertNotNull(getFooterElement(grid, filterRow, 3)); + + // Show (1,2) + grid.getFooterCell(1, 1).$(ButtonElement.class).first().click(); + + TextFieldElement textfield = getFooterElement(grid, filterRow, 1); + Assert.assertNotNull(textfield); + Assert.assertEquals("Filter: string", textfield.getValue()); + + textfield.setValue("foo"); + Assert.assertEquals("1. value change for field in string to foo", + getLogRow(0)); + } + + private TextFieldElement getFooterElement(GridElement grid, int row, int col) { + GridCellElement cell = grid.getFooterCell(row, col); + List<TextFieldElement> all = cell.$(TextFieldElement.class).all(); + if (all.size() == 0) { + return null; + } else if (all.size() == 1) { + return all.get(0); + } else { + throw new RuntimeException( + "Multiple elements found in the footer cell at " + row + + "," + col); + } + } + +} |