Skip to content

Commit

Permalink
Stabilize integration test using Grid
Browse files Browse the repository at this point in the history
  • Loading branch information
Henri Sara committed Aug 2, 2017
1 parent 0f64197 commit eecf663
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 30 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,61 @@
import com.vaadin.server.ClassResource;
import com.vaadin.server.Resource;
import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.Grid;
import com.vaadin.ui.Image;
import com.vaadin.ui.Label;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.declarative.Design;
import com.vaadin.v7.data.Item;
import com.vaadin.v7.data.Property.ValueChangeEvent;
import com.vaadin.v7.data.Property.ValueChangeListener;
import com.vaadin.v7.ui.Table;

@Widgetset("com.vaadin.v7.Vaadin7WidgetSet")
@Widgetset("com.vaadin.DefaultWidgetSet")
public class ServletIntegrationUI extends UI {

public static class Country {
private final String name;
private final String id;
private final Resource icon;

public Country(String name, String id, Resource icon) {
this.name = name;
this.id = id;
this.icon = icon;
}

public String getName() {
return name;
}

public String getId() {
return id;
}

public Resource getIcon() {
return icon;
}
}

@Override
protected void init(VaadinRequest request) {
VerticalLayout layout = new VerticalLayout();
layout.setMargin(true);
setContent(layout);

final Table table = new Table();
table.addContainerProperty("icon", Resource.class, null);
table.setItemIconPropertyId("icon");
table.addContainerProperty("country", String.class, null);
table.setRowHeaderMode(Table.RowHeaderMode.ICON_ONLY);
table.setImmediate(true);
table.setSelectable(true);
table.setVisibleColumns(new Object[] { "country" });
layout.addComponent(table);
table.setWidth("200px");

Item item = table.addItem("FI");
item.getItemProperty("icon").setValue(new ClassResource("fi.gif"));
item.getItemProperty("country").setValue("Finland");
item = table.addItem("SE");
item.getItemProperty("icon").setValue(new FlagSeResource());
item.getItemProperty("country").setValue("Sweden");
final Grid<Country> grid = new Grid<>();
// TODO ImageRenderer does not support ClassResource
grid.addComponentColumn(country -> new Image(null, country.getIcon()))
.setWidth(50).setCaption("");
grid.addColumn(country -> country.getName()).setWidth(100)
.setCaption("Country");
grid.setItems(new Country("Finland", "FI", new ClassResource("fi.gif")),
new Country("Sweden", "SE", new FlagSeResource()));
grid.setHeight("200px");
grid.setWidth("200px");
layout.addComponent(grid);

final Label selectedLabel = new LabelFromDesign();
table.addValueChangeListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
selectedLabel.setValue(String.valueOf(table.getValue()));
}
});
grid.addSelectionListener(event -> selectedLabel.setValue(
event.getFirstSelectedItem().map(c -> c.getId()).orElse("")));
layout.addComponent(selectedLabel);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.junit.Test;

import com.vaadin.testbench.elements.TableElement;
import com.vaadin.testbench.elements.GridElement;

public abstract class AbstractServletIntegrationTest
extends AbstractIntegrationTest {
Expand All @@ -12,7 +12,7 @@ public void runTest() throws Exception {
// make sure no fading progress indicator from table update is lingering
Thread.sleep(2000);
compareScreen("initial");
$(TableElement.class).first().getCell(0, 1).click();
$(GridElement.class).first().getCell(0, 1).click();
// without this, table fetch might have a fading progress indicator
Thread.sleep(2000);
compareScreen("finland");
Expand Down

0 comments on commit eecf663

Please sign in to comment.