mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
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>
This commit is contained in:
@@ -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>
|
||||
|
||||
24
install/ui/test/binding_tests.html
Normal file
24
install/ui/test/binding_tests.html
Normal file
@@ -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>
|
||||
125
install/ui/test/binding_tests.js
Normal file
125
install/ui/test/binding_tests.js
Normal file
@@ -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);
|
||||
});
|
||||
|
||||
|
||||
};});
|
||||
@@ -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>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user