diff options
author | Endi S. Dewata <edewata@redhat.com> | 2010-09-30 15:37:33 -0500 |
---|---|---|
committer | Adam Young <ayoung@redhat.com> | 2010-10-01 09:06:47 -0400 |
commit | c53831037cbe388d961420e87b036b1caf6cf723 (patch) | |
tree | 1d43f011ffaabad7307e5181b715659c41676815 /install/static/test/navigation_tests.js | |
parent | 4f2d2fda93b1a118869579efa70d800a28b97a8b (diff) | |
download | freeipa.git-c53831037cbe388d961420e87b036b1caf6cf723.tar.gz freeipa.git-c53831037cbe388d961420e87b036b1caf6cf723.tar.xz freeipa.git-c53831037cbe388d961420e87b036b1caf6cf723.zip |
Refactoring navigation.js.
The navigation.js has been modified to make it more abstract, i.e.
unaware of entity facets. The nav_update_tabs() has been modified
such that it activates and updates the tabs based on the current
state stored in the URL.
The facets are now handled in entity.js. The ipa_entity_setup() has
been modified to update the facets based on the current state and
cached state.
The navigation.js also has been modified to be more class-like. The
nav_create() has been modified to store the tab configuration and
the tab container in internal variables nav_tabs_lists and
nav_container. The nav_update_tabs() now can be called without any
parameters.
Functions nav_push_state(), nav_get_state(), and nav_remove_state()
have been added to wrap BBQ API. This is to allow unit tests to
replace them with mockup functions to remove dependency on BBQ.
Diffstat (limited to 'install/static/test/navigation_tests.js')
-rw-r--r-- | install/static/test/navigation_tests.js | 98 |
1 files changed, 89 insertions, 9 deletions
diff --git a/install/static/test/navigation_tests.js b/install/static/test/navigation_tests.js index 4144e81a..318ac664 100644 --- a/install/static/test/navigation_tests.js +++ b/install/static/test/navigation_tests.js @@ -27,7 +27,7 @@ test("Testing nav_create().", function() { [ { name:'identity', label:'IDENTITY', children: [ {name:'user', label:'Users', setup:mock_setup_user}, - {name:'group', label:'Users', setup:mock_setup_group}, + {name:'group', label:'Users', setup:mock_setup_group} ]}]; function mock_setup_user (jobj){ user_mock_called = true; @@ -44,7 +44,7 @@ test("Testing nav_create().", function() { var navigation = $('<div id="navigation"/>').appendTo(document.body); var user_mock_called = false; var group_mock_called = false; - nav_create(mock_tabs_lists, navigation, 'tabs') + nav_create(mock_tabs_lists, navigation, 'tabs'); ok(user_mock_called, "mock user setup was called"); ok(!group_mock_called, "mock group setup was not called because the tab is inactive"); same( navigation[0].children.length, 2, "Two Child tabs"); @@ -54,24 +54,104 @@ test("Testing nav_create().", function() { navigation.remove(); }); -test("Testing nav_select_tabs().", function() { +test("Testing nav_update_tabs() with valid index.", function() { + var orig_push_state = nav_push_state; + var orig_get_state = nav_get_state; + var orig_remove_state = nav_remove_state; + + var state = {}; + + nav_push_state = function(params) { + $.extend(state, params); + }; + nav_get_state = function(key) { + return state[key]; + }; + nav_remove_state = function(key) { + delete state[key]; + }; var mock_tabs_lists = [ { name:'identity', label:'IDENTITY', children: [ {name:'one', label:'One', setup: function (){}}, - {name:'two', label:'Two', setup: function (){}}, + {name:'two', label:'Two', setup: function (){}} ]}]; var navigation = $('<div id="navigation"/>').appendTo(document.body); - nav_create(mock_tabs_lists, navigation, 'tabs') + nav_create(mock_tabs_lists, navigation, 'tabs'); + + nav_push_state({"identity":1}); + nav_update_tabs(); + + same( + navigation.tabs('option', 'selected'), 0, + "Active tab at level 1" + ); - $.bbq.pushState({"identity":2}); - nav_select_tabs(mock_tabs_lists, navigation); - same( navigation[0].children[1].children[2].id, 'two', "Tab two"); - $.bbq.removeState(["identity"]); + same( + $('#identity').tabs('option', 'selected'), 1, + "Active tab at level 2" + ); + + nav_remove_state("identity"); navigation.remove(); + + nav_push_state = orig_push_state; + nav_get_state = orig_get_state; + nav_remove_state = orig_remove_state; +}); + +test("Testing nav_update_tabs() with out-of-range index.", function() { + + var orig_push_state = nav_push_state; + var orig_get_state = nav_get_state; + var orig_remove_state = nav_remove_state; + + var state = {}; + + nav_push_state = function(params) { + $.extend(state, params); + }; + nav_get_state = function(key) { + return state[key]; + }; + nav_remove_state = function(key) { + delete state[key]; + }; + + var mock_tabs_lists = + [ + { name:'identity', label:'IDENTITY', children: [ + {name:'one', label:'One', setup: function (){}}, + {name:'two', label:'Two', setup: function (){}} + ]}]; + + var navigation = $('<div id="navigation"/>').appendTo(document.body); + + nav_create(mock_tabs_lists, navigation, 'tabs'); + + nav_push_state({"identity":2}); + nav_update_tabs(); + + same( + navigation.tabs('option', 'selected'), 0, + "Active tab at level 1" + ); + + same( + $('#identity').tabs('option', 'selected'), 0, + "Active tab at level 2" + ); + + nav_remove_state("identity"); + + navigation.remove(); + + nav_push_state = orig_push_state; + nav_get_state = orig_get_state; + nav_remove_state = orig_remove_state; }); |