Test framework for Web UI.

Test framework for Web UI has been created using qUnit. The test files
are located in install/static/test. The main page is index.html which
contains links to all test suites (xxx_tests.html). The test cases are
stored in xxx_tests.js. All test suites can be executed at once using
all_tests.html. The test data is stored in data folder. This patch
includes test suites for ipa.js and entity.js.

Some variables and functions in ipa.js have been modified to accomodate
testing (e.g. JSON URL, error handler, synchronous operation). The
sampledata has been moved to test/data. The develop.js and webui.js also
have been modified accordingly.
This commit is contained in:
Endi Sukma Dewata 2010-09-24 19:50:29 -04:00 committed by Adam Young
parent 59d46abcd5
commit 346615d4a0
43 changed files with 1785 additions and 36 deletions

View File

@ -1,2 +1,4 @@
ipa_use_sampledata = (window.location.protocol == 'file:');
if (window.location.protocol == 'file:') {
ipa_json_url = "test/data";
ipa_use_static_files = true;
}

View File

@ -21,9 +21,17 @@
/* IPA JSON-RPC helper */
var IPA_DEFAULT_JSON_URL = '/ipa/json';
var IPA_SAMPLEDATA_URL = 'sampledata';
var ipa_use_sampledata = false;
var ipa_json_url;
var ipa_use_static_files;
var ipa_ajax_options = {
type: 'POST',
contentType: 'application/json',
dataType: 'json',
async: true,
processData: false,
};
/* JSON-RPC ID counter */
var ipa_jsonrpc_id = 0;
@ -31,42 +39,27 @@ var ipa_jsonrpc_id = 0;
/* IPA objects data in JSON format */
var ipa_objs = {};
var _ipa_init_on_win_callback = null;
/* initialize the IPA JSON-RPC helper
* arguments:
* url - JSON-RPC URL to use (optional) */
function ipa_init(url, on_win, use_sampledata)
function ipa_init(url, use_static_files, on_win, on_error)
{
if (url)
ipa_json_url = url;
else
ipa_json_url = IPA_DEFAULT_JSON_URL;
if (use_sampledata)
ipa_use_sampledata = use_sampledata;
_ipa_init_on_win_callback = on_win;
if (use_static_files)
ipa_use_static_files = use_static_files;
var options = {
type: 'POST',
contentType: 'application/json',
dataType: 'json',
processData: false,
};
$.ajaxSetup(ipa_ajax_options);
$.ajaxSetup(options);
ipa_cmd('json_metadata', [], {}, _ipa_load_objs,
function(response){
alert('init failed');
});
}
function _ipa_load_objs(data, textStatus, xhr)
{
ipa_objs = data.result.result;
if (_ipa_init_on_win_callback)
_ipa_init_on_win_callback(data, textStatus, xhr);
ipa_cmd('json_metadata', [], {},
function(data, status, xhr) {
ipa_objs = data.result.result;
if (on_win) on_win(data, status, xhr);
},
on_error
);
}
/* call an IPA command over JSON-RPC
@ -84,8 +77,12 @@ function ipa_cmd(name, args, options, win_callback, fail_callback, objname)
name = objname + '_' + name;
var url = ipa_json_url;
if (ipa_use_sampledata && IPA_SAMPLEDATA_URL)
url = IPA_SAMPLEDATA_URL + '/' + name + '.json';
if (!url)
url = IPA_DEFAULT_JSON_URL;
if (ipa_use_static_files)
url += '/' + name + '.json';
var data = {
method: name,
@ -132,7 +129,10 @@ function ipa_parse_qs(qs)
/* helper function used to retrieve information about an attribute */
function ipa_get_param_info(obj_name, attr)
{
var takes_params = ipa_objs[obj_name].takes_params;
var ipa_obj = ipa_objs[obj_name];
if (!ipa_obj) return null;
var takes_params = ipa_obj.takes_params;
if (!takes_params)
return (null);
@ -147,7 +147,10 @@ function ipa_get_param_info(obj_name, attr)
/* helper function used to retrieve attr name with members of type `member` */
function ipa_get_member_attribute(obj_name, member)
{
var attribute_members = ipa_objs[obj_name].attribute_members
var ipa_obj = ipa_objs[obj_name];
if (!ipa_obj) return null;
var attribute_members = ipa_obj.attribute_members
for (var a in attribute_members) {
var objs = attribute_members[a];
for (var i = 0; i < objs.length; ++i) {
@ -155,5 +158,7 @@ function ipa_get_member_attribute(obj_name, member)
return a;
}
}
return null;
}

View File

@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<title>Complete Test Suite</title>
<link rel="stylesheet" href="qunit.css" type="text/css" media="screen">
<script type="text/javascript" src="qunit.js"></script>
<script type="text/javascript" src="../jquery.js"></script>
<script type="text/javascript" src="../ipa.js"></script>
<script type="text/javascript" src="../details.js"></script>
<script type="text/javascript" src="../search.js"></script>
<script type="text/javascript" src="../add.js"></script>
<script type="text/javascript" src="../entity.js"></script>
<script type="text/javascript" src="ipa_tests.js"></script>
<script type="text/javascript" src="entity_tests.js"></script>
</head>
<body>
<h1 id="qunit-header">Complete Test Suite</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">test markup</div>
</body>
</html>

View File

@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<title>Entity Test Suite</title>
<link rel="stylesheet" href="qunit.css" type="text/css" media="screen">
<script type="text/javascript" src="qunit.js"></script>
<script type="text/javascript" src="../jquery.js"></script>
<script type="text/javascript" src="../ipa.js"></script>
<script type="text/javascript" src="../details.js"></script>
<script type="text/javascript" src="../search.js"></script>
<script type="text/javascript" src="../add.js"></script>
<script type="text/javascript" src="../entity.js"></script>
<script type="text/javascript" src="entity_tests.js"></script>
</head>
<body>
<h1 id="qunit-header">Entity Test Suite</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">test markup</div>
</body>
</html>

View File

@ -0,0 +1,120 @@
/* 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; version 2 only
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
test("Testing ipa_entity_set_search_definition().", function() {
var uid_callback = function() {
return true;
};
ipa_entity_set_search_definition("user", [
["uid", "Login", uid_callback],
]);
var list = ipa_entity_search_list["user"];
ok(
list,
"ipa_entity_search_list[\"user\"] is not null"
);
var attr = list[0];
ok(
attr,
"ipa_entity_search_list[\"user\"][0] is not null"
);
equals(
attr[0], "uid",
"ipa_entity_search_list[\"user\"][0][0]"
);
equals(
attr[1], "Login",
"ipa_entity_search_list[\"user\"][0][1]"
);
var callback = attr[2];
ok(
callback,
"ipa_entity_search_list[\"user\"][0][2] not null"
);
ok(
callback(),
"ipa_entity_search_list[\"user\"][0][2]() works"
);
});
test("Testing ipa_entity_generate_views().", function() {
ipa_ajax_options["async"] = false;
ipa_init(
"data",
true,
function(data, status, xhr) {
ok(true, "ipa_init() succeeded.");
},
function(xhr, options, thrownError) {
ok(false, "ipa_init() failed: "+thrownError);
}
);
var container = $("<div/>");
ipa_entity_generate_views("user", container);
var list = container.children();
var facets = list.children();
equals(
facets.length, 6,
"Checking number of facets"
)
var search = facets.first();
equals(
search.attr("title"), "search",
"Checking the first facet"
)
var details = search.next();
equals(
details.attr("title"), "details",
"Checking the second facet"
)
var facet = details.next();
var attribute_members = ipa_objs["user"].attribute_members;
for (attribute_member in attribute_members) {
var objects = attribute_members[attribute_member];
for (var i = 0; i < objects.length; i++) {
var object = objects[i];
equals(
facet.attr("title"), object,
"Checking the next facet"
);
facet = facet.next();
}
}
});

View File

@ -0,0 +1,37 @@
<!DOCTYPE html>
<html>
<head>
<title>IPA Test Suite</title>
<link rel="stylesheet" href="qunit.css" type="text/css" media="screen">
<style type="text/css">
#content {
font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial;
font-size: smaller;
border-bottom: 1px solid #fff;
padding: 0.5em 0.5em 0.5em 2.5em;
color: #2b81af;
background-color: #D2E0E6;
}
</style>
</head>
<body>
<h1 id="qunit-header">IPA Test Suite</h1>
<h2 id="qunit-banner" class="qunit-pass"></h2>
<div id="content">
<a href="all_tests.html">Complete Test Suite</a>
<ul>
<li><a href="ipa_tests.html">Core Test Suite</a>
<li><a href="entity_tests.html">Entity Test Suite</a>
</ul>
</div>
<div id="qunit-testresult">
<br>
</div>
</body>
</html>

View File

@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<title>Core Test Suite</title>
<link rel="stylesheet" href="qunit.css" type="text/css" media="screen">
<script type="text/javascript" src="qunit.js"></script>
<script type="text/javascript" src="../jquery.js"></script>
<script type="text/javascript" src="../ipa.js"></script>
<script type="text/javascript" src="ipa_tests.js"></script>
</head>
<body>
<h1 id="qunit-header">Core Test Suite</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">test markup</div>
</body>
</html>

View File

@ -0,0 +1,94 @@
/* 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; version 2 only
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
test("Testing ipa_init().", function() {
expect(1);
ipa_ajax_options["async"] = false;
ipa_init(
"data",
true,
function(data, status, xhr) {
ok(true, "ipa_init() succeeded.");
},
function(xhr, options, thrownError) {
ok(false, "ipa_init() failed: "+thrownError);
}
);
});
test("Testing ipa_get_param_info().", function() {
var param_info = ipa_get_param_info("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_param_info("user", "wrong_attribute"), null,
"ipa_get_param_info(\"user\", \"wrong_attribute\")"
);
equals(
ipa_get_param_info("user", null), null,
"ipa_get_param_info(\"user\", null)"
);
equals(
ipa_get_param_info("wrong_entity", "uid"), null,
"ipa_get_param_info(\"wrong_entity\", \"uid\")"
);
equals(
ipa_get_param_info(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\")"
);
});

View File

@ -0,0 +1,155 @@
/** Font Family and Sizes */
#qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult {
font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial;
}
#qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; }
#qunit-tests { font-size: smaller; }
/** Resets */
#qunit-tests, #qunit-tests ol, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult {
margin: 0;
padding: 0;
}
/** Header */
#qunit-header {
padding: 0.5em 0 0.5em 1em;
color: #fff;
text-shadow: rgba(0, 0, 0, 0.5) 4px 4px 1px;
background-color: #0d3349;
border-radius: 15px 15px 0 0;
-moz-border-radius: 15px 15px 0 0;
-webkit-border-top-right-radius: 15px;
-webkit-border-top-left-radius: 15px;
}
#qunit-header a {
text-decoration: none;
color: white;
}
#qunit-banner {
height: 5px;
}
#qunit-testrunner-toolbar {
padding: 0em 0 0.5em 2em;
}
#qunit-userAgent {
padding: 0.5em 0 0.5em 2.5em;
background-color: #2b81af;
color: #fff;
text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px;
}
/** Tests: Pass/Fail */
#qunit-tests {
list-style-position: inside;
}
#qunit-tests li {
padding: 0.4em 0.5em 0.4em 2.5em;
border-bottom: 1px solid #fff;
list-style-position: inside;
}
#qunit-tests li strong {
cursor: pointer;
}
#qunit-tests ol {
margin-top: 0.5em;
padding: 0.5em;
background-color: #fff;
border-radius: 15px;
-moz-border-radius: 15px;
-webkit-border-radius: 15px;
box-shadow: inset 0px 2px 13px #999;
-moz-box-shadow: inset 0px 2px 13px #999;
-webkit-box-shadow: inset 0px 2px 13px #999;
}
/*** Test Counts */
#qunit-tests b.counts { color: black; }
#qunit-tests b.passed { color: #5E740B; }
#qunit-tests b.failed { color: #710909; }
#qunit-tests li li {
margin: 0.5em;
padding: 0.4em 0.5em 0.4em 0.5em;
background-color: #fff;
border-bottom: none;
list-style-position: inside;
}
/*** Passing Styles */
#qunit-tests li li.pass {
color: #5E740B;
background-color: #fff;
border-left: 26px solid #C6E746;
}
#qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; }
#qunit-tests .pass .test-name { color: #366097; }
#qunit-tests .pass .test-actual,
#qunit-tests .pass .test-expected { color: #999999; }
#qunit-banner.qunit-pass { background-color: #C6E746; }
/*** Failing Styles */
#qunit-tests li li.fail {
color: #710909;
background-color: #fff;
border-left: 26px solid #EE5757;
}
#qunit-tests .fail { color: #000000; background-color: #EE5757; }
#qunit-tests .fail .test-name,
#qunit-tests .fail .module-name { color: #000000; }
#qunit-tests .fail .test-actual { color: #EE5757; }
#qunit-tests .fail .test-expected { color: green; }
#qunit-banner.qunit-fail,
#qunit-testrunner-toolbar { background-color: #EE5757; }
/** Footer */
#qunit-testresult {
padding: 0.5em 0.5em 0.5em 2.5em;
color: #2b81af;
background-color: #D2E0E6;
border-radius: 0 0 15px 15px;
-moz-border-radius: 0 0 15px 15px;
-webkit-border-bottom-right-radius: 15px;
-webkit-border-bottom-left-radius: 15px;
}
/** Fixture */
#qunit-fixture {
position: absolute;
top: -10000px;
left: -10000px;
}

1261
install/static/test/qunit.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -72,10 +72,19 @@ $(function() {
};
function init_on_win(data, text_status, xhr) {
ipa_cmd('user_find', [], {"whoami":"true","all":"true"}, whoami_on_win, null, null);
ipa_cmd('user_find', [], {"whoami":"true","all":"true"}, whoami_on_win,
function(xhr, options, thrownError) {
alert("Error: "+thrownError);
},
null
);
};
ipa_init(null, init_on_win);
ipa_init(null, null, init_on_win,
function(xhr, options, thrownError) {
alert("Error: "+thrownError);
}
);
});
/* use this to track individual changes between two hashchange events */