diff options
author | Endi S. Dewata <edewata@redhat.com> | 2010-09-29 00:52:56 -0500 |
---|---|---|
committer | Adam Young <ayoung@redhat.com> | 2010-09-29 15:43:23 -0400 |
commit | 4b4ecef4a32319932f31413feaf60e0dbfa96973 (patch) | |
tree | d1aec20a48073b23719efe81d0b5263e830a4bcc /install/static/test/ipa_tests.js | |
parent | 09555fae17dcd142c4b39643e3f7d376ed8d4841 (diff) | |
download | freeipa.git-4b4ecef4a32319932f31413feaf60e0dbfa96973.tar.gz freeipa.git-4b4ecef4a32319932f31413feaf60e0dbfa96973.tar.xz freeipa.git-4b4ecef4a32319932f31413feaf60e0dbfa96973.zip |
Added error handler for ipa_cmd().
The ipa_cmd() has been modified such that when an error occurs a
dialog box will appear showing the error message with 2 buttons:
Retry and Cancel. If Retry is clicked, it will attempt to execute
the same operation again. If Cancel is clicked, the operation will
be canceled and the control is returned to the caller.
New unit tests have been added to test ipa_cmd() on successfull
and unsuccessfull cases.
The associate.js, details.js, entity.js, search.js, and webui.js
have been modified to display the error message inside the page.
This behavior can be changed in the future (e.g. redirect to error
page).
The navigation.js and webui.js have been modified to render only
the visible tabs. This improves the performance and reduce hidden
errors. The navigation unit test has been modified to reflect this
behavior.
Some variables/functions also have been renamed for consistency.
Diffstat (limited to 'install/static/test/ipa_tests.js')
-rw-r--r-- | install/static/test/ipa_tests.js | 201 |
1 files changed, 201 insertions, 0 deletions
diff --git a/install/static/test/ipa_tests.js b/install/static/test/ipa_tests.js index 8dbdd62d..8617a843 100644 --- a/install/static/test/ipa_tests.js +++ b/install/static/test/ipa_tests.js @@ -92,3 +92,204 @@ test("Testing ipa_get_member_attribute().", function() { "ipa_get_member_attribute(null, \"group\")" ); }); + +test("Testing successful ipa_cmd().", function() { + + var method = 'method'; + var args = ['arg1', 'arg2', 'arg3']; + var options = { + opt1: 'val1', + opt2: 'val2', + opt3: 'val3' + }; + var object = 'object'; + + var success_handler_counter = 0; + var error_handler_counter = 0; + + function success_handler(data, status, xhr) { + success_handler_counter++; + } + + function error_handler(xhr, text_status, error_thrown) { + error_handler_counter++; + } + + var orig = $.ajax; + + var xhr = {}; + var text_status = null; + var error_thrown = {name:'ERROR', message:'An error has occured'}; + + var ajax_counter = 0; + + $.ajax = function(request) { + ajax_counter++; + + equals( + request.url, "data/"+object+"_"+method+".json", + "Checking request.url" + ); + + var data = JSON.parse(request.data); + + equals( + data.method, object+'_'+method, + "Checking method" + ); + + same( + data.params, [args, options], + "Checking parameters" + ); + + request.success(xhr, text_status, error_thrown); + }; + + ipa_cmd(method, args, options, success_handler, error_handler, object); + + equals( + ajax_counter, 1, + "Checking ajax invocation counter" + ); + + var dialog = ipa_dialog.parent('.ui-dialog'); + + ok( + !dialog.length, + "The dialog box is not created." + ); + + ok( + success_handler_counter == 1 && error_handler_counter == 0, + "Only the success handler is called." + ); + + $.ajax = orig; +}); + +test("Testing unsuccessful ipa_cmd().", function() { + + var method = 'method'; + var args = ['arg1', 'arg2', 'arg3']; + var options = { + opt1: 'val1', + opt2: 'val2', + opt3: 'val3' + }; + var object = 'object'; + + var success_handler_counter = 0; + var error_handler_counter = 0; + + function success_handler(data, status, xhr) { + success_handler_counter++; + } + + function error_handler(xhr, text_status, error_thrown) { + error_handler_counter++; + } + + var orig = $.ajax; + + var xhr = {}; + var text_status = null; + var error_thrown = {name:'ERROR', message:'An error has occured'}; + + var ajax_counter = 0; + + $.ajax = function(request) { + ajax_counter++; + + equals( + request.url, "data/"+object+"_"+method+".json", + "Checking request.url" + ); + + var data = JSON.parse(request.data); + + equals( + data.method, object+'_'+method, + "Checking method" + ); + + same( + data.params, [args, options], + "Checking parameters" + ); + + request.error(xhr, text_status, error_thrown); + }; + + ipa_cmd(method, args, options, success_handler, error_handler, object); + + var dialog = ipa_dialog.parent('.ui-dialog'); + + equals( + ajax_counter, 1, + "Checking ajax invocation counter" + ); + + ok( + dialog.length == 1 && ipa_dialog.dialog('isOpen'), + "The dialog box is created and open." + ); + + ok( + success_handler_counter == 0 && error_handler_counter == 0, + "Initially none of the handlers are called." + ); + + // search the retry button from the beginning + var retry = $('button', dialog).first(); + retry.trigger('click'); + + equals( + ajax_counter, 2, + "Checking ajax invocation counter" + ); + + ok( + success_handler_counter == 0 && error_handler_counter == 0, + "After 1st retry, none of the handlers are called." + ); + + // search the retry button from the beginning again because the dialog + // has been recreated + dialog = ipa_dialog.parent('.ui-dialog'); + retry = $('button', dialog).first(); + retry.trigger('click'); + + equals( + ajax_counter, 3, + "Checking ajax invocation counter" + ); + + ok( + success_handler_counter == 0 && error_handler_counter == 0, + "After 2nd retry, none of the handlers are called." + ); + + // search the cancel button from the beginning because the dialog has + // been recreated + dialog = ipa_dialog.parent('.ui-dialog'); + var cancel = $('button', dialog).first().next(); + cancel.trigger('click'); + + equals( + ajax_counter, 3, + "Checking ajax invocation counter" + ); + + ok( + !ipa_dialog.dialog('isOpen'), + "After cancel, the dialog box is closed." + ); + + ok( + success_handler_counter == 0 && error_handler_counter == 1, + "Only the error handler is called." + ); + + $.ajax = orig; +}); |