Update tests

With newer QUnit the API has changed, therefor there are necesary changes
in tests. QUnit methods does not pollute global workspace they use global
QUnit object or assert object passed as argument to test method.

Related: https://pagure.io/freeipa/issue/7278
Reviewed-By: Christian Heimes <cheimes@redhat.com>
This commit is contained in:
Pavel Vomacka 2017-11-21 08:56:11 +01:00 committed by Christian Heimes
parent c47784dc9f
commit 2dd7741075
15 changed files with 459 additions and 716 deletions

View File

@ -39,8 +39,8 @@ var target_facet;
var entity = IPA.entity({ name: 'bogus', redirect_facet: 'details' });
var group_entity = IPA.entity({ name: 'group' });
module('aci', {
setup: function() {
QUnit.module('aci', {
beforeEach: function(assert) {
fields.register();
widgets.register();
@ -52,7 +52,7 @@ module('aci', {
IPA.init({
url: 'data',
on_error: function(xhr, text_status, error_thrown) {
ok(false, "ipa_init() failed: "+error_thrown);
assert.ok(false, "ipa_init() failed: "+error_thrown);
}
});
@ -130,13 +130,13 @@ module('aci', {
target_facet.create();
target_widget = target_facet.widgets.get_widget('target');
},
teardown: function() {
afterEach: function() {
target_container.remove();
}}
);
test("aci.attributes_widget", function() {
QUnit.test("aci.attributes_widget", function(assert) {
var aciattrs = md.source.objects.user.aciattrs;
@ -154,7 +154,7 @@ test("aci.attributes_widget", function() {
var list = $('ul', container);
ok(
assert.ok(
list,
'Widget contains list');
@ -163,7 +163,7 @@ test("aci.attributes_widget", function() {
list = $('ul', container); // reload the DOM node which contains options
var li = $('li', list);
same(
assert.deepEqual(
li.length, aciattrs.length,
'Widget contains all user ACI attributes');
@ -175,7 +175,7 @@ test("aci.attributes_widget", function() {
]
};
same(
assert.deepEqual(
widget.save(), [],
'Widget has no initialy checked values');
@ -184,16 +184,16 @@ test("aci.attributes_widget", function() {
list = $('ul', container); // reload the DOM node which contains options
li = $('li', list);
same(
assert.deepEqual(
li.length, aciattrs.length+1,
'Widget contains all user ACI attributes plus 1 unmatched attribute');
same(
assert.deepEqual(
widget.save(), record.attrs.sort(),
'All loaded values are saved and sorted');
});
test("aci.rights_widget.", function() {
QUnit.test("aci.rights_widget.", function(assert) {
var container = $('<span/>', {
name: 'permissions'
@ -208,7 +208,7 @@ test("aci.rights_widget.", function() {
var inputs = $('input', container);
same(
assert.deepEqual(
inputs.length, widget.rights.length,
'Widget displays all permissions');
});
@ -231,7 +231,7 @@ var get_visible_rows = function(section) {
};
test("Testing type target.", function() {
QUnit.test("Testing type target.", function(assert) {
var data = {
id: null,
error: null,
@ -240,11 +240,11 @@ test("Testing type target.", function() {
target_facet.load(data);
same(target_widget.target, 'type', 'type selected');
assert.deepEqual(target_widget.target, 'type', 'type selected');
var attrs_w = target_widget.widgets.get_widget('attrs');
var options = attrs_w.options;
ok(options.length > 0, "Attrs has some options");
assert.ok(options.length > 0, "Attrs has some options");
// check them all
var values = [];
for (var i=0,l=options.length; i<l; i++) {
@ -256,18 +256,18 @@ test("Testing type target.", function() {
var record = {};
target_facet.save(record);
same(record.type[0], data.result.result.type,
assert.deepEqual(record.type[0], data.result.result.type,
"saved type matches sample data");
same(get_visible_rows(target_widget), ['type', 'extratargetfilter',
assert.deepEqual(get_visible_rows(target_widget), ['type', 'extratargetfilter',
'ipapermtarget', 'memberof', 'attrs'],
'type and attrs rows visible');
same(record.attrs.length, options.length, "response contains all checked attrs");
assert.deepEqual(record.attrs.length, options.length, "response contains all checked attrs");
});
test("Testing general target.", function() {
QUnit.test("Testing general target.", function(assert) {
var data = {
id: null,
@ -280,13 +280,13 @@ test("Testing general target.", function() {
var record = {};
target_facet.save(record);
same(target_widget.target, 'general', 'general selected');
assert.deepEqual(target_widget.target, 'general', 'general selected');
same(get_visible_rows(target_widget), ['type', 'ipapermlocation',
assert.deepEqual(get_visible_rows(target_widget), ['type', 'ipapermlocation',
'extratargetfilter', 'ipapermtarget', 'memberof',
'attrs_multi'], 'general target fields visible');
same(record.extratargetfilter[0], data.result.result.extratargetfilter, 'filter set correctly');
assert.deepEqual(record.extratargetfilter[0], data.result.result.extratargetfilter, 'filter set correctly');
});
};});

View File

@ -3,13 +3,23 @@
<head>
<title>Complete Test Suite</title>
<link rel="stylesheet" href="qunit.css" type="text/css" media="screen">
<script type="text/javascript" src="qunit.js"></script>
<script type="text/javascript" src="../js/libs/loader.js"></script>
<script type="text/javascript" src="../js/libs/jquery.js"></script>
<script>
// import qunit.js only in situations it is not imported by grunt-contrib-qunit
// allows to run tests using grunt and using Firefox (FF needs explicit import)
if (window.QUnit === undefined) {
var s = document.createElement("script");
s.type = "text/javascript";
s.src = "qunit.js";
$("head script:last-of-type").before(s); // insert qunit.js import before dojo import
}
</script>
<script type="text/javascript" src="../js/libs/jquery.ordered-map.js"></script>
<script type="text/javascript" src="../js/libs/bootstrap.js"></script>
<script type="text/javascript" src="config.js"></script>
<script type="text/javascript" src="../js/dojo/dojo.js"></script>
<script class='insertBefore' type="text/javascript" src="../js/dojo/dojo.js"></script>
<script type="text/javascript">
require([
@ -18,7 +28,6 @@
'test/details_tests',
'test/entity_tests',
'test/association_tests',
'test/navigation_tests',
'test/certificate_tests',
'test/aci_tests',
'test/widget_tests',
@ -26,13 +35,13 @@
'test/utils_tests',
'test/build_tests',
'test/binding_tests',
], function(om, ipa, details, entity, as, nav, cert, aci, wid, ip, ut, bt, bi){
], function(om, ipa, details, entity, as, cert, aci, wid, ip, ut, bt, bi){
QUnit.start();
om();
ipa();
details();
entity();
as();
nav();
cert();
aci();
wid();

View File

@ -28,12 +28,12 @@ define([
], function(IPA, $, rpc)
{ return function() {
module('association');
QUnit.module('association');
test("Testing serial_associator().", function() {
QUnit.test("Testing serial_associator().", function(assert) {
expect(11);
assert.expect(11);
var orig_ipa_batch_command = rpc.batch_command;
@ -54,7 +54,7 @@ test("Testing serial_associator().", function() {
var that = orig_ipa_batch_command(spec);
that.execute = function() {
equals(that.commands.length, params.values.length,
assert.equal(that.commands.length, params.values.length,
'Checking rpc.batch_command command count');
var i, command;
@ -62,15 +62,15 @@ test("Testing serial_associator().", function() {
for(i=0; i < params.values.length; i++) {
command = that.commands[i];
equals(
assert.equal(
command.entity, params.other_entity.name,
'Checking rpc.command() parameter: entity');
equals(
assert.equal(
command.method, params.method,
'Checking rpc.command() parameter: method');
equals(
assert.equal(
command.args[0], 'user'+(i+1),
'Checking rpc.command() parameter: primary key');
}
@ -82,7 +82,7 @@ test("Testing serial_associator().", function() {
};
params.on_success = function() {
ok(true, "on_success() is invoked.");
assert.ok(true, "on_success() is invoked.");
};
var associator = IPA.serial_associator(params);
@ -91,9 +91,9 @@ test("Testing serial_associator().", function() {
rpc.batch_command = orig_ipa_batch_command;
});
test("Testing bulk_associator().", function() {
QUnit.test("Testing bulk_associator().", function(assert) {
expect(4);
assert.expect(4);
var orig_ipa_command = rpc.command;
@ -118,15 +118,15 @@ test("Testing bulk_associator().", function() {
that.execute = function() {
counter++;
equals(
assert.equal(
that.method, params.method,
'Checking rpc.command() parameter: method');
equals(
assert.equal(
that.args[0], params.pkey,
'Checking rpc.command() parameter: primary key');
equals(
assert.equal(
that.options[params.other_entity.name], 'user1,user2,user3',
'Checking rpc.command() parameter: options[\""+params.other_entity+"\"]');
@ -137,7 +137,7 @@ test("Testing bulk_associator().", function() {
};
params.on_success = function() {
ok(true, "on_success() is invoked.");
assert.ok(true, "on_success() is invoked.");
};
var associator = IPA.bulk_associator(params);
@ -146,4 +146,4 @@ test("Testing bulk_associator().", function() {
rpc.command = orig_ipa_command;
});
};});
};});

View File

@ -28,13 +28,7 @@ define([
function(builder, FieldBinder, mod_widget, mod_field) { return function() {
module('build',{
setup: function() {
},
teardown: function() {
}
});
QUnit.module('binding');
/**
@ -42,17 +36,17 @@ module('build',{
*
* All three have to have the same value.
*/
test('Testing two way bindings', function() {
QUnit.test('Testing two way bindings', function(assert) {
function test_same_value(value, dirty) {
if (dirty) {
ok(field.dirty, "Field is dirty")
assert.ok(field.dirty, "Field is dirty")
} else {
ok(!field.dirty, "Field is not dirty")
assert.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');
assert.deepEqual(widget1.get_value(), value, 'Testing Widget 1 value');
assert.deepEqual(widget2.get_value(), value, 'Testing Widget 2 value');
assert.deepEqual(field.get_value(), value, 'Testing Field value');
}
mod_widget.register();
@ -110,9 +104,9 @@ test('Testing two way bindings', function() {
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');
assert.deepEqual(widget1.get_value(), value2, 'Testing Widget 1 value');
assert.deepEqual(widget2.get_value(), value3, 'Testing Widget 2 value');
assert.deepEqual(field.get_value(), value, 'Testing Field value');
// bind again
b1.bind();

View File

@ -29,15 +29,9 @@ define([
function(declare, Builder, C_reg, Spec_mod, IPA, su) { return function() {
module('build',{
QUnit.module('build');
setup: function() {
},
teardown: function() {
}
});
test('Testing builder', function() {
QUnit.test('Testing builder', function(assert) {
var simple_factory = function(spec) {
@ -69,18 +63,18 @@ test('Testing builder', function() {
var r2 = new Simple_class({});
var r21 = new Simple_class({ foo:'baz'});
deepEqual(o1, r1, 'Factory, default');
deepEqual(o11, r11, 'Factory, spec use');
assert.deepEqual(o1, r1, 'Factory, default');
assert.deepEqual(o11, r11, 'Factory, spec use');
deepEqual(o2, r2, 'Constructor, default');
deepEqual(o21, r21, 'Constructor, spec use');
assert.deepEqual(o2, r2, 'Constructor, default');
assert.deepEqual(o21, r21, 'Constructor, spec use');
strictEqual(o11, o12, 'Don\'t build built object - factory');
strictEqual(o21, o22, 'Don\'t build built object - constructor');
assert.strictEqual(o11, o12, 'Don\'t build built object - factory');
assert.strictEqual(o21, o22, 'Don\'t build built object - constructor');
});
test('Testing Spec_mod', function() {
QUnit.test('Testing Spec_mod', function(assert) {
var sm = new Spec_mod();
@ -149,7 +143,7 @@ test('Testing Spec_mod', function() {
sm.mod(spec, diff);
deepEqual(spec, ref, 'Complex Modification');
assert.deepEqual(spec, ref, 'Complex Modification');
spec = {
a: [ 'a1', 'a2', 'a3' ]
@ -157,10 +151,10 @@ test('Testing Spec_mod', function() {
var rules = [[ 'a', 'new', 1]];
sm.add(spec, rules);
deepEqual(spec, { a: ['a1', 'new', 'a2', 'a3'] }, 'Add on position');
assert.deepEqual(spec, { a: ['a1', 'new', 'a2', 'a3'] }, 'Add on position');
});
test('Testing Construct registry', function() {
QUnit.test('Testing Construct registry', function(assert) {
var undefined;
@ -171,22 +165,22 @@ test('Testing Construct registry', function() {
cr.register('ctor', ctor);
var ctor_cs = cr.get('ctor');
equals(ctor_cs.type, 'ctor', 'Ctor: Match type');
equals(ctor_cs.ctor, ctor, 'Ctor: Match ctor');
equals(ctor_cs.factory, undefined, 'Ctor: Match factory');
equals(ctor_cs.pre_ops.length, 0, 'Ctor: No pre_ops');
equals(ctor_cs.post_ops.length, 0, 'Ctor: No post_ops');
assert.equal(ctor_cs.type, 'ctor', 'Ctor: Match type');
assert.equal(ctor_cs.ctor, ctor, 'Ctor: Match ctor');
assert.equal(ctor_cs.factory, undefined, 'Ctor: Match factory');
assert.equal(ctor_cs.pre_ops.length, 0, 'Ctor: No pre_ops');
assert.equal(ctor_cs.post_ops.length, 0, 'Ctor: No post_ops');
// test simple factory registration
var fac = function(){};
cr.register('fac', fac);
var fac_cs = cr.get('fac');
equals(fac_cs.type, 'fac', 'Factory: Match type');
equals(fac_cs.ctor, undefined, 'Factory: Match ctor');
equals(fac_cs.factory, fac, 'Factory: Match factory');
equals(fac_cs.pre_ops.length, 0, 'Factory: No pre_ops');
equals(fac_cs.post_ops.length, 0, 'Factory: No post_ops');
assert.equal(fac_cs.type, 'fac', 'Factory: Match type');
assert.equal(fac_cs.ctor, undefined, 'Factory: Match ctor');
assert.equal(fac_cs.factory, fac, 'Factory: Match factory');
assert.equal(fac_cs.pre_ops.length, 0, 'Factory: No pre_ops');
assert.equal(fac_cs.post_ops.length, 0, 'Factory: No post_ops');
// test complex registration
@ -201,22 +195,22 @@ test('Testing Construct registry', function() {
};
cr.register(cs);
var complex_cs = cr.get('complex');
equals(complex_cs.type, 'complex', 'Complex: Match type');
equals(complex_cs.ctor, ctor, 'Complex: Match ctor');
equals(complex_cs.factory, fac, 'Complex: Match factory');
equals(complex_cs.pre_ops.length, 0, 'Complex: No pre_ops');
equals(complex_cs.post_ops.length, 0, 'Complex: No post_ops');
deepEqual(complex_cs.spec, spec, 'Complex: Match spec');
assert.equal(complex_cs.type, 'complex', 'Complex: Match type');
assert.equal(complex_cs.ctor, ctor, 'Complex: Match ctor');
assert.equal(complex_cs.factory, fac, 'Complex: Match factory');
assert.equal(complex_cs.pre_ops.length, 0, 'Complex: No pre_ops');
assert.equal(complex_cs.post_ops.length, 0, 'Complex: No post_ops');
assert.deepEqual(complex_cs.spec, spec, 'Complex: Match spec');
// copy: new cs based on existing
cr.copy('complex', 'copy', {}); // pure copy
var copy_cs = cr.get('copy');
equals(copy_cs.type, 'copy', 'Copy: Match type');
equals(copy_cs.ctor, ctor, 'Copy: Match ctor');
equals(copy_cs.factory, fac, 'Copy: Match factory');
equals(copy_cs.pre_ops.length, 0, 'Copy: No pre_ops');
equals(copy_cs.post_ops.length, 0, 'Copy: No post_ops');
deepEqual(copy_cs.spec, spec, 'Copy: Match spec');
assert.equal(copy_cs.type, 'copy', 'Copy: Match type');
assert.equal(copy_cs.ctor, ctor, 'Copy: Match ctor');
assert.equal(copy_cs.factory, fac, 'Copy: Match factory');
assert.equal(copy_cs.pre_ops.length, 0, 'Copy: No pre_ops');
assert.equal(copy_cs.post_ops.length, 0, 'Copy: No post_ops');
assert.deepEqual(copy_cs.spec, spec, 'Copy: Match spec');
// add post op and pre op to complex
var op1 = function() {};
@ -226,11 +220,11 @@ test('Testing Construct registry', function() {
cr.register_pre_op('complex', op1);
cr.register_pre_op('complex', op2, true /* first*/);
deepEqual(complex_cs.pre_ops, [op2, op1], 'Adding pre_ops');
assert.deepEqual(complex_cs.pre_ops, [op2, op1], 'Adding pre_ops');
cr.register_post_op('complex', op3);
cr.register_post_op('complex', op4, true);
deepEqual(complex_cs.post_ops, [op4, op3], 'Adding post_ops');
assert.deepEqual(complex_cs.post_ops, [op4, op3], 'Adding post_ops');
// copy: altered
@ -249,16 +243,16 @@ test('Testing Construct registry', function() {
});
var a_copy_cs = cr.get('copy2');
equals(a_copy_cs.type, 'copy2', 'Altered copy: Match type');
equals(a_copy_cs.ctor, ctor2, 'Altered copy: Match ctor');
equals(a_copy_cs.factory, fac2, 'Altered copy: Match factory');
deepEqual(a_copy_cs.spec, {
assert.equal(a_copy_cs.type, 'copy2', 'Altered copy: Match type');
assert.equal(a_copy_cs.ctor, ctor2, 'Altered copy: Match ctor');
assert.equal(a_copy_cs.factory, fac2, 'Altered copy: Match factory');
assert.deepEqual(a_copy_cs.spec, {
name: 'spec',
foo: 'bar'
}, 'Altered copy: Match spec');
deepEqual(a_copy_cs.pre_ops, [op2, op1, op5], 'Altered copy: Match pre_ops');
deepEqual(a_copy_cs.post_ops, [op4, op3, op6], 'Altered copy: Match post_ops');
assert.deepEqual(a_copy_cs.pre_ops, [op2, op1, op5], 'Altered copy: Match pre_ops');
assert.deepEqual(a_copy_cs.post_ops, [op4, op3, op6], 'Altered copy: Match post_ops');
});
};});
};});

View File

@ -18,42 +18,45 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
define(['freeipa/ipa', 'freeipa/jquery', 'freeipa/certificate'], function(IPA, $) {
return function() {
define(['freeipa/ipa',
'freeipa/jquery',
'freeipa/certificate'],
function(IPA, $) {
return function() {
module('certificate');
QUnit.module('certificate');
test("Testing certificate_parse_dn().", function() {
QUnit.test("Testing certificate_parse_dn().", function(assert) {
same(
assert.deepEqual(
IPA.cert.parse_dn(), {},
"Checking IPA.cert.parse_dn()");
same(
assert.deepEqual(
IPA.cert.parse_dn(''), {},
"Checking IPA.cert.parse_dn('')");
same(
assert.deepEqual(
IPA.cert.parse_dn('c=US'), {'c': 'US'},
"Checking IPA.cert.parse_dn('c=US')");
same(
assert.deepEqual(
IPA.cert.parse_dn('st=TX,c=US'), {'st': 'TX','c': 'US'},
"Checking IPA.cert.parse_dn('st=TX,c=US')");
same(
assert.deepEqual(
IPA.cert.parse_dn('c=US,st=TX'), {'st': 'TX','c': 'US'},
"Checking IPA.cert.parse_dn('c=US,st=TX')");
same(
assert.deepEqual(
IPA.cert.parse_dn(' st = New Mexico , c = US '), {'st': 'New Mexico','c': 'US'},
"Checking IPA.cert.parse_dn(' st = New Mexico , c = US ')");
same(
assert.deepEqual(
IPA.cert.parse_dn('ST=TX,C=US'), {'st': 'TX','c': 'US'},
"Checking IPA.cert.parse_dn('ST=TX,C=US')");
same(
assert.deepEqual(
IPA.cert.parse_dn('cn=dev.example.com,ou=Engineering,o=Example,l=Austin,ST=TX,C=US'),
{ 'cn': 'dev.example.com',
'ou': 'Engineering',
@ -64,7 +67,7 @@ test("Testing certificate_parse_dn().", function() {
},
"Checking IPA.cert.parse_dn('cn=dev.example.com,ou=Engineering,o=Example,l=Austin,ST=TX,C=US')");
same(
assert.deepEqual(
IPA.cert.parse_dn('cn=John Smith,ou=Developers,ou=Users,dc=example,dc=com'),
{
'cn': 'John Smith',
@ -74,4 +77,4 @@ test("Testing certificate_parse_dn().", function() {
"Checking IPA.cert.parse_dn('cn=John Smith,ou=Developers,ou=Users,dc=example,dc=com')");
});
};});
};});

View File

@ -35,8 +35,8 @@ define([
var details_container;
module('details', {
setup: function() {
QUnit.module('details', {
beforeEach: function(assert) {
IPA.ajax_options.async = false;
mod_facet.register();
@ -46,7 +46,7 @@ module('details', {
IPA.init({
url: 'data',
on_error: function(xhr, text_status, error_thrown) {
ok(false, "ipa_init() failed: "+error_thrown);
assert.ok(false, "ipa_init() failed: "+error_thrown);
}
});
@ -60,14 +60,14 @@ module('details', {
});
});
},
teardown: function() {
afterEach: function() {
details_container.remove();
reg.facet.remove('details');
}
});
test("Testing IPA.details_section.create().", function() {
QUnit.test("Testing IPA.details_section.create().", function(assert) {
var facet = IPA.details_facet({
entity: IPA.get_entity('user'),
@ -84,7 +84,7 @@ test("Testing IPA.details_section.create().", function() {
var section = facet.widgets.get_widget('IDIDID');
ok(section !== null, 'Verifying section existence.');
assert.ok(section !== null, 'Verifying section existence.');
var fields = section.widgets.get_widgets();
var container = $("<div/>");
@ -92,12 +92,12 @@ test("Testing IPA.details_section.create().", function() {
var section_el = $('.details-section-content', container);
same(
assert.deepEqual(
section_el.length, 1,
'Verifying section element');
var controls = $('.form-group', section_el);
same(
assert.deepEqual(
controls.length, fields.length,
'Verifying number of controls');
@ -105,17 +105,17 @@ test("Testing IPA.details_section.create().", function() {
var field = fields[i];
var field_label = $('.control-label label[name='+field.name+']', container);
same(
assert.deepEqual(
field_label.text(), field.label,
'Verifying label for field '+field.name);
var field_container = $('.controls div[name='+field.name+']', container);
ok(
assert.ok(
field_container.length,
'Verifying container for field '+field.name);
ok(
assert.ok(
field_container.hasClass('widget'),
'Verifying field '+field.name+' was created');
}
@ -123,7 +123,7 @@ test("Testing IPA.details_section.create().", function() {
test("Testing details lifecycle: create, load.", function(){
QUnit.test("Testing details lifecycle: create, load.", function(assert){
var data = {};
data.result = {};
@ -134,10 +134,10 @@ test("Testing details lifecycle: create, load.", function(){
method: 'show',
args: ['kfrog'],
on_success: function(data, text_status, xhr) {
ok(true, "rpc.command() succeeded.");
assert.ok(true, "rpc.command() succeeded.");
},
on_error: function(xhr, text_status, error_thrown) {
ok(false, "rpc.command() failed: "+error_thrown);
assert.ok(false, "rpc.command() failed: "+error_thrown);
}
}).execute();
@ -237,23 +237,23 @@ test("Testing details lifecycle: create, load.", function(){
var contact = $('.details-section[name=contact]', facet.dom_node);
ok(
assert.ok(
contact.length,
'Verifying section for contact is created');
var identity = $('.details-section[name=identity]', facet.dom_node);
ok(
assert.ok(
identity.length,
'Verifying section for identity is created');
var rows = $('.form-group', identity);
same(
assert.deepEqual(
rows.length, 6,
'Verifying rows for identity');
ok (load_called, 'load manager called');
assert.ok(load_called, 'load manager called');
var field = facet.fields.get_field('test');
field.set_value("foo");
@ -265,14 +265,14 @@ test("Testing details lifecycle: create, load.", function(){
function(){update_success_called = true;},
function(){update_failure_called = true;});
ok (update_success_called,'update success called');
ok (!update_failure_called,'update failure not called');
ok (save_called, 'save called');
assert.ok(update_success_called,'update success called');
assert.ok(!update_failure_called,'update failure not called');
assert.ok(save_called, 'save called');
});
test("Testing IPA.details_section_create again()",function() {
QUnit.test("Testing IPA.details_section_create again()",function(assert) {
var facet = IPA.details_facet({
entity: IPA.get_entity('user'),
@ -301,7 +301,7 @@ test("Testing IPA.details_section_create again()",function() {
});
var section = facet.widgets.get_widget('IDIDID');
ok(section !== null, 'Verifying section existence.');
assert.ok(section !== null, 'Verifying section existence.');
var fields = section.widgets.get_widgets();
var container = $("<div title='entity'/>");
@ -317,12 +317,12 @@ test("Testing IPA.details_section_create again()",function() {
var section_el = $('.details-section-content', container);
same(
assert.deepEqual(
section_el.length, 1,
'Verifying section element');
var controls = $('.form-group', section_el);
same(
assert.deepEqual(
controls.length, fields.length,
'Verifying number of controls');
@ -330,17 +330,17 @@ test("Testing IPA.details_section_create again()",function() {
var field = fields[i];
var field_label = $('.control-label label[name='+field.name+']', container);
same(
assert.deepEqual(
field_label.text(), field.label,
'Verifying label for field '+field.name);
var field_container = $('.controls div[name='+field.name+']', container);
ok(
assert.ok(
field_container.length,
'Verifying container for field '+field.name);
ok(
assert.ok(
field_container.hasClass('widget'),
'Verifying field '+field.name+' was created');
}

View File

@ -32,8 +32,8 @@ define([
var container;
module('entity',{
setup: function() {
QUnit.module('entity',{
beforeEach: function(assert) {
IPA.ajax_options.async = false;
@ -60,20 +60,20 @@ module('entity',{
});
},
on_error: function(xhr, text_status, error_thrown) {
ok(false, "ipa_init() failed: "+error_thrown);
assert.ok(false, "ipa_init() failed: "+error_thrown);
}
});
container = $('<div id="content"/>').appendTo(document.body);
},
teardown: function() {
afterEach: function() {
container.remove();
reg.facet.remove('search');
}
});
test('Testing IPA.entity_set_search_definition().', function() {
QUnit.test('Testing IPA.entity_set_search_definition().', function(assert) {
var uid_callback = function() {
return true;
@ -85,15 +85,15 @@ test('Testing IPA.entity_set_search_definition().', function() {
facet.create();
var column = facet.get_columns()[0];
ok(
assert.ok(
column,
'column is not null');
equals(
assert.equal(
column.name, 'uid',
'column.name');
equals(
assert.equal(
column.label, 'User login',
'column.label');

View File

@ -21,288 +21,283 @@
define(['freeipa/ipa', 'freeipa/net'], function(IPA, NET) {
return function() {
module('ip-addresses',{
setup: function() {
},
teardown: function() {
}
});
QUnit.module('ip-addresses');
var get_reverse = function(str) {
var address = NET.ip_address(str);
return address.get_reverse();
};
test('Testing correct IPv4 addresses', function() {
QUnit.test('Testing correct IPv4 addresses', function(assert) {
var address = NET.ip_address('255.0.173.1');
ok(address.valid, 'Dotted decimal - 255.0.173.1');
same(address.parts, ['255', '0', '173', '1'], 'Checking parts');
assert.ok(address.valid, 'Dotted decimal - 255.0.173.1');
assert.deepEqual(address.parts, ['255', '0', '173', '1'], 'Checking parts');
address = NET.ip_address('0377.0.0255.01');
ok(address.valid, 'Dotted octal - 0377.0.0255.01');
same(address.parts, ['255', '0', '173', '1'], 'Checking parts');
assert.ok(address.valid, 'Dotted octal - 0377.0.0255.01');
assert.deepEqual(address.parts, ['255', '0', '173', '1'], 'Checking parts');
address = NET.ip_address('0xFF.0x0.0xAD.0x1');
ok(address.valid, 'Dotted hexadecimal - 0xFF.0x.0xAD.0x1');
same(address.parts, ['255', '0', '173', '1'], 'Checking parts');
assert.ok(address.valid, 'Dotted hexadecimal - 0xFF.0x.0xAD.0x1');
assert.deepEqual(address.parts, ['255', '0', '173', '1'], 'Checking parts');
address = NET.ip_address('4294967295');
ok(address.valid, 'Max decimal - 4294967295');
same(address.parts, ['255', '255', '255', '255'], 'Checking parts');
assert.ok(address.valid, 'Max decimal - 4294967295');
assert.deepEqual(address.parts, ['255', '255', '255', '255'], 'Checking parts');
address = NET.ip_address('037777777777');
ok(address.valid, 'Max octal - 037777777777');
same(address.parts, ['255', '255', '255', '255'], 'Checking parts');
assert.ok(address.valid, 'Max octal - 037777777777');
assert.deepEqual(address.parts, ['255', '255', '255', '255'], 'Checking parts');
address = NET.ip_address('0xFFFFFFFF');
ok(address.valid, 'Max hexadecimal - 0xFFFFFFFF');
same(address.parts, ['255', '255', '255', '255'], 'Checking parts');
assert.ok(address.valid, 'Max hexadecimal - 0xFFFFFFFF');
assert.deepEqual(address.parts, ['255', '255', '255', '255'], 'Checking parts');
address = NET.ip_address('255.0.0xAD.01');
ok(address.valid, 'Dotted mixed - 255.0.0xAD.01');
same(address.parts, ['255', '0', '173', '1'], 'Checking parts');
assert.ok(address.valid, 'Dotted mixed - 255.0.0xAD.01');
assert.deepEqual(address.parts, ['255', '0', '173', '1'], 'Checking parts');
address = NET.ip_address('0');
ok(address.valid, 'Zero decimal - 0');
same(address.parts, ['0', '0', '0', '0'], 'Checking parts');
assert.ok(address.valid, 'Zero decimal - 0');
assert.deepEqual(address.parts, ['0', '0', '0', '0'], 'Checking parts');
address = NET.ip_address('00');
ok(address.valid, 'Zero octal - 00');
same(address.parts, ['0', '0', '0', '0'], 'Checking parts');
assert.ok(address.valid, 'Zero octal - 00');
assert.deepEqual(address.parts, ['0', '0', '0', '0'], 'Checking parts');
address = NET.ip_address('0X0');
ok(address.valid, 'Zero hexa - 0X0');
same(address.parts, ['0', '0', '0', '0'], 'Checking parts');
assert.ok(address.valid, 'Zero hexa - 0X0');
assert.deepEqual(address.parts, ['0', '0', '0', '0'], 'Checking parts');
});
test('Testing incorrect IPv4 addresses', function() {
QUnit.test('Testing incorrect IPv4 addresses', function(assert) {
var address = NET.ip_address('256.0.0.1');
ok(!address.valid, 'Out of range - 256.0.0.1');
assert.ok(!address.valid, 'Out of range - 256.0.0.1');
address = NET.ip_address('0x100.0.0.1');
ok(!address.valid, 'Out of range - 0x100.0.0.1');
assert.ok(!address.valid, 'Out of range - 0x100.0.0.1');
address = NET.ip_address('0400.0.0.1');
ok(!address.valid, 'Out of range - 0400.0.0.1');
assert.ok(!address.valid, 'Out of range - 0400.0.0.1');
address = NET.ip_address('0x100000000');
ok(!address.valid, 'Out of range - 0x100000000');
assert.ok(!address.valid, 'Out of range - 0x100000000');
address = NET.ip_address('040000000000');
ok(!address.valid, 'Out of range - 040000000000');
assert.ok(!address.valid, 'Out of range - 040000000000');
address = NET.ip_address('4294967296');
ok(!address.valid, 'Out of range - 4294967296');
assert.ok(!address.valid, 'Out of range - 4294967296');
address = NET.ip_address('250.0.173');
ok(!address.valid, '3 parts - 250.0.173');
assert.ok(!address.valid, '3 parts - 250.0.173');
address = NET.ip_address('250.0.173.21.21');
ok(!address.valid, '5 parts - 250.0.173.21.21');
assert.ok(!address.valid, '5 parts - 250.0.173.21.21');
address = NET.ip_address('250.001.173.21');
ok(!address.valid, 'Trailing zeros - 250.001.173.21');
assert.ok(!address.valid, 'Trailing zeros - 250.001.173.21');
address = NET.ip_address('250.001.173.FF');
ok(!address.valid, 'Bad hexapart - 250.01.173.FF');
assert.ok(!address.valid, 'Bad hexapart - 250.01.173.FF');
address = NET.ip_address('abcd');
ok(!address.valid, 'Word - abcd');
assert.ok(!address.valid, 'Word - abcd');
address = NET.ip_address('192.168 .0.21');
ok(!address.valid, 'With space - 192.168 .0.21');
assert.ok(!address.valid, 'With space - 192.168 .0.21');
address = NET.ip_address(' 192.168.0.21');
ok(!address.valid, 'With space - " 192.168.0.21"');
assert.ok(!address.valid, 'With space - " 192.168.0.21"');
});
test('Testing correct IPv6 addresses', function() {
QUnit.test('Testing correct IPv6 addresses', function(assert) {
var address = NET.ip_address('2001:0db8:85a3:0000:0000:8a2e:0370:7334');
ok(address.valid, 'Address - 2001:0db8:85a3:0000:0000:8a2e:0370:7334');
same(address.parts, ['2001', '0db8', '85a3', '0000','0000','8a2e','0370','7334'], 'Checking parts');
assert.ok(address.valid, 'Address - 2001:0db8:85a3:0000:0000:8a2e:0370:7334');
assert.deepEqual(address.parts, ['2001', '0db8', '85a3', '0000','0000','8a2e','0370','7334'], 'Checking parts');
address = NET.ip_address('2001:db8:85a3:0:0:8a2e:370:7334');
ok(address.valid, 'Without trailing zeros - 2001:db8:85a3:0:0:8a2e:370:7334');
same(address.parts, ['2001', '0db8', '85a3', '0000','0000','8a2e','0370','7334'], 'Checking parts');
assert.ok(address.valid, 'Without trailing zeros - 2001:db8:85a3:0:0:8a2e:370:7334');
assert.deepEqual(address.parts, ['2001', '0db8', '85a3', '0000','0000','8a2e','0370','7334'], 'Checking parts');
address = NET.ip_address('2001:db8::1:0:0:1');
ok(address.valid, 'With :: - 2001:db8::1:0:0:1');
same(address.parts, ['2001', '0db8', '0000', '0000','0001','0000','0000','0001'], 'Checking parts');
assert.ok(address.valid, 'With :: - 2001:db8::1:0:0:1');
assert.deepEqual(address.parts, ['2001', '0db8', '0000', '0000','0001','0000','0000','0001'], 'Checking parts');
address = NET.ip_address('::1');
ok(address.valid, 'Address - ::1');
same(address.parts, ['0000', '0000', '0000', '0000','0000','0000','0000','0001'], 'Checking parts');
assert.ok(address.valid, 'Address - ::1');
assert.deepEqual(address.parts, ['0000', '0000', '0000', '0000','0000','0000','0000','0001'], 'Checking parts');
address = NET.ip_address('::');
ok(address.valid, 'Address - ::');
same(address.parts, ['0000', '0000', '0000', '0000','0000','0000','0000','0000'], 'Checking parts');
assert.ok(address.valid, 'Address - ::');
assert.deepEqual(address.parts, ['0000', '0000', '0000', '0000','0000','0000','0000','0000'], 'Checking parts');
address = NET.ip_address('1::');
ok(address.valid, 'Address - 1::');
same(address.parts, ['0001', '0000', '0000', '0000','0000','0000','0000','0000'], 'Checking parts');
assert.ok(address.valid, 'Address - 1::');
assert.deepEqual(address.parts, ['0001', '0000', '0000', '0000','0000','0000','0000','0000'], 'Checking parts');
address = NET.ip_address('::ffff:192.0.2.128');
ok(address.valid, 'With IPv4 part - ::ffff:192.0.2.128');
same(address.parts, ['0000', '0000', '0000', '0000','0000','ffff','c000','0280'], 'Checking parts');
assert.ok(address.valid, 'With IPv4 part - ::ffff:192.0.2.128');
assert.deepEqual(address.parts, ['0000', '0000', '0000', '0000','0000','ffff','c000','0280'], 'Checking parts');
});
test('Testing incorrect IPv6 addresses', function() {
QUnit.test('Testing incorrect IPv6 addresses', function(assert) {
var address = NET.ip_address('02001:0db8:85a3:0000:0000:8a2e:0370:7334');
ok(!address.valid, 'Too long part- 02001:0db8:85a3:0000:0000:8a2e:0370:7334');
assert.ok(!address.valid, 'Too long part- 02001:0db8:85a3:0000:0000:8a2e:0370:7334');
address = NET.ip_address('2001:db8:85a3:0:0:8a2e:370');
ok(!address.valid, 'Missing part - 2001:db8:85a3:0:0:8a2e:370');
assert.ok(!address.valid, 'Missing part - 2001:db8:85a3:0:0:8a2e:370');
address = NET.ip_address(':');
ok(!address.valid, 'Address - :');
assert.ok(!address.valid, 'Address - :');
address = NET.ip_address('::1::');
ok(!address.valid, 'Address - ::1::');
assert.ok(!address.valid, 'Address - ::1::');
address = NET.ip_address(':::');
ok(!address.valid, 'Address - :::');
assert.ok(!address.valid, 'Address - :::');
address = NET.ip_address('1::1::1');
ok(!address.valid, 'Address - 1::1::1');
assert.ok(!address.valid, 'Address - 1::1::1');
address = NET.ip_address('::ffff:192.0.0x2.128');
ok(!address.valid, 'With IPv4 hex part - ::ffff:192.0.0x2.128');
assert.ok(!address.valid, 'With IPv4 hex part - ::ffff:192.0.0x2.128');
address = NET.ip_address('::ffff:192.0.02.128');
ok(!address.valid, 'With IPv4 oct part - ::ffff:192.0.02.128');
assert.ok(!address.valid, 'With IPv4 oct part - ::ffff:192.0.02.128');
address = NET.ip_address('aa:rt::');
ok(!address.valid, 'Invalid chars - aa:rt::');
assert.ok(!address.valid, 'Invalid chars - aa:rt::');
});
test('Testing reverse addresses', function() {
QUnit.test('Testing reverse addresses', function(assert) {
var reverse_valid = '4.3.3.7.0.7.3.0.e.2.a.8.0.0.0.0.0.0.0.0.3.a.5.8.8.b.d.0.1.0.0.2.ip6.arpa';
var reverse = get_reverse('2001:0db8:85a3:0000:0000:8a2e:0370:7334');
same(reverse, reverse_valid, '2001:0db8:85a3:0000:0000:8a2e:0370:7334');
assert.deepEqual(reverse, reverse_valid, '2001:0db8:85a3:0000:0000:8a2e:0370:7334');
reverse = get_reverse('2001:db8:85a3::8a2e:370:7334');
same(reverse, reverse_valid, '2001:db8:85a3::8a2e:370:7334');
assert.deepEqual(reverse, reverse_valid, '2001:db8:85a3::8a2e:370:7334');
reverse_valid = '1.0.168.192.in-addr.arpa';
reverse = get_reverse('192.168.0.1');
same(reverse, reverse_valid, '192.168.0.1');
assert.deepEqual(reverse, reverse_valid, '192.168.0.1');
reverse_valid = '0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa';
reverse = get_reverse('::');
same(reverse, reverse_valid, '::');
assert.deepEqual(reverse, reverse_valid, '::');
reverse_valid = '1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa';
reverse = get_reverse('::1');
same(reverse, reverse_valid, '::1');
assert.deepEqual(reverse, reverse_valid, '::1');
reverse_valid = '0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.0.0.0.ip6.arpa';
reverse = get_reverse('1::');
same(reverse, reverse_valid, '1::');
assert.deepEqual(reverse, reverse_valid, '1::');
reverse_valid = '5.1.0.0.8.a.0.c.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa';
reverse = get_reverse('::192.168.0.21');
same(reverse, reverse_valid, '::192.168.0.21');
assert.deepEqual(reverse, reverse_valid, '::192.168.0.21');
reverse_valid = '255.254.253.252.in-addr.arpa';
reverse = get_reverse('0xFCFDFEFF');
same(reverse, reverse_valid, '0xFCFDFEFF');
assert.deepEqual(reverse, reverse_valid, '0xFCFDFEFF');
reverse = get_reverse('4244504319');
same(reverse, reverse_valid, '4244504319');
assert.deepEqual(reverse, reverse_valid, '4244504319');
reverse = get_reverse('037477377377');
same(reverse, reverse_valid, '037477377377');
assert.deepEqual(reverse, reverse_valid, '037477377377');
reverse_valid = '0.0.0.0.in-addr.arpa';
reverse = get_reverse('0');
same(reverse, reverse_valid, '0');
assert.deepEqual(reverse, reverse_valid, '0');
reverse = get_reverse('00');
same(reverse, reverse_valid, '00');
assert.deepEqual(reverse, reverse_valid, '00');
reverse = get_reverse('0x0');
same(reverse, reverse_valid, '0x0');
assert.deepEqual(reverse, reverse_valid, '0x0');
});
test('Usage - constructor direct input', function() {
QUnit.test('Usage - constructor direct input', function(assert) {
var address = NET.ip_address('0xC0A80001');
ok(address.valid, 'Valid');
same(address.type, 'v4-int', 'Checking type');
same(address.parts, ['192', '168', '0', '1'], 'Checking parts');
assert.ok(address.valid, 'Valid');
assert.deepEqual(address.type, 'v4-int', 'Checking type');
assert.deepEqual(address.parts, ['192', '168', '0', '1'], 'Checking parts');
var reverse_valid = '1.0.168.192.in-addr.arpa';
same(address.get_reverse(), reverse_valid, 'Checking reverse address');
assert.deepEqual(address.get_reverse(), reverse_valid, 'Checking reverse address');
});
test('Usage - constructor spec object', function() {
QUnit.test('Usage - constructor spec object', function(assert) {
var address = NET.ip_address({ address: '0xC0A80001' });
ok(address.valid, 'Valid');
same(address.type, 'v4-int', 'Checking type');
same(address.parts, ['192', '168', '0', '1'], 'Checking parts');
assert.ok(address.valid, 'Valid');
assert.deepEqual(address.type, 'v4-int', 'Checking type');
assert.deepEqual(address.parts, ['192', '168', '0', '1'], 'Checking parts');
var reverse_valid = '1.0.168.192.in-addr.arpa';
same(address.get_reverse(), reverse_valid, 'Checking reverse address');
assert.deepEqual(address.get_reverse(), reverse_valid, 'Checking reverse address');
});
test('Usage - constructor spec object - by parts', function() {
QUnit.test('Usage - constructor spec object - by parts', function(assert) {
var address = NET.ip_address({
parts: ['0xC0', '168', '00', '1'],
type: 'v4-quads'
});
ok(address.valid, 'Valid');
same(address.type, 'v4-quads', 'Checking type');
same(address.parts, ['192', '168', '0', '1'], 'Checking parts');
assert.ok(address.valid, 'Valid');
assert.deepEqual(address.type, 'v4-quads', 'Checking type');
assert.deepEqual(address.parts, ['192', '168', '0', '1'], 'Checking parts');
var reverse_valid = '1.0.168.192.in-addr.arpa';
same(address.get_reverse(), reverse_valid, 'Checking reverse address');
assert.deepEqual(address.get_reverse(), reverse_valid, 'Checking reverse address');
});
test('Usage - constructor spec object - by parts - IPv6', function() {
QUnit.test('Usage - constructor spec object - by parts - IPv6', function(assert) {
var address = NET.ip_address({
parts: ['2001','db8','85a3','0','0','8a2e','370','7334'],
type: 'v6'
});
ok(address.valid, 'Valid');
same(address.type, 'v6', 'Checking type');
same(address.parts, ['2001','0db8','85a3','0000','0000','8a2e','0370','7334'], 'Checking parts');
assert.ok(address.valid, 'Valid');
assert.deepEqual(address.type, 'v6', 'Checking type');
assert.deepEqual(address.parts, ['2001','0db8','85a3','0000','0000','8a2e','0370','7334'], 'Checking parts');
var reverse_valid = '4.3.3.7.0.7.3.0.e.2.a.8.0.0.0.0.0.0.0.0.3.a.5.8.8.b.d.0.1.0.0.2.ip6.arpa';
same(address.get_reverse(), reverse_valid, 'Checking reverse address');
assert.deepEqual(address.get_reverse(), reverse_valid, 'Checking reverse address');
});
test('Usage - set address.input', function() {
QUnit.test('Usage - set address.input', function(assert) {
var address = NET.ip_address();
ok(!address.valid, 'No input - invalid');
assert.ok(!address.valid, 'No input - invalid');
address.input = '192.168.0.1';
address.parse();
ok(address.valid, 'Valid');
same(address.type, 'v4-quads', 'Checking type');
same(address.parts, ['192', '168', '0', '1'], 'Checking parts');
assert.ok(address.valid, 'Valid');
assert.deepEqual(address.type, 'v4-quads', 'Checking type');
assert.deepEqual(address.parts, ['192', '168', '0', '1'], 'Checking parts');
var reverse_valid = '1.0.168.192.in-addr.arpa';
same(address.get_reverse(), reverse_valid, 'Checking reverse address');
assert.deepEqual(address.get_reverse(), reverse_valid, 'Checking reverse address');
});
test('Usage - set address.parts, no type', function() {
QUnit.test('Usage - set address.parts, no type', function(assert) {
var address = NET.ip_address();
ok(!address.valid, 'No input - invalid');
assert.ok(!address.valid, 'No input - invalid');
address.parts = ['192', '168', '0', '1'];
address.parse();
ok(!address.valid, 'Still invalid');
same(address.type, null, 'Checking type');
assert.ok(!address.valid, 'Still invalid');
assert.deepEqual(address.type, null, 'Checking type');
});
};});
};});

View File

@ -29,73 +29,72 @@ define([
function(IPA, $, rpc) {
return function() {
module('ipa');
QUnit.module('ipa', {
beforeEach: function(assert) {
var done = assert.async();
test("Testing ipa_init().", function() {
expect(1);
IPA.ajax_options.async = false;
IPA.init({
url: 'data',
on_success: function(data, text_status, xhr) {
ok(true, "ipa_init() succeeded.");
},
on_error: function(xhr, text_status, error_thrown) {
ok(false, "ipa_init() failed: "+error_thrown);
}
});
IPA.init({
url: 'data',
on_success: function(data, text_status, xhr) {
assert.ok(true, "ipa_init() succeeded.");
done();
},
on_error: function(xhr, text_status, error_thrown) {
assert.ok(false, "ipa_init() failed: "+error_thrown);
done();
}
});
}
});
test("Testing IPA.get_entity_param().", function() {
QUnit.test("Testing IPA.get_entity_param().", function(assert) {
var metadata = IPA.get_entity_param("user", "uid");
ok(
assert.ok(
metadata,
"IPA.get_entity_param(\"user\", \"uid\") not null");
equals(
assert.equal(
metadata["label"], "User login",
"IPA.get_entity_param(\"user\", \"uid\")[\"label\"]");
equals(
assert.equal(
IPA.get_entity_param("user", "wrong_attribute"), null,
"IPA.get_entity_param(\"user\", \"wrong_attribute\")");
equals(
assert.equal(
IPA.get_entity_param("user", null), null,
"IPA.get_entity_param(\"user\", null)");
equals(
assert.equal(
IPA.get_entity_param("wrong_entity", "uid"), null,
"IPA.get_entity_param(\"wrong_entity\", \"uid\")");
equals(
assert.equal(
IPA.get_entity_param(null, "uid"), null,
"IPA.get_entity_param(null, \"uid\")");
});
test("Testing IPA.get_member_attribute().", function() {
QUnit.test("Testing IPA.get_member_attribute().", function(assert) {
equals(
assert.equal(
IPA.get_member_attribute("user", "group"), "memberofindirect",
"IPA.get_member_attribute(\"user\", \"group\")");
equals(
assert.equal(
IPA.get_member_attribute("user", "host"), null,
"IPA.get_member_attribute(\"user\", \"host\")");
equals(
assert.equal(
IPA.get_member_attribute("user", null), null,
"IPA.get_member_attribute(\"user\", null)");
equals(
assert.equal(
IPA.get_member_attribute(null, "group"), null,
"IPA.get_member_attribute(null, \"group\")");
});
test("Testing successful rpc.command().", function() {
QUnit.test("Testing successful rpc.command().", function(assert) {
var method = 'method';
var args = ['arg1', 'arg2', 'arg3'];
@ -130,20 +129,20 @@ test("Testing successful rpc.command().", function() {
$.ajax = function(request) {
ajax_counter++;
equals(
assert.equal(
request.url, "data/"+object+"_"+method+".json",
"Checking request.url");
var data = JSON.parse(request.data);
equals(
assert.equal(
data.method, object+'_'+method,
"Checking method");
// By default all rpc calls contain version of API
$.extend(options, {'version': window.ipa_loader.api_version});
same(
assert.deepEqual(
data.params, [args, options],
"Checking parameters");
@ -159,24 +158,24 @@ test("Testing successful rpc.command().", function() {
on_error: error_handler
}).execute();
equals(
assert.equal(
ajax_counter, 1,
"Checking ajax invocation counter");
var dialog = $('[data-name=error_dialog]');
ok(
assert.ok(
dialog.length === 0,
"The dialog box is not created.");
ok(
assert.ok(
success_handler_counter === 1 && error_handler_counter === 0,
"Only the success handler is called.");
$.ajax = orig;
});
test("Testing unsuccessful rpc.command().", function() {
QUnit.test("Testing unsuccessful rpc.command().", function(assert) {
var method = 'method';
var args = ['arg1', 'arg2', 'arg3'];
@ -210,17 +209,17 @@ test("Testing unsuccessful rpc.command().", function() {
$.ajax = function(request) {
ajax_counter++;
equals(request.url, "data/"+object+"_"+method+".json",
assert.equal(request.url, "data/"+object+"_"+method+".json",
"Checking request.url");
var data = JSON.parse(request.data);
equals(data.method, object+'_'+method, "Checking method");
assert.equal(data.method, object+'_'+method, "Checking method");
// By default all rpc calls contain version of API
$.extend(options, { 'version': window.ipa_loader.api_version});
same(data.params, [args, options], "Checking parameters");
assert.deepEqual(data.params, [args, options], "Checking parameters");
// remove api version from options object
delete options.version;
@ -245,42 +244,42 @@ test("Testing unsuccessful rpc.command().", function() {
var dialog = $(dialog_selector);
equals(
assert.equal(
ajax_counter, 1,
"Checking ajax invocation counter");
ok(
assert.ok(
dialog.length === 1,
"The dialog box is created and open.");
ok(
assert.ok(
success_handler_counter === 0 && error_handler_counter === 0,
"Initially none of the handlers are called.");
click_button('retry');
equals(
assert.equal(
ajax_counter, 2,
"Checking ajax invocation counter");
ok(
assert.ok(
success_handler_counter === 0 && error_handler_counter === 0,
"After 1st retry, none of the handlers are called.");
click_button('retry');
equals(ajax_counter, 3,
assert.equal(ajax_counter, 3,
"Checking ajax invocation counter");
ok(success_handler_counter === 0 && error_handler_counter === 0,
assert.ok(success_handler_counter === 0 && error_handler_counter === 0,
"After 2nd retry, none of the handlers are called.");
click_button('cancel');
equals(ajax_counter, 3,
assert.equal(ajax_counter, 3,
"Checking ajax invocation counter");
ok(success_handler_counter === 0 && error_handler_counter === 1,
assert.ok(success_handler_counter === 0 && error_handler_counter === 1,
"Only the error handler is called.");
// cleanup - qunit doesn't really play well with asynchronous opening and
@ -292,8 +291,8 @@ test("Testing unsuccessful rpc.command().", function() {
$.ajax = orig;
});
test("Testing observer.", function() {
expect(6);
QUnit.test("Testing observer.", function(assert) {
assert.expect(7);
var obj = {};
var param1_value = 'p1';
var param2_value = 'p2';
@ -301,20 +300,20 @@ test("Testing observer.", function() {
obj.event = IPA.observer();
obj.event.attach(function(param1, param2) {
ok(true, "Proper function 1 callback");
assert.ok(true, "Proper function 1 callback");
});
var first = true;
var func = function(param1, param2) {
if(first) {
ok(true, "Proper function 2 callback");
equals(param1, param1_value, "Testing Parameter 1");
equals(param2, param2_value, "Testing Parameter 2");
equals(this, obj, "Testing Context");
assert.ok(true, "Proper function 2 callback");
assert.equal(param1, param1_value, "Testing Parameter 1");
assert.equal(param2, param2_value, "Testing Parameter 2");
assert.equal(this, obj, "Testing Context");
first = false;
} else {
ok(false, "Fail function 2 callback");
assert.ok(false, "Fail function 2 callback");
}
};

View File

@ -1,25 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>Navigation Test Suite</title>
<link rel="stylesheet" href="qunit.css" type="text/css" media="screen">
<script type="text/javascript" src="qunit.js"></script>
<script type="text/javascript" src="../js/libs/loader.js"></script>
<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="config.js"></script>
<script type="text/javascript" src="../js/dojo/dojo.js"></script>
<script type="text/javascript">
require(['test/navigation_tests'], function(tests){ tests() });
</script>
</head>
<body>
<h1 id="qunit-header">Navigation 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>

View File

@ -1,225 +0,0 @@
/* Authors:
* Adam Young <ayoung@redhat.com>
*
* Copyright (C) 2010 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/ipa', 'freeipa/jquery', 'freeipa/navigation', 'freeipa/entity'],
function(IPA, $) {
return function() {
module('navigation', {
// setup: function() {
// IPA.ajax_options.async = false;
// IPA.init({
// url: 'data',
// on_error: function(xhr, text_status, error_thrown) {
// ok(false, 'ipa_init() failed: '+error_thrown);
// }
// });
// }
});
test("Testing IPA.navigation.create().", function() {
// var entity;
// var user_mock_called = false;
// var group_mock_called = false;
// //Force reset of entities
// IPA.entities = $.ordered_map();
//
// IPA.register('user', function(spec) {
//
// var that = IPA.entity({
// name: 'user',
// metadata: IPA.metadata.objects.user,
// facets: [
// {
// type: 'search'
// }
// ]
// });
//
// that.display = function(container){
// user_mock_called = true;
// same(container.attr('name'), 'user', 'user container name');
// same(container[0].nodeName, 'DIV', 'user container element');
// };
//
// return that;
// });
//
// IPA.register('group', function(spec) {
//
// var that = IPA.entity({
// name: 'group',
// metadata: IPA.metadata.objects.group
// });
//
// that.display = function(container){
// group_mock_called = true;
// same(container.attr('name'), 'group','user container name');
// same(container[0].nodeName, 'DIV', 'user container element');
// };
//
// return that;
// });
//
// var navigation_container = $('<div id="navigation"/>').appendTo(document.body);
// var entity_container = $('<div id="content"/>').appendTo(document.body);
//
// var navigation = IPA.navigation({
// container: navigation_container,
// content: entity_container,
// tabs: [
// { name:'identity', label:'IDENTITY', children: [
// {name:'user', entity:'user'},
// {name:'group', entity:'group'}
// ]}
// ]
// });
//
// navigation.create();
// navigation.update();
//
// ok(user_mock_called, "mock user setup was called");
// ok(!group_mock_called, "mock group setup was not called because the tab is inactive");
//
// var tabs_container = navigation_container.children('div');
//
// var level1_tabs = tabs_container.children('div');
// same(level1_tabs.length, 1, "One level 1 tab");
//
// var identity_tab = level1_tabs.first();
// same(identity_tab.attr('name'), 'identity', "Identity Tab");
//
// var level2_tabs = identity_tab.children('div');
// same(level2_tabs.length, 2, "Two level 2 tabs");
//
// var user_tab = level2_tabs.first();
// same(user_tab.attr('name'), 'user', "User Tab");
//
// var group_tab = user_tab.next();
// same(group_tab.attr('name'), 'group', "Group Tab");
//
// entity_container.remove();
// navigation_container.remove();
});
test("Testing IPA.navigation.update() with valid index.", function() {
// var navigation_container = $('<div id="navigation"/>').appendTo(document.body);
// var entity_container = $('<div id="content"/>').appendTo(document.body);
//
// var navigation = IPA.navigation({
// container: navigation_container,
// content: entity_container,
// tabs: [
// { name:'identity', label:'IDENTITY', children: [
// {name:'one', label:'One'},
// {name:'two', label:'Two'}
// ]}
// ]
// });
//
// var state = {};
//
// navigation.push_state = function(params) {
// $.extend(state, params);
// };
//
// navigation.get_state = function(key) {
// return key ? state[key] : {};
// };
//
// navigation.remove_state = function(key) {
// delete state[key];
// };
//
// navigation.create();
// navigation.push_state({'identity': 'two'});
// navigation.update();
//
// var tabs_container = navigation_container.children('div');
//
// same(
// tabs_container.tabs('option', 'selected'), 0,
// "Active tab at level 1");
//
// same(
// $('.tabs[name=identity]', tabs_container).tabs('option', 'selected'), 1,
// "Active tab at level 2");
//
// navigation.remove_state("identity");
//
// entity_container.remove();
// navigation_container.remove();
// });
//
// test("Testing IPA.navigation.update() with out-of-range index.", function() {
//
// var navigation_container = $('<div id="navigation"/>').appendTo(document.body);
// var entity_container = $('<div id="content"/>').appendTo(document.body);
//
// var navigation = IPA.navigation({
// container: navigation_container,
// content: entity_container,
// tabs: [
// { name:'identity', label:'IDENTITY', children: [
// {name:'one', label:'One', setup: function (){}},
// {name:'two', label:'Two', setup: function (){}}
// ]}
// ]
// });
//
// var state = {};
//
// navigation.push_state = function(params) {
// $.extend(state, params);
// };
//
// navigation.get_state = function(key) {
// return key ? state[key] : {};
// };
//
// navigation.remove_state = function(key) {
// delete state[key];
// };
//
// navigation.create();
// navigation.push_state({'identity': 'three'});
// navigation.update();
//
// var tabs_container = navigation_container.children('div');
//
// same(
// tabs_container.tabs('option', 'selected'), 0,
// "Active tab at level 1");
//
// same(
// $('.tabs[name=identity]', tabs_container).tabs('option', 'selected'), 0,
// "Active tab at level 2");
//
// navigation.remove_state("identity");
//
// entity_container.remove();
// navigation_container.remove();
});
};});

View File

@ -18,21 +18,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
define(['freeipa/jquery'], function($) {
define(['freeipa/jquery'], function($) {
return function() {
QUnit.module('ordered_map');
module('ordered_map');
test("Testing $.ordered_map constructor.", function() {
QUnit.test("Testing $.ordered_map constructor.", function(assert) {
var test = $.ordered_map();
strictEqual(test.length, 0, "Checking length.");
deepEqual(test.keys, [], "Checking keys.");
deepEqual(test.values, [], "Checking values.");
assert.strictEqual(test.length, 0, "Checking length.");
assert.deepEqual(test.keys, [], "Checking keys.");
assert.deepEqual(test.values, [], "Checking values.");
});
test("Testing $.ordered_map.put().", function() {
QUnit.test("Testing $.ordered_map.put().", function(assert) {
var test = $.ordered_map();
@ -80,12 +79,12 @@ test("Testing $.ordered_map.put().", function() {
test.put(key7, value7, 100); //put at end
test.put(key8, value8, 'foobar'); //put at end
strictEqual(test.length, 8, 'Checking length.');
deepEqual(test.keys, [key5, key4, key1, key3, key2, key6, key7, key8], 'Checking keys.');
deepEqual(test.values, [value5, value4, value1, value3, value2, value6, value7, value8], 'Checking values.');
assert.strictEqual(test.length, 8, 'Checking length.');
assert.deepEqual(test.keys, [key5, key4, key1, key3, key2, key6, key7, key8], 'Checking keys.');
assert.deepEqual(test.values, [value5, value4, value1, value3, value2, value6, value7, value8], 'Checking values.');
});
test("Testing $.ordered_map.get().", function() {
QUnit.test("Testing $.ordered_map.get().", function(assert) {
var test = $.ordered_map();
@ -105,14 +104,14 @@ test("Testing $.ordered_map.get().", function() {
var result1 = test.get(key1);
var result2 = test.get(key2);
strictEqual(test.length, 2, 'Checking length.');
deepEqual(test.keys, [key1, key2], 'Checking keys.');
deepEqual(test.values, [value1, value2], 'Checking values.');
strictEqual(result1, value1, 'Checking result 1.');
strictEqual(result2, value2, 'Checking result 2.');
assert.strictEqual(test.length, 2, 'Checking length.');
assert.deepEqual(test.keys, [key1, key2], 'Checking keys.');
assert.deepEqual(test.values, [value1, value2], 'Checking values.');
assert.strictEqual(result1, value1, 'Checking result 1.');
assert.strictEqual(result2, value2, 'Checking result 2.');
});
test("Testing $.ordered_map.remove().", function() {
QUnit.test("Testing $.ordered_map.remove().", function(assert) {
var test = $.ordered_map();
@ -130,13 +129,13 @@ test("Testing $.ordered_map.remove().", function() {
var result1 = test.remove(key1);
strictEqual(test.length, 1, 'Checking length.');
deepEqual(test.keys, [key2], 'Checking keys.');
deepEqual(test.values, [value2], 'Checking values.');
strictEqual(result1, value1, 'Checking result.');
assert.strictEqual(test.length, 1, 'Checking length.');
assert.deepEqual(test.keys, [key2], 'Checking keys.');
assert.deepEqual(test.values, [value2], 'Checking values.');
assert.strictEqual(result1, value1, 'Checking result.');
});
test("Testing $.ordered_map.empty().", function() {
QUnit.test("Testing $.ordered_map.empty().", function(assert) {
var test = $.ordered_map();
@ -151,9 +150,9 @@ test("Testing $.ordered_map.empty().", function() {
test.empty();
strictEqual(test.length, 0, 'Checking length.');
deepEqual(test.keys, [], 'Checking keys.');
deepEqual(test.values, [], 'Checking values.');
assert.strictEqual(test.length, 0, 'Checking length.');
assert.deepEqual(test.keys, [], 'Checking keys.');
assert.deepEqual(test.values, [], 'Checking values.');
});
};});
};});

View File

@ -29,9 +29,9 @@ define([
var old;
module('utils',{
QUnit.module('utils',{
setup: function() {
beforeEach: function() {
old = IPA.messages;
IPA.messages = {
widget: {
@ -45,12 +45,12 @@ module('utils',{
}
};
},
teardown: function() {
afterEach: function() {
IPA.messages = old;
}
});
test('Testing metadata validator', function() {
QUnit.test('Testing metadata validator', function(assert) {
// using strings as values because it is an output of inputs
@ -69,24 +69,24 @@ test('Testing metadata validator', function() {
var value;
value = "50";
ok(validator.validate(value, context).valid, 'Checking lower maximun, alphabetically higher');
assert.ok(validator.validate(value, context).valid, 'Checking lower maximun, alphabetically higher');
value = "200";
ok(validator.validate(value, context).valid, 'Checking higher minimum, alphabetically lower');
assert.ok(validator.validate(value, context).valid, 'Checking higher minimum, alphabetically lower');
value = "29";
ok(!validator.validate(value, context).valid, 'Checking below minimum');
assert.ok(!validator.validate(value, context).valid, 'Checking below minimum');
value = "301";
ok(!validator.validate(value, context).valid, 'Checking above maximum');
assert.ok(!validator.validate(value, context).valid, 'Checking above maximum');
context.metadata.minvalue = 0;
value = "-1";
ok(!validator.validate(value, context).valid, 'Checking zero minimum - below');
assert.ok(!validator.validate(value, context).valid, 'Checking zero minimum - below');
value = "0";
ok(validator.validate(value, context).valid, 'Checking zero minimum - above');
assert.ok(validator.validate(value, context).valid, 'Checking zero minimum - above');
value = "1";
ok(validator.validate(value, context).valid, 'Checking zero minimum - same');
assert.ok(validator.validate(value, context).valid, 'Checking zero minimum - same');
context.metadata = {
type: 'int',
@ -94,21 +94,21 @@ test('Testing metadata validator', function() {
minvalue: ""
};
ok(validator.validate(value, context).valid, 'Checking empty strings as boundaries');
assert.ok(validator.validate(value, context).valid, 'Checking empty strings as boundaries');
context.metadata = {
type: 'int',
maxvalue: null,
minvalue: null
};
ok(validator.validate(value, context).valid, 'Checking null as boundaries');
assert.ok(validator.validate(value, context).valid, 'Checking null as boundaries');
context.metadata = {
type: 'int',
maxvalue: undefined,
minvalue: undefined
};
ok(validator.validate(value, context).valid, 'Checking undefined as boundaries');
assert.ok(validator.validate(value, context).valid, 'Checking undefined as boundaries');
context.metadata = {
type: 'Decimal',
@ -117,51 +117,51 @@ test('Testing metadata validator', function() {
};
value = "10.333";
ok(validator.validate(value, context).valid, 'Decimal: checking maximum');
assert.ok(validator.validate(value, context).valid, 'Decimal: checking maximum');
value = "10.3331";
ok(!validator.validate(value, context).valid, 'Decimal: checking maximum - invalid');
assert.ok(!validator.validate(value, context).valid, 'Decimal: checking maximum - invalid');
value = "-10.333";
ok(validator.validate(value, context).valid, 'Decimal: checking minimum');
assert.ok(validator.validate(value, context).valid, 'Decimal: checking minimum');
value = "-10.3331";
ok(!validator.validate(value, context).valid, 'Decimal: checking minimum - invalid');
assert.ok(!validator.validate(value, context).valid, 'Decimal: checking minimum - invalid');
});
test('Testing IPA.defined', function() {
QUnit.test('Testing IPA.defined', function(assert) {
// positive
same(IPA.defined({}), true, 'Object');
same(IPA.defined(0), true, 'Zero number');
same(IPA.defined(1), true, 'Some number');
same(IPA.defined(false), true, 'false');
same(IPA.defined(true), true, 'true');
same(IPA.defined(function(){}), true, 'function');
same(IPA.defined(''), true, 'Empty string - not checking');
assert.deepEqual(IPA.defined({}), true, 'Object');
assert.deepEqual(IPA.defined(0), true, 'Zero number');
assert.deepEqual(IPA.defined(1), true, 'Some number');
assert.deepEqual(IPA.defined(false), true, 'false');
assert.deepEqual(IPA.defined(true), true, 'true');
assert.deepEqual(IPA.defined(function(){}), true, 'function');
assert.deepEqual(IPA.defined(''), true, 'Empty string - not checking');
// negative
same(IPA.defined('', true), false, 'Empty string - checking');
same(IPA.defined(undefined), false, 'undefined');
same(IPA.defined(null), false, 'null');
assert.deepEqual(IPA.defined('', true), false, 'Empty string - checking');
assert.deepEqual(IPA.defined(undefined), false, 'undefined');
assert.deepEqual(IPA.defined(null), false, 'null');
});
test('Testing util.equals', function() {
QUnit.test('Testing util.equals', function(assert) {
ok(util.equals([], []), 'Empty Arrays');
ok(util.equals([1, "a", false, true], [1, "a", false, true]), 'Arrays');
ok(util.equals(true, true), 'Boolean: true');
ok(util.equals(false, false), 'Boolean: false');
ok(!util.equals(true, false), 'Negative: boolean');
ok(!util.equals(false, true), 'Negative: boolean');
ok(util.equals("abc", "abc"), 'Positive: strings');
ok(!util.equals("abc", "aBC"), 'Negative: string casing');
ok(util.equals(1, 1), 'Positive: number');
ok(util.equals(1.0, 1), 'Positive: number');
ok(util.equals(2.2, 2.2), 'Positive: number');
assert.ok(util.equals([], []), 'Empty Arrays');
assert.ok(util.equals([1, "a", false, true], [1, "a", false, true]), 'Arrays');
assert.ok(util.equals(true, true), 'Boolean: true');
assert.ok(util.equals(false, false), 'Boolean: false');
assert.ok(!util.equals(true, false), 'Negative: boolean');
assert.ok(!util.equals(false, true), 'Negative: boolean');
assert.ok(util.equals("abc", "abc"), 'Positive: strings');
assert.ok(!util.equals("abc", "aBC"), 'Negative: string casing');
assert.ok(util.equals(1, 1), 'Positive: number');
assert.ok(util.equals(1.0, 1), 'Positive: number');
assert.ok(util.equals(2.2, 2.2), 'Positive: number');
ok(!util.equals([], [""]), 'Negative: empty array');
assert.ok(!util.equals([], [""]), 'Negative: empty array');
});
test('Testing datetime', function() {
QUnit.test('Testing datetime', function(assert) {
var valid = [
// [format, str, data, utc, output]
@ -219,19 +219,19 @@ test('Testing datetime', function() {
var parsed = datetime.parse(str);
ok(parsed, "Parse successful: "+str);
assert.ok(parsed, "Parse successful: "+str);
if (!parsed) return; // don't die for other tests
strictEqual(parsed.getTime(), expected.getTime(), "Valid date: "+str);
assert.strictEqual(parsed.getTime(), expected.getTime(), "Valid date: "+str);
var formatted = datetime.format(parsed, format, !utc);
expected = output || str;
strictEqual(formatted, expected, "Format: "+format);
assert.strictEqual(formatted, expected, "Format: "+format);
}
function test_invalid(str, utc) {
datetime.allow_local = !utc;
var parsed = datetime.parse(str);
strictEqual(parsed, null, "Parse invalid date: "+str);
assert.strictEqual(parsed, null, "Parse invalid date: "+str);
}
for (i=0, l=valid.length; i < l; i++) {
@ -243,4 +243,4 @@ test('Testing datetime', function() {
}
});
};});
};});

View File

@ -34,13 +34,13 @@ var factory;
var spec;
module('widget',{
setup: function() {
QUnit.module('widget',{
beforeEach: function(assert) {
IPA.ajax_options.async = false;
IPA.init({
url: 'data',
on_error: function(xhr, text_status, error_thrown) {
ok(false, "ipa_init() failed: "+error_thrown);
assert.ok(false, "ipa_init() failed: "+error_thrown);
}
});
widget_container = $('<div id="widget"/>').appendTo(document.body);
@ -52,13 +52,13 @@ module('widget',{
group.register();
},
teardown: function() {
afterEach: function() {
widget_container.remove();
}}
);
function base_widget_test(value){
function base_widget_test(assert, value){
spec.entity = {
name:'user'
};
@ -66,7 +66,7 @@ function base_widget_test(value){
widget = factory(spec);
var field_name = widget.name;
ok(widget, "Created Widget");
assert.ok(widget, "Created Widget");
//init reads param info for an entity. We'll use the user entity
widget.name = field_name;
@ -75,32 +75,32 @@ function base_widget_test(value){
// ok(widget.tooltip,'widget with entity and name has tooltip');
ok(!widget.container,'widget has no container before create');
assert.ok(!widget.container,'widget has no container before create');
widget.create(widget_container);
ok(widget.container,'widget has container after create');
assert.ok(widget.container,'widget has container after create');
}
function widget_string_test() {
function widget_string_test(assert) {
var value = 'test_title';
var mock_record = {'title': value};
widget.update(mock_record.title);
ok(widget.save() instanceof Array,'save returns array');
assert.ok(widget.save() instanceof Array,'save returns array');
mock_record = {'title':[value]};
widget.update(mock_record.title);
ok(widget.save() instanceof Array,'save returns array');
assert.ok(widget.save() instanceof Array,'save returns array');
}
function text_tests(widget,input){
function text_tests(assert, widget, input){
var value_changed = false;
var undo_clicked = false;
@ -115,15 +115,15 @@ function text_tests(widget,input){
input.val('changed');
input.keyup();
same(widget.save(),['changed'], "Setting Value");
same(value_changed, true, "Click triggers value_changed");
assert.deepEqual(widget.save(),['changed'], "Setting Value");
assert.deepEqual(value_changed, true, "Click triggers value_changed");
var undo = widget.get_undo();
undo.click();
same(undo_clicked, true, "Click on 'undo' triggers undo_clicked");
assert.deepEqual(undo_clicked, true, "Click on 'undo' triggers undo_clicked");
}
function multivalued_text_tests(widget) {
function multivalued_text_tests(assert, widget) {
var values = ['val1', 'val2', 'val3'];
var changed = false;
@ -134,23 +134,23 @@ function multivalued_text_tests(widget) {
widget.update(values);
same(widget.save(), values, "All values loaded");
assert.deepEqual(widget.save(), values, "All values loaded");
values = ['val1', 'val2', 'val3', 'val4'];
widget.add_row(['val4']);
same(widget.save(), values, "Value added");
ok(changed, "Value changed");
assert.deepEqual(widget.save(), values, "Value added");
assert.ok(changed, "Value changed");
changed = false;
values = ['val1', 'val3', 'val4'];
widget.remove_row(widget.rows[1]);
same(widget.save(), values, "Value removed");
ok(changed, "Value changed");
assert.deepEqual(widget.save(), values, "Value removed");
assert.ok(changed, "Value changed");
changed = false;
}
test("IPA.table_widget" ,function(){
QUnit.test("IPA.table_widget" , function(assert) {
factory = IPA.table_widget;
spec = {
undo:true,
@ -175,9 +175,9 @@ test("IPA.table_widget" ,function(){
width:'20em'
}));
ok(!widget.container,'widget has no container before create');
assert.ok(!widget.container,'widget has no container before create');
widget.create(widget_container);
ok(widget.container,'widget has container after create');
assert.ok(widget.container,'widget has container after create');
var mock_results = {
@ -187,72 +187,72 @@ test("IPA.table_widget" ,function(){
widget.load(mock_results);
same ($('tr' ,widget_container).length, 4, 'four rows after load');
assert.deepEqual($('tr' ,widget_container).length, 4, 'four rows after load');
});
test("Testing base widget.", function() {
QUnit.test("Testing base widget.", function(assert) {
var update_called = false;
spec = {
name:'title'
};
factory = IPA.input_widget;
base_widget_test('test_value');
widget_string_test();
base_widget_test(assert, 'test_value');
widget_string_test(assert);
});
test("IPA.textarea_widget" ,function(){
QUnit.test("IPA.textarea_widget" , function(assert) {
spec = {undo:true,name:'title'};
factory = IPA.textarea_widget;
base_widget_test('test_value');
widget_string_test();
text_tests(widget, $('textarea',widget_container));
base_widget_test(assert, 'test_value');
widget_string_test(assert);
text_tests(assert, widget, $('textarea',widget_container));
});
test("Testing text widget.", function() {
QUnit.test("Testing text widget.", function(assert) {
factory = IPA.text_widget;
spec = {undo:true,name:'title'};
base_widget_test('test_value');
widget_string_test();
text_tests(widget, $('input[type=text]',widget_container));
base_widget_test(assert, 'test_value');
widget_string_test(assert);
text_tests(assert, widget, $('input[type=text]',widget_container));
});
test("Testing multi-valued text widget.", function() {
QUnit.test("Testing multi-valued text widget.", function(assert) {
factory = IPA.multivalued_widget;
spec = {undo:true,name:'title'};
base_widget_test('test_value');
widget_string_test();
multivalued_text_tests(widget);
base_widget_test(assert, 'test_value');
widget_string_test(assert);
multivalued_text_tests(assert, widget);
});
test("Testing checkbox widget.", function() {
QUnit.test("Testing checkbox widget.", function(assert) {
factory = IPA.checkbox_widget;
spec = {name:'title'};
base_widget_test('test_value');
base_widget_test(assert, 'test_value');
//Changing mock record from 'TRUE' to true. Value normalization is field's
//job. Checkbox should work with booleans values.
var mock_record = { 'title': [true] };
widget.update(mock_record.title);
same(widget.save(),[true], "Checkbox is set");
assert.deepEqual(widget.save(),[true], "Checkbox is set");
mock_record = {'title':null};
widget.update(mock_record.title);
same(widget.save(), [false], "Checkbox is not set");
assert.deepEqual(widget.save(), [false], "Checkbox is not set");
var input = $('input[type=checkbox]',widget_container);
same(input.length,1,'One control in the container');
assert.deepEqual(input.length,1,'One control in the container');
var value_changed = false;
widget.value_changed.attach(function() {
@ -261,29 +261,29 @@ test("Testing checkbox widget.", function() {
input.click();
same(widget.save(),[true], "Click sets checkbox");
same(value_changed, true, "Click triggers value_changed");
assert.deepEqual(widget.save(),[true], "Click sets checkbox");
assert.deepEqual(value_changed, true, "Click triggers value_changed");
});
test("IPA.checkboxes_widget" ,function(){
QUnit.test("IPA.checkboxes_widget" ,function(assert){
factory = IPA.checkboxes_widget;
spec = {undo:true, name:'title' };
base_widget_test('test_value');
base_widget_test(assert, 'test_value');
});
test("IPA.select_widget" ,function(){
QUnit.test("IPA.select_widget" ,function(assert){
factory = IPA.select_widget;
spec = {undo:true,name:'title'};
base_widget_test('test_value');
base_widget_test(assert, 'test_value');
});
test("IPA.entity_select_widget" ,function() {
QUnit.test("IPA.entity_select_widget" ,function(assert) {
var user = IPA.entity({ name: 'user' });
factory = IPA.entity_select_widget;
spec = {
@ -292,17 +292,17 @@ test("IPA.entity_select_widget" ,function() {
other_field: 'uid'
};
base_widget_test('test_value');
base_widget_test(assert, 'test_value');
var mock_record = { uid: ['kfrog']};
widget.update(mock_record.uid);
ok($('option', widget.list).length > 1,"options come from AJAX");
assert.ok($('option', widget.list).length > 1,"options come from AJAX");
var value = widget.save();
same(value, ['kfrog'],'select set from values');
assert.deepEqual(value, ['kfrog'],'select set from values');
});
test("IPA.entity_link_widget" ,function(){
QUnit.test("IPA.entity_link_widget" , function(assert){
factory = IPA.link_widget;
spec = {
name: 'gidnumber',
@ -311,7 +311,7 @@ test("IPA.entity_link_widget" ,function(){
return ['kfrog'];
}
};
base_widget_test(widget,'user','test_value');
base_widget_test(assert, widget,'user','test_value');
var mock_entity = {
get_primary_key: function(){
@ -324,42 +324,42 @@ test("IPA.entity_link_widget" ,function(){
var nonlink = widget_container.find('label');
var link = widget_container.find('a');
ok(nonlink.length === 1, "Only one <label> element exists");
ok(link.length === 1, "Only one <a> element exists");
assert.ok(nonlink.length === 1, "Only one <label> element exists");
assert.ok(link.length === 1, "Only one <a> element exists");
var mock_record = { gidnumber: ['123456']};
widget.update(mock_record.gidnumber);
link = widget_container.find('a:contains("123456")');
same(link.length, 1,'link is populated');
same(link.css('display'), 'inline','link is displayed');
same(widget.nonlink.css('display'), 'none','text is not displayed');
assert.deepEqual(link.length, 1,'link is populated');
assert.deepEqual(link.css('display'), 'inline','link is displayed');
assert.deepEqual(widget.nonlink.css('display'), 'none','text is not displayed');
});
test("IPA.radio_widget" ,function(){
QUnit.test("IPA.radio_widget" , function(assert){
var options = [{label:"Engineer",value:"engineer"},
{label:"Manager", value:"manager"},
{label:"Director",value:"director"},
{label:"Vice President",value:"VP"}];
factory = IPA.radio_widget;
spec = {undo:true, name: 'title',options:options};
base_widget_test('test_value');
base_widget_test(assert, 'test_value');
var mock_record = {'title':["director"]};
widget.update(mock_record.title);
var values = widget.save();
same(values[0],'director','Options set correctly');
assert.deepEqual(values[0],'director','Options set correctly');
mock_record = { title: ["VP"]};
widget.update(mock_record.title);
values = widget.save();
same(values[0],'VP','Options set correctly');
assert.deepEqual(values[0],'VP','Options set correctly');
var i =0;
$('label', widget_container).each( function(){
same( $(this).text(),options[i].label, 'labels match');
assert.deepEqual($(this).text(),options[i].label, 'labels match');
i += 1;
});