From: Johannes Dahlström Date: Mon, 5 Sep 2016 09:24:20 +0000 (+0300) Subject: Add new base class for Listing UI tests X-Git-Tag: 8.0.0.alpha1~21 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2cafb5f128f718399b112a0c87e9a3d303018371;p=vaadin-framework.git Add new base class for Listing UI tests Change-Id: I6901fc49379d9bd740e24c01de6ce9d530bbc585 --- diff --git a/uitest/src/main/java/com/vaadin/tests/components/abstractlisting/AbstractListingTestUI.java b/uitest/src/main/java/com/vaadin/tests/components/abstractlisting/AbstractListingTestUI.java new file mode 100644 index 0000000000..e9fd2d0c36 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/abstractlisting/AbstractListingTestUI.java @@ -0,0 +1,60 @@ +package com.vaadin.tests.components.abstractlisting; + +import java.util.LinkedHashMap; +import java.util.stream.IntStream; + +import com.vaadin.tests.components.AbstractComponentTest; +import com.vaadin.ui.AbstractListing; + +public abstract class AbstractListingTestUI, V> + extends AbstractComponentTest { + + @Override + protected void createActions() { + super.createActions(); + createItemsSelect(); + createSelectionSelect(); + } + + protected void createItemsSelect() { + LinkedHashMap options = new LinkedHashMap<>(); + for (int i = 0; i <= 10; i++) { + options.put(String.valueOf(i), i); + } + options.put("20", 20); + options.put("100", 100); + options.put("1000", 1000); + options.put("10000", 10000); + options.put("100000", 100000); + + createSelectAction("Items", "Data source", options, "20", + (c, number, data) -> { + c.setItems(createItems(number)); + }); + } + + protected void createSelectionSelect() { + LinkedHashMap options = new LinkedHashMap<>(); + options.put("None", null); + options.put("Item 0", "Item 0"); + options.put("Item 1", "Item 1"); + options.put("Item 2", "Item 2"); + options.put("Item 10", "Item 10"); + options.put("Item 100", "Item 100"); + + createSelectAction("Select", "Selection", options, "None", + (c, selected, data) -> { + if (selected != null) { + c.select(selected); + } else { + c.getSelectedItems().forEach(c::deselect); + } + }); + } + + protected Object[] createItems(int number) { + return IntStream.rangeClosed(0, number) + .mapToObj(i -> "Item " + i) + .toArray(); + } +}