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: I8d43ab435327478c7199b8b0a7739d6d1064c822tags/8.0.0.alpha8
@@ -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; | |||
} | |||
} |
@@ -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"); | |||
} | |||
} |
@@ -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"); | |||
} | |||
} |
@@ -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()); | |||
} | |||
} |
@@ -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 { | |||
} |
@@ -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 { | |||
} |