/* Authors: * Adam Young * * 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 . */ define([ 'freeipa/metadata', 'freeipa/ipa', 'freeipa/jquery', 'freeipa/details', 'freeipa/facet', 'freeipa/field', 'freeipa/reg', 'freeipa/rpc', 'freeipa/entity', 'freeipa/widget'], function(md, IPA, $, mod_details, mod_facet, mod_field, reg, rpc) { return function() { var details_container; module('details', { setup: function() { IPA.ajax_options.async = false; mod_facet.register(); mod_details.register(); mod_field.register(); IPA.init({ url: 'data', on_error: function(xhr, text_status, error_thrown) { ok(false, "ipa_init() failed: "+error_thrown); } }); details_container = $('
').appendTo(document.body); IPA.register('user', function(spec) { return IPA.entity({ name: 'user', metadata: md.source.objects.user }); }); }, teardown: function() { details_container.remove(); reg.facet.remove('details'); } }); test("Testing IPA.details_section.create().", function() { var facet = IPA.details_facet({ entity: IPA.get_entity('user'), sections: [ { name:'IDIDID', label:'NAMENAMENAME', fields: [ 'cn', 'uid', 'mail' ] } ] }); var section = facet.widgets.get_widget('IDIDID'); ok(section !== null, 'Verifying section existence.'); var fields = section.widgets.get_widgets(); var container = $("
"); section.create(container); var section_el = $('.details-section', container); same( section_el.length, 1, 'Verifying section element'); var controls = $('.control-group', section_el); same( controls.length, fields.length, 'Verifying number of controls'); for (var i=0; i', {}).appendTo(details_container); var facet = entity.get_facet('details'); facet.container_node = container[0]; facet.create(); facet.load(data); var contact = $('.details-section[name=contact]', facet.dom_node); ok( contact.length, 'Verifying section for contact is created'); var identity = $('.details-section[name=identity]', facet.dom_node); ok( identity.length, 'Verifying section for identity is created'); var rows = $('.control-group', identity); same( rows.length, 6, 'Verifying rows for identity'); ok (load_called, 'load manager called'); var field = facet.fields.get_field('test'); field.set_value("foo"); var widget = facet.widgets.get_widget('contact.test'); // simulate user change widget.emit('value-change', { source: widget, value: "foo" }); facet.update( 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'); }); test("Testing IPA.details_section_create again()",function() { var facet = IPA.details_facet({ entity: IPA.get_entity('user'), sections: [ { name:'IDIDID', label:'NAMENAMENAME', fields: [ { name: 'cn', label: 'Entity Name' }, { name: 'description', label: 'Description' }, { name: 'number', label: 'Entity ID' } ] } ] }); var section = facet.widgets.get_widget('IDIDID'); ok(section !== null, 'Verifying section existence.'); var fields = section.widgets.get_widgets(); var container = $("
"); var details = $("
"); container.append(details); var data = {}; data.result = {}; data.result.result = {}; section.create(container); facet.load(data); var section_el = $('.details-section', container); same( section_el.length, 1, 'Verifying section element'); var controls = $('.control-group', section_el); same( controls.length, fields.length, 'Verifying number of controls'); for (var i=0; i