diff options
author | Denis <denis@vaadin.com> | 2016-12-05 12:21:05 +0300 |
---|---|---|
committer | Henri Sara <henri.sara@gmail.com> | 2016-12-05 11:21:05 +0200 |
commit | 154a6a01148e84344e9730f9654ca3fc0190d907 (patch) | |
tree | 0f287e97ce7ea33104346dea6396779aca0d38cb /server | |
parent | e746963efb1135e256da78cdd8cc24c88fdfd194 (diff) | |
download | vaadin-framework-154a6a01148e84344e9730f9654ca3fc0190d907.tar.gz vaadin-framework-154a6a01148e84344e9730f9654ca3fc0190d907.zip |
Extends declarative tests for selection components for "data-" attribute (#85)
Fixes vaadin/framework8-issues#392
Diffstat (limited to 'server')
3 files changed, 70 insertions, 16 deletions
diff --git a/server/src/test/java/com/vaadin/tests/design/DeclarativeTestBaseBase.java b/server/src/test/java/com/vaadin/tests/design/DeclarativeTestBaseBase.java index 5d91415193..1bab760530 100644 --- a/server/src/test/java/com/vaadin/tests/design/DeclarativeTestBaseBase.java +++ b/server/src/test/java/com/vaadin/tests/design/DeclarativeTestBaseBase.java @@ -213,6 +213,14 @@ public abstract class DeclarativeTestBaseBase<T extends Component> { return read; } + public DesignContext readComponentAndCompare(String design, T expected) { + TestLogHandler l = new TestLogHandler(); + DesignContext context = readAndReturnContext(design); + assertEquals(expected, context.getRootComponent()); + Assert.assertEquals("", l.getMessages()); + return context; + } + public void testWrite(String design, T expected) { TestLogHandler l = new TestLogHandler(); testWrite(design, expected, false); diff --git a/server/src/test/java/com/vaadin/tests/server/component/abstractmultiselect/AbstractMultiSelectDeclarativeTest.java b/server/src/test/java/com/vaadin/tests/server/component/abstractmultiselect/AbstractMultiSelectDeclarativeTest.java index 53d826592b..5a13d51aaa 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/abstractmultiselect/AbstractMultiSelectDeclarativeTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/abstractmultiselect/AbstractMultiSelectDeclarativeTest.java @@ -20,11 +20,14 @@ import java.util.Arrays; import java.util.HashSet; import java.util.List; +import org.junit.Assert; import org.junit.Test; import com.vaadin.data.Listing; +import com.vaadin.tests.design.DeclarativeTestBaseBase; import com.vaadin.tests.server.component.abstractlisting.AbstractListingDeclarativeTest; import com.vaadin.ui.AbstractMultiSelect; +import com.vaadin.ui.declarative.DesignContext; /** * {@link AbstractMultiSelect} component declarative test. @@ -50,19 +53,29 @@ public abstract class AbstractMultiSelectDeclarativeTest<T extends AbstractMulti IllegalAccessException, InvocationTargetException { List<String> items = Arrays.asList("foo", "bar", "foobar"); + String type = "com.vaadin.SomeType"; + String attribute = "data-type"; + String design = String.format( - "<%s>\n" + "<option item='foo' selected>foo1</option>\n" + "<%s %s='%s'>\n" + "<option item='foo' selected>foo1</option>\n" + "<option item='bar'>bar1</option>" + "<option item='foobar' selected>foobar1</option></%s>", - getComponentTag(), getComponentTag()); + getComponentTag(), attribute, type, getComponentTag()); T component = getComponentClass().newInstance(); component.setItems(items); component.select("foo"); component.select("foobar"); component.setItemCaptionGenerator(item -> item + "1"); - testRead(design, component); - testWrite(design, component, true); + DesignContext context = readComponentAndCompare(design, component); + Assert.assertEquals(type, + context.getCustomAttributes(context.getRootComponent()) + .get(attribute)); + context = new DesignContext(); + context.setCustomAttribute(component, attribute, type); + context.setShouldWriteDataDelegate( + DeclarativeTestBaseBase.ALWAYS_WRITE_DATA); + testWrite(component, design, context); } @Override @@ -71,18 +84,28 @@ public abstract class AbstractMultiSelectDeclarativeTest<T extends AbstractMulti IllegalAccessException, InvocationTargetException { List<String> items = Arrays.asList("foo", "bar", "foobar"); + String type = "com.vaadin.SomeType"; + String attribute = "data-type"; + String design = String.format( - "<%s>\n" + "<option item='foo' selected>foo1</option>\n" + "<%s %s='%s'>\n" + "<option item='foo' selected>foo1</option>\n" + "<option item='bar'>bar1</option>" + "<option item='foobar' selected>foobar1</option></%s>", - getComponentTag(), getComponentTag()); + getComponentTag(), attribute, type, getComponentTag()); T component = getComponentClass().newInstance(); component.setItems(items); component.setValue(new HashSet<>(Arrays.asList("foo", "foobar"))); component.setItemCaptionGenerator(item -> item + "1"); - testRead(design, component); - testWrite(design, component, true); + DesignContext context = readComponentAndCompare(design, component); + Assert.assertEquals(type, + context.getCustomAttributes(context.getRootComponent()) + .get(attribute)); + context = new DesignContext(); + context.setCustomAttribute(component, attribute, type); + context.setShouldWriteDataDelegate( + DeclarativeTestBaseBase.ALWAYS_WRITE_DATA); + testWrite(component, design, context); } @Override diff --git a/server/src/test/java/com/vaadin/tests/server/component/abstractsingleselect/AbstractSingleSelectDeclarativeTest.java b/server/src/test/java/com/vaadin/tests/server/component/abstractsingleselect/AbstractSingleSelectDeclarativeTest.java index 1ef1f7addf..182b9045fd 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/abstractsingleselect/AbstractSingleSelectDeclarativeTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/abstractsingleselect/AbstractSingleSelectDeclarativeTest.java @@ -20,12 +20,15 @@ import java.lang.reflect.Method; import java.util.Arrays; import java.util.List; +import org.junit.Assert; import org.junit.Test; import com.vaadin.data.Listing; +import com.vaadin.tests.design.DeclarativeTestBaseBase; import com.vaadin.tests.server.component.abstractlisting.AbstractListingDeclarativeTest; import com.vaadin.ui.AbstractSingleSelect; import com.vaadin.ui.ItemCaptionGenerator; +import com.vaadin.ui.declarative.DesignContext; /** * {@link AbstractSingleSelect} component declarative test. @@ -49,17 +52,27 @@ public abstract class AbstractSingleSelectDeclarativeTest<T extends AbstractSing IllegalAccessException, InvocationTargetException { List<String> items = Arrays.asList("foo", "bar", "foobar"); + String type = "com.vaadin.SomeType"; + String attribute = "data-type"; + String design = String.format( - "<%s>\n" + "<option item='foo'>foo</option>\n" + "<%s %s='%s'>\n" + "<option item='foo'>foo</option>\n" + "<option item='bar' selected>bar</option>" + "<option item='foobar'>foobar</option></%s>", - getComponentTag(), getComponentTag()); + getComponentTag(), attribute, type, getComponentTag()); T component = getComponentClass().newInstance(); component.setItems(items); component.setSelectedItem("bar"); - testRead(design, component); - testWrite(design, component, true); + DesignContext context = readComponentAndCompare(design, component); + Assert.assertEquals(type, + context.getCustomAttributes(context.getRootComponent()) + .get(attribute)); + context = new DesignContext(); + context.setCustomAttribute(component, attribute, type); + context.setShouldWriteDataDelegate( + DeclarativeTestBaseBase.ALWAYS_WRITE_DATA); + testWrite(component, design, context); } @Override @@ -68,17 +81,27 @@ public abstract class AbstractSingleSelectDeclarativeTest<T extends AbstractSing IllegalAccessException, InvocationTargetException { List<String> items = Arrays.asList("foo", "bar", "foobar"); + String type = "com.vaadin.SomeType"; + String attribute = "data-type"; + String design = String.format( - "<%s>\n" + "<option item='foo'>foo</option>\n" + "<%s %s='%s'>\n" + "<option item='foo'>foo</option>\n" + "<option item='bar' selected>bar</option>" + "<option item='foobar'>foobar</option></%s>", - getComponentTag(), getComponentTag()); + getComponentTag(), attribute, type, getComponentTag()); T component = getComponentClass().newInstance(); component.setItems(items); component.setValue("bar"); - testRead(design, component); - testWrite(design, component, true); + DesignContext context = readComponentAndCompare(design, component); + Assert.assertEquals(type, + context.getCustomAttributes(context.getRootComponent()) + .get(attribute)); + context = new DesignContext(); + context.setCustomAttribute(component, attribute, type); + context.setShouldWriteDataDelegate( + DeclarativeTestBaseBase.ALWAYS_WRITE_DATA); + testWrite(component, design, context); } @Test |