123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- /*
- * 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.radiobuttongroup;
-
- import static org.junit.Assert.assertEquals;
- import static org.junit.Assert.assertTrue;
-
- import java.util.List;
-
- import org.junit.Before;
- import org.junit.Test;
- import org.openqa.selenium.WebElement;
-
- import com.vaadin.icons.VaadinIcons;
- import com.vaadin.testbench.By;
- import com.vaadin.testbench.TestBenchElement;
- import com.vaadin.testbench.elements.RadioButtonGroupElement;
- import com.vaadin.tests.components.radiobutton.RadioButtonGroupTestUI;
- import com.vaadin.tests.tb3.MultiBrowserTest;
-
- /**
- * 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 provider", "Items", "5");
- assertItems(5);
- }
-
- @Test
- public void disabled_reduceItemCount_containsCorrectItems() {
- selectMenuPath("Component", "State", "Enabled");
- selectMenuPath("Component", "Data provider", "Items", "5");
- assertItems(5);
- }
-
- @Test
- public void initialItems_increaseItemCount_containsCorrectItems() {
- selectMenuPath("Component", "Data provider", "Items", "100");
- assertItems(100);
- }
-
- @Test
- public void disabled_increaseItemCountWithinPushRows_containsCorrectItems() {
- selectMenuPath("Component", "Data provider", "Items", "5");
- selectMenuPath("Component", "State", "Enabled");
- selectMenuPath("Component", "Data provider", "Items", "20");
- assertItems(20);
- }
-
- @Test
- public void disabled_increaseItemCountBeyondPushRows_containsCorrectItems() {
- selectMenuPath("Component", "Data provider", "Items", "5");
- selectMenuPath("Component", "State", "Enabled");
- selectMenuPath("Component", "Data provider", "Items", "100");
- assertItems(100);
- }
-
- @Test
- public void clickToSelect() {
- selectMenuPath("Component", "Listeners", "Selection listener");
-
- getSelect().selectByText("Item 4");
- assertEquals("1. Selected: Optional[Item 4]", getLogRow(0));
-
- getSelect().selectByText("Item 2");
- assertEquals("2. Selected: Optional[Item 2]", getLogRow(0));
-
- getSelect().selectByText("Item 4");
- assertEquals("3. Selected: Optional[Item 4]", getLogRow(0));
- }
-
- @Test
- public void disabled_clickToSelect() {
- selectMenuPath("Component", "State", "Enabled");
-
- assertTrue(getSelect().findElements(By.tagName("input")).stream()
- .allMatch(element -> element.getAttribute("disabled") != null));
-
- selectMenuPath("Component", "Listeners", "Selection listener");
-
- String lastLogRow = getLogRow(0);
-
- getSelect().selectByText("Item 4");
- assertEquals(lastLogRow, getLogRow(0));
-
- getSelect().selectByText("Item 2");
- assertEquals(lastLogRow, getLogRow(0));
-
- getSelect().selectByText("Item 4");
- assertEquals(lastLogRow, getLogRow(0));
- }
-
- @Test
- public void itemIconGenerator() {
- selectMenuPath("Component", "Item Icon Generator",
- "Use Item Icon Generator");
- assertItemsSuffices(20);
-
- List<WebElement> icons = getSelect()
- .findElements(By.cssSelector(".v-select-optiongroup .v-icon"));
-
- assertEquals(20, icons.size());
-
- for (int i = 0; i < icons.size(); i++) {
- assertEquals(VaadinIcons.values()[i + 1].getCodepoint(),
- icons.get(i).getText().charAt(0));
- }
- }
-
- @Test
- public void clickToSelect_reenable() {
- selectMenuPath("Component", "State", "Enabled");
- selectMenuPath("Component", "Listeners", "Selection listener");
-
- getSelect().selectByText("Item 4");
-
- selectMenuPath("Component", "State", "Enabled");
-
- getSelect().selectByText("Item 5");
- assertEquals("3. Selected: Optional[Item 5]", getLogRow(0));
-
- getSelect().selectByText("Item 2");
- assertEquals("4. Selected: Optional[Item 2]", getLogRow(0));
-
- getSelect().selectByText("Item 4");
- assertEquals("5. Selected: Optional[Item 4]", getLogRow(0));
- }
-
- @Test
- public void itemCaptionGenerator() {
- selectMenuPath("Component", "Item Caption Generator",
- "Item Caption Generator", "Custom Caption Generator");
- assertItems(20, " Caption");
- }
-
- @Test
- public void nullItemCaptionGenerator() {
- selectMenuPath("Component", "Item Caption Generator",
- "Item Caption Generator", "Null Caption Generator");
- for (String text : getSelect().getOptions()) {
- assertEquals("", text);
- }
- }
-
- @Test
- public void selectProgramatically() {
- selectMenuPath("Component", "Listeners", "Selection listener");
-
- selectMenuPath("Component", "Selection", "Toggle Item 5");
- assertEquals("2. Selected: Optional[Item 5]", getLogRow(0));
- assertSelected("Item 5");
-
- selectMenuPath("Component", "Selection", "Toggle Item 1");
- assertEquals("4. Selected: Optional[Item 1]", getLogRow(0));
- // DOM order
- assertSelected("Item 1");
-
- selectMenuPath("Component", "Selection", "Toggle Item 5");
- assertEquals("6. Selected: Optional[Item 5]", getLogRow(0));
- assertSelected("Item 5");
- }
-
- @Test
- public void testItemDescriptionGenerators() {
- TestBenchElement label;
-
- selectMenuPath("Component", "Item Description Generator",
- "Item Description Generator", "Default Description Generator");
-
- label = (TestBenchElement) findElements(By.tagName("label")).get(5);
- label.showTooltip();
- assertEquals("Tooltip should contain the same text as caption",
- label.getText(), getTooltipElement().getText());
-
- selectMenuPath("Component", "Item Description Generator",
- "Item Description Generator", "Custom Description Generator");
-
- label = (TestBenchElement) findElements(By.tagName("label")).get(5);
- label.showTooltip();
- assertEquals("Tooltip should contain caption + ' Description'",
- label.getText() + " Description",
- getTooltipElement().getText());
- }
-
- private void assertSelected(String expectedSelection) {
- assertEquals(expectedSelection, getSelect().getValue());
- }
-
- @Override
- protected Class<?> getUIClass() {
- return RadioButtonGroupTestUI.class;
- }
-
- protected RadioButtonGroupElement getSelect() {
- return $(RadioButtonGroupElement.class).first();
- }
-
- protected void assertItems(int count) {
- assertItems(count, "");
- }
-
- protected void assertItems(int count, String suffix) {
- int i = 0;
- for (String text : getSelect().getOptions()) {
- assertEquals("Item " + i + suffix, text);
- i++;
- }
- assertEquals("Number of items", count, i);
- }
-
- protected void assertItemsSuffices(int count) {
- int i = 0;
- for (String text : getSelect().getOptions()) {
- assertTrue(text.endsWith("Item " + i));
- i++;
- }
- assertEquals("Number of items", count, i);
- }
-
- // needed to make tooltips work in IE tests
- @Override
- protected boolean requireWindowFocusForIE() {
- return true;
- }
- }
|