rhymix/common/js/unittest/unittest_validator.html
taggon c2baeee4a3 fix unittest_validator
git-svn-id: http://xe-core.googlecode.com/svn/sandbox@7332 201d5d3c-b55e-5fd7-737f-ddc643e51545
2010-03-09 09:49:30 +00:00

109 lines
3 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<title>JSSpec results</title>
<link rel="stylesheet" type="text/css" href="css/JSSpec.css" />
<script type="text/javascript" src="JSSpec/JSSpec.js"></script>
<script type="text/javascript" src="JSSpec/diff_match_patch.js"></script>
<script type="text/javascript" src="../jquery.js"></script>
<script type="text/javascript" src="../js_app.js"></script>
<script type="text/javascript" src="../xml_js_filter.js"></script>
<script type="text/javascript">// <![CDATA[
var v, f, t, last_alert='';
var validate, set_filter, set_value;
describe('Validator', {
'before' : function() {
v = xe.getApp('Validator')[0];
f = $('#form1');
t = f[0].elements['text'];
validate = function(){ return v.cast('VALIDATE', [f[0]]); };
set_filter = function(filter_name){ f[0]._filter.value = filter_name };
set_value = function(val){ t.value = val };
var silent = xe.createPlugin('silent', {
API_BEFORE_SHOW_ALERT : function(sender, params) { last_alert=params[1]; return false; }
});
v.registerPlugin(new silent);
},
'should be true with no filter' : function() {
// no filter
set_filter('');
value_of(validate()).should_be_true();
},
'should check required feild' : function() {
v.cast('ADD_FILTER', ['required', {
'text' : {required:true}
}]);
set_filter('required');
set_value('');
value_of(validate()).should_be_false();
set_value('1');
value_of(validate()).should_be_true();
},
'validate email' : function() {
v.cast('ADD_FILTER', ['email', {
'text' : {required:true, rule:'email'}
}]);
set_filter('email');
set_value('not_email');
value_of(validate()).should_be_false();
set_value('email@mail.com');
value_of(validate()).should_be_true();
},
'validate with length' : function() {
v.cast('ADD_FILTER', ['minlength', {
'text' : {required:true, minlength:5}
}]);
v.cast('ADD_FILTER', ['maxlength', {
'text' : {required:true, maxlength:10}
}]);
v.cast('ADD_FILTER', ['minmaxlength', {
'text' : {required:true, minlength:5, maxlength:10}
}]);
set_filter('minlength');
set_value('1');
value_of(validate()).should_be_false();
set_value('12345');
value_of(validate()).should_be_true();
set_filter('maxlength');
set_value('12345678901');
value_of(validate()).should_be_false();
set_value('1');
value_of(validate()).should_be_true();
set_filter('minmaxlength');
set_value('1');
value_of(validate()).should_be_false();
set_value('12345678901');
value_of(validate()).should_be_false();
set_value('12345');
value_of(validate()).should_be_true();
set_value('1234567');
value_of(validate()).should_be_true();
}
})
// ]]></script>
</head>
<body>
<form id="form1">
<input type="hidden" name="_filter" value="" />
<input type="hidden" name="text" value="" />
</form>
</body>
</html>