From 480eba26a14cc616c4c336a6db69fb8ba66a0a60 Mon Sep 17 00:00:00 2001 From: Petr Vobornik Date: Fri, 21 Mar 2014 15:09:43 +0100 Subject: webui-tests: binding test suite Add basic tests for two-way binding between a field and two widgets Reviewed-By: Adam Misnyovszki --- install/ui/test/all_tests.html | 6 +- install/ui/test/binding_tests.html | 24 +++++++ install/ui/test/binding_tests.js | 125 +++++++++++++++++++++++++++++++++++++ install/ui/test/index.html | 1 + 4 files changed, 154 insertions(+), 2 deletions(-) create mode 100644 install/ui/test/binding_tests.html create mode 100644 install/ui/test/binding_tests.js (limited to 'install/ui') 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(); }); 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 @@ + + + + IPA Binding test suite + + + + + + + + + + +

IPA Binding test suite

+

+
+

+
    +
    + + \ 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 + * + * 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 . + */ + +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 = $("
    "); + var c2 = $("
    "); + 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 @@
  1. IP Addresses Test Suite
  2. Utils Test Suite
  3. Build Test Suite +
  4. Binding Test Suite
  5. -- cgit