Skip to content

Commit

Permalink
Stabilize integration test using Grid (#9766)
Browse files Browse the repository at this point in the history
  • Loading branch information
hesara committed Aug 2, 2017
1 parent 7b9a09e commit 9153f15
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.
Expand Up @@ -5,49 +5,61 @@
import com.vaadin.server.ClassResource; import com.vaadin.server.ClassResource;
import com.vaadin.server.Resource; import com.vaadin.server.Resource;
import com.vaadin.server.VaadinRequest; import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.Grid;
import com.vaadin.ui.Image;
import com.vaadin.ui.Label; import com.vaadin.ui.Label;
import com.vaadin.ui.UI; import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.declarative.Design; 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 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 @Override
protected void init(VaadinRequest request) { protected void init(VaadinRequest request) {
VerticalLayout layout = new VerticalLayout(); VerticalLayout layout = new VerticalLayout();
layout.setMargin(true); layout.setMargin(true);
setContent(layout); setContent(layout);


final Table table = new Table(); final Grid<Country> grid = new Grid<>();
table.addContainerProperty("icon", Resource.class, null); // TODO ImageRenderer does not support ClassResource
table.setItemIconPropertyId("icon"); grid.addComponentColumn(country -> new Image(null, country.getIcon()))
table.addContainerProperty("country", String.class, null); .setWidth(50).setCaption("");
table.setRowHeaderMode(Table.RowHeaderMode.ICON_ONLY); grid.addColumn(country -> country.getName()).setWidth(100)
table.setImmediate(true); .setCaption("Country");
table.setSelectable(true); grid.setItems(new Country("Finland", "FI", new ClassResource("fi.gif")),
table.setVisibleColumns(new Object[] { "country" }); new Country("Sweden", "SE", new FlagSeResource()));
layout.addComponent(table); grid.setHeight("200px");
table.setWidth("112px"); grid.setWidth("200px");

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


Expand Down
Expand Up @@ -2,7 +2,7 @@


import org.junit.Test; import org.junit.Test;


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


public abstract class AbstractServletIntegrationTest public abstract class AbstractServletIntegrationTest
extends AbstractIntegrationTest { extends AbstractIntegrationTest {
Expand All @@ -12,7 +12,7 @@ public void runTest() throws Exception {
// make sure no fading progress indicator from table update is lingering // make sure no fading progress indicator from table update is lingering
Thread.sleep(2000); Thread.sleep(2000);
compareScreen("initial"); 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 // without this, table fetch might have a fading progress indicator
Thread.sleep(2000); Thread.sleep(2000);
compareScreen("finland"); compareScreen("finland");
Expand Down

0 comments on commit 9153f15

Please sign in to comment.