diff options
author | Teemu Suo-Anttila <tsuoanttila@users.noreply.github.com> | 2017-05-03 11:57:03 +0300 |
---|---|---|
committer | Henri Sara <henri.sara@gmail.com> | 2017-05-03 11:57:03 +0300 |
commit | ff52c42738a96c3fde01c40d33075376bcae1339 (patch) | |
tree | 77262dd6f028fca86232dedd611a8fcfe262d872 /uitest | |
parent | b60ab78e7ca9ed232eac2388c3a9ca6e1af423af (diff) | |
download | vaadin-framework-ff52c42738a96c3fde01c40d33075376bcae1339.tar.gz vaadin-framework-ff52c42738a96c3fde01c40d33075376bcae1339.zip |
Fix ComponentLocator with inherited classes without custom connector (#9176)
Logic for finding elements corresponding a server-side classname does
not work with inherited classes. For example making MyGrid extends Grid,
you could not find the specific MyGrid, but only the common Grid.
In most cases this is not a problem since these components are usually
the only instance of said superclass, but the Composite introduced in
the same UI, which makes testing them impossible.
This patch adds the specific classname information for ServerConnectors
that can be used to find the correct connector instance.
Diffstat (limited to 'uitest')
2 files changed, 73 insertions, 0 deletions
diff --git a/uitest/src/main/java/com/vaadin/tests/componentlocator/ComponentLocatorInheritedClasses.java b/uitest/src/main/java/com/vaadin/tests/componentlocator/ComponentLocatorInheritedClasses.java new file mode 100644 index 0000000000..46fb7cc00e --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/componentlocator/ComponentLocatorInheritedClasses.java @@ -0,0 +1,36 @@ +package com.vaadin.tests.componentlocator; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.VaadinRequest; +import com.vaadin.ui.Label; +import com.vaadin.ui.UI; +import com.vaadin.ui.VerticalLayout; + +@Widgetset("com.vaadin.DefaultWidgetSet") +public class ComponentLocatorInheritedClasses extends UI { + + public static class DefaultLabel extends Label { + + protected DefaultLabel(String content) { + super(content); + } + + public DefaultLabel() { + this("Default Custom Label"); + } + } + + public static class MyCustomLabel extends DefaultLabel { + public MyCustomLabel(String content) { + super(content); + } + } + + @Override + protected void init(VaadinRequest request) { + VerticalLayout layout = new VerticalLayout(); + layout.addComponents(new Label("Vaadin Basic Label"), + new DefaultLabel(), new MyCustomLabel("My Custom Label")); + setContent(layout); + } +} diff --git a/uitest/src/test/java/com/vaadin/tests/componentlocator/ComponentLocatorInheritedClassesTest.java b/uitest/src/test/java/com/vaadin/tests/componentlocator/ComponentLocatorInheritedClassesTest.java new file mode 100644 index 0000000000..4d8449fa38 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/componentlocator/ComponentLocatorInheritedClassesTest.java @@ -0,0 +1,37 @@ +package com.vaadin.tests.componentlocator; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.testbench.elements.LabelElement; +import com.vaadin.testbench.elementsbase.ServerClass; +import com.vaadin.tests.tb3.SingleBrowserTest; + +public class ComponentLocatorInheritedClassesTest extends SingleBrowserTest { + + @ServerClass("com.vaadin.tests.componentlocator.ComponentLocatorInheritedClasses.DefaultLabel") + public static class DefaultLabelElement extends LabelElement { + } + + @ServerClass("com.vaadin.tests.componentlocator.ComponentLocatorInheritedClasses.MyCustomLabel") + public static class MyCustomLabelElement extends DefaultLabelElement { + } + + @Test + public void label_finds_all_three() { + openTestURL(); + Assert.assertEquals(3, $(LabelElement.class).all().size()); + } + + @Test + public void defaultlabel_finds_two() { + openTestURL(); + Assert.assertEquals(2, $(DefaultLabelElement.class).all().size()); + } + + @Test + public void mycustomlabel_finds_one() { + openTestURL(); + Assert.assertEquals(1, $(MyCustomLabelElement.class).all().size()); + } +} |