summaryrefslogtreecommitdiffstats
path: root/install/static/test
diff options
context:
space:
mode:
Diffstat (limited to 'install/static/test')
-rw-r--r--install/static/test/ipa_tests.html3
-rw-r--r--install/static/test/ipa_tests.js201
-rw-r--r--install/static/test/navigation_tests.js12
3 files changed, 211 insertions, 5 deletions
diff --git a/install/static/test/ipa_tests.html b/install/static/test/ipa_tests.html
index 3031f2310..dfe2720a5 100644
--- a/install/static/test/ipa_tests.html
+++ b/install/static/test/ipa_tests.html
@@ -3,8 +3,11 @@
<head>
<title>Core Test Suite</title>
<link rel="stylesheet" href="qunit.css" type="text/css" media="screen">
+ <link rel="stylesheet" type="text/css" href="../jquery-ui.css" />
+
<script type="text/javascript" src="qunit.js"></script>
<script type="text/javascript" src="../jquery.js"></script>
+ <script type="text/javascript" src="../jquery-ui.js"></script>
<script type="text/javascript" src="../ipa.js"></script>
<script type="text/javascript" src="ipa_tests.js"></script>
</head>
diff --git a/install/static/test/ipa_tests.js b/install/static/test/ipa_tests.js
index 8dbdd62d5..8617a8439 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;
+});
diff --git a/install/static/test/navigation_tests.js b/install/static/test/navigation_tests.js
index 16b3ae925..4144e81a4 100644
--- a/install/static/test/navigation_tests.js
+++ b/install/static/test/navigation_tests.js
@@ -41,17 +41,17 @@ test("Testing nav_create().", function() {
}
ipa_objs= {};
- var navigation = $('<div id="navigation"/>');
+ 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')
- ok(user_mock_called, "mock setup was called");
- ok(group_mock_called, "mock setup was called");
+ 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");
same( navigation[0].children[1].id, 'identity', "Identity Tab");
same( navigation[0].children[1].children[1].id, 'user', "User Tab");
same( navigation[0].children[1].children[2].id, 'group', "User Tab");
-
+ navigation.remove();
});
test("Testing nav_select_tabs().", function() {
@@ -64,12 +64,14 @@ test("Testing nav_select_tabs().", function() {
{name:'two', label:'Two', setup: function (){}},
]}];
- var navigation = $('<div id="navigation"/>');
+ var navigation = $('<div id="navigation"/>').appendTo(document.body);
nav_create(mock_tabs_lists, navigation, 'tabs')
$.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"]);
+ navigation.remove();
});