describe('stringLength', function() { beforeEach(function() { $([ '
', '
', '', '
', '
', '', '
', '
', '', '
', '
', '', '
', '
', '', '
', '
', '', '
', '
', '', '
', '
', '', '
', '
', '', '
', '
', '', '
', '
', '', '
', '
', '', '
', '
' ].join('\n')).appendTo('body'); $('#stringLengthForm').bootstrapValidator(); this.bv = $('#stringLengthForm').data('bootstrapValidator'); this.$textCharMaxLength = this.bv.getFieldElements('textCharMaxLength'); this.$textareaCharMaxLength = this.bv.getFieldElements('textareaCharMaxLength'); this.$textUTF8BytesMaxLength = this.bv.getFieldElements('textUTF8BytesMaxLength'); this.$textareaUTF8BytesMaxLength = this.bv.getFieldElements('textareaUTF8BytesMaxLength'); this.$textCharMinLength = this.bv.getFieldElements('textCharMinLength'); this.$textareaCharMinLength = this.bv.getFieldElements('textareaCharMinLength'); this.$textUTF8BytesMinLength = this.bv.getFieldElements('textUTF8BytesMinLength'); this.$textareaUTF8BytesMinLength = this.bv.getFieldElements('textareaUTF8BytesMinLength'); this.$textCharMinMaxLength = this.bv.getFieldElements('textCharMinMaxLength'); this.$textareaCharMinMaxLength = this.bv.getFieldElements('textareaCharMinMaxLength'); this.$textUTF8BytesMinMaxLength = this.bv.getFieldElements('textUTF8BytesMinMaxLength'); this.$textareaUTF8BytesMinMaxLength = this.bv.getFieldElements('textareaUTF8BytesMinMaxLength'); }); afterEach(function() { $('#stringLengthForm').bootstrapValidator('destroy').remove(); }); it('Valid Max Lengths', function() { this.$textCharMaxLength.val('123456789♥'); this.$textareaCharMaxLength.val('123456789♥'); this.$textUTF8BytesMaxLength.val('1234567♥'); this.$textareaUTF8BytesMaxLength.val('1234567♥'); this.bv.validate(); expect(this.bv.isValid()).toBeTruthy(); }); it('Valid Min Lengths', function() { this.$textCharMinLength.val('1234♥'); this.$textareaCharMinLength.val('1234♥'); this.$textUTF8BytesMinLength.val('12♥'); this.$textareaUTF8BytesMinLength.val('12♥'); this.bv.validate(); expect(this.bv.isValid()).toBeTruthy(); }); it('Valid Min and Max Lengths', function() { this.$textCharMinMaxLength.val('1234♥'); this.$textareaCharMinMaxLength.val('1234♥'); this.$textUTF8BytesMinMaxLength.val('12♥'); this.$textareaUTF8BytesMinMaxLength.val('12♥'); this.bv.validate(); expect(this.bv.isValid()).toBeTruthy(); this.bv.resetForm(); this.$textCharMinMaxLength.val('123456789♥'); this.$textareaCharMinMaxLength.val('123456789♥'); this.$textUTF8BytesMinMaxLength.val('1234567♥'); this.$textareaUTF8BytesMinMaxLength.val('1234567♥'); this.bv.validate(); expect(this.bv.isValid()).toBeTruthy(); }); it('Invalid Max Lengths', function() { this.$textCharMaxLength.val('1234567890♥'); // 11 chars when max is 10 this.bv.validate(); expect(this.bv.isValid()).toEqual(false); this.bv.resetForm(); this.$textareaCharMaxLength.val('1234567890♥'); // 11 chars when max is 10 this.bv.validate(); expect(this.bv.isValid()).toEqual(false); this.bv.resetForm(); this.$textUTF8BytesMaxLength.val('12345678♥'); // 11 UTF-8 bytes when max is 10 this.bv.validate(); expect(this.bv.isValid()).toEqual(false); this.bv.resetForm(); this.$textareaUTF8BytesMaxLength.val('12345678♥'); // 11 UTF-8 bytes when max is 10 this.bv.validate(); expect(this.bv.isValid()).toEqual(false); }); it('Invalid Min Lengths', function() { this.$textCharMinLength.val('123♥'); // 4 chars when min is 5 this.bv.validate(); expect(this.bv.isValid()).toEqual(false); this.bv.resetForm(); this.$textareaCharMinLength.val('123♥'); // 4 chars when min is 5 this.bv.validate(); expect(this.bv.isValid()).toEqual(false); this.bv.resetForm(); this.$textUTF8BytesMinLength.val('1♥'); // 4 UTF-8 bytes when min is 5 this.bv.validate(); expect(this.bv.isValid()).toEqual(false); this.bv.resetForm(); this.$textareaUTF8BytesMinLength.val('1♥'); // 4 UTF-8 bytes when min is 5 this.bv.validate(); expect(this.bv.isValid()).toEqual(false); }); it('Invalid Min and Max Lengths', function() { this.$textCharMinMaxLength.val('123♥'); // 4 chars when min is 5 and max is 10 this.bv.validate(); expect(this.bv.isValid()).toEqual(false); this.bv.resetForm(); this.$textareaCharMinMaxLength.val('123♥'); // 4 chars when min is 5 and max is 10 this.bv.validate(); expect(this.bv.isValid()).toEqual(false); this.bv.resetForm(); this.$textUTF8BytesMinMaxLength.val('1♥'); // 4 UTF-8 bytes when min is 5 and max is 10 this.bv.validate(); expect(this.bv.isValid()).toEqual(false); this.bv.resetForm(); this.$textareaUTF8BytesMinMaxLength.val('1♥'); // 4 UTF-8 bytes when min is 5 and max is 10 this.bv.validate(); expect(this.bv.isValid()).toEqual(false); this.bv.resetForm(); this.$textCharMinMaxLength.val('1234567890♥'); // 11 chars when min is 5 and max is 10 this.bv.validate(); expect(this.bv.isValid()).toEqual(false); this.bv.resetForm(); this.$textareaCharMinMaxLength.val('1234567890♥'); // 11 chars when min is 5 and max is 10 this.bv.validate(); expect(this.bv.isValid()).toEqual(false); this.bv.resetForm(); this.$textUTF8BytesMinMaxLength.val('12345678♥'); // 11 UTF-8 bytes when min is 5 and max is 10 this.bv.validate(); expect(this.bv.isValid()).toEqual(false); this.bv.resetForm(); this.$textareaUTF8BytesMinMaxLength.val('12345678♥'); // 11 UTF-8 bytes when min is 5 and max is 10 this.bv.validate(); expect(this.bv.isValid()).toEqual(false); }); });