mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
core widget unit tests baseline set of unit tests for checking that each widget conforms to the contract
This commit is contained in:
parent
04ba37500b
commit
2518612b0d
@ -372,12 +372,6 @@ IPA.details_section = function (spec){
|
||||
return field;
|
||||
};
|
||||
|
||||
that.create_button = function(spec) {
|
||||
var field = IPA.button_widget(spec);
|
||||
that.add_field(field);
|
||||
return field;
|
||||
};
|
||||
|
||||
that.init = function() {
|
||||
for (var i=0; i<that.fields.length; i++) {
|
||||
var field = that.fields[i];
|
||||
|
@ -1,22 +1,19 @@
|
||||
{
|
||||
"error": null,
|
||||
"id": 0,
|
||||
"id": 4,
|
||||
"result": {
|
||||
"result": {
|
||||
"aciname": "delegme",
|
||||
"aciname": "test-deleg",
|
||||
"attrs": [
|
||||
"cn"
|
||||
],
|
||||
"filter": "(memberOf=cn=ipausers,cn=groups,cn=accounts,dc=ayoung,dc=boston,dc=devel,dc=redhat,dc=com)",
|
||||
"group": "admins",
|
||||
"membergroup": [
|
||||
"admins"
|
||||
"audio"
|
||||
],
|
||||
"group": "ipausers",
|
||||
"memberof": "editors",
|
||||
"permissions": [
|
||||
"write"
|
||||
]
|
||||
},
|
||||
"summary": null,
|
||||
"value": "delegme"
|
||||
"value": "test-deleg"
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"error": null,
|
||||
"id": 0,
|
||||
"id": 2,
|
||||
"result": {
|
||||
"count": 5,
|
||||
"result": [
|
||||
@ -11,9 +11,9 @@
|
||||
"description": [
|
||||
"Account administrators group"
|
||||
],
|
||||
"dn": "cn=admins,cn=groups,cn=accounts,dc=ayoung,dc=boston,dc=devel,dc=redhat,dc=com",
|
||||
"dn": "cn=admins,cn=groups,cn=accounts,dc=ipa14,dc=ayoung,dc=boston,dc=devel,dc=redhat,dc=com",
|
||||
"gidnumber": [
|
||||
"1948497956"
|
||||
"1420800000"
|
||||
],
|
||||
"member_user": [
|
||||
"admin"
|
||||
@ -26,13 +26,17 @@
|
||||
"description": [
|
||||
"Default group for all users"
|
||||
],
|
||||
"dn": "cn=ipausers,cn=groups,cn=accounts,dc=ayoung,dc=boston,dc=devel,dc=redhat,dc=com",
|
||||
"dn": "cn=ipausers,cn=groups,cn=accounts,dc=ipa14,dc=ayoung,dc=boston,dc=devel,dc=redhat,dc=com",
|
||||
"gidnumber": [
|
||||
"1948497957"
|
||||
"1420800001"
|
||||
],
|
||||
"member_user": [
|
||||
"kfrog",
|
||||
"moi"
|
||||
"count123",
|
||||
"scram",
|
||||
"elmo",
|
||||
"zoe",
|
||||
"pdawn"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -42,34 +46,37 @@
|
||||
"description": [
|
||||
"Limited admins who can edit other users"
|
||||
],
|
||||
"dn": "cn=editors,cn=groups,cn=accounts,dc=ayoung,dc=boston,dc=devel,dc=redhat,dc=com",
|
||||
"dn": "cn=editors,cn=groups,cn=accounts,dc=ipa14,dc=ayoung,dc=boston,dc=devel,dc=redhat,dc=com",
|
||||
"gidnumber": [
|
||||
"1948497958"
|
||||
"1420800002"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cn": [
|
||||
"deleteme"
|
||||
"monsters"
|
||||
],
|
||||
"description": [
|
||||
"This is a group that should go away."
|
||||
"Monsters on Sesame Street"
|
||||
],
|
||||
"dn": "cn=deleteme,cn=groups,cn=accounts,dc=ayoung,dc=boston,dc=devel,dc=redhat,dc=com"
|
||||
"dn": "cn=monsters,cn=groups,cn=accounts,dc=ipa14,dc=ayoung,dc=boston,dc=devel,dc=redhat,dc=com",
|
||||
"gidnumber": [
|
||||
"1420800009"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cn": [
|
||||
"testgroup"
|
||||
"muppets"
|
||||
],
|
||||
"description": [
|
||||
"Detlete this if you see it"
|
||||
"Muppets moonlighting for CTW"
|
||||
],
|
||||
"dn": "cn=testgroup,cn=groups,cn=accounts,dc=ayoung,dc=boston,dc=devel,dc=redhat,dc=com",
|
||||
"dn": "cn=muppets,cn=groups,cn=accounts,dc=ipa14,dc=ayoung,dc=boston,dc=devel,dc=redhat,dc=com",
|
||||
"gidnumber": [
|
||||
"1948497959"
|
||||
"1420800010"
|
||||
]
|
||||
}
|
||||
],
|
||||
"summary": "5 groups matched",
|
||||
"truncated": false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -29,7 +29,6 @@ module('widget',{
|
||||
"data",
|
||||
true,
|
||||
function(data, text_status, xhr) {
|
||||
ok(true, "ipa_init() succeeded.");
|
||||
},
|
||||
function(xhr, text_status, error_thrown) {
|
||||
ok(false, "ipa_init() failed: "+error_thrown);
|
||||
@ -42,9 +41,8 @@ module('widget',{
|
||||
}}
|
||||
);
|
||||
|
||||
|
||||
|
||||
function base_widget_test(widget,entity_name, field_name,value){
|
||||
function base_widget_test(widget,entity_name, value){
|
||||
var field_name = widget.name;
|
||||
ok (widget, "Created Widget");
|
||||
widget.init();
|
||||
ok(!widget.label,'widget with no entity has no label');
|
||||
@ -85,29 +83,10 @@ function widget_string_test(widget, value){
|
||||
|
||||
}
|
||||
|
||||
test("Testing base widget.", function() {
|
||||
var update_called = false;
|
||||
var spec = {
|
||||
update:function(){
|
||||
update_called = true;
|
||||
}
|
||||
};
|
||||
|
||||
var widget = IPA.widget(spec);
|
||||
base_widget_test(widget,'user','title','test_value');
|
||||
widget_string_test(widget);
|
||||
ok (update_called, 'Update called');
|
||||
|
||||
});
|
||||
|
||||
|
||||
test("Testing text widget.", function() {
|
||||
var widget = IPA.text_widget({undo:true});
|
||||
base_widget_test(widget,'user','title','test_value');
|
||||
widget_string_test(widget);
|
||||
function text_tests(widget,input){
|
||||
|
||||
|
||||
var input = $('input[type=text]',widget_container);
|
||||
input.val('changed');
|
||||
input.keyup();
|
||||
same(widget.save(),['changed'], "Setting Value");
|
||||
@ -136,11 +115,85 @@ test("Testing text widget.", function() {
|
||||
|
||||
widget.param_info.pattern = old_pattern;
|
||||
|
||||
}
|
||||
|
||||
test("IPA.table_widget" ,function(){
|
||||
var widget = IPA.table_widget({undo:true,name:'users'});
|
||||
|
||||
widget.add_column(IPA.column({
|
||||
name:'uid',
|
||||
label:'User ID',
|
||||
primary_key:'uid',
|
||||
width:'20em',
|
||||
entity_name:'user'
|
||||
}));
|
||||
widget.add_column(IPA.column({
|
||||
name:'title',
|
||||
lable:'Title',
|
||||
primary_key:'uid',
|
||||
width:'20em',
|
||||
entity_name:'user'
|
||||
}));
|
||||
|
||||
widget.init();
|
||||
|
||||
ok(!widget.container,'widget has no container before setup');
|
||||
widget.create(widget_container);
|
||||
widget.setup(widget_container);
|
||||
|
||||
ok(widget.container,'widget has container after setup');
|
||||
|
||||
|
||||
var mock_results = {
|
||||
users:[{ uid: 'kfrog', title:'reporter' },
|
||||
{ uid: 'grover',title:'waiter' }]
|
||||
};
|
||||
|
||||
widget.load(mock_results);
|
||||
|
||||
same ($('tr' ,widget_container).length, 4, 'four rows after load');
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
test("Testing base widget.", function() {
|
||||
var update_called = false;
|
||||
var spec = {
|
||||
name:'title',
|
||||
update:function(){
|
||||
update_called = true;
|
||||
}
|
||||
};
|
||||
|
||||
var widget = IPA.widget(spec);
|
||||
base_widget_test(widget,'user','test_value');
|
||||
widget_string_test(widget);
|
||||
ok (update_called, 'Update called');
|
||||
|
||||
});
|
||||
|
||||
|
||||
test("IPA.textarea_widget" ,function(){
|
||||
var widget = IPA.textarea_widget({undo:true,name:'title'});
|
||||
base_widget_test(widget,'user','test_value');
|
||||
widget_string_test(widget);
|
||||
text_tests(widget, $('textarea',widget_container));
|
||||
|
||||
});
|
||||
|
||||
|
||||
test("Testing text widget.", function() {
|
||||
var widget = IPA.text_widget({undo:true,name:'title'});
|
||||
base_widget_test(widget,'user','test_value');
|
||||
widget_string_test(widget);
|
||||
text_tests(widget, $('input[type=text]',widget_container));
|
||||
|
||||
});
|
||||
|
||||
test("Testing checkbox widget.", function() {
|
||||
var widget = IPA.checkbox_widget();
|
||||
base_widget_test(widget,'user','title','test_value');
|
||||
var widget = IPA.checkbox_widget({name:'title'});
|
||||
base_widget_test(widget,'user','test_value');
|
||||
|
||||
mock_record = {'title':'something'};
|
||||
|
||||
@ -164,3 +217,63 @@ test("Testing checkbox widget.", function() {
|
||||
|
||||
});
|
||||
|
||||
|
||||
test("IPA.checkboxes_widget" ,function(){
|
||||
var widget = IPA.checkboxes_widget({undo:true, name:'title' });
|
||||
base_widget_test(widget,'user','test_value');
|
||||
|
||||
});
|
||||
test("IPA.select_widget" ,function(){
|
||||
|
||||
var widget = IPA.select_widget({undo:true,name:'title'});
|
||||
base_widget_test(widget,'user','test_value');
|
||||
|
||||
});
|
||||
|
||||
|
||||
test("IPA.entity_select_widget" ,function(){
|
||||
var widget = IPA.entity_select_widget({
|
||||
name: 'uid', entity:'user',field_name:'uid'});
|
||||
base_widget_test(widget,'user','test_value');
|
||||
ok( $('#uid-entity-select option').length > 1,"options populatedfrom AJAX");
|
||||
mock_record = {'uid':'kfrog'};
|
||||
widget.load(mock_record);
|
||||
same(widget.values[0],'kfrog','select set from values');
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
test("IPA.radio_widget" ,function(){
|
||||
var options = [{label:"Engineer",value:"engineer"},
|
||||
{label:"Manager", value:"manager"},
|
||||
{label:"Director",value:"director"},
|
||||
{label:"Vice President",value:"VP"}];
|
||||
var widget = IPA.radio_widget({undo:true, name: 'title',options:options});
|
||||
base_widget_test(widget,'user','test_value');
|
||||
var mock_record = {'title':["director"]};
|
||||
widget.load(mock_record);
|
||||
var values = widget.save();
|
||||
same(values[0],'director','Options set correctly');
|
||||
|
||||
mock_record = {'title':"VP"};
|
||||
widget.load(mock_record);
|
||||
values = widget.save();
|
||||
same(values[0],'VP','Options set correctly');
|
||||
|
||||
var i =0;
|
||||
$('label', widget_container).each( function(){
|
||||
same( $(this).text(),options[i].label, 'labels match');
|
||||
i += 1;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -282,7 +282,7 @@ IPA.text_widget = function(spec) {
|
||||
if(that.undo){
|
||||
that.show_undo();
|
||||
}
|
||||
var value = $('input[name="'+that.name+'"]', that.container).val();
|
||||
var value = $(this).val();
|
||||
that.validate_input(value);
|
||||
});
|
||||
|
||||
@ -520,10 +520,21 @@ IPA.radio_widget = function(spec) {
|
||||
};
|
||||
|
||||
that.update = function() {
|
||||
if (that.values && that.values.length) {
|
||||
var input = $('input[name="'+that.name+'"][value="'+that.values[0]+'"]', that.container);
|
||||
|
||||
|
||||
|
||||
if (that.values) {
|
||||
var value;
|
||||
if ((that.values instanceof Array ) && that.values.length){
|
||||
value = that.values[0]
|
||||
}else{
|
||||
value = that.values;
|
||||
}
|
||||
|
||||
var input = $('input[name="'+that.name+'"][value="'+value+'"]',
|
||||
that.container);
|
||||
if (input.length) {
|
||||
input.get(0).checked = true;
|
||||
input.attr('checked', true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -637,6 +648,13 @@ IPA.textarea_widget = function (spec) {
|
||||
if (that.undo) {
|
||||
that.create_undo(container);
|
||||
}
|
||||
|
||||
$("<span/>",{
|
||||
name:'error_link',
|
||||
html:"Text does not match field pattern",
|
||||
"class":"ui-state-error ui-corner-all",
|
||||
style:"display:none"
|
||||
}).appendTo(container);
|
||||
};
|
||||
|
||||
that.setup = function(container) {
|
||||
@ -646,6 +664,10 @@ IPA.textarea_widget = function (spec) {
|
||||
var input = $('textarea[name="'+that.name+'"]', that.container);
|
||||
input.keyup(function() {
|
||||
undo.css('display', 'inline');
|
||||
|
||||
var value = $(this).val();
|
||||
that.validate_input(value);
|
||||
|
||||
});
|
||||
|
||||
var undo = that.get_undo();
|
||||
@ -677,35 +699,6 @@ IPA.textarea_widget = function (spec) {
|
||||
return that;
|
||||
};
|
||||
|
||||
IPA.button_widget = function (spec) {
|
||||
|
||||
spec = spec || {};
|
||||
|
||||
spec.setup = spec.setup || setup;
|
||||
spec.load = spec.load || load;
|
||||
spec.save = spec.save || save;
|
||||
|
||||
var that = IPA.widget(spec);
|
||||
|
||||
that.click = spec.click;
|
||||
|
||||
function setup(container) {
|
||||
|
||||
that.widget_setup(container);
|
||||
|
||||
var input = $('[name="'+that.name+'"]', that.container);
|
||||
input.replaceWith(IPA.button({ 'label': that.label, 'click': that.click }));
|
||||
}
|
||||
|
||||
function load(record) {
|
||||
}
|
||||
|
||||
function save() {
|
||||
return [];
|
||||
}
|
||||
|
||||
return that;
|
||||
};
|
||||
|
||||
IPA.column = function (spec) {
|
||||
|
||||
@ -1066,19 +1059,23 @@ IPA.entity_select_widget = function(spec){
|
||||
|
||||
var that = IPA.widget(spec);
|
||||
var entity = spec.entity || 'group';
|
||||
var field_name = spec.field_name || 'cn';
|
||||
|
||||
function populate_select(value){
|
||||
function find_success(result){
|
||||
$('option', that.entity_select).remove();
|
||||
var entities = result.result.result;
|
||||
for (var i =0; i < result.result.count; i +=1){
|
||||
var entity = entities[i];
|
||||
var field_array = entity[field_name];
|
||||
var field_value = field_array[0];
|
||||
var option =
|
||||
$('<option/>',{
|
||||
text:entities[i].cn[0],
|
||||
value:entities[i].cn[0]
|
||||
text:field_value,
|
||||
value:field_value
|
||||
}).
|
||||
appendTo(that.entity_select);
|
||||
if (value === entities[i].cn[0]){
|
||||
if (value === field_value){
|
||||
option.attr('selected','selected');
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user