mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-08 03:01:43 +09:00
Add tests for common javascript files
git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@8996 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
76999d3054
commit
8dfab7ec21
5 changed files with 1932 additions and 0 deletions
35
tests/common/js/index.html
Normal file
35
tests/common/js/index.html
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="stylesheet" href="qunit.css" type="text/css" />
|
||||
<script type="text/javascript" src="../../../common/js/jquery.js"></script>
|
||||
<script type="text/javascript" src="../../../common/js/common.js"></script>
|
||||
<script type="text/javascript" src="../../../common/js/js_app.js"></script>
|
||||
<script type="text/javascript" src="../../../common/js/xml_handler.js"></script>
|
||||
<script type="text/javascript" src="../../../common/js/xml_js_filter.js"></script>
|
||||
<script type="text/javascript" src="qunit.js"></script>
|
||||
<script type="text/javascript" src="js_app.test.js"></script>
|
||||
<script type="text/javascript" src="xml_js_filter.test.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1 id="qunit-header">Common JavaScript Test</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 id="plugin-test"></div>
|
||||
<form id="validator-test">
|
||||
<input type="hidden" name="ruleset" value="ruleset" />
|
||||
<input type="text" name="user_1" value="" />
|
||||
<input type="text" name="user_2" value="" />
|
||||
<input type="text" name="user_3" value="" />
|
||||
<input type="checkbox" name="chkbox1" value="" />
|
||||
<input type="checkbox" name="chkbox1" value="" />
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
105
tests/common/js/js_app.test.js
Normal file
105
tests/common/js/js_app.test.js
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
jQuery(function($){
|
||||
module('JAF');
|
||||
|
||||
var App = xe.createApp('App', {
|
||||
value : 1,
|
||||
init : function() {
|
||||
this.value = 2;
|
||||
},
|
||||
API_GET_VALUE : function(sender, params) {
|
||||
return this.value;
|
||||
},
|
||||
API_SET_VALUE : function(sender, params) {
|
||||
this.value = params[0];
|
||||
}
|
||||
});
|
||||
|
||||
var Plugin = xe.createPlugin('Plugin', {
|
||||
API_BEFORE_GET_VALUE : function(sender, params) {
|
||||
if (params[0]) return false;
|
||||
},
|
||||
API_BEFORE_SET_VALUE : function(sender, params) {
|
||||
params[0] = params[0] * 3;
|
||||
},
|
||||
API_METHOD : function(sender, params) {
|
||||
$('#plugin-test').html(params[0]);
|
||||
}
|
||||
});
|
||||
|
||||
test('Global object - xe', function(){
|
||||
equal(xe.getName(), 'Core');
|
||||
ok($.isFunction(xe.createApp), 'xe has createApp method');
|
||||
ok($.isFunction(xe.createPlugin), 'xe has createPlugin method');
|
||||
ok($.isFunction(xe.getApps), 'xe has getApps method');
|
||||
ok($.isFunction(xe.getApp), 'xe has getApp method');
|
||||
ok($.isFunction(xe.registerApp), 'xe has registerApp method');
|
||||
ok($.isFunction(xe.unregisterApp), 'xe has unregisterApp method');
|
||||
ok($.isFunction(xe.broadcast), 'xe has broadcast method');
|
||||
});
|
||||
test('App', function() {
|
||||
var app1 = new App();
|
||||
|
||||
equal(app1.getName(), 'App', 'The app1 is an instance of App.');
|
||||
ok(xe.getApp('App') == null, 'The app1 is NOT registered yet.');
|
||||
|
||||
xe.registerApp(app1);
|
||||
|
||||
ok(xe.getApp('App')[0] === app1, 'The app1 is registered successfully.');
|
||||
equal(app1.cast('GET_VALUE'), 2);
|
||||
|
||||
xe.unregisterApp(app1);
|
||||
|
||||
ok(xe.getApp('App') == null, 'The app1 is unregistered.');
|
||||
});
|
||||
test('Plugin', function() {
|
||||
xe.registerApp(new App());
|
||||
|
||||
var plugin1 = new Plugin();
|
||||
|
||||
equal(plugin1.getName(), 'Plugin', 'The plugin1 is an instance of Plugin.');
|
||||
|
||||
var app1 = xe.getApp('App')[0];
|
||||
|
||||
app1.registerPlugin(plugin1);
|
||||
|
||||
ok(typeof app1.cast('GET_VALUE', [true]) == 'undefined', 'Stop GET_VALUE action');
|
||||
|
||||
var val = app1.cast('GET_VALUE');
|
||||
equal(app1.cast('GET_VALUE'), val, 'Check current value');
|
||||
|
||||
app1.cast('SET_VALUE', [3]);
|
||||
equal(app1.cast('GET_VALUE'), 9, 'Before hooker should change input value 3 into');
|
||||
|
||||
// original method
|
||||
var obj = $('#plugin-test');
|
||||
equal(obj.html(), '', 'There is no content');
|
||||
|
||||
app1.cast('METHOD', ['hello']);
|
||||
equal(obj.html(), 'hello', 'The plugin set the content');
|
||||
|
||||
obj.hide();
|
||||
|
||||
xe.unregisterApp(app1);
|
||||
});
|
||||
test('Function : You can register a function as a message handler', function() {
|
||||
xe.registerApp(new App());
|
||||
|
||||
function handler(sender, params) {
|
||||
params[0] = params[0] + ', world!';
|
||||
}
|
||||
|
||||
var app1 = xe.getApp('App')[0];
|
||||
app1.registerPlugin(new Plugin());
|
||||
|
||||
var obj = $('#plugin-test');
|
||||
app1.cast('METHOD', ['Hello']);
|
||||
equal(obj.html(), 'Hello', 'The plugin set the content');
|
||||
|
||||
app1.registerHandler('BEFORE_METHOD', handler);
|
||||
app1.cast('METHOD', ['Hello']);
|
||||
equal(obj.html(), 'Hello, world!', 'The handler function changes a passed parameter.');
|
||||
|
||||
xe.unregisterApp(app1);
|
||||
});
|
||||
|
||||
});
|
||||
228
tests/common/js/qunit.css
Normal file
228
tests/common/js/qunit.css
Normal file
|
|
@ -0,0 +1,228 @@
|
|||
/**
|
||||
* QUnit - A JavaScript Unit Testing Framework
|
||||
*
|
||||
* http://docs.jquery.com/QUnit
|
||||
*
|
||||
* Copyright (c) 2011 John Resig, Jörn Zaefferer
|
||||
* Dual licensed under the MIT (MIT-LICENSE.txt)
|
||||
* or GPL (GPL-LICENSE.txt) licenses.
|
||||
* Pulled Live from Git Fri Sep 2 02:15:01 UTC 2011
|
||||
* Last Commit: 7f292170fa1109f1355f3e96f8973c32fc553946
|
||||
*/
|
||||
|
||||
/** 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, sans-serif;
|
||||
}
|
||||
|
||||
#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: #8699a4;
|
||||
background-color: #0d3349;
|
||||
|
||||
font-size: 1.5em;
|
||||
line-height: 1em;
|
||||
font-weight: normal;
|
||||
|
||||
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: #c2ccd1;
|
||||
}
|
||||
|
||||
#qunit-header a:hover,
|
||||
#qunit-header a:focus {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
#qunit-banner {
|
||||
height: 5px;
|
||||
}
|
||||
|
||||
#qunit-testrunner-toolbar {
|
||||
padding: 0.5em 0 0.5em 2em;
|
||||
color: #5E740B;
|
||||
background-color: #eee;
|
||||
}
|
||||
|
||||
#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.hidepass li.pass, #qunit-tests.hidepass li.running {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#qunit-tests li strong {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#qunit-tests li a {
|
||||
padding: 0.5em;
|
||||
color: #c2ccd1;
|
||||
text-decoration: none;
|
||||
}
|
||||
#qunit-tests li a:hover,
|
||||
#qunit-tests li a:focus {
|
||||
color: #000;
|
||||
}
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
#qunit-tests table {
|
||||
border-collapse: collapse;
|
||||
margin-top: .2em;
|
||||
}
|
||||
|
||||
#qunit-tests th {
|
||||
text-align: right;
|
||||
vertical-align: top;
|
||||
padding: 0 .5em 0 0;
|
||||
}
|
||||
|
||||
#qunit-tests td {
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
#qunit-tests pre {
|
||||
margin: 0;
|
||||
white-space: pre-wrap;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
|
||||
#qunit-tests del {
|
||||
background-color: #e0f2be;
|
||||
color: #374e0c;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
#qunit-tests ins {
|
||||
background-color: #ffcaca;
|
||||
color: #500;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
/*** 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;
|
||||
white-space: pre;
|
||||
}
|
||||
|
||||
#qunit-tests > li:last-child {
|
||||
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;
|
||||
}
|
||||
|
||||
#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 { background-color: #EE5757; }
|
||||
|
||||
|
||||
/** Result */
|
||||
|
||||
#qunit-testresult {
|
||||
padding: 0.5em 0.5em 0.5em 2.5em;
|
||||
|
||||
color: #2b81af;
|
||||
background-color: #D2E0E6;
|
||||
|
||||
border-bottom: 1px solid white;
|
||||
}
|
||||
|
||||
/** Fixture */
|
||||
|
||||
#qunit-fixture {
|
||||
position: absolute;
|
||||
top: -10000px;
|
||||
left: -10000px;
|
||||
}
|
||||
1512
tests/common/js/qunit.js
Normal file
1512
tests/common/js/qunit.js
Normal file
File diff suppressed because it is too large
Load diff
52
tests/common/js/xml_js_filter.test.js
Normal file
52
tests/common/js/xml_js_filter.test.js
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
jQuery(function($){
|
||||
module('Validator');
|
||||
|
||||
var
|
||||
v = xe.getApp('validator')[0],
|
||||
$form = $('#validator-test'),
|
||||
form = $form[0], elems = form.elements;
|
||||
|
||||
var Mute = xe.createPlugin('Mute', {
|
||||
API_BEFORE_ALERT : function(){ return false }
|
||||
});
|
||||
v.registerPlugin(new Mute());
|
||||
|
||||
test('Basics', function(){
|
||||
ok(v.run(form), 'Default return value is true');
|
||||
});
|
||||
|
||||
test('attr : required?', function(){
|
||||
form.reset();
|
||||
form.ruleset.value = 'ruleset';
|
||||
|
||||
v.cast('ADD_FILTER', ['ruleset', {'user_1':{required:true}}]);
|
||||
ok(!v.run(form), 'The required field should have some value. - test1');
|
||||
|
||||
elems.user_1.value = 'myname';
|
||||
ok(v.run(form), 'The required field should have some value. - test2');
|
||||
});
|
||||
|
||||
test('attr : name pattern', function(){
|
||||
form.reset();
|
||||
form.ruleset.value = 'ruleset';
|
||||
|
||||
v.cast(
|
||||
'ADD_FILTER',
|
||||
['ruleset',
|
||||
{
|
||||
'^user_':{required:true}
|
||||
}
|
||||
]
|
||||
);
|
||||
|
||||
elems.user_1.value = 'value1';
|
||||
ok(!v.run(form), 'This test should be failed. (only one of three fields has value)');
|
||||
|
||||
elems.user_2.value = 'value2';
|
||||
ok(!v.run(form), 'not yet (2 of 3)');
|
||||
|
||||
elems.user_3.value = 'value3';
|
||||
ok(v.run(form), 'ok! you should pass at this time. (3 of 3)');
|
||||
});
|
||||
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue