diff options
author | Endi S. Dewata <edewata@redhat.com> | 2010-11-02 20:16:55 -0500 |
---|---|---|
committer | Adam Young <ayoung@redhat.com> | 2010-11-04 14:22:32 -0400 |
commit | d99ebc0f3798c84e612c79c43eb85c31b20ab1ce (patch) | |
tree | f2a758dfc9028d32f00236340b409469c73848a4 /install/static/test/details_tests.js | |
parent | 05a16f50d7fe8c01408ec445e6b5ad26ff65d9d5 (diff) | |
download | freeipa-d99ebc0f3798c84e612c79c43eb85c31b20ab1ce.tar.gz freeipa-d99ebc0f3798c84e612c79c43eb85c31b20ab1ce.tar.xz freeipa-d99ebc0f3798c84e612c79c43eb85c31b20ab1ce.zip |
HBAC Details Page
The UI framework has been extended to include a collection of widgets:
- ipa_widget: base class
- ipa_text_widget: text field
- ipa_radio_widget: radio button
- ipa_textarea_widget: textarea
- ipa_button_widget: button
- ipa_column_widget: column for table
- ipa_table_widget: table
These widgets can be used to create input controls. They can also be
extended to create custom controls.
The framework has also been enhanced to support custom layouts. This
can be used to change the look of the application without changing
the code. Initially this is only available in details section.
Layout consists of a collection of HTML templates. Each template is a
complete and valid HTML file representing a portion of a page. The
template will be loaded and initialized by the code, then filled with
the data from the server. The layouts are located in
install/static/layouts/<name> folder.
By default, if no templates are used, the fields in the details page
are rendered vertically using dd/dt/dd tags. For pages that require
different layout, a custom UI needs to be developed. There are two ways
to do that:
- write a custom widget to generate the UI dynamically
- create an HTML template and write the initialization code
For components that are quite complex or used frequently, it's might
be better to use the first method. For simple pages that are used only
in one location or need to support customization, the second method
might be preferable. Other benefits of templates:
- cleaner code and UI separation
- more flexibility in customization
- new pages can be developed quickly and require less coding
- multiple templates can be used with the same initialization code
- easier to maintain
The HBAC details page has been implemented using both methods. By
default it will use custom widgets to generate the page. To use a
custom layout, add the following parameter to the URL, then reload
the page:
&layout=<name>
Currently the only available layout is 'default' which produces the
same look as the custom widgets.
The HBAC details page is usable, but it still needs additional work.
The access time is not working yet. There is no undo button, hint,
or validation yet.
The table in the association facet has also been changed to use
ipa_association_widget which is derived from ipa_table_widget.
The Makefile has been updated to include the layouts. The unit tests
have been updated as well.
Diffstat (limited to 'install/static/test/details_tests.js')
-rw-r--r-- | install/static/test/details_tests.js | 187 |
1 files changed, 102 insertions, 85 deletions
diff --git a/install/static/test/details_tests.js b/install/static/test/details_tests.js index 4a60216ef..8482f6df0 100644 --- a/install/static/test/details_tests.js +++ b/install/static/test/details_tests.js @@ -19,45 +19,96 @@ */ -test("Testing ipa_details_create().", function() { +test("Testing ipa_details_section.setup().", function() { - var name = 'NAMENAMENAME'; - var identity = 'IDIDID'; + IPA.ajax_options.async = false; + + IPA.init( + "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); + } + ); + + var result = {}; - var section = ipa_stanza({name:identity, label:name}). + var section = ipa_stanza({name:'IDIDID', label:'NAMENAMENAME'}). input({name:'cn', label:'Entity Name'}). input({name:'description', label:'Description'}). input({name:'number', label:'Entity ID'}); - var details = section.fields; - var parent = $("<div/>"); - var container = $("<div title='entity'/>"); - parent.append(container); - ipa_details_section_setup(parent,container, section); + var fields = section.fields; + var container = $("<div/>"); + section.setup(container, result); - ok(parent.find('hr').length); + var dl = container.find('dl'); - var h2= parent.find('h2'); - ok(h2.length); - ok(h2[0].innerHTML.indexOf(name) > 1,"find name in html"); + same( + dl.length, 1, + 'Checking dl tag' + ); + + same( + dl.attr('id'), section.name, + 'Checking section name' + ); + + var dts = $('dt', dl); + same( + dts.length, fields.length, // each field generates dt & dd + 'Checking number of children' + ); + + for (var i=0; i<fields.length; i++) { + var dt = dts.get(i); + same( + dt.title, fields[i].name, + 'Checking field '+i+'\'s title' + ); + + same( + dt.innerHTML, fields[i].label+':', + 'Checking field '+i+'\'s label' + ); + } +}); - var dl = parent.find('dl'); - ok(dl.length); - same(dl[0].children.length,3,"children tag count"); - same(dl[0].id, identity,"identity"); - same(details[0].name, dl[0].children[0].title,"name"); - var d = dl[0].children[0].innerHTML; - same(details[0].label+":",d); - same(details[2].name,dl[0].children[2].title); - d = dl[0].children[2].innerHTML; - same(details[2].label+":" ,d); -}); +test("Testing details lifecycle: create, save ().", function(){ + IPA.ajax_options.async = false; -test("Testing details lifecycle:setup, load, save ().", function(){ + IPA.init( + "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); + } + ); + + var result = {}; + + ipa_cmd( + 'user_show', + ['kfrog'], + {}, + function(data, text_status, xhr) { + result = data.result.result; + ok(true, "ipa_cmd() succeeded."); + }, + function(xhr, text_status, error_thrown) { + ok(false, "ipa_cmd() failed: "+error_thrown); + } + ); var setup_status_called = false; var save_password_called= false; @@ -82,6 +133,7 @@ test("Testing details lifecycle:setup, load, save ().", function(){ function setup_st(){ } + var container = $("<div/>"); var obj_name = 'user'; ipa_entity_set_details_definition(obj_name, [ @@ -116,46 +168,42 @@ test("Testing details lifecycle:setup, load, save ().", function(){ var entity = ipa_get_entity(obj_name); var facet = entity.get_facet('details'); - var sections = facet.get_sections(); - ipa_details_create(container, sections); + facet.create(container, result); var contact = container.find('dl#contact.entryattrs'); - ok(contact); - var identity = container.find('dl#identity.entryattrs'); - ok(identity); - var dts= identity.find('dt'); - ok(dts); - same(6, dts.length); - same('initials',dts[5].title); - //TODO extract into Fixture - IPA.ajax_options.async = false; - $.ajaxSetup(IPA.ajax_options); - IPA.json_url = './data'; - IPA.use_static_files = true; - - container.attr('id','user'); - - ok (setup_status_called , 'setup status called'); + ok( + contact, + 'dl tag for contact is created' + ); + var identity = container.find('dl#identity.entryattrs'); - ipa_details_load(container, - 'kfrog', - function(){load_success_called = true}, - function(){load_failure_called = true}); + ok( + identity, + 'dl tag for identity is created' + ); - ok (load_success_called,'load success called'); - ok (!load_failure_called,'load failure not called'); + var dts= identity.find('dt'); + same( + dts.length, 6, + 'Checking dt tags for identity' + ); - ok (load_manager_called, 'load manager called'); + same( + dts[5].title, facet.get_sections()[0].get_fields()[5].name, + 'Checking dt title' + ); + container.attr('id','user'); - ipa_details_load(container, - 'kfrog', - function(){load_success_called = true}, - function(){load_failure_called = true}); + ok ( + setup_status_called, + 'Setup status called' + ); + ok (load_manager_called, 'load manager called'); ipa_details_update(container, 'kfrog', @@ -183,34 +231,3 @@ test("Testing _ipa_create_text_input().", function(){ same(text[0].value,value ); same(text[0].type,"text" ); }); - - -test("Testing ipa_details_section_setup()",function(){ - - var section = ipa_stanza({name: 'IDIDID', label: 'NAMENAMENAME'}). - input({name:'cn', label:'Entity Name'}). - input({name:'description', label:'Description'}). - input({name:'number', label:'Entity ID'}); - var fields = section.fields; - var container = $("<div title='entity'/>"); - var details = $("<div/>"); - container.append(details); - - ipa_details_section_setup(container, details, section); - - ok(container.find('hr')); - - var h2= container.find('h2'); - ok(h2); - ok(h2[0].innerHTML.indexOf(section.label) > 1,"find name in html"); - - var dl = container.find('dl'); - ok(dl); - same(dl[0].children.length,3); - same(dl[0].id, section.name); - same(dl[0].children[0].title, fields[0].name); - same(dl[0].children[0].innerHTML, fields[0].label+":"); - same(dl[0].children[2].title, fields[2].name); - same(dl[0].children[2].innerHTML, fields[2].label+":"); - -}); |