summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorelmot <elmot@vaadin.com>2016-09-14 17:48:50 +0300
committerVaadin Code Review <review@vaadin.com>2016-09-16 13:35:05 +0000
commit05c051717401660a857ee7a314361a1735f376e6 (patch)
tree7e9f94925a0f3360ceb3833ec43a23d7c7b49fa0 /uitest
parent36ad322721e3548899cbca9516d91edabd252f2f (diff)
downloadvaadin-framework-05c051717401660a857ee7a314361a1735f376e6.tar.gz
vaadin-framework-05c051717401660a857ee7a314361a1735f376e6.zip
Create a RadioButtonGroup that replaces the single select case of OptionGroup
Change-Id: I56b0f1dfa889e2eaa3db9b0b0aac860f1bb4dea8
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/radiobutton/RadioButtonGroupTestUI.java75
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/radiobutton/RadioButtonGroupTest.java112
2 files changed, 187 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/radiobutton/RadioButtonGroupTestUI.java b/uitest/src/main/java/com/vaadin/tests/components/radiobutton/RadioButtonGroupTestUI.java
new file mode 100644
index 0000000000..1b4e9ac0df
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/components/radiobutton/RadioButtonGroupTestUI.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2000-2014 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.radiobutton;
+
+import com.vaadin.shared.data.selection.SelectionModel;
+import com.vaadin.tests.components.abstractlisting.AbstractListingTestUI;
+import com.vaadin.ui.RadioButtonGroup;
+
+import java.util.stream.IntStream;
+
+/**
+ * Test UI for RadioButtonGroup component
+ *
+ * @author Vaadin Ltd
+ */
+public class RadioButtonGroupTestUI
+ extends AbstractListingTestUI<RadioButtonGroup<Object>> {
+
+ private final String selectionCategory = "Selection";
+
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ @Override
+ protected Class<RadioButtonGroup<Object>> getTestClass() {
+ return (Class) RadioButtonGroup.class;
+ }
+
+ @Override
+ protected void createActions() {
+ super.createActions();
+ createListenerMenu();
+ createSelectionMenu();
+ }
+
+ protected void createSelectionMenu() {
+ createClickAction(
+ "Clear selection", selectionCategory, (component, item,
+ data) -> component.getSelectionModel().deselectAll(),
+ "");
+
+ Command<RadioButtonGroup<Object>, String> toggleSelection = (component,
+ item, data) -> toggleSelection(item);
+
+ IntStream.of(0, 1, 5, 10, 25).mapToObj(i -> "Item " + i)
+ .forEach(item -> createClickAction("Toggle " + item, selectionCategory,
+ toggleSelection, item));
+ }
+
+ private void toggleSelection(String item) {
+ SelectionModel.Single<Object> selectionModel = getComponent().getSelectionModel();
+ if (selectionModel.isSelected(item)) {
+ selectionModel.deselect(item);
+ } else {
+ selectionModel.select(item);
+ }
+ }
+
+ protected void createListenerMenu() {
+ createListenerAction("Selection listener", "Listeners",
+ c -> c.addSelectionListener(
+ e -> log("Selected: " + e.getSelectedItem())));
+ }
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/radiobutton/RadioButtonGroupTest.java b/uitest/src/test/java/com/vaadin/tests/components/radiobutton/RadioButtonGroupTest.java
new file mode 100644
index 0000000000..a591924641
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/radiobutton/RadioButtonGroupTest.java
@@ -0,0 +1,112 @@
+/*
+ * Copyright 2000-2014 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.radiobutton;
+
+import com.vaadin.testbench.customelements.RadioButtonGroupElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Arrays;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Test for RadioButtonGroup
+ *
+ * @author Vaadin Ltd
+ * @since 8.0
+ */
+public class RadioButtonGroupTest extends MultiBrowserTest {
+
+ @Before
+ public void setUp() throws Exception {
+ openTestURL();
+ }
+
+ @Test
+ public void initialLoad_containsCorrectItems() {
+ assertItems(20);
+ }
+
+ @Test
+ public void initialItems_reduceItemCount_containsCorrectItems() {
+ selectMenuPath("Component", "Data source", "Items", "5");
+ assertItems(5);
+ }
+
+ @Test
+ public void initialItems_increaseItemCount_containsCorrectItems() {
+ selectMenuPath("Component", "Data source", "Items", "100");
+ assertItems(100);
+ }
+
+ @Test
+ public void clickToSelect() {
+ selectMenuPath("Component", "Listeners", "Selection listener");
+
+ getSelect().selectByText("Item 4");
+ Assert.assertEquals("1. Selected: Optional[Item 4]", getLogRow(0));
+
+ getSelect().selectByText("Item 2");
+ Assert.assertEquals("2. Selected: Optional[Item 2]", getLogRow(0));
+
+ getSelect().selectByText("Item 4");
+ Assert.assertEquals("3. Selected: Optional[Item 4]", getLogRow(0));
+ }
+
+ @Test
+ public void selectProgramatically() {
+ selectMenuPath("Component", "Listeners", "Selection listener");
+
+ selectMenuPath("Component", "Selection", "Toggle Item 5");
+ Assert.assertEquals("2. Selected: Optional[Item 5]", getLogRow(0));
+ assertSelected("Item 5");
+
+ selectMenuPath("Component", "Selection", "Toggle Item 1");
+ Assert.assertEquals("4. Selected: Optional[Item 1]", getLogRow(0));
+ // DOM order
+ assertSelected("Item 1");
+
+ selectMenuPath("Component", "Selection", "Toggle Item 5");
+ Assert.assertEquals("6. Selected: Optional[Item 5]", getLogRow(0));
+ assertSelected("Item 5");
+ }
+
+ private void assertSelected(String... expectedSelection) {
+ Assert.assertEquals(Arrays.asList(expectedSelection),
+ getSelect().getSelection());
+ }
+
+ @Override
+ protected Class<?> getUIClass() {
+ return RadioButtonGroupTestUI.class;
+ }
+
+ protected RadioButtonGroupElement getSelect() {
+ return $(RadioButtonGroupElement.class).first();
+ }
+
+ protected void assertItems(int count) {
+ int i = 0;
+ for (String text : getSelect().getOptions()) {
+ assertEquals("Item " + i, text);
+ i++;
+ }
+ assertEquals("Number of items", count, i);
+ }
+}