diff options
author | Denis Anisimov <denis@vaadin.com> | 2016-11-24 18:15:27 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2016-11-25 13:18:22 +0000 |
commit | 98366af1e2703f0606d231a43b32f768e88c1f70 (patch) | |
tree | 8487fdf90762bf55c2976eca1f50cf14ffb3a1c8 /uitest/src | |
parent | d37b2d430eca6b0eeacb48626c0bbfb33d1502de (diff) | |
download | vaadin-framework-98366af1e2703f0606d231a43b32f768e88c1f70.tar.gz vaadin-framework-98366af1e2703f0606d231a43b32f768e88c1f70.zip |
Provide tests for "required indicator" property for options groups.
Fixes vaadin/framework8-issues#459
This is not a fix because the issue is about AL only and it's by design.
But this patch provides tests for CheckBoxGroup and RadioButtonGroup.
Change-Id: I8d43ab435327478c7199b8b0a7739d6d1064c822
Diffstat (limited to 'uitest/src')
6 files changed, 307 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/components/HasValueRequiredIndicator.java b/uitest/src/main/java/com/vaadin/tests/components/HasValueRequiredIndicator.java new file mode 100644 index 0000000000..1f9e586670 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/HasValueRequiredIndicator.java @@ -0,0 +1,121 @@ +/* + * Copyright 2000-2016 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; + +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.List; + +import com.googlecode.gentyref.GenericTypeReflector; +import com.vaadin.data.HasValue; +import com.vaadin.server.VaadinRequest; +import com.vaadin.ui.AbsoluteLayout; +import com.vaadin.ui.AbsoluteLayout.ComponentPosition; +import com.vaadin.ui.Component; +import com.vaadin.ui.CssLayout; +import com.vaadin.ui.FormLayout; +import com.vaadin.ui.GridLayout; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.Layout; +import com.vaadin.ui.VerticalLayout; + +/** + * @author Vaadin Ltd + * + */ +public abstract class HasValueRequiredIndicator<C extends HasValue & Component> + extends AbstractTestUI { + + private static final List<Class<? extends Layout>> LAYOUTS = getVaadinLayouts(); + + @Override + protected void setup(VaadinRequest request) { + getContent().setSizeFull(); + getVaadinLayouts().stream().map(this::createLayout).forEach(layout -> { + addComponent(layout, createComponent()); + addComponent(layout); + }); + } + + protected void addComponent(Layout layout, C component) { + layout.addComponent(component); + if (layout instanceof AbsoluteLayout) { + AbsoluteLayout absLayout = (AbsoluteLayout) layout; + ComponentPosition position = absLayout.new ComponentPosition(); + position.setTop(30f, Unit.PIXELS); + absLayout.setPosition(component, position); + } + } + + protected Layout createLayout(Class<? extends Layout> clazz) { + try { + Layout layout = clazz.newInstance(); + if (clazz.equals(AbsoluteLayout.class)) { + layout.setWidth("100px"); + layout.setHeight("150px"); + } + layout.addStyleName("vaadin-layout"); + return layout; + } catch (InstantiationException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } + + protected C createComponent() { + Type type = GenericTypeReflector.getTypeParameter(getClass(), + HasValueRequiredIndicator.class.getTypeParameters()[0]); + if (type instanceof ParameterizedType) { + type = ((ParameterizedType) type).getRawType(); + } + + if (type instanceof Class<?>) { + Class<?> clazz = (Class<?>) type; + try { + C component = (C) clazz.newInstance(); + initValue(component); + component.setRequiredIndicatorVisible(true); + component.addStyleName("test-component"); + return component; + } catch (InstantiationException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } else { + throw new IllegalStateException( + "Cannot infer component type " + type.getTypeName()); + } + } + + /** + * Initialize value for the {@code component}. + * + * @param component + * a UI component + */ + protected abstract void initValue(C component); + + private static List<Class<? extends Layout>> getVaadinLayouts() { + List<Class<? extends Layout>> layouts = new ArrayList<>(); + layouts.add(AbsoluteLayout.class); + layouts.add(VerticalLayout.class); + layouts.add(HorizontalLayout.class); + layouts.add(FormLayout.class); + layouts.add(CssLayout.class); + layouts.add(GridLayout.class); + return layouts; + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/components/checkboxgroup/CheckBoxGroupRequiredIndicator.java b/uitest/src/main/java/com/vaadin/tests/components/checkboxgroup/CheckBoxGroupRequiredIndicator.java new file mode 100644 index 0000000000..8d8ef522b1 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/checkboxgroup/CheckBoxGroupRequiredIndicator.java @@ -0,0 +1,37 @@ +/* + * Copyright 2000-2016 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.checkboxgroup; + +import com.vaadin.tests.components.HasValueRequiredIndicator; +import com.vaadin.ui.CheckBoxGroup; + +/** + * The whole logic is inside HasValueRequiredIndicator. The code here just set + * value for the component. + * + * @author Vaadin Ltd + * + */ +public class CheckBoxGroupRequiredIndicator + extends HasValueRequiredIndicator<CheckBoxGroup<String>> { + + @Override + protected void initValue(CheckBoxGroup<String> component) { + component.setCaption("a"); + component.setItems("a", "b", "c"); + } + +} diff --git a/uitest/src/main/java/com/vaadin/tests/components/radiobuttongroup/RadioButtonGroupRequiredIndicator.java b/uitest/src/main/java/com/vaadin/tests/components/radiobuttongroup/RadioButtonGroupRequiredIndicator.java new file mode 100644 index 0000000000..ebece0f8ed --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/radiobuttongroup/RadioButtonGroupRequiredIndicator.java @@ -0,0 +1,36 @@ +/* + * Copyright 2000-2016 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 com.vaadin.tests.components.HasValueRequiredIndicator; +import com.vaadin.ui.RadioButtonGroup; + +/** + * The whole logic is inside HasValueRequiredIndicator. The code here just set + * value for the component. + * + * @author Vaadin Ltd + * + */ +public class RadioButtonGroupRequiredIndicator + extends HasValueRequiredIndicator<RadioButtonGroup<String>> { + + @Override + protected void initValue(RadioButtonGroup<String> component) { + component.setItems("a", "b", "c"); + } + +}
\ No newline at end of file diff --git a/uitest/src/test/java/com/vaadin/tests/components/HasValueRequiredIndicatorTest.java b/uitest/src/test/java/com/vaadin/tests/components/HasValueRequiredIndicatorTest.java new file mode 100644 index 0000000000..09c4572526 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/HasValueRequiredIndicatorTest.java @@ -0,0 +1,55 @@ +/* + * Copyright 2000-2016 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; + +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.Point; +import org.openqa.selenium.WebElement; + +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * @author Vaadin Ltd + * + */ +public abstract class HasValueRequiredIndicatorTest extends MultiBrowserTest { + + @Test + public void requiredIndicatorVisible() { + openTestURL(); + List<WebElement> layouts = findElements(By.className("vaadin-layout")); + Assert.assertTrue(layouts.size() > 0); + layouts.stream().forEach(this::checkRequiredIndicator); + } + + protected void checkRequiredIndicator(WebElement layout) { + WebElement caption = layout.findElement(By.className("v-caption")); + Assert.assertTrue(caption.isDisplayed()); + WebElement indicator = caption + .findElement(By.className("v-required-field-indicator")); + Assert.assertTrue(indicator.isDisplayed()); + Point layoutLocation = layout.getLocation(); + Point indicatorLocation = indicator.getLocation(); + Assert.assertTrue("Indicator x-axis location is not inside layout", + indicatorLocation.getX() >= layoutLocation.getX()); + Assert.assertTrue("Indicator y-axis location is not inside layout", + indicatorLocation.getY() >= layoutLocation.getY()); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/checkboxgroup/CheckBoxGroupRequiredIndicatorTest.java b/uitest/src/test/java/com/vaadin/tests/components/checkboxgroup/CheckBoxGroupRequiredIndicatorTest.java new file mode 100644 index 0000000000..8ec52b630a --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/checkboxgroup/CheckBoxGroupRequiredIndicatorTest.java @@ -0,0 +1,29 @@ +/* + * Copyright 2000-2016 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.checkboxgroup; + +import com.vaadin.tests.components.HasValueRequiredIndicatorTest; + +/** + * The test logic is in the superclass. + * + * @author Vaadin Ltd + * + */ +public class CheckBoxGroupRequiredIndicatorTest + extends HasValueRequiredIndicatorTest { + +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/radiobuttongroup/RadioButtonGroupRequiredIndicatorTest.java b/uitest/src/test/java/com/vaadin/tests/components/radiobuttongroup/RadioButtonGroupRequiredIndicatorTest.java new file mode 100644 index 0000000000..bb1a1ba1d9 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/radiobuttongroup/RadioButtonGroupRequiredIndicatorTest.java @@ -0,0 +1,29 @@ +/* + * Copyright 2000-2016 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 com.vaadin.tests.components.HasValueRequiredIndicatorTest; + +/** + * The tests are in the superclass. + * + * @author Vaadin Ltd + * + */ +public class RadioButtonGroupRequiredIndicatorTest + extends HasValueRequiredIndicatorTest { + +} |