Skip to content
Browse files

not finished yet, getting different result on FF and Chrome

  • Loading branch information...
1 parent b2edcdf commit eb44809687ae3c3cacd586f308903e1cf1ecfc33 Joshy Cyriac committed Apr 16, 2012
Showing with 68 additions and 37 deletions.
  1. +11 −19 test/index.html
  2. +57 −18 test/tests.js
View
30 test/index.html
@@ -18,29 +18,21 @@ <h2 id="qunit-userAgent"></h2>
<div id="qunit-fixture">
<form id="form1">
- <input id="input_text" type="text" size="20" value="2"><span class="msg"></span><br><br>
+ <!-- valid input, numeric values allowed -->
+ <input id="input_text1" type="text" size="20" value="2"><span class="msg"></span><br><br>
</form>
+
+ <form id="form2">
+ <!-- valid input, numeric values allowed -->
+ <div id="form2-div1">
+ <input id="input_text2" type="text" value="2" />
+ </div>
+ <!-- invalid input -->
+ <input id="input_text3" type="text" value="qwer" />
+ </form>
</div>
</body>
-<script type="text/javascript">
-
- var remoteValidation = function(field){
- console.log('starting remotevalidation'+$(field).attr('id'));
- return $.ajax({
- url: 'validate/form1',
- });
- };
-
- $('input_text').on('validation_valid', function(event, data){
- $(this).nextAll('.msg').first().text("valid");
- return false;
- });
-
- $(document).ready(function() {
- $('#input_text').validate({validate:[remoteValidation]});
- });
-</script>
</html>
View
75 test/tests.js
@@ -1,32 +1,71 @@
-// without input form is invalid
+function DefaultRemoteValidation(url) {
+ this.url = url;
+ this.validate = [function(field){return remoteValidation(field, url)}];
+}
+
+var remoteValidation = function(field, url) {
+ return $.ajax({
+ url: url,
+ data: $(field).attr('id')+"="+$(field).val()
+ });
+};
+
+//
+test('get field value from input', function() {
+ expect(1);
+ equal($.fn.validate('getFieldValue', $('#input_text1')), 2, 'correctly read value from input field');
+});
+
+
+// evaluate global state test
+// input_text3 is invalid -> global state is invalid
test('evaluate global state', function() {
- var validation_state;
+ expect(3);
+
+ $.mockjax({
+ url: 'validate/form2/input_text3',
+ dataType: 'json',
+ responseText: {
+ state: 'invalid'
+ }
+ });
+
+ $('#input_text3').validate(new DefaultRemoteValidation('validate/form2/input_text3'));
+
$(document).on('global_validation_result', function(event, data) {
validation_state = data.state;
ok(true, 'global validation result triggered');
+ equal(data.state, 'invalid', 'global state is invalid');
});
+
$.when($.fn.validate('evaluateGlobalState')).then(function() {
ok(true, 'evaluate globale state called');
- equal(validation_state, 'invalid');
});
+
+ $.mockjaxClear();
});
-//
-test('get field value from input', function() {
- equal($.fn.validate('getFieldValue', $('#input_text')), 2);
-});
-
-// test engine with remote validation
-test('validateInputField', function() {
+// testing the scope functionality
+test('scope test', function() {
+ expect(1);
+
$.mockjax({
- url : 'validate/form1',
- dataType : 'json',
- responseText : {
- state : 'valid',
- msg : 'input is valid'
+ url: 'validate/form2/input_text2',
+ dataType: 'json',
+ responseText: {
+ state: 'valid'
}
});
- $.fn.validate('validateAll');
- ok($('#input_text').nextAll('.msg').text === 'valid', 'text input is valid');
+
+ $('#input_text2').validate(new DefaultRemoteValidation('validate/form2/input_text2'));
+
+ $('#input_text2').on('validation_valid', function(event, data){
+ equal(data.state, 'valid', 'input_text2 is valid');
+ start();
+ });
+
+ $.fn.validate('validateAll', $('#form2-div1'));
+ stop();
+
$.mockjaxClear();
-});
+});

0 comments on commit eb44809

Please sign in to comment.
Something went wrong with that request. Please try again.