|
|
@@ -1221,74 +1221,77 @@ describe('i18n', function() {
|
|
|
});
|
|
|
|
|
|
it('default message', function() {
|
|
|
+ var format = $.fn.bootstrapValidator.helpers.format,
|
|
|
+ i18n = $.fn.bootstrapValidator.i18n;
|
|
|
+
|
|
|
this.bv.validate();
|
|
|
- expect(this.bv.getMessages(this.$fullName, 'notEmpty')[0]).toEqual($.fn.bootstrapValidator.i18n.notEmpty['default']);
|
|
|
+ expect(this.bv.getMessages(this.$fullName, 'notEmpty')[0]).toEqual(i18n.notEmpty['default']);
|
|
|
|
|
|
this.$fullName.val('lowerName');
|
|
|
this.bv.revalidateField('fullName');
|
|
|
- expect(this.bv.getMessages('fullName', 'stringCase')[0]).toEqual($.fn.bootstrapValidator.i18n.stringCase.upper);
|
|
|
+ expect(this.bv.getMessages('fullName', 'stringCase')[0]).toEqual(i18n.stringCase.upper);
|
|
|
|
|
|
this.bv.resetForm();
|
|
|
this.$userName.val('123');
|
|
|
this.bv.validate();
|
|
|
- expect(this.bv.getMessages('username', 'stringLength')[0]).toEqual($.fn.bootstrapValidator.i18n.stringLength.getMessage({ min: 6, max: 20 }));
|
|
|
+ expect(this.bv.getMessages('username', 'stringLength')[0]).toEqual(i18n.stringLength.getMessage({ min: 6, max: 20 }));
|
|
|
|
|
|
this.bv.resetForm();
|
|
|
this.$userName.val('contain@#$');
|
|
|
this.bv.validate();
|
|
|
- expect(this.bv.getMessages(this.$userName, 'regexp')[0]).toEqual($.fn.bootstrapValidator.i18n.regexp['default']);
|
|
|
+ expect(this.bv.getMessages(this.$userName, 'regexp')[0]).toEqual(i18n.regexp['default']);
|
|
|
|
|
|
this.bv.resetForm();
|
|
|
this.$userName.val('validUserName');
|
|
|
this.$password.val('validUserName');
|
|
|
this.bv.validate();
|
|
|
- expect(this.bv.getMessages('username', 'different')[0]).toEqual($.fn.bootstrapValidator.i18n.different['default']);
|
|
|
+ expect(this.bv.getMessages('username', 'different')[0]).toEqual(i18n.different['default']);
|
|
|
|
|
|
this.bv.resetForm();
|
|
|
this.$email.val('invalid#email@address');
|
|
|
this.bv.validate();
|
|
|
- expect(this.bv.getMessages(this.$email, 'emailAddress')[0]).toEqual($.fn.bootstrapValidator.i18n.emailAddress['default']);
|
|
|
+ expect(this.bv.getMessages(this.$email, 'emailAddress')[0]).toEqual(i18n.emailAddress['default']);
|
|
|
|
|
|
this.bv.resetForm();
|
|
|
this.$password.val('@S3cur3P@@w0rd');
|
|
|
this.$confirm.val('notMatch');
|
|
|
this.bv.validate();
|
|
|
- expect(this.bv.getMessages('password', 'identical')[0]).toEqual($.fn.bootstrapValidator.i18n.identical['default']);
|
|
|
+ expect(this.bv.getMessages('password', 'identical')[0]).toEqual(i18n.identical['default']);
|
|
|
|
|
|
this.bv.resetForm();
|
|
|
this.$age.val('notDigit');
|
|
|
this.bv.validate();
|
|
|
- expect(this.bv.getMessages('age', 'digits')[0]).toEqual($.fn.bootstrapValidator.i18n.digits['default']);
|
|
|
+ expect(this.bv.getMessages('age', 'digits')[0]).toEqual(i18n.digits['default']);
|
|
|
|
|
|
this.bv.resetForm();
|
|
|
this.$age.val(10);
|
|
|
this.bv.validate();
|
|
|
- expect(this.bv.getMessages(this.$age, 'greaterThan')[0]).toEqual($.fn.bootstrapValidator.i18n.greaterThan.getMessage({ value: 18 }));
|
|
|
+ expect(this.bv.getMessages(this.$age, 'greaterThan')[0]).toEqual(format(i18n.greaterThan['default'], 18));
|
|
|
|
|
|
this.bv.resetForm();
|
|
|
this.$age.val(120);
|
|
|
this.bv.validate();
|
|
|
- expect(this.bv.getMessages('age', 'lessThan')[0]).toEqual($.fn.bootstrapValidator.i18n.lessThan.getMessage({ value: 100 }));
|
|
|
+ expect(this.bv.getMessages('age', 'lessThan')[0]).toEqual(format(i18n.lessThan['default'], 100));
|
|
|
|
|
|
this.bv.resetForm();
|
|
|
this.$website.val('http://invalidWebsite');
|
|
|
this.bv.validate();
|
|
|
- expect(this.bv.getMessages('website', 'uri')[0]).toEqual($.fn.bootstrapValidator.i18n.uri['default']);
|
|
|
+ expect(this.bv.getMessages('website', 'uri')[0]).toEqual(i18n.uri['default']);
|
|
|
|
|
|
this.bv.resetForm();
|
|
|
this.$phone.val('123456');
|
|
|
this.bv.validate();
|
|
|
- expect(this.bv.getMessages('phoneNumber', 'phone')[0]).toEqual($.fn.bootstrapValidator.i18n.phone.getMessage({ country: 'US' }));
|
|
|
+ expect(this.bv.getMessages('phoneNumber', 'phone')[0]).toEqual(i18n.phone.getMessage({ country: 'US' }));
|
|
|
|
|
|
this.bv.resetForm();
|
|
|
this.$program.eq(0).prop('checked', 'checked');
|
|
|
this.bv.validate();
|
|
|
- expect(this.bv.getMessages(this.$program, 'choice')[0]).toEqual($.fn.bootstrapValidator.i18n.choice.getMessage({ min: 2, max: 4 }));
|
|
|
+ expect(this.bv.getMessages(this.$program, 'choice')[0]).toEqual(i18n.choice.getMessage({ min: 2, max: 4 }));
|
|
|
|
|
|
this.bv.resetForm();
|
|
|
this.$program.prop('checked', 'checked');
|
|
|
this.bv.validate();
|
|
|
- expect(this.bv.getMessages('programs[]', 'choice')[0]).toEqual($.fn.bootstrapValidator.i18n.choice.getMessage({ min: 2, max: 4 }));
|
|
|
+ expect(this.bv.getMessages('programs[]', 'choice')[0]).toEqual(i18n.choice.getMessage({ min: 2, max: 4 }));
|
|
|
});
|
|
|
});
|
|
|
|
|
|
@@ -2900,6 +2903,118 @@ describe('issn', function() {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
+function lessThanCompare() {
|
|
|
+ var compareTo = $('#lessThanForm').find('[name="maxAge"]').val();
|
|
|
+ $('#msg').html('lessThanCompare() called; compare to ' + compareTo);
|
|
|
+ return compareTo;
|
|
|
+};
|
|
|
+
|
|
|
+TestSuite = $.extend({}, TestSuite, {
|
|
|
+ lessThan: {
|
|
|
+ compareTo: function(value, validator, $field) {
|
|
|
+ var compareTo = $('#lessThanForm').find('[name="maxAge"]').val();
|
|
|
+ $('#msg').html('TestSuite.lessThan.compareTo() called; compare to ' + compareTo);
|
|
|
+ return compareTo;
|
|
|
+ }
|
|
|
+ }
|
|
|
+});
|
|
|
+
|
|
|
+describe('lessThan', function() {
|
|
|
+ beforeEach(function() {
|
|
|
+ $([
|
|
|
+ '<form class="form-horizontal" id="lessThanForm">',
|
|
|
+ '<div id="msg"></div>',
|
|
|
+ '<div class="form-group">',
|
|
|
+ '<input type="text" name="maxAge" />',
|
|
|
+ '</div>',
|
|
|
+ '<div class="form-group">',
|
|
|
+ '<input type="text" name="age" data-bv-lessthan data-bv-lessthan-value="100" />',
|
|
|
+ '</div>',
|
|
|
+ '</form>'
|
|
|
+ ].join('\n')).appendTo('body');
|
|
|
+
|
|
|
+ $('#lessThanForm').bootstrapValidator();
|
|
|
+
|
|
|
+ this.bv = $('#lessThanForm').data('bootstrapValidator');
|
|
|
+ this.$maxAge = this.bv.getFieldElements('maxAge');
|
|
|
+ this.$age = this.bv.getFieldElements('age');
|
|
|
+ });
|
|
|
+
|
|
|
+ afterEach(function() {
|
|
|
+ $('#lessThanForm').bootstrapValidator('destroy').remove();
|
|
|
+ });
|
|
|
+
|
|
|
+ it('compare to value', function() {
|
|
|
+ this.$age.val(120);
|
|
|
+ this.bv.validate();
|
|
|
+ expect(this.bv.isValid()).toEqual(false);
|
|
|
+
|
|
|
+ this.bv.resetForm();
|
|
|
+ this.$age.val(30);
|
|
|
+ this.bv.validate();
|
|
|
+ expect(this.bv.isValid()).toBeTruthy();
|
|
|
+ });
|
|
|
+
|
|
|
+ // Compare to maxAge field
|
|
|
+ it('compare to other field', function() {
|
|
|
+ this.$age.attr('data-bv-lessthan-value', 'maxAge');
|
|
|
+ this.bv.destroy();
|
|
|
+ this.bv = $('#lessThanForm').bootstrapValidator().data('bootstrapValidator');
|
|
|
+
|
|
|
+ this.$maxAge.val(40);
|
|
|
+ this.$age.val(20);
|
|
|
+ this.bv.validate();
|
|
|
+ expect(this.bv.isValid()).toBeTruthy();
|
|
|
+
|
|
|
+ this.bv.resetForm();
|
|
|
+ this.$maxAge.val(20);
|
|
|
+ this.$age.val(30);
|
|
|
+ this.bv.validate();
|
|
|
+ expect(this.bv.isValid()).toEqual(false);
|
|
|
+ expect(this.bv.getMessages('age', 'lessThan')[0]).toEqual($.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.lessThan['default'], this.$maxAge.val()));
|
|
|
+ });
|
|
|
+
|
|
|
+ it('compare to return value of a function', function() {
|
|
|
+ this.$age.attr('data-bv-lessthan-value', 'lessThanCompare');
|
|
|
+ this.bv.destroy();
|
|
|
+ this.bv = $('#lessThanForm').bootstrapValidator().data('bootstrapValidator');
|
|
|
+
|
|
|
+ this.$maxAge.val(50);
|
|
|
+ this.$age.val(60);
|
|
|
+ this.bv.validate();
|
|
|
+ expect($('#msg').html()).toEqual('lessThanCompare() called; compare to 50');
|
|
|
+ expect(this.bv.isValid()).toEqual(false);
|
|
|
+ expect(this.bv.getMessages('age', 'lessThan')[0]).toEqual($.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.lessThan['default'], this.$maxAge.val()));
|
|
|
+
|
|
|
+ this.bv.resetForm();
|
|
|
+ this.$maxAge.val(60);
|
|
|
+ this.$age.val(30);
|
|
|
+ this.bv.validate();
|
|
|
+ expect($('#msg').html()).toEqual('lessThanCompare() called; compare to 60');
|
|
|
+ expect(this.bv.isValid()).toBeTruthy();
|
|
|
+ });
|
|
|
+
|
|
|
+ it('compare to return value of a namespace function', function() {
|
|
|
+ this.$age.attr('data-bv-lessthan-value', 'TestSuite.lessThan.compareTo');
|
|
|
+ this.bv.destroy();
|
|
|
+ this.bv = $('#lessThanForm').bootstrapValidator().data('bootstrapValidator');
|
|
|
+
|
|
|
+ this.$maxAge.val(50);
|
|
|
+ this.$age.val(60);
|
|
|
+ this.bv.validate();
|
|
|
+ expect($('#msg').html()).toEqual('TestSuite.lessThan.compareTo() called; compare to 50');
|
|
|
+ expect(this.bv.isValid()).toEqual(false);
|
|
|
+ expect(this.bv.getMessages('age', 'lessThan')[0]).toEqual($.fn.bootstrapValidator.helpers.format($.fn.bootstrapValidator.i18n.lessThan['default'], this.$maxAge.val()));
|
|
|
+
|
|
|
+ this.bv.resetForm();
|
|
|
+ this.$maxAge.val(60);
|
|
|
+ this.$age.val(30);
|
|
|
+ this.bv.validate();
|
|
|
+ expect($('#msg').html()).toEqual('TestSuite.lessThan.compareTo() called; compare to 60');
|
|
|
+ expect(this.bv.isValid()).toBeTruthy();
|
|
|
+ });
|
|
|
+});
|
|
|
+
|
|
|
describe('vat', function() {
|
|
|
beforeEach(function() {
|
|
|
$([
|