Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize integration test using Grid #9766

Merged
merged 2 commits into from
Aug 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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("112px");

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