summaryrefslogtreecommitdiffstats
path: root/install
diff options
context:
space:
mode:
authorPetr Vobornik <pvoborni@redhat.com>2014-03-21 15:09:43 +0100
committerPetr Vobornik <pvoborni@redhat.com>2014-04-03 12:40:37 +0200
commit480eba26a14cc616c4c336a6db69fb8ba66a0a60 (patch)
treea7dc9c0f25af5f0c0b32caeda87cbfd64d5d5e6f /install
parentdf18a3bc040299dae2dc573667ec7ee2db45a8e5 (diff)
downloadfreeipa-480eba26a14cc616c4c336a6db69fb8ba66a0a60.tar.gz
freeipa-480eba26a14cc616c4c336a6db69fb8ba66a0a60.tar.xz
freeipa-480eba26a14cc616c4c336a6db69fb8ba66a0a60.zip
webui-tests: binding test suite
Add basic tests for two-way binding between a field and two widgets Reviewed-By: Adam Misnyovszki <amisnyov@redhat.com>
Diffstat (limited to 'install')
-rw-r--r--install/ui/test/all_tests.html6
-rw-r--r--install/ui/test/binding_tests.html24
-rw-r--r--install/ui/test/binding_tests.js125
-rw-r--r--install/ui/test/index.html1
4 files changed, 154 insertions, 2 deletions
diff --git a/install/ui/test/all_tests.html b/install/ui/test/all_tests.html
index e9cd6bb80..28ab2dbc8 100644
--- a/install/ui/test/all_tests.html
+++ b/install/ui/test/all_tests.html
@@ -22,8 +22,9 @@
'test/widget_tests',
'test/ip_tests',
'test/utils_tests',
- 'test/build_tests'
- ], function(om, ipa, details, entity, as, nav, cert, aci, wid, ip, ut, bt){
+ 'test/build_tests',
+ 'test/binding_tests',
+ ], function(om, ipa, details, entity, as, nav, cert, aci, wid, ip, ut, bt, bi){
om();
ipa();
details();
@@ -36,6 +37,7 @@
ip();
ut();
bt();
+ bi();
});
</script>
</head>
diff --git a/install/ui/test/binding_tests.html b/install/ui/test/binding_tests.html
new file mode 100644
index 000000000..4b58c52b4
--- /dev/null
+++ b/install/ui/test/binding_tests.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>IPA Binding test suite</title>
+ <link rel="stylesheet" href="qunit.css" type="text/css" media="screen">
+ <script type="text/javascript" src="../js/libs/jquery.js"></script>
+ <script type="text/javascript" src="../js/libs/jquery.ordered-map.js"></script>
+ <script type="text/javascript" src="qunit.js"></script>
+ <script type="text/javascript" src="config.js"></script>
+ <script type="text/javascript" src="../js/dojo/dojo.js"></script>
+
+ <script type="text/javascript">
+ require(['test/binding_tests'], function(tests){ tests() });
+ </script>
+</head>
+<body>
+ <h1 id="qunit-header">IPA Binding test suite</h1>
+ <h2 id="qunit-banner"></h2>
+ <div id="qunit-testrunner-toolbar"></div>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+ <div id="qunit-fixture"></div>
+</body>
+</html> \ No newline at end of file
diff --git a/install/ui/test/binding_tests.js b/install/ui/test/binding_tests.js
new file mode 100644
index 000000000..3969485fc
--- /dev/null
+++ b/install/ui/test/binding_tests.js
@@ -0,0 +1,125 @@
+/* Authors:
+ * Petr Vobornik <pvoborni@redhat.com>
+ *
+ * Copyright (C) 2013 Red Hat
+ * see file 'COPYING' for use and warranty information
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+define([
+ 'freeipa/builder',
+ 'freeipa/FieldBinder',
+ 'freeipa/widget',
+ 'freeipa/field',
+ 'freeipa/entity'
+ ],
+ function(builder, FieldBinder, mod_widget, mod_field) { return function() {
+
+
+module('build',{
+
+ setup: function() {
+ },
+ teardown: function() {
+ }
+});
+
+
+/**
+ * This test tests two-way binding between one field and two widgets
+ *
+ * All three have to have the same value.
+ */
+test('Testing two way bindings', function() {
+
+ function test_same_value(value, dirty) {
+ if (dirty) {
+ ok(field.dirty, "Field is dirty")
+ } else {
+ ok(!field.dirty, "Field is not dirty")
+ }
+ same(widget1.get_value(), value, 'Testing Widget 1 value');
+ same(widget2.get_value(), value, 'Testing Widget 2 value');
+ same(field.get_value(), value, 'Testing Field value');
+ }
+
+ mod_widget.register();
+ mod_field.register();
+
+ var field = builder.build('field', 'f1');
+ var widget1 = builder.build('widget', 'w1');
+ var widget2 = builder.build('widget', 'w2');
+
+ // is it a bug that widgets needs to be created?
+ var c1 = $("<div/>");
+ var c2 = $("<div/>");
+ widget1.create(c1);
+ widget2.create(c2);
+
+ var b1 = new FieldBinder(field, widget1);
+ b1.bind();
+
+ var b2 = new FieldBinder(field, widget2);
+ b2.bind();
+
+ test_same_value([], false); // initial is empty
+
+ // set pristine value to field
+ var value = ['val1'];
+ field.set_value(value, true); // pristine = true
+ test_same_value(value, false);
+
+ // set value from widget 1
+ var value2 = ['val2'];
+ widget1.set_value(value2);
+ test_same_value(value2, true);
+
+ // set value from widget 2
+ var value3 = ['val3'];
+ widget1.set_value(value3);
+ test_same_value(value3, true);
+
+ // reset the field, all should have original value
+ field.reset();
+ test_same_value(value, false);
+
+ // make the field dirty again and click on undo button
+ widget1.set_value(value2);
+ test_same_value(value2, true);
+ widget1.get_undo().click();
+ test_same_value(value, false);
+
+ // set new value to field
+ field.set_value(value2);
+ test_same_value(value2, true);
+
+ // unbind the fields, set different value to each
+ b1.unbind();
+ b2.unbind();
+ field.reset();
+ widget2.set_value(value3);
+ same(widget1.get_value(), value2, 'Testing Widget 1 value');
+ same(widget2.get_value(), value3, 'Testing Widget 2 value');
+ same(field.get_value(), value, 'Testing Field value');
+
+ // bind again
+ b1.bind();
+ b2.bind();
+ field.set_value(value2);
+ test_same_value(value2, true);
+});
+
+
+};});
diff --git a/install/ui/test/index.html b/install/ui/test/index.html
index 948f9a448..89af3211c 100644
--- a/install/ui/test/index.html
+++ b/install/ui/test/index.html
@@ -36,6 +36,7 @@
<li><a href="ip_tests.html">IP Addresses Test Suite</a>
<li><a href="utils_tests.html">Utils Test Suite</a>
<li><a href="build_tests.html">Build Test Suite</a>
+ <li><a href="binding_tests.html">Binding Test Suite</a>
</ul>
</div>