]> source.dussan.org Git - vaadin-framework.git/commitdiff
New declarative tests
authorArtur Signell <artur@vaadin.com>
Wed, 4 Feb 2015 21:33:18 +0000 (23:33 +0200)
committerVaadin Code Review <review@vaadin.com>
Thu, 5 Feb 2015 14:16:27 +0000 (14:16 +0000)
* ListSelect (#15547)
* ComboBox (#15546)
* NativeSelect (#15548)
* Upload (#16323)
* Tree (#16317)
* TwinColSelect (#16317)

Change-Id: Ic3443ec94971dc5bf9f63c8c11e5023863f9588c

server/tests/src/com/vaadin/tests/design/DeclarativeTestBaseBase.java
server/tests/src/com/vaadin/tests/server/component/abstractselect/AbstractSelectDeclarativeTest.java
server/tests/src/com/vaadin/tests/server/component/combobox/ComboBoxDeclarativeTest.java [new file with mode: 0644]
server/tests/src/com/vaadin/tests/server/component/listselect/ListSelectDeclarativeTest.java [new file with mode: 0644]
server/tests/src/com/vaadin/tests/server/component/nativeselect/NativeSelectDeclarativeTest.java [new file with mode: 0644]
server/tests/src/com/vaadin/tests/server/component/tree/TreeDeclarativeTest.java [new file with mode: 0644]
server/tests/src/com/vaadin/tests/server/component/twincolselect/TwinColSelectDeclarativeTest.java [new file with mode: 0644]
server/tests/src/com/vaadin/tests/server/component/upload/UploadDeclarativeTest.java [new file with mode: 0644]

index 1874c3ec9577fb1e6d7304ffdd0e305316078650..8dc32e00d671139765f3c79e7ff893f12c55d298 100644 (file)
@@ -166,4 +166,10 @@ public abstract class DeclarativeTestBaseBase<T extends Component> {
         sb.append("</").append(producedElem.tagName()).append(">");
         return sb.toString();
     }
+
+    protected String stripOptionTags(String design) {
+        return design.replaceAll("[ \n]*<option(.*)</option>[ \n]*", "");
+
+    }
+
 }
index 1f5c90516d3c73c67ba684c04625adadfbcac75d..61128a1803f1aafbeb2a9a4729d646a1a1ba93cf 100644 (file)
@@ -138,11 +138,9 @@ public class AbstractSelectDeclarativeTest extends
 
     @Test
     public void testWriteInlineData() {
-        String modifiedDesign = getDesignForInlineData();
         // No data is written by default
-        modifiedDesign = modifiedDesign.replaceAll(
-                "[ \n]*<option(.*)</option>[ \n]*", "");
-        testWrite(modifiedDesign, getExpectedComponentForInlineData());
+        testWrite(stripOptionTags(getDesignForInlineData()),
+                getExpectedComponentForInlineData());
     }
 
     private String getDesignForInlineData() {
diff --git a/server/tests/src/com/vaadin/tests/server/component/combobox/ComboBoxDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/combobox/ComboBoxDeclarativeTest.java
new file mode 100644 (file)
index 0000000..e9d66b4
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2000-2014 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.server.component.combobox;
+
+import org.junit.Test;
+
+import com.vaadin.shared.ui.combobox.FilteringMode;
+import com.vaadin.tests.design.DeclarativeTestBase;
+import com.vaadin.ui.ComboBox;
+
+public class ComboBoxDeclarativeTest extends DeclarativeTestBase<ComboBox> {
+
+    @Test
+    public void testReadOnlyWithOptionsRead() {
+        testRead(getReadOnlyWithOptionsDesign(),
+                getReadOnlyWithOptionsExpected());
+    }
+
+    private ComboBox getReadOnlyWithOptionsExpected() {
+        ComboBox cb = new ComboBox();
+        cb.setTextInputAllowed(false);
+        cb.addItem("Hello");
+        cb.addItem("World");
+        return cb;
+    }
+
+    private String getReadOnlyWithOptionsDesign() {
+        return "<v-combo-box text-input-allowed='false'><option>Hello</option><option>World</option></v-combo-box>";
+    }
+
+    @Test
+    public void testReadOnlyWithOptionsWrite() {
+        testWrite(stripOptionTags(getReadOnlyWithOptionsDesign()),
+                getReadOnlyWithOptionsExpected());
+    }
+
+    @Test
+    public void testBasicRead() {
+        testRead(getBasicDesign(), getBasicExpected());
+    }
+
+    @Test
+    public void testBasicWrite() {
+        testWrite(getBasicDesign(), getBasicExpected());
+    }
+
+    private String getBasicDesign() {
+        return "<v-combo-box input-prompt=\"Select something\" filtering-mode=\"off\" scroll-to-selected-item='false'>";
+    }
+
+    private ComboBox getBasicExpected() {
+        ComboBox cb = new ComboBox();
+        cb.setInputPrompt("Select something");
+        cb.setTextInputAllowed(true);
+        cb.setFilteringMode(FilteringMode.OFF);
+        cb.setScrollToSelectedItem(false);
+        return cb;
+    }
+}
diff --git a/server/tests/src/com/vaadin/tests/server/component/listselect/ListSelectDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/listselect/ListSelectDeclarativeTest.java
new file mode 100644 (file)
index 0000000..fcff6cd
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2000-2014 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.server.component.listselect;
+
+import org.junit.Test;
+
+import com.vaadin.tests.design.DeclarativeTestBase;
+import com.vaadin.ui.ListSelect;
+
+public class ListSelectDeclarativeTest extends DeclarativeTestBase<ListSelect> {
+
+    private ListSelect getWithOptionsExpected() {
+        ListSelect ls = new ListSelect();
+        ls.setRows(10);
+        ls.addItem("Male");
+        ls.addItem("Female");
+        return ls;
+    }
+
+    private String getWithOptionsDesign() {
+        return "<v-list-select rows=10>\n" + "        <option>Male</option>\n"
+                + "        <option>Female</option>\n" + "</v-list-select>\n"
+                + "";
+    }
+
+    @Test
+    public void testReadWithOptions() {
+        testRead(getWithOptionsDesign(), getWithOptionsExpected());
+    }
+
+    @Test
+    public void testWriteWithOptions() {
+        testWrite(stripOptionTags(getWithOptionsDesign()),
+                getWithOptionsExpected());
+    }
+
+    private ListSelect getBasicExpected() {
+        ListSelect ls = new ListSelect();
+        ls.setCaption("Hello");
+        return ls;
+    }
+
+    private String getBasicDesign() {
+        return "<v-list-select caption='Hello' />";
+    }
+
+    @Test
+    public void testReadBasic() {
+        testRead(getBasicDesign(), getBasicExpected());
+    }
+
+    @Test
+    public void testWriteBasic() {
+        testWrite(getBasicDesign(), getBasicExpected());
+    }
+
+}
diff --git a/server/tests/src/com/vaadin/tests/server/component/nativeselect/NativeSelectDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/nativeselect/NativeSelectDeclarativeTest.java
new file mode 100644 (file)
index 0000000..8f1b995
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2000-2014 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.server.component.nativeselect;
+
+import org.junit.Test;
+
+import com.vaadin.tests.design.DeclarativeTestBase;
+import com.vaadin.ui.NativeSelect;
+
+/**
+ * Test cases for reading the properties of selection components.
+ * 
+ * @author Vaadin Ltd
+ */
+public class NativeSelectDeclarativeTest extends
+        DeclarativeTestBase<NativeSelect> {
+
+    public String getBasicDesign() {
+        return "<v-native-select><option>foo</option><option>bar</option></v-native-select>";
+
+    }
+
+    public NativeSelect getBasicExpected() {
+        NativeSelect ns = new NativeSelect();
+        ns.addItem("foo");
+        ns.addItem("bar");
+        return ns;
+    }
+
+    @Test
+    public void testReadBasic() {
+        testRead(getBasicDesign(), getBasicExpected());
+    }
+
+    @Test
+    public void testWriteBasic() {
+        testWrite(stripOptionTags(getBasicDesign()), getBasicExpected());
+    }
+
+}
\ No newline at end of file
diff --git a/server/tests/src/com/vaadin/tests/server/component/tree/TreeDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/tree/TreeDeclarativeTest.java
new file mode 100644 (file)
index 0000000..b5e86d0
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2000-2014 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.server.component.tree;
+
+import org.junit.Test;
+
+import com.vaadin.shared.ui.MultiSelectMode;
+import com.vaadin.tests.design.DeclarativeTestBase;
+import com.vaadin.ui.Tree;
+import com.vaadin.ui.Tree.TreeDragMode;
+
+/**
+ * Tests the declarative support for implementations of {@link Tree}.
+ * 
+ * @since 7.4
+ * @author Vaadin Ltd
+ */
+public class TreeDeclarativeTest extends DeclarativeTestBase<Tree> {
+
+    @Test
+    public void testReadBasic() {
+        testRead(getBasicDesign(), getBasicExpected());
+    }
+
+    @Test
+    public void testWriteBasic() {
+        testWrite(getBasicDesign(), getBasicExpected());
+    }
+
+    private String getBasicDesign() {
+        return "<v-tree selectable='false' drag-mode='node' multiselect-mode='simple' />";
+    }
+
+    private Tree getBasicExpected() {
+        Tree t = new Tree();
+        t.setSelectable(false);
+        t.setDragMode(TreeDragMode.NODE);
+        t.setMultiselectMode(MultiSelectMode.SIMPLE);
+        return t;
+    }
+
+    @Test
+    public void testReadEmpty() {
+        testRead("<v-tree />", new Tree());
+    }
+
+    @Test
+    public void testWriteEmpty() {
+        testWrite("<v-tree />", new Tree());
+    }
+}
diff --git a/server/tests/src/com/vaadin/tests/server/component/twincolselect/TwinColSelectDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/twincolselect/TwinColSelectDeclarativeTest.java
new file mode 100644 (file)
index 0000000..5690802
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2000-2014 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.server.component.twincolselect;
+
+import java.util.Arrays;
+
+import org.junit.Test;
+
+import com.vaadin.tests.design.DeclarativeTestBase;
+import com.vaadin.ui.TwinColSelect;
+
+/**
+ * Test cases for reading the properties of selection components.
+ * 
+ * @author Vaadin Ltd
+ */
+public class TwinColSelectDeclarativeTest extends
+        DeclarativeTestBase<TwinColSelect> {
+
+    public String getBasicDesign() {
+        return "<v-twin-col-select rows=5 right-column-caption='Selected values' left-column-caption='Unselected values'>\n"
+                + "        <option>First item</option>\n"
+                + "        <option selected>Second item</option>\n"
+                + "        <option selected>Third item</option>\n"
+                + "</v-twin-col-select>";
+
+    }
+
+    public TwinColSelect getBasicExpected() {
+        TwinColSelect s = new TwinColSelect();
+        s.setRightColumnCaption("Selected values");
+        s.setLeftColumnCaption("Unselected values");
+        s.addItem("First item");
+        s.addItem("Second item");
+        s.addItem("Third item");
+        s.setValue(Arrays.asList(new Object[] { "Second item", "Third item" }));
+        s.setRows(5);
+        return s;
+    }
+
+    @Test
+    public void testReadBasic() {
+        testRead(getBasicDesign(), getBasicExpected());
+    }
+
+    @Test
+    public void testWriteBasic() {
+        testWrite(stripOptionTags(getBasicDesign()), getBasicExpected());
+    }
+
+    @Test
+    public void testReadEmpty() {
+        testRead("<v-twin-col-select />", new TwinColSelect());
+    }
+
+    @Test
+    public void testWriteEmpty() {
+        testWrite("<v-twin-col-select />", new TwinColSelect());
+    }
+
+}
\ No newline at end of file
diff --git a/server/tests/src/com/vaadin/tests/server/component/upload/UploadDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/upload/UploadDeclarativeTest.java
new file mode 100644 (file)
index 0000000..e089800
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2000-2014 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.server.component.upload;
+
+import org.junit.Test;
+
+import com.vaadin.tests.design.DeclarativeTestBase;
+import com.vaadin.ui.Upload;
+
+/**
+ * Tests the declarative support for implementations of {@link Upload}.
+ * 
+ * @since 7.4
+ * @author Vaadin Ltd
+ */
+public class UploadDeclarativeTest extends DeclarativeTestBase<Upload> {
+
+    @Test
+    public void testReadBasic() {
+        testRead(getBasicDesign(), getBasicExpected());
+    }
+
+    @Test
+    public void testWriteBasic() {
+        testWrite(getBasicDesign(), getBasicExpected());
+    }
+
+    private String getBasicDesign() {
+        return "<v-upload button-caption='Send the file' tabindex=5 />";
+    }
+
+    private Upload getBasicExpected() {
+        Upload u = new Upload();
+        u.setButtonCaption("Send the file");
+        u.setTabIndex(5);
+        return u;
+    }
+
+    @Test
+    public void testReadEmpty() {
+        testRead("<v-upload />", new Upload());
+    }
+
+    @Test
+    public void testWriteEmpty() {
+        testWrite("<v-upload />", new Upload());
+    }
+}