1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
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);
});
};});
|