From 154a6a01148e84344e9730f9654ca3fc0190d907 Mon Sep 17 00:00:00 2001 From: Denis Date: Mon, 5 Dec 2016 12:21:05 +0300 Subject: [PATCH] Extends declarative tests for selection components for "data-" attribute (#85) Fixes vaadin/framework8-issues#392 --- .../tests/design/DeclarativeTestBaseBase.java | 8 ++++ .../AbstractMultiSelectDeclarativeTest.java | 39 +++++++++++++++---- .../AbstractSingleSelectDeclarativeTest.java | 39 +++++++++++++++---- 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 { 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 items = Arrays.asList("foo", "bar", "foobar"); + String type = "com.vaadin.SomeType"; + String attribute = "data-type"; + String design = String.format( - "<%s>\n" + "\n" + "<%s %s='%s'>\n" + "\n" + "" + "", - 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 items = Arrays.asList("foo", "bar", "foobar"); + String type = "com.vaadin.SomeType"; + String attribute = "data-type"; + String design = String.format( - "<%s>\n" + "\n" + "<%s %s='%s'>\n" + "\n" + "" + "", - 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 items = Arrays.asList("foo", "bar", "foobar"); + String type = "com.vaadin.SomeType"; + String attribute = "data-type"; + String design = String.format( - "<%s>\n" + "\n" + "<%s %s='%s'>\n" + "\n" + "" + "", - 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 items = Arrays.asList("foo", "bar", "foobar"); + String type = "com.vaadin.SomeType"; + String attribute = "data-type"; + String design = String.format( - "<%s>\n" + "\n" + "<%s %s='%s'>\n" + "\n" + "" + "", - 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 -- 2.39.5