freeipa/install/ui/test/ipa_tests.js

310 lines
7.3 KiB
JavaScript
Raw Normal View History

/* Authors:
* Endi Sukma Dewata <edewata@redhat.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
module('ipa');
test("Testing ipa_init().", function() {
expect(1);
Framework for custom UI This patch introduces a new framework for implementing custom UI. It consists of the following classes: Main: - IPA: global namespace and object repository - ipa_entity: base class for entities - ipa_facet: base class for facets Add dialog: - ipa_add_dialog: default add dialog - ipa_add_field: the fields used in the dialog Search facet: - ipa_search_facet: default search facet - ipa_search_column: the columns in the search result Details facet: - ipa_details_facet: default details facet - ipa_details_section: the sections in the details facet - ipa_details_field: the fields in the details facet Association facet: - ipa_association_facet: default association facet - ipa_association_config: the association configurations To use this framework, create a class extending the ipa_entity (e.g. ipa_hbac). Use the create_* methods to create add dialog, search facet, details facet, and association facet. The fields/columns for the dialog and facets can be specified using the init() function. Custom UI can be defined by overwriting the base methods (e.g. setup, save, load). The entity must be added into the repository using IPA.add_entity(). The original ipa_entity_setup() has been generalized by moving facet- specific codes into the corresponding facet. Some facet names are still hard-coded. This will be fixed in follow-up patches. Some global variables have been removed because their function has been replaced by the object repository: - ipa_entity_add_list - ipa_entity_search_list - ipa_entity_details_list - window_hash_cache Some functions and variables have been moved into IPA namespace: - ipa_json_url -> IPA.json_url - ipa_use_static_files -> IPA.use_static_files - ipa_ajax_options -> IPA.ajax_options - ipa_objs -> IPA.metadata - ipa_messages -> IPA.messages - ipa_dialog -> IPA.error_dialog - ipa_init() -> IPA.init() Initially the HBAC and Service entities have been rewritten to use the new framework. The DNS is partially converted, the ipa_records_facet is used to define custom records facet. Other entities can still work using the old framework. The old framework has been modified to be a wrapper for the new framework. Eventually all entities will be converted to use the new framework. Some unit tests have been modified to use the new framework.
2010-10-27 22:32:30 -05:00
IPA.ajax_options.async = false;
Framework for custom UI This patch introduces a new framework for implementing custom UI. It consists of the following classes: Main: - IPA: global namespace and object repository - ipa_entity: base class for entities - ipa_facet: base class for facets Add dialog: - ipa_add_dialog: default add dialog - ipa_add_field: the fields used in the dialog Search facet: - ipa_search_facet: default search facet - ipa_search_column: the columns in the search result Details facet: - ipa_details_facet: default details facet - ipa_details_section: the sections in the details facet - ipa_details_field: the fields in the details facet Association facet: - ipa_association_facet: default association facet - ipa_association_config: the association configurations To use this framework, create a class extending the ipa_entity (e.g. ipa_hbac). Use the create_* methods to create add dialog, search facet, details facet, and association facet. The fields/columns for the dialog and facets can be specified using the init() function. Custom UI can be defined by overwriting the base methods (e.g. setup, save, load). The entity must be added into the repository using IPA.add_entity(). The original ipa_entity_setup() has been generalized by moving facet- specific codes into the corresponding facet. Some facet names are still hard-coded. This will be fixed in follow-up patches. Some global variables have been removed because their function has been replaced by the object repository: - ipa_entity_add_list - ipa_entity_search_list - ipa_entity_details_list - window_hash_cache Some functions and variables have been moved into IPA namespace: - ipa_json_url -> IPA.json_url - ipa_use_static_files -> IPA.use_static_files - ipa_ajax_options -> IPA.ajax_options - ipa_objs -> IPA.metadata - ipa_messages -> IPA.messages - ipa_dialog -> IPA.error_dialog - ipa_init() -> IPA.init() Initially the HBAC and Service entities have been rewritten to use the new framework. The DNS is partially converted, the ipa_records_facet is used to define custom records facet. Other entities can still work using the old framework. The old framework has been modified to be a wrapper for the new framework. Eventually all entities will be converted to use the new framework. Some unit tests have been modified to use the new framework.
2010-10-27 22:32:30 -05:00
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);
}
);
});
test("Testing IPA.get_param_info().", function() {
var param_info = IPA.get_entity_param("user", "uid");
ok(
param_info,
"IPA.get_param_info(\"user\", \"uid\") not null"
);
equals(
param_info["label"], "User login",
"IPA.get_param_info(\"user\", \"uid\")[\"label\"]"
);
equals(
IPA.get_entity_param("user", "wrong_attribute"), null,
"IPA.get_param_info(\"user\", \"wrong_attribute\")"
);
equals(
IPA.get_entity_param("user", null), null,
"IPA.get_param_info(\"user\", null)"
);
equals(
IPA.get_entity_param("wrong_entity", "uid"), null,
"IPA.get_param_info(\"wrong_entity\", \"uid\")"
);
equals(
IPA.get_entity_param(null, "uid"), null,
"IPA.get_param_info(null, \"uid\")"
);
});
test("Testing IPA.get_member_attribute().", function() {
equals(
IPA.get_member_attribute("user", "group"), "memberof",
"IPA.get_member_attribute(\"user\", \"group\")"
);
equals(
IPA.get_member_attribute("user", "host"), null,
"IPA.get_member_attribute(\"user\", \"host\")"
);
equals(
IPA.get_member_attribute("user", null), null,
"IPA.get_member_attribute(\"user\", null)"
);
equals(
IPA.get_member_attribute(null, "group"), null,
"IPA.get_member_attribute(null, \"group\")"
);
});
test("Testing successful IPA.command().", 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.command({
entity: object,
method: method,
args: args,
options: options,
on_success: success_handler,
on_error: error_handler
}).execute();
equals(
ajax_counter, 1,
"Checking ajax invocation counter"
);
ok(
!IPA.error_dialog,
"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.command().", 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.command({
entity: object,
method: method,
args: args,
options: options,
on_success: success_handler,
on_error: error_handler
}).execute();
Framework for custom UI This patch introduces a new framework for implementing custom UI. It consists of the following classes: Main: - IPA: global namespace and object repository - ipa_entity: base class for entities - ipa_facet: base class for facets Add dialog: - ipa_add_dialog: default add dialog - ipa_add_field: the fields used in the dialog Search facet: - ipa_search_facet: default search facet - ipa_search_column: the columns in the search result Details facet: - ipa_details_facet: default details facet - ipa_details_section: the sections in the details facet - ipa_details_field: the fields in the details facet Association facet: - ipa_association_facet: default association facet - ipa_association_config: the association configurations To use this framework, create a class extending the ipa_entity (e.g. ipa_hbac). Use the create_* methods to create add dialog, search facet, details facet, and association facet. The fields/columns for the dialog and facets can be specified using the init() function. Custom UI can be defined by overwriting the base methods (e.g. setup, save, load). The entity must be added into the repository using IPA.add_entity(). The original ipa_entity_setup() has been generalized by moving facet- specific codes into the corresponding facet. Some facet names are still hard-coded. This will be fixed in follow-up patches. Some global variables have been removed because their function has been replaced by the object repository: - ipa_entity_add_list - ipa_entity_search_list - ipa_entity_details_list - window_hash_cache Some functions and variables have been moved into IPA namespace: - ipa_json_url -> IPA.json_url - ipa_use_static_files -> IPA.use_static_files - ipa_ajax_options -> IPA.ajax_options - ipa_objs -> IPA.metadata - ipa_messages -> IPA.messages - ipa_dialog -> IPA.error_dialog - ipa_init() -> IPA.init() Initially the HBAC and Service entities have been rewritten to use the new framework. The DNS is partially converted, the ipa_records_facet is used to define custom records facet. Other entities can still work using the old framework. The old framework has been modified to be a wrapper for the new framework. Eventually all entities will be converted to use the new framework. Some unit tests have been modified to use the new framework.
2010-10-27 22:32:30 -05:00
var dialog = IPA.error_dialog.parent('.ui-dialog');
equals(
ajax_counter, 1,
"Checking ajax invocation counter"
);
ok(
Framework for custom UI This patch introduces a new framework for implementing custom UI. It consists of the following classes: Main: - IPA: global namespace and object repository - ipa_entity: base class for entities - ipa_facet: base class for facets Add dialog: - ipa_add_dialog: default add dialog - ipa_add_field: the fields used in the dialog Search facet: - ipa_search_facet: default search facet - ipa_search_column: the columns in the search result Details facet: - ipa_details_facet: default details facet - ipa_details_section: the sections in the details facet - ipa_details_field: the fields in the details facet Association facet: - ipa_association_facet: default association facet - ipa_association_config: the association configurations To use this framework, create a class extending the ipa_entity (e.g. ipa_hbac). Use the create_* methods to create add dialog, search facet, details facet, and association facet. The fields/columns for the dialog and facets can be specified using the init() function. Custom UI can be defined by overwriting the base methods (e.g. setup, save, load). The entity must be added into the repository using IPA.add_entity(). The original ipa_entity_setup() has been generalized by moving facet- specific codes into the corresponding facet. Some facet names are still hard-coded. This will be fixed in follow-up patches. Some global variables have been removed because their function has been replaced by the object repository: - ipa_entity_add_list - ipa_entity_search_list - ipa_entity_details_list - window_hash_cache Some functions and variables have been moved into IPA namespace: - ipa_json_url -> IPA.json_url - ipa_use_static_files -> IPA.use_static_files - ipa_ajax_options -> IPA.ajax_options - ipa_objs -> IPA.metadata - ipa_messages -> IPA.messages - ipa_dialog -> IPA.error_dialog - ipa_init() -> IPA.init() Initially the HBAC and Service entities have been rewritten to use the new framework. The DNS is partially converted, the ipa_records_facet is used to define custom records facet. Other entities can still work using the old framework. The old framework has been modified to be a wrapper for the new framework. Eventually all entities will be converted to use the new framework. Some unit tests have been modified to use the new framework.
2010-10-27 22:32:30 -05:00
dialog.length == 1 && IPA.error_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
Framework for custom UI This patch introduces a new framework for implementing custom UI. It consists of the following classes: Main: - IPA: global namespace and object repository - ipa_entity: base class for entities - ipa_facet: base class for facets Add dialog: - ipa_add_dialog: default add dialog - ipa_add_field: the fields used in the dialog Search facet: - ipa_search_facet: default search facet - ipa_search_column: the columns in the search result Details facet: - ipa_details_facet: default details facet - ipa_details_section: the sections in the details facet - ipa_details_field: the fields in the details facet Association facet: - ipa_association_facet: default association facet - ipa_association_config: the association configurations To use this framework, create a class extending the ipa_entity (e.g. ipa_hbac). Use the create_* methods to create add dialog, search facet, details facet, and association facet. The fields/columns for the dialog and facets can be specified using the init() function. Custom UI can be defined by overwriting the base methods (e.g. setup, save, load). The entity must be added into the repository using IPA.add_entity(). The original ipa_entity_setup() has been generalized by moving facet- specific codes into the corresponding facet. Some facet names are still hard-coded. This will be fixed in follow-up patches. Some global variables have been removed because their function has been replaced by the object repository: - ipa_entity_add_list - ipa_entity_search_list - ipa_entity_details_list - window_hash_cache Some functions and variables have been moved into IPA namespace: - ipa_json_url -> IPA.json_url - ipa_use_static_files -> IPA.use_static_files - ipa_ajax_options -> IPA.ajax_options - ipa_objs -> IPA.metadata - ipa_messages -> IPA.messages - ipa_dialog -> IPA.error_dialog - ipa_init() -> IPA.init() Initially the HBAC and Service entities have been rewritten to use the new framework. The DNS is partially converted, the ipa_records_facet is used to define custom records facet. Other entities can still work using the old framework. The old framework has been modified to be a wrapper for the new framework. Eventually all entities will be converted to use the new framework. Some unit tests have been modified to use the new framework.
2010-10-27 22:32:30 -05:00
dialog = IPA.error_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
Framework for custom UI This patch introduces a new framework for implementing custom UI. It consists of the following classes: Main: - IPA: global namespace and object repository - ipa_entity: base class for entities - ipa_facet: base class for facets Add dialog: - ipa_add_dialog: default add dialog - ipa_add_field: the fields used in the dialog Search facet: - ipa_search_facet: default search facet - ipa_search_column: the columns in the search result Details facet: - ipa_details_facet: default details facet - ipa_details_section: the sections in the details facet - ipa_details_field: the fields in the details facet Association facet: - ipa_association_facet: default association facet - ipa_association_config: the association configurations To use this framework, create a class extending the ipa_entity (e.g. ipa_hbac). Use the create_* methods to create add dialog, search facet, details facet, and association facet. The fields/columns for the dialog and facets can be specified using the init() function. Custom UI can be defined by overwriting the base methods (e.g. setup, save, load). The entity must be added into the repository using IPA.add_entity(). The original ipa_entity_setup() has been generalized by moving facet- specific codes into the corresponding facet. Some facet names are still hard-coded. This will be fixed in follow-up patches. Some global variables have been removed because their function has been replaced by the object repository: - ipa_entity_add_list - ipa_entity_search_list - ipa_entity_details_list - window_hash_cache Some functions and variables have been moved into IPA namespace: - ipa_json_url -> IPA.json_url - ipa_use_static_files -> IPA.use_static_files - ipa_ajax_options -> IPA.ajax_options - ipa_objs -> IPA.metadata - ipa_messages -> IPA.messages - ipa_dialog -> IPA.error_dialog - ipa_init() -> IPA.init() Initially the HBAC and Service entities have been rewritten to use the new framework. The DNS is partially converted, the ipa_records_facet is used to define custom records facet. Other entities can still work using the old framework. The old framework has been modified to be a wrapper for the new framework. Eventually all entities will be converted to use the new framework. Some unit tests have been modified to use the new framework.
2010-10-27 22:32:30 -05:00
dialog = IPA.error_dialog.parent('.ui-dialog');
var cancel = $('button', dialog).first().next();
cancel.trigger('click');
equals(
ajax_counter, 3,
"Checking ajax invocation counter"
);
ok(
!IPA.error_dialog,
"After cancel, the dialog box is closed."
);
ok(
success_handler_counter == 0 && error_handler_counter == 1,
"Only the error handler is called."
);
$.ajax = orig;
});