* Grid UI tests migration P2. Fixes vaadin/framework8-issues#588 * Grid UI tests migration P3. Fixes vaadin/framework8-issues#589 * Merge branch 'master' into 589-grid-tests-migration Conflicts: uitest/src/main/java/com/vaadin/tests/components/grid/GridCellFocusOnResetSize.java uitest/src/main/java/com/vaadin/tests/components/grid/GridClientDataChangeHandler.java * Update screenshot submodule reference.tags/8.0.0.beta2
@@ -1 +1 @@ | |||
Subproject commit 2f2e57cf41694f724aaee7a63202d3763b0e55d8 | |||
Subproject commit eec6eee6610e80e28736e8a27aaaa2166ea2fa7c |
@@ -17,13 +17,13 @@ package com.vaadin.tests.components.grid; | |||
import com.vaadin.annotations.Widgetset; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.tests.components.AbstractReindeerTestUI; | |||
import com.vaadin.tests.components.AbstractTestUI; | |||
import com.vaadin.tests.widgetset.TestingWidgetSet; | |||
import com.vaadin.tests.widgetset.client.grid.GridCellFocusOnResetSizeWidget; | |||
import com.vaadin.tests.widgetset.server.TestWidgetComponent; | |||
@Widgetset(TestingWidgetSet.NAME) | |||
public class GridCellFocusOnResetSize extends AbstractReindeerTestUI { | |||
public class GridCellFocusOnResetSize extends AbstractTestUI { | |||
@Override | |||
protected void setup(VaadinRequest request) { |
@@ -17,13 +17,13 @@ package com.vaadin.tests.components.grid; | |||
import com.vaadin.annotations.Widgetset; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.tests.components.AbstractReindeerTestUI; | |||
import com.vaadin.tests.components.AbstractTestUI; | |||
import com.vaadin.tests.widgetset.TestingWidgetSet; | |||
import com.vaadin.tests.widgetset.client.grid.GridDataChangeHandlerWidget; | |||
import com.vaadin.tests.widgetset.server.TestWidgetComponent; | |||
@Widgetset(TestingWidgetSet.NAME) | |||
public class GridClientDataChangeHandler extends AbstractReindeerTestUI { | |||
public class GridClientDataChangeHandler extends AbstractTestUI { | |||
@Override | |||
protected void setup(VaadinRequest request) { |
@@ -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.stream.Collectors; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.tests.components.AbstractTestUI; | |||
import com.vaadin.tests.data.bean.Person; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.Grid; | |||
import com.vaadin.ui.Grid.Column; | |||
import com.vaadin.ui.Grid.SelectionMode; | |||
import com.vaadin.ui.components.grid.FooterRow; | |||
import com.vaadin.ui.components.grid.HeaderRow; | |||
import com.vaadin.ui.renderers.NumberRenderer; | |||
public class GridColspans extends AbstractTestUI { | |||
@Override | |||
protected void setup(VaadinRequest request) { | |||
Person person = new Person(); | |||
person.setFirstName("Rudolph"); | |||
person.setLastName("Reindeer"); | |||
person.setEmail("test@vaadin.com"); | |||
person.setAge(34); | |||
person.setSalary(3210); | |||
Grid<Person> grid = new Grid<>(); | |||
grid.setWidth("600px"); | |||
Column<Person, String> firstNameColumn = grid | |||
.addColumn(Person::getFirstName); | |||
firstNameColumn.setId("firstName").setCaption("First name"); | |||
Column<Person, String> lastNameColumn = grid | |||
.addColumn(Person::getLastName); | |||
lastNameColumn.setCaption("Last name"); | |||
Column<Person, String> emailColumn = grid.addColumn(Person::getEmail); | |||
Column<Person, Number> ageColumn = grid.addColumn(Person::getAge, | |||
new NumberRenderer()); | |||
ageColumn.setCaption("Age"); | |||
ageColumn.setId("ageColumn"); | |||
Column<Person, Number> salaryColumn = grid.addColumn(Person::getSalary, | |||
new NumberRenderer()); | |||
grid.setItems(person); | |||
grid.setSelectionMode(SelectionMode.MULTI); | |||
addComponent(grid); | |||
HeaderRow row = grid.prependHeaderRow(); | |||
row.join(row.getCell(firstNameColumn), row.getCell(lastNameColumn)) | |||
.setText("Full Name"); | |||
row.join(row.getCell(emailColumn), row.getCell(ageColumn), | |||
row.getCell(salaryColumn)).setText("Misc"); | |||
grid.prependHeaderRow().join(grid.getColumns().stream() | |||
.map(row::getCell).collect(Collectors.toSet())) | |||
.setText("All the stuff"); | |||
FooterRow footerRow = grid.appendFooterRow(); | |||
footerRow.join(footerRow.getCell(firstNameColumn), | |||
footerRow.getCell(lastNameColumn)).setText("Full Name"); | |||
footerRow.join(footerRow.getCell(emailColumn), | |||
footerRow.getCell(ageColumn), footerRow.getCell(salaryColumn)) | |||
.setText("Misc"); | |||
grid.appendFooterRow().join(grid.getColumns().stream() | |||
.map(footerRow::getCell).collect(Collectors.toSet())) | |||
.setText("All the stuff"); | |||
addComponent(new Button("Show/Hide firstName", event -> { | |||
Column<Person, ?> column = grid.getColumn("firstName"); | |||
if (column != null) { | |||
grid.removeColumn(column); | |||
} else { | |||
grid.addColumn(Person::getFirstName).setId("firstName"); | |||
} | |||
})); | |||
addComponent(new Button("Change column order", event -> { | |||
grid.setColumnOrder(grid.getColumn("ageColumn"), | |||
grid.getColumn("firstName")); | |||
})); | |||
} | |||
@Override | |||
protected String getTestDescription() { | |||
return "Grid header and footer colspans"; | |||
} | |||
@Override | |||
protected Integer getTicketNumber() { | |||
return 13334; | |||
} | |||
} |
@@ -13,15 +13,15 @@ | |||
* 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 com.vaadin.data.ValueProvider; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.tests.components.AbstractReindeerTestUI; | |||
import com.vaadin.tests.components.AbstractTestUI; | |||
import com.vaadin.ui.Grid; | |||
import com.vaadin.ui.VerticalLayout; | |||
import com.vaadin.v7.ui.Grid; | |||
import com.vaadin.v7.ui.Grid.Column; | |||
public class GridColumnAutoExpand extends AbstractReindeerTestUI { | |||
public class GridColumnAutoExpand extends AbstractTestUI { | |||
@Override | |||
protected void setup(VaadinRequest request) { | |||
@@ -30,16 +30,15 @@ public class GridColumnAutoExpand extends AbstractReindeerTestUI { | |||
layout.setMargin(true); | |||
addComponent(layout); | |||
Grid grid = new Grid("Broken Grid with Caption"); | |||
Grid<String> grid = new Grid<>(); | |||
grid.setCaption("Broken Grid with Caption"); | |||
grid.setWidth("100%"); | |||
grid.setHeight("100px"); | |||
Column col1 = grid.addColumn("Col1"); | |||
col1.setWidth(100); | |||
Column col2 = grid.addColumn("Col2"); | |||
col2.setMinimumWidth(100); | |||
col2.setExpandRatio(1); | |||
grid.addColumn(ValueProvider.identity()).setCaption("Col1") | |||
.setWidth(100); | |||
grid.addColumn(ValueProvider.identity()).setCaption("Col2") | |||
.setMinimumWidth(100).setExpandRatio(1); | |||
layout.addComponent(grid); | |||
} |
@@ -0,0 +1,54 @@ | |||
/* | |||
* 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.server.VaadinRequest; | |||
import com.vaadin.tests.components.AbstractReindeerTestUI; | |||
import com.vaadin.ui.Grid; | |||
import com.vaadin.ui.Grid.Column; | |||
import com.vaadin.ui.Grid.SelectionMode; | |||
import com.vaadin.ui.renderers.HtmlRenderer; | |||
public class GridColumnAutoWidth extends AbstractReindeerTestUI { | |||
@Override | |||
protected void setup(VaadinRequest request) { | |||
Grid<Object> grid = new Grid<>(); | |||
grid.addColumn(item -> "<span>equal width</span>", new HtmlRenderer()) | |||
.setId("equal width"); | |||
grid.addColumn(item -> "<span>a very long cell content</span>", | |||
new HtmlRenderer()).setId("short"); | |||
grid.addColumn(item -> "<span>short</span>", new HtmlRenderer()) | |||
.setId("a very long header content"); | |||
grid.addColumn(item -> "<span>fixed width narrow</span>", | |||
new HtmlRenderer()).setId("fixed width narrow").setWidth(50); | |||
grid.addColumn(item -> "<span>fixed width wide</span>", | |||
new HtmlRenderer()).setId("fixed width wide").setWidth(200); | |||
for (Column<Object, ?> column : grid.getColumns()) { | |||
column.setExpandRatio(0); | |||
grid.getHeaderRow(0).getCell(column) | |||
.setHtml("<span>" + column.getId() + "</span>"); | |||
} | |||
grid.setItems(new Object()); | |||
grid.setSelectionMode(SelectionMode.NONE); | |||
grid.setWidth("750px"); | |||
addComponent(grid); | |||
} | |||
} |
@@ -13,13 +13,13 @@ | |||
* 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 com.vaadin.annotations.Widgetset; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.tests.components.AbstractReindeerTestUI; | |||
import com.vaadin.tests.widgetset.TestingWidgetSet; | |||
import com.vaadin.tests.widgetset.client.v7.grid.GridColumnAutoWidthClientWidget; | |||
import com.vaadin.tests.widgetset.client.grid.GridColumnAutoWidthClientWidget; | |||
import com.vaadin.tests.widgetset.server.TestWidgetComponent; | |||
@Widgetset(TestingWidgetSet.NAME) |
@@ -0,0 +1,100 @@ | |||
/* | |||
* 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.EnumSet; | |||
import java.util.List; | |||
import com.vaadin.data.provider.DataProvider; | |||
import com.vaadin.server.SerializablePredicate; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.tests.components.AbstractTestUI; | |||
import com.vaadin.tests.data.bean.Person; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.Grid; | |||
import com.vaadin.ui.Grid.SelectionMode; | |||
import com.vaadin.ui.NativeSelect; | |||
import com.vaadin.ui.VerticalLayout; | |||
public class GridColumnWidthsWithoutData extends AbstractTestUI { | |||
private SelectionMode selectionMode = SelectionMode.NONE; | |||
private List<Person> items; | |||
private DataProvider<Person, SerializablePredicate<Person>> provider; | |||
private Grid<Person> grid = createGrid(true); | |||
@Override | |||
protected void setup(VaadinRequest request) { | |||
addComponent(grid); | |||
NativeSelect<SelectionMode> selectionModeSelector = new NativeSelect<>( | |||
"Selection mode", EnumSet.allOf(SelectionMode.class)); | |||
selectionModeSelector.setValue(selectionMode); | |||
selectionModeSelector.addValueChangeListener(event -> { | |||
selectionMode = selectionModeSelector.getValue(); | |||
grid.setSelectionMode(selectionMode); | |||
}); | |||
addComponent(selectionModeSelector); | |||
addComponent(new Button("Recreate without data", | |||
event -> replaceGrid(createGrid(false)))); | |||
addComponent(new Button("Recreate with data", | |||
event -> replaceGrid(createGrid(true)))); | |||
addComponent(new Button("Add data", event -> addDataToGrid())); | |||
addComponent(new Button("Remove data", event -> { | |||
items.clear(); | |||
provider.refreshAll(); | |||
})); | |||
} | |||
private void replaceGrid(Grid<Person> newGrid) { | |||
((VerticalLayout) grid.getParent()).replaceComponent(grid, newGrid); | |||
grid = newGrid; | |||
} | |||
private Grid<Person> createGrid(boolean withData) { | |||
Grid<Person> grid = new Grid<>(); | |||
grid.addColumn(Person::getFirstName); | |||
grid.addColumn(Person::getLastName); | |||
grid.setWidth("300px"); | |||
grid.setSelectionMode(selectionMode); | |||
items = new ArrayList<>(); | |||
provider = DataProvider.create(items); | |||
grid.setDataProvider(provider); | |||
if (withData) { | |||
addDataToGrid(); | |||
} | |||
return grid; | |||
} | |||
private void addDataToGrid() { | |||
Person person = new Person(); | |||
person.setFirstName("Some"); | |||
person.setLastName("Data with more data in one col"); | |||
items.add(person); | |||
provider.refreshAll(); | |||
} | |||
} |
@@ -13,45 +13,40 @@ | |||
* 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 java.util.ArrayList; | |||
import java.util.List; | |||
import java.util.Random; | |||
import com.vaadin.data.provider.DataProvider; | |||
import com.vaadin.data.provider.ListDataProvider; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.tests.components.AbstractReindeerTestUI; | |||
import com.vaadin.tests.components.AbstractTestUI; | |||
import com.vaadin.tests.fieldgroup.ComplexPerson; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.Button.ClickEvent; | |||
import com.vaadin.ui.Button.ClickListener; | |||
import com.vaadin.v7.data.util.BeanItemContainer; | |||
import com.vaadin.v7.ui.Grid; | |||
import com.vaadin.ui.Grid; | |||
public class GridDataSourceReset extends AbstractReindeerTestUI { | |||
public class GridDataSourceReset extends AbstractTestUI { | |||
BeanItemContainer<ComplexPerson> container; | |||
List<ComplexPerson> persons; | |||
Grid grid; | |||
private List<ComplexPerson> persons; | |||
private Grid<ComplexPerson> grid; | |||
@Override | |||
protected void setup(VaadinRequest request) { | |||
persons = createPersons(10, new Random(1)); | |||
container = new BeanItemContainer<>(ComplexPerson.class, persons); | |||
grid = new Grid(container); | |||
grid.select(container.firstItemId()); | |||
addComponent(new Button("Remove first", new ClickListener() { | |||
grid = new Grid<>(); | |||
ListDataProvider<ComplexPerson> provider = DataProvider.create(persons); | |||
grid.setDataProvider(provider); | |||
grid.getSelectionModel().select(persons.get(0)); | |||
addComponent(new Button("Remove first", event -> { | |||
persons.remove(0); | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
container.removeAllItems(); | |||
persons.remove(0); | |||
container.addAll(persons); | |||
grid.select(container.firstItemId()); | |||
} | |||
provider.refreshAll(); | |||
grid.getSelectionModel().select(persons.get(0)); | |||
})); | |||
addComponent(grid); | |||
} | |||
@@ -13,30 +13,29 @@ | |||
* 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 java.util.ArrayList; | |||
import java.util.List; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.tests.components.AbstractReindeerTestUI; | |||
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.SelectionMode; | |||
import com.vaadin.ui.Label; | |||
import com.vaadin.ui.VerticalLayout; | |||
import com.vaadin.v7.data.util.BeanItemContainer; | |||
import com.vaadin.v7.event.ItemClickEvent; | |||
import com.vaadin.v7.event.ItemClickEvent.ItemClickListener; | |||
import com.vaadin.v7.ui.Grid; | |||
import com.vaadin.v7.ui.Grid.DetailsGenerator; | |||
import com.vaadin.v7.ui.Grid.RowReference; | |||
import com.vaadin.v7.ui.Grid.SelectionMode; | |||
import com.vaadin.ui.renderers.NumberRenderer; | |||
public class GridDetailsDetach extends AbstractReindeerTestUI { | |||
public class GridDetailsDetach extends AbstractTestUI { | |||
private Grid currentGrid; | |||
@Override | |||
protected void setup(VaadinRequest request) { | |||
VerticalLayout layout = new VerticalLayout(); | |||
layout.setSpacing(false); | |||
layout.setMargin(false); | |||
layout.setSizeFull(); | |||
Button button = new Button("Test"); | |||
@@ -45,24 +44,17 @@ public class GridDetailsDetach extends AbstractReindeerTestUI { | |||
currentGrid = generateGrid(); | |||
final VerticalLayout gridContainer = new VerticalLayout(); | |||
gridContainer.setSpacing(false); | |||
gridContainer.setMargin(false); | |||
gridContainer.addComponent(currentGrid); | |||
button.addClickListener(new Button.ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
gridContainer.replaceComponent(currentGrid, new Label("Foo")); | |||
} | |||
}); | |||
button.addClickListener(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(new Button("Reattach Grid", event -> { | |||
gridContainer.removeAllComponents(); | |||
gridContainer.addComponent(currentGrid); | |||
})); | |||
layout.addComponent(gridContainer); | |||
layout.setExpandRatio(gridContainer, 1f); | |||
@@ -70,36 +62,30 @@ public class GridDetailsDetach extends AbstractReindeerTestUI { | |||
addComponent(layout); | |||
} | |||
private Grid generateGrid() { | |||
BeanItemContainer<GridExampleBean> container = new BeanItemContainer<>( | |||
GridExampleBean.class); | |||
private Grid<GridExampleBean> generateGrid() { | |||
List<GridExampleBean> items = new ArrayList<>(); | |||
for (int i = 0; i < 1000; i++) { | |||
container.addItem(new GridExampleBean("Bean " + i, i * i, i / 10d)); | |||
items.add(new GridExampleBean("Bean " + i, i * i, i / 10d)); | |||
} | |||
final Grid grid = new Grid(container); | |||
grid.setColumnOrder("name", "amount", "count"); | |||
final Grid<GridExampleBean> grid = new Grid<>(); | |||
grid.setItems(items); | |||
grid.addColumn(GridExampleBean::getName); | |||
grid.addColumn(GridExampleBean::getAmount, new NumberRenderer()); | |||
grid.addColumn(GridExampleBean::getCount, new NumberRenderer()); | |||
grid.setSizeFull(); | |||
grid.setSelectionMode(SelectionMode.NONE); | |||
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.setDetailsGenerator(item -> { | |||
VerticalLayout layout = new VerticalLayout( | |||
new Label("Extra data for " + item.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)); | |||
} | |||
grid.addItemClickListener(event -> { | |||
GridExampleBean item = event.getItem(); | |||
grid.setDetailsVisible(item, !grid.isDetailsVisible(item)); | |||
}); | |||
return grid; | |||
} |
@@ -0,0 +1,113 @@ | |||
/* | |||
* 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.List; | |||
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.HorizontalLayout; | |||
import com.vaadin.ui.Label; | |||
import com.vaadin.ui.renderers.NumberRenderer; | |||
/** | |||
* Tests the layouting of Grid's details row when it contains a HorizontalLayout | |||
* with expand ratios. | |||
* | |||
* @author Vaadin Ltd | |||
*/ | |||
@SuppressWarnings("serial") | |||
public class GridDetailsLayoutExpand extends AbstractTestUI { | |||
@Override | |||
protected void setup(VaadinRequest request) { | |||
final Grid<Person> grid = new Grid<>(); | |||
grid.setSizeFull(); | |||
grid.addColumn(Person::getFirstName); | |||
grid.addColumn(Person::getAge, new NumberRenderer()); | |||
List<Person> persons = new ArrayList<>(); | |||
Person person = new Person(); | |||
person.setFirstName("Nicolaus Copernicus"); | |||
person.setAge(1543); | |||
persons.add(person); | |||
person = new Person(); | |||
person.setFirstName("Galileo Galilei"); | |||
person.setAge(1564); | |||
persons.add(person); | |||
person = new Person(); | |||
person.setFirstName("Johannes Kepler"); | |||
person.setAge(1571); | |||
persons.add(person); | |||
grid.setItems(persons); | |||
addComponent(grid); | |||
grid.setDetailsGenerator(item -> { | |||
final HorizontalLayout detailsLayout = new HorizontalLayout(); | |||
detailsLayout.setSizeFull(); | |||
detailsLayout.setHeightUndefined(); | |||
// Label 1 first element of the detailsLayout, taking 200 pixels | |||
final Label lbl1 = new Label("test1"); | |||
lbl1.setWidth("200px"); | |||
detailsLayout.addComponent(lbl1); | |||
// layout2 second element of the detailsLayout, taking the rest | |||
// of the available space | |||
final HorizontalLayout layout2 = new HorizontalLayout(); | |||
layout2.setSizeFull(); | |||
layout2.setHeightUndefined(); | |||
detailsLayout.addComponent(layout2); | |||
detailsLayout.setExpandRatio(layout2, 1); | |||
// 2 Labels added to the layout2 | |||
final Label lbl2 = new Label("test2"); | |||
lbl2.setWidth("100%"); | |||
lbl2.setId("lbl2"); | |||
layout2.addComponent(lbl2); | |||
final Label lbl3 = new Label("test3"); | |||
lbl3.setWidth("100%"); | |||
lbl3.setId("lbl3"); | |||
layout2.addComponent(lbl3); | |||
return detailsLayout; | |||
}); | |||
grid.addItemClickListener(event -> { | |||
final Person itemId = event.getItem(); | |||
grid.setDetailsVisible(itemId, !grid.isDetailsVisible(itemId)); | |||
}); | |||
} | |||
@Override | |||
protected Integer getTicketNumber() { | |||
return 18821; | |||
} | |||
@Override | |||
protected String getTestDescription() { | |||
return "Details row must be the same after opening another details row"; | |||
} | |||
} |
@@ -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.util.stream.IntStream; | |||
import com.vaadin.data.ValueProvider; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.tests.components.AbstractTestUI; | |||
import com.vaadin.ui.Grid; | |||
import com.vaadin.ui.Grid.Column; | |||
import com.vaadin.ui.HorizontalLayout; | |||
import com.vaadin.ui.TextArea; | |||
import com.vaadin.ui.VerticalLayout; | |||
public class GridDetailsWidth extends AbstractTestUI { | |||
@Override | |||
protected void setup(VaadinRequest request) { | |||
final VerticalLayout layout = new VerticalLayout(); | |||
layout.setMargin(true); | |||
final Grid<String> grid = new Grid<>(); | |||
Column<String, String> column = grid.addColumn(ValueProvider.identity()) | |||
.setCaption("Hello"); | |||
grid.setItems(IntStream.range(0, 3).mapToObj(i -> "Hello " + i)); | |||
column.setWidth(600); | |||
grid.setWidth(400, Unit.PIXELS); | |||
grid.setDetailsGenerator(item -> { | |||
HorizontalLayout myLayout = new HorizontalLayout(); | |||
TextArea textArea1 = new TextArea(); | |||
TextArea textArea2 = new TextArea(); | |||
textArea1.setSizeFull(); | |||
textArea2.setSizeFull(); | |||
myLayout.addComponent(textArea1); | |||
myLayout.addComponent(textArea2); | |||
myLayout.setWidth(100, Unit.PERCENTAGE); | |||
myLayout.setHeight(null); | |||
myLayout.setMargin(true); | |||
return myLayout; | |||
}); | |||
grid.addItemClickListener(event -> grid.setDetailsVisible( | |||
event.getItem(), !grid.isDetailsVisible(event.getItem()))); | |||
layout.addComponent(grid); | |||
addComponent(layout); | |||
} | |||
@Override | |||
protected Integer getTicketNumber() { | |||
return 18223; | |||
} | |||
@Override | |||
protected String getTestDescription() { | |||
return "Tests that Escalator will not set explicit widths to the TD element in a details row."; | |||
} | |||
} |
@@ -19,6 +19,7 @@ import java.util.HashMap; | |||
import java.util.Map; | |||
import com.google.gwt.core.client.GWT; | |||
import com.google.gwt.dom.client.Style.Position; | |||
import com.google.gwt.user.client.Element; | |||
import com.google.gwt.user.client.ui.Label; | |||
import com.google.gwt.user.client.ui.SimplePanel; | |||
@@ -35,6 +36,11 @@ import com.vaadin.tests.widgetset.server.TestWidgetComponent; | |||
public class TestWidgetConnector extends AbstractComponentConnector { | |||
public static class SubPartAwareSimplePanel extends SimplePanel | |||
implements SubPartAware { | |||
public SubPartAwareSimplePanel() { | |||
getElement().getStyle().setPosition(Position.ABSOLUTE); | |||
} | |||
@Override | |||
public Element getSubPartElement(String subPart) { | |||
Widget target = getWidget(); |
@@ -13,16 +13,16 @@ | |||
* License for the specific language governing permissions and limitations under | |||
* the License. | |||
*/ | |||
package com.vaadin.tests.widgetset.client.v7.grid; | |||
package com.vaadin.tests.widgetset.client.grid; | |||
import java.util.ArrayList; | |||
import java.util.Arrays; | |||
import java.util.List; | |||
import com.vaadin.v7.client.renderers.HtmlRenderer; | |||
import com.vaadin.v7.client.widget.grid.datasources.ListDataSource; | |||
import com.vaadin.v7.client.widgets.Grid; | |||
import com.vaadin.v7.client.widgets.Grid.SelectionMode; | |||
import com.vaadin.client.renderers.HtmlRenderer; | |||
import com.vaadin.client.widget.grid.datasources.ListDataSource; | |||
import com.vaadin.client.widget.grid.selection.SelectionModel; | |||
import com.vaadin.client.widgets.Grid; | |||
public class GridColumnAutoWidthClientWidget | |||
extends PureGWTTestApplication<Grid<List<String>>> { | |||
@@ -45,20 +45,20 @@ public class GridColumnAutoWidthClientWidget | |||
public GridColumnAutoWidthClientWidget() { | |||
super(new Grid<List<String>>()); | |||
grid = getTestedWidget(); | |||
grid.setSelectionMode(SelectionMode.NONE); | |||
grid.setSelectionModel(new SelectionModel.NoSelectionModel<>()); | |||
grid.setWidth("750px"); | |||
List<List<String>> list = new ArrayList<>(); | |||
list.add(Arrays.asList("equal length", "a very long cell content", | |||
"short", "fixed width narrow", "fixed width wide")); | |||
grid.setDataSource(new ListDataSource<>(list)); | |||
addColumn("equal length"); | |||
addColumn("short"); | |||
addColumn("a very long header content"); | |||
addColumn("fixed width narrow").setWidth(50); | |||
addColumn("fixed width wide").setWidth(200); | |||
List<List<String>> list = new ArrayList<>(); | |||
list.add(Arrays.asList("equal length", "a very long cell content", | |||
"short", "fixed width narrow", "fixed width wide")); | |||
grid.setDataSource(new ListDataSource<>(list)); | |||
addNorth(grid, 400); | |||
} | |||
@@ -1,102 +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.ui.Button; | |||
import com.vaadin.ui.Button.ClickEvent; | |||
import com.vaadin.v7.data.Container.Indexed; | |||
import com.vaadin.v7.data.Item; | |||
import com.vaadin.v7.data.util.IndexedContainer; | |||
import com.vaadin.v7.ui.Grid; | |||
import com.vaadin.v7.ui.Grid.FooterRow; | |||
import com.vaadin.v7.ui.Grid.HeaderRow; | |||
import com.vaadin.v7.ui.Grid.SelectionMode; | |||
import com.vaadin.v7.ui.renderers.NumberRenderer; | |||
public class GridColspans extends AbstractReindeerTestUI { | |||
@Override | |||
protected void setup(VaadinRequest request) { | |||
Indexed dataSource = new IndexedContainer(); | |||
final Grid grid; | |||
dataSource.addContainerProperty("firstName", String.class, ""); | |||
dataSource.addContainerProperty("lastName", String.class, ""); | |||
dataSource.addContainerProperty("streetAddress", String.class, ""); | |||
dataSource.addContainerProperty("zipCode", Integer.class, null); | |||
dataSource.addContainerProperty("city", String.class, ""); | |||
Item i = dataSource.addItem(0); | |||
i.getItemProperty("firstName").setValue("Rudolph"); | |||
i.getItemProperty("lastName").setValue("Reindeer"); | |||
i.getItemProperty("streetAddress").setValue("Ruukinkatu 2-4"); | |||
i.getItemProperty("zipCode").setValue(20540); | |||
i.getItemProperty("city").setValue("Turku"); | |||
grid = new Grid(dataSource); | |||
grid.setWidth("600px"); | |||
grid.getColumn("zipCode").setRenderer(new NumberRenderer()); | |||
grid.setSelectionMode(SelectionMode.MULTI); | |||
addComponent(grid); | |||
HeaderRow row = grid.prependHeaderRow(); | |||
row.join("firstName", "lastName").setText("Full Name"); | |||
row.join("streetAddress", "zipCode", "city").setText("Address"); | |||
grid.prependHeaderRow() | |||
.join(dataSource.getContainerPropertyIds().toArray()) | |||
.setText("All the stuff"); | |||
FooterRow footerRow = grid.appendFooterRow(); | |||
footerRow.join("firstName", "lastName").setText("Full Name"); | |||
footerRow.join("streetAddress", "zipCode", "city").setText("Address"); | |||
grid.appendFooterRow() | |||
.join(dataSource.getContainerPropertyIds().toArray()) | |||
.setText("All the stuff"); | |||
addComponent( | |||
new Button("Show/Hide firstName", new Button.ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
if (grid.getColumn("firstName") != null) { | |||
grid.removeColumn("firstName"); | |||
} else { | |||
grid.addColumn("firstName"); | |||
} | |||
} | |||
})); | |||
addComponent( | |||
new Button("Change column order", new Button.ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
grid.setColumnOrder("zipCode", "firstName"); | |||
} | |||
})); | |||
} | |||
@Override | |||
protected String getTestDescription() { | |||
return "Grid header and footer colspans"; | |||
} | |||
@Override | |||
protected Integer getTicketNumber() { | |||
return 13334; | |||
} | |||
} |
@@ -1,63 +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.data.Container; | |||
import com.vaadin.v7.data.util.IndexedContainer; | |||
import com.vaadin.v7.ui.Grid; | |||
import com.vaadin.v7.ui.Grid.Column; | |||
import com.vaadin.v7.ui.Grid.SelectionMode; | |||
import com.vaadin.v7.ui.renderers.HtmlRenderer; | |||
public class GridColumnAutoWidth extends AbstractReindeerTestUI { | |||
@Override | |||
protected void setup(VaadinRequest request) { | |||
Grid grid = new Grid(createContainer()); | |||
grid.getColumn("fixed width narrow").setWidth(50); | |||
grid.getColumn("fixed width wide").setWidth(200); | |||
for (Object propertyId : grid.getContainerDataSource() | |||
.getContainerPropertyIds()) { | |||
Column column = grid.getColumn(propertyId); | |||
column.setExpandRatio(0); | |||
column.setRenderer(new HtmlRenderer()); | |||
grid.getHeaderRow(0).getCell(propertyId) | |||
.setHtml("<span>" + column.getHeaderCaption() + "</span>"); | |||
} | |||
grid.setSelectionMode(SelectionMode.NONE); | |||
grid.setWidth("750px"); | |||
addComponent(grid); | |||
} | |||
private static Container.Indexed createContainer() { | |||
IndexedContainer c = new IndexedContainer(); | |||
c.addContainerProperty("equal width", String.class, | |||
"<span>equal width</span>"); | |||
c.addContainerProperty("short", String.class, | |||
"<span>a very long cell content</span>"); | |||
c.addContainerProperty("a very long header content", String.class, | |||
"<span>short</span>"); | |||
c.addContainerProperty("fixed width narrow", String.class, | |||
"<span>fixed width narrow</span>"); | |||
c.addContainerProperty("fixed width wide", String.class, | |||
"<span>fixed width wide</span>"); | |||
c.addItem(); | |||
return c; | |||
} | |||
} |
@@ -1,160 +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.annotations.Theme; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.tests.components.AbstractReindeerTestUI; | |||
import com.vaadin.tests.util.PersonContainer; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.Button.ClickEvent; | |||
import com.vaadin.ui.Component; | |||
import com.vaadin.ui.CssLayout; | |||
import com.vaadin.ui.HorizontalLayout; | |||
import com.vaadin.ui.Label; | |||
import com.vaadin.v7.ui.Grid; | |||
import com.vaadin.v7.ui.Grid.Column; | |||
import com.vaadin.v7.ui.themes.Reindeer; | |||
@Theme(Reindeer.THEME_NAME) | |||
public class GridColumnExpand extends AbstractReindeerTestUI { | |||
private Grid grid; | |||
private Label firstInfo = new Label(); | |||
private Label secondInfo = new Label(); | |||
private Column firstColumn; | |||
private Column secondColumn; | |||
@Override | |||
protected void setup(VaadinRequest request) { | |||
grid = new Grid(PersonContainer.createWithTestData()); | |||
grid.removeAllColumns(); | |||
grid.addColumn("address.streetAddress"); | |||
grid.addColumn("lastName"); | |||
firstColumn = grid.getColumns().get(0); | |||
secondColumn = grid.getColumns().get(1); | |||
updateInfoLabels(); | |||
addComponent(grid); | |||
addComponent(firstInfo); | |||
addComponent(secondInfo); | |||
addButtons(); | |||
} | |||
private void addButtons() { | |||
HorizontalLayout layout = new HorizontalLayout(); | |||
layout.addComponent(createButtons(firstColumn)); | |||
layout.addComponent(createButtons(secondColumn)); | |||
layout.setExpandRatio(layout.getComponent(1), 1); | |||
addComponent(layout); | |||
} | |||
private Component createButtons(Column column) { | |||
CssLayout layout = new CssLayout(); | |||
layout.addComponent(new Label("Column 1")); | |||
CssLayout widthLayout = new CssLayout(); | |||
layout.addComponent(widthLayout); | |||
widthLayout.addComponent(new Label("Width")); | |||
widthLayout.addComponent(createWidthButton(column, -1)); | |||
widthLayout.addComponent(createWidthButton(column, 50)); | |||
widthLayout.addComponent(createWidthButton(column, 200)); | |||
CssLayout minLayout = new CssLayout(); | |||
layout.addComponent(minLayout); | |||
minLayout.addComponent(new Label("Min width")); | |||
minLayout.addComponent(createMinButton(column, -1)); | |||
minLayout.addComponent(createMinButton(column, 50)); | |||
minLayout.addComponent(createMinButton(column, 200)); | |||
CssLayout maxLayout = new CssLayout(); | |||
maxLayout.addComponent(new Label("Max width")); | |||
maxLayout.addComponent(createMaxButton(column, -1)); | |||
maxLayout.addComponent(createMaxButton(column, 50)); | |||
maxLayout.addComponent(createMaxButton(column, 200)); | |||
layout.addComponent(maxLayout); | |||
CssLayout expandLayout = new CssLayout(); | |||
expandLayout.addComponent(new Label("Expand ratio")); | |||
expandLayout.addComponent(createExpandButton(column, -1)); | |||
expandLayout.addComponent(createExpandButton(column, 0)); | |||
expandLayout.addComponent(createExpandButton(column, 1)); | |||
expandLayout.addComponent(createExpandButton(column, 2)); | |||
layout.addComponent(expandLayout); | |||
return layout; | |||
} | |||
private Component createWidthButton(final Column column, | |||
final double width) { | |||
return new Button("" + width, new Button.ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
if (width >= 0) { | |||
column.setWidth(width); | |||
} else { | |||
column.setWidthUndefined(); | |||
} | |||
updateInfoLabels(); | |||
} | |||
}); | |||
} | |||
private Component createMinButton(final Column column, final double width) { | |||
return new Button("" + width, new Button.ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
column.setMinimumWidth(width); | |||
updateInfoLabels(); | |||
} | |||
}); | |||
} | |||
private Component createMaxButton(final Column column, final double width) { | |||
return new Button("" + width, new Button.ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
column.setMaximumWidth(width); | |||
updateInfoLabels(); | |||
} | |||
}); | |||
} | |||
private Component createExpandButton(final Column column, final int ratio) { | |||
return new Button("" + ratio, new Button.ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
column.setExpandRatio(ratio); | |||
updateInfoLabels(); | |||
} | |||
}); | |||
} | |||
private void updateInfoLabels() { | |||
updateLabel(firstInfo, firstColumn); | |||
updateLabel(secondInfo, secondColumn); | |||
} | |||
private void updateLabel(Label label, Column column) { | |||
int expandRatio = column.getExpandRatio(); | |||
double minimumWidth = Math.round(column.getMinimumWidth() * 100) / 100; | |||
double maximumWidth = Math.round(column.getMaximumWidth() * 100) / 100; | |||
double width = Math.round(column.getWidth() * 100) / 100; | |||
Object propertyId = column.getPropertyId(); | |||
label.setValue(String.format( | |||
"[%s] Expand ratio: %s - min: %s - max: %s - width: %s", | |||
propertyId, expandRatio, minimumWidth, maximumWidth, width)); | |||
} | |||
} |
@@ -1,92 +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.ArrayList; | |||
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.v7.data.Container.Indexed; | |||
import com.vaadin.v7.data.Item; | |||
import com.vaadin.v7.data.Property; | |||
import com.vaadin.v7.ui.Grid; | |||
public class GridColumnWidthRecalculation extends AbstractTestUI { | |||
@Override | |||
protected void setup(VaadinRequest request) { | |||
final Grid grid = new Grid(); | |||
grid.addColumn("Column 1"); | |||
grid.addColumn("Column 2"); | |||
grid.addRow("Narrow", | |||
"Wiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiide"); | |||
addComponent(grid); | |||
Button b = new Button("Swap content", new Button.ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
swapData(grid); | |||
} | |||
}); | |||
addComponent(b); | |||
b = new Button("Swap content and recalculate columns", | |||
new Button.ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
swapData(grid); | |||
grid.recalculateColumnWidths(); | |||
} | |||
}); | |||
addComponent(b); | |||
} | |||
@SuppressWarnings("unchecked") | |||
protected void swapData(Grid grid) { | |||
Indexed dataSource = grid.getContainerDataSource(); | |||
Object itemId = dataSource.getItemIds().iterator().next(); | |||
Item item = dataSource.getItem(itemId); | |||
ArrayList<Object> pIds = new ArrayList<>(item.getItemPropertyIds()); | |||
for (int i = 0; i < pIds.size() / 2; i++) { | |||
int j = pIds.size() - 1 - i; | |||
Object pid1 = pIds.get(i); | |||
Object pid2 = pIds.get(j); | |||
Property<Object> property1 = item.getItemProperty(pid1); | |||
Property<Object> property2 = item.getItemProperty(pid2); | |||
Object tmp = property1.getValue(); | |||
property1.setValue(property2.getValue()); | |||
property2.setValue(tmp); | |||
} | |||
} | |||
@Override | |||
protected String getTestDescription() { | |||
return "There should be a way to ask Grid to recalculate column widths from server-side."; | |||
} | |||
@Override | |||
protected Integer getTicketNumber() { | |||
return 16748; | |||
} | |||
} |
@@ -1,108 +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.EnumSet; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.tests.components.AbstractReindeerTestUI; | |||
import com.vaadin.ui.Button; | |||
import com.vaadin.ui.Button.ClickEvent; | |||
import com.vaadin.ui.VerticalLayout; | |||
import com.vaadin.v7.data.Property.ValueChangeEvent; | |||
import com.vaadin.v7.data.Property.ValueChangeListener; | |||
import com.vaadin.v7.ui.Grid; | |||
import com.vaadin.v7.ui.Grid.SelectionMode; | |||
import com.vaadin.v7.ui.NativeSelect; | |||
public class GridColumnWidthsWithoutData extends AbstractReindeerTestUI { | |||
private SelectionMode selectionMode = SelectionMode.NONE; | |||
private Grid grid = createGrid(true); | |||
@Override | |||
protected void setup(VaadinRequest request) { | |||
addComponent(grid); | |||
NativeSelect selectionModeSelector = new NativeSelect("Selection mode", | |||
EnumSet.allOf(SelectionMode.class)); | |||
selectionModeSelector.setValue(selectionMode); | |||
selectionModeSelector.setNullSelectionAllowed(false); | |||
selectionModeSelector.addValueChangeListener(new ValueChangeListener() { | |||
@Override | |||
public void valueChange(ValueChangeEvent event) { | |||
selectionMode = (SelectionMode) event.getProperty().getValue(); | |||
grid.setSelectionMode(selectionMode); | |||
} | |||
}); | |||
addComponent(selectionModeSelector); | |||
addComponent( | |||
new Button("Recreate without data", new Button.ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
replaceGrid(createGrid(false)); | |||
} | |||
})); | |||
addComponent( | |||
new Button("Recreate with data", new Button.ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
replaceGrid(createGrid(true)); | |||
} | |||
})); | |||
addComponent(new Button("Add data", new Button.ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
addDataToGrid(grid); | |||
} | |||
})); | |||
addComponent(new Button("Remove data", new Button.ClickListener() { | |||
@Override | |||
public void buttonClick(ClickEvent event) { | |||
grid.getContainerDataSource().removeAllItems(); | |||
} | |||
})); | |||
} | |||
private void replaceGrid(Grid newGrid) { | |||
((VerticalLayout) grid.getParent()).replaceComponent(grid, newGrid); | |||
grid = newGrid; | |||
} | |||
private Grid createGrid(boolean withData) { | |||
Grid grid = new Grid(); | |||
grid.addColumn("foo"); | |||
grid.addColumn("bar"); | |||
grid.setWidth("300px"); | |||
grid.setSelectionMode(selectionMode); | |||
if (withData) { | |||
addDataToGrid(grid); | |||
} | |||
return grid; | |||
} | |||
private void addDataToGrid(Grid grid) { | |||
grid.addRow("Some", "Data with more data in one col"); | |||
} | |||
} |
@@ -1,105 +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.ui.Component; | |||
import com.vaadin.ui.HorizontalLayout; | |||
import com.vaadin.ui.Label; | |||
import com.vaadin.v7.event.ItemClickEvent; | |||
import com.vaadin.v7.event.ItemClickEvent.ItemClickListener; | |||
import com.vaadin.v7.ui.Grid; | |||
import com.vaadin.v7.ui.Grid.DetailsGenerator; | |||
import com.vaadin.v7.ui.Grid.RowReference; | |||
/** | |||
* Tests the layouting of Grid's details row when it contains a HorizontalLayout | |||
* with expand ratios. | |||
* | |||
* @author Vaadin Ltd | |||
*/ | |||
@SuppressWarnings("serial") | |||
public class GridDetailsLayoutExpand extends AbstractReindeerTestUI { | |||
@Override | |||
protected void setup(VaadinRequest request) { | |||
final Grid grid = new Grid(); | |||
grid.setSizeFull(); | |||
grid.addColumn("name", String.class); | |||
grid.addColumn("born", Integer.class); | |||
grid.addRow("Nicolaus Copernicus", 1543); | |||
grid.addRow("Galileo Galilei", 1564); | |||
grid.addRow("Johannes Kepler", 1571); | |||
addComponent(grid); | |||
grid.setDetailsGenerator(new DetailsGenerator() { | |||
@Override | |||
public Component getDetails(final RowReference rowReference) { | |||
final HorizontalLayout detailsLayout = new HorizontalLayout(); | |||
detailsLayout.setSizeFull(); | |||
detailsLayout.setHeightUndefined(); | |||
// Label 1 first element of the detailsLayout, taking 200 pixels | |||
final Label lbl1 = new Label("test1"); | |||
lbl1.setWidth("200px"); | |||
detailsLayout.addComponent(lbl1); | |||
// layout2 second element of the detailsLayout, taking the rest | |||
// of the available space | |||
final HorizontalLayout layout2 = new HorizontalLayout(); | |||
layout2.setSizeFull(); | |||
layout2.setHeightUndefined(); | |||
detailsLayout.addComponent(layout2); | |||
detailsLayout.setExpandRatio(layout2, 1); | |||
// 2 Labels added to the layout2 | |||
final Label lbl2 = new Label("test2"); | |||
lbl2.setWidth("100%"); | |||
lbl2.setId("lbl2"); | |||
layout2.addComponent(lbl2); | |||
final Label lbl3 = new Label("test3"); | |||
lbl3.setWidth("100%"); | |||
lbl3.setId("lbl3"); | |||
layout2.addComponent(lbl3); | |||
return detailsLayout; | |||
} | |||
}); | |||
grid.addItemClickListener(new ItemClickListener() { | |||
@Override | |||
public void itemClick(final ItemClickEvent event) { | |||
final Object itemId = event.getItemId(); | |||
grid.setDetailsVisible(itemId, !grid.isDetailsVisible(itemId)); | |||
} | |||
}); | |||
} | |||
@Override | |||
protected Integer getTicketNumber() { | |||
return 18821; | |||
} | |||
@Override | |||
protected String getTestDescription() { | |||
return "Details row must be the same after opening another details row"; | |||
} | |||
} |
@@ -32,6 +32,13 @@ import com.vaadin.v7.ui.Grid.DetailsGenerator; | |||
import com.vaadin.v7.ui.Grid.RowReference; | |||
import com.vaadin.v7.ui.Grid.SelectionMode; | |||
/** | |||
* This test cannot be migrated to V8 since there is no Grid::scrollTo method. | |||
* Will it be there in the future ? (may be this test should be just removed). | |||
* | |||
* @author Vaadin Ltd | |||
* | |||
*/ | |||
public class GridDetailsLocation extends UI { | |||
private final DetailsGenerator detailsGenerator = new DetailsGenerator() { |
@@ -1,91 +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.ui.Component; | |||
import com.vaadin.ui.HorizontalLayout; | |||
import com.vaadin.ui.VerticalLayout; | |||
import com.vaadin.v7.event.ItemClickEvent; | |||
import com.vaadin.v7.event.ItemClickEvent.ItemClickListener; | |||
import com.vaadin.v7.ui.Grid; | |||
import com.vaadin.v7.ui.Grid.Column; | |||
import com.vaadin.v7.ui.Grid.DetailsGenerator; | |||
import com.vaadin.v7.ui.Grid.RowReference; | |||
import com.vaadin.v7.ui.TextArea; | |||
public class GridDetailsWidth extends AbstractReindeerTestUI { | |||
@Override | |||
protected void setup(VaadinRequest request) { | |||
final VerticalLayout layout = new VerticalLayout(); | |||
layout.setMargin(true); | |||
final Grid grid = new Grid(); | |||
Column column = grid.addColumn("Hello", String.class); | |||
for (int i = 0; i < 3; i++) { | |||
grid.addRow("Hello " + i); | |||
} | |||
column.setWidth(600); | |||
grid.setWidth(400, Unit.PIXELS); | |||
grid.setDetailsGenerator(new DetailsGenerator() { | |||
@Override | |||
public Component getDetails(RowReference rowReference) { | |||
HorizontalLayout myLayout = new HorizontalLayout(); | |||
TextArea textArea1 = new TextArea(); | |||
TextArea textArea2 = new TextArea(); | |||
textArea1.setSizeFull(); | |||
textArea2.setSizeFull(); | |||
myLayout.addComponent(textArea1); | |||
myLayout.addComponent(textArea2); | |||
myLayout.setWidth(100, Unit.PERCENTAGE); | |||
myLayout.setHeight(null); | |||
myLayout.setMargin(true); | |||
return myLayout; | |||
} | |||
}); | |||
grid.addItemClickListener(new ItemClickListener() { | |||
@Override | |||
public void itemClick(ItemClickEvent event) { | |||
grid.setDetailsVisible(event.getItemId(), | |||
!grid.isDetailsVisible(event.getItemId())); | |||
} | |||
}); | |||
layout.addComponent(grid); | |||
addComponent(layout); | |||
} | |||
@Override | |||
protected Integer getTicketNumber() { | |||
return 18223; | |||
} | |||
@Override | |||
protected String getTestDescription() { | |||
return "Tests that Escalator will not set explicit widths to the TD element in a details row."; | |||
} | |||
} |
@@ -0,0 +1,118 @@ | |||
/* | |||
* 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 java.io.IOException; | |||
import java.util.regex.Pattern; | |||
import org.junit.Before; | |||
import org.junit.Test; | |||
import org.openqa.selenium.By; | |||
import org.openqa.selenium.WebElement; | |||
import com.vaadin.testbench.parallel.BrowserUtil; | |||
import com.vaadin.testbench.parallel.TestCategory; | |||
import com.vaadin.tests.tb3.MultiBrowserTest; | |||
@SuppressWarnings("boxing") | |||
@TestCategory("grid") | |||
public abstract class AbstractGridColumnAutoWidthTest extends MultiBrowserTest { | |||
public static final int TOTAL_MARGIN_PX = 21; | |||
@Before | |||
public void before() { | |||
openTestURL(); | |||
} | |||
@Test | |||
public void testNarrowHeaderWideBody() { | |||
WebElement[] col = getColumn(1); | |||
int headerWidth = col[0].getSize().getWidth(); | |||
int bodyWidth = col[1].getSize().getWidth(); | |||
int colWidth = col[2].getSize().getWidth() - TOTAL_MARGIN_PX; | |||
assertLessThan("header should've been narrower than body", headerWidth, | |||
bodyWidth); | |||
assertEquals("column should've been roughly as wide as the body", | |||
bodyWidth, colWidth, 5); | |||
} | |||
@Test | |||
public void testWideHeaderNarrowBody() { | |||
WebElement[] col = getColumn(2); | |||
int headerWidth = col[0].getSize().getWidth(); | |||
int bodyWidth = col[1].getSize().getWidth(); | |||
int colWidth = col[2].getSize().getWidth() - TOTAL_MARGIN_PX; | |||
assertGreater("header should've been wider than body", headerWidth, | |||
bodyWidth); | |||
assertEquals("column should've been roughly as wide as the header", | |||
headerWidth, colWidth, 5); | |||
} | |||
@Test | |||
public void testTooNarrowColumn() { | |||
if (BrowserUtil.isIE(getDesiredCapabilities())) { | |||
// IE can't deal with overflow nicely. | |||
return; | |||
} | |||
WebElement[] col = getColumn(3); | |||
int headerWidth = col[0].getSize().getWidth(); | |||
int colWidth = col[2].getSize().getWidth() - TOTAL_MARGIN_PX; | |||
assertLessThan("column should've been narrower than content", colWidth, | |||
headerWidth); | |||
} | |||
@Test | |||
public void testTooWideColumn() { | |||
WebElement[] col = getColumn(4); | |||
int headerWidth = col[0].getSize().getWidth(); | |||
int colWidth = col[2].getSize().getWidth() - TOTAL_MARGIN_PX; | |||
assertGreater("column should've been wider than content", colWidth, | |||
headerWidth); | |||
} | |||
@Test | |||
public void testColumnsRenderCorrectly() throws IOException { | |||
WebElement loadingIndicator = findElement( | |||
By.className("v-loading-indicator")); | |||
Pattern pattern = Pattern.compile("display: *none;"); | |||
waitUntil(driver -> { | |||
return pattern.matcher(loadingIndicator.getAttribute("style")) | |||
.find(); | |||
}); | |||
compareScreen("grid-v8-initialRender"); | |||
} | |||
private WebElement[] getColumn(int i) { | |||
WebElement[] col = new WebElement[3]; | |||
col[0] = getDriver().findElement( | |||
By.xpath("//thead//th[" + (i + 1) + "]/div[1]/span")); | |||
col[1] = getDriver() | |||
.findElement(By.xpath("//tbody//td[" + (i + 1) + "]//span")); | |||
col[2] = getDriver() | |||
.findElement(By.xpath("//tbody//td[" + (i + 1) + "]")); | |||
return col; | |||
} | |||
} |
@@ -13,10 +13,10 @@ | |||
* 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 static org.junit.Assert.assertEquals; | |||
import static org.junit.Assert.assertTrue; | |||
import static org.junit.Assert.assertFalse; | |||
import org.junit.Before; | |||
import org.junit.Test; | |||
@@ -37,20 +37,14 @@ public class GridColspansTest extends MultiBrowserTest { | |||
} | |||
@Test | |||
public void testHeaderColSpans() { | |||
public void testColSpans() { | |||
openTestURL(); | |||
GridElement grid = $(GridElement.class).first(); | |||
assertEquals("5", grid.getHeaderCell(0, 1).getAttribute("colspan")); | |||
assertEquals("2", grid.getHeaderCell(1, 1).getAttribute("colspan")); | |||
assertEquals("3", grid.getHeaderCell(1, 3).getAttribute("colspan")); | |||
} | |||
@Test | |||
public void testFooterColSpans() { | |||
openTestURL(); | |||
GridElement grid = $(GridElement.class).first(); | |||
assertEquals("5", grid.getFooterCell(1, 1).getAttribute("colspan")); | |||
assertEquals("2", grid.getFooterCell(0, 1).getAttribute("colspan")); | |||
assertEquals("3", grid.getFooterCell(0, 3).getAttribute("colspan")); | |||
@@ -84,8 +78,8 @@ public class GridColspansTest extends MultiBrowserTest { | |||
grid.getHeaderCell(2, 1).getText().toLowerCase()); | |||
$(ButtonElement.class).get(1).click(); | |||
headerCell = grid.getHeaderCell(1, 1); | |||
assertEquals("Header text not changed on column reorder.", "address", | |||
headerCell.getText().toLowerCase()); | |||
assertEquals("Joined Header text not changed on column reorder.", | |||
"misc", headerCell.getText().toLowerCase()); | |||
assertEquals("Unexpected colspan", "1", | |||
headerCell.getAttribute("colspan")); | |||
headerCell = grid.getHeaderCell(1, 2); | |||
@@ -94,7 +88,7 @@ public class GridColspansTest extends MultiBrowserTest { | |||
assertEquals("Unexpected colspan", "2", | |||
headerCell.getAttribute("colspan")); | |||
assertTrue("Error indicator not present", | |||
assertFalse("Error indicator not present", | |||
isElementPresent(By.className("v-errorindicator"))); | |||
} |
@@ -13,11 +13,14 @@ | |||
* 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 static org.junit.Assert.assertTrue; | |||
import java.util.List; | |||
import org.junit.Test; | |||
import org.openqa.selenium.remote.DesiredCapabilities; | |||
import com.vaadin.testbench.customelements.GridElement; | |||
import com.vaadin.testbench.elements.GridElement.GridCellElement; | |||
@@ -25,6 +28,13 @@ import com.vaadin.tests.tb3.MultiBrowserTest; | |||
public class GridColumnAutoExpandTest extends MultiBrowserTest { | |||
@Override | |||
public List<DesiredCapabilities> getBrowsersToTest() { | |||
// The functionality doesn't work for PHJS_1. And the test fails. It | |||
// works for PHJS_2. | |||
return getBrowsersExcludingPhantomJS(); | |||
} | |||
@Test | |||
public void testSecondColumnHasExpanded() { | |||
openTestURL(); |
@@ -13,7 +13,7 @@ | |||
* 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 com.vaadin.testbench.parallel.TestCategory; | |||
@@ -13,7 +13,7 @@ | |||
* 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 com.vaadin.testbench.parallel.TestCategory; | |||
@@ -13,7 +13,7 @@ | |||
* 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 java.util.List; | |||
@@ -82,7 +82,7 @@ public class GridColumnWidthsWithoutDataTest extends SingleBrowserTest { | |||
setDebug(true); | |||
openTestURL(); | |||
$(NativeSelectElement.class).caption("Selection mode").first() | |||
.selectByText("Multi"); | |||
.selectByText("MULTI"); | |||
GridElement grid = $(GridElement.class).first(); | |||
@@ -13,7 +13,7 @@ | |||
* 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 static org.junit.Assert.assertFalse; | |||
import static org.junit.Assert.assertTrue; |
@@ -13,7 +13,7 @@ | |||
* 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 java.util.List; | |||
@@ -50,8 +50,8 @@ public class GridDetailsDetachTest extends MultiBrowserTest { | |||
setDebug(true); | |||
openTestURL(); | |||
$(GridElement.class).first().getCell(1, 0).click(); | |||
$(GridElement.class).first().getCell(3, 0).click(); | |||
$(GridElement.class).first().getCell(5, 0).click(); | |||
assertNoErrorNotifications(); | |||
@@ -66,9 +66,9 @@ public class GridDetailsDetachTest extends MultiBrowserTest { | |||
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()); | |||
"Extra data for Bean 1", spacers.get(0).getText()); | |||
Assert.assertEquals("Spacer content not visible", | |||
"Extra data for Bean 5", spacers.get(1).getText()); | |||
"Extra data for Bean 3", spacers.get(1).getText()); | |||
} | |||
@Test | |||
@@ -76,8 +76,8 @@ public class GridDetailsDetachTest extends MultiBrowserTest { | |||
setDebug(true); | |||
openTestURL(); | |||
$(GridElement.class).first().getCell(1, 0).click(); | |||
$(GridElement.class).first().getCell(3, 0).click(); | |||
$(GridElement.class).first().getCell(5, 0).click(); | |||
assertNoErrorNotifications(); | |||
@@ -89,9 +89,9 @@ public class GridDetailsDetachTest extends MultiBrowserTest { | |||
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()); | |||
"Extra data for Bean 1", spacers.get(0).getText()); | |||
Assert.assertEquals("Spacer content not visible", | |||
"Extra data for Bean 5", spacers.get(1).getText()); | |||
"Extra data for Bean 3", spacers.get(1).getText()); | |||
} | |||
} |
@@ -13,7 +13,7 @@ | |||
* 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 static org.hamcrest.MatcherAssert.assertThat; | |||
import static org.hamcrest.number.IsCloseTo.closeTo; |
@@ -13,7 +13,7 @@ | |||
* 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 java.util.List; | |||
@@ -85,7 +85,7 @@ public class GridDetailsWidthTest extends SingleBrowserTest { | |||
cell.getText()); | |||
Assert.assertEquals("Details row was not in correct location", | |||
cell.getLocation().getY() + cell.getSize().getHeight(), | |||
spacer.getLocation().getY()); | |||
spacer.getLocation().getY(), 2); | |||
} | |||
@@ -1,82 +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 org.junit.Assert; | |||
import org.junit.Before; | |||
import org.junit.Test; | |||
import org.openqa.selenium.Dimension; | |||
import com.vaadin.testbench.customelements.GridElement; | |||
import com.vaadin.testbench.elements.ButtonElement; | |||
import com.vaadin.testbench.elements.GridElement.GridCellElement; | |||
import com.vaadin.testbench.parallel.TestCategory; | |||
import com.vaadin.tests.tb3.SingleBrowserTest; | |||
@TestCategory("grid") | |||
public class GridColumnWidthRecalculationTest extends SingleBrowserTest { | |||
private GridElement grid; | |||
@Before | |||
public void open() { | |||
openTestURL(); | |||
grid = $(GridElement.class).first(); | |||
} | |||
@Test | |||
public void columnWidthAfterSwap() { | |||
int column0Width = getColumnWidth(0); | |||
int column1Width = getColumnWidth(1); | |||
Assert.assertTrue("Column 0 should be narrower than column 1 initially", | |||
column0Width < column1Width); | |||
$(ButtonElement.class).caption("Swap content").first().click(); | |||
Assert.assertEquals( | |||
"Column 0 width should not change when swapping contents only", | |||
column0Width, getColumnWidth(0)); | |||
Assert.assertEquals( | |||
"Column 1 width should not change when swapping contents only", | |||
column1Width, getColumnWidth(1)); | |||
} | |||
@Test | |||
public void columnWidthAfterSwapAndRecalculate() { | |||
int column0Width = getColumnWidth(0); | |||
int column1Width = getColumnWidth(1); | |||
Assert.assertTrue("Column 0 should be narrower than column 1 initially", | |||
column0Width < column1Width); | |||
$(ButtonElement.class).caption("Swap content and recalculate columns") | |||
.first().click(); | |||
column0Width = getColumnWidth(0); | |||
column1Width = getColumnWidth(1); | |||
Assert.assertTrue( | |||
"Column 1 should be narrower than column 0 after resize", | |||
column1Width < column0Width); | |||
} | |||
private int getColumnWidth(int columnIndex) { | |||
GridCellElement headerColumn = grid.getHeaderCells(0).get(columnIndex); | |||
Dimension column1Size = headerColumn.getSize(); | |||
int columnWidth = column1Size.getWidth(); | |||
return columnWidth; | |||
} | |||
} |