Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#2525] Add tests for jQuery.fn.slugPreview()
- Loading branch information
Showing
3 changed files
with
69 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
ckan/public/base/test/spec/plugins/jquery.slug-preview.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/*globals describe it assert jQuery*/ | ||
describe('jQuery.fn.slugPreview()', function () { | ||
beforeEach(function () { | ||
this.element = jQuery('<div><input /></div>'); | ||
}); | ||
|
||
it('should return the preview element', function () { | ||
var target = this.element.slugPreview(); | ||
assert.ok(target.hasClass('slug-preview')); | ||
}); | ||
|
||
it('should restore the stack when .end() is called', function () { | ||
var target = this.element.slugPreview(); | ||
assert.equal(target.end(), this.element); | ||
}); | ||
|
||
it('should allow a prefix to be provided', function () { | ||
var target = this.element.slugPreview({prefix: 'prefix'}); | ||
assert.equal(target.find('.slug-preview-prefix').text(), 'prefix'); | ||
}); | ||
|
||
it('should allow a placeholder to be provided', function () { | ||
var target = this.element.slugPreview({placeholder: 'placeholder'}); | ||
assert.equal(target.find('.slug-preview-value').text(), 'placeholder'); | ||
}); | ||
|
||
it('should allow translations for strings to be provided', function () { | ||
var target = this.element.slugPreview({ | ||
trans: {edit: 'translated'} | ||
}); | ||
assert.equal(target.find('button').text(), 'translated'); | ||
}); | ||
|
||
it('should set preview value to the initial value of the input', function () { | ||
var input = this.element.find('input').val('initial'); | ||
var target = this.element.slugPreview(); | ||
|
||
assert.equal(target.find('.slug-preview-value').text(), 'initial'); | ||
}); | ||
|
||
it('should update the preview value when the target input changes', function () { | ||
var target = this.element.slugPreview(); | ||
var input = this.element.find('input').val('initial'); | ||
|
||
input.val('updated').change(); | ||
assert.equal(target.find('.slug-preview-value').text(), 'updated'); | ||
}); | ||
|
||
it('should hide the original element', function () { | ||
var target = this.element.slugPreview(); | ||
assert.ok(this.element.css('display') === 'none'); | ||
}); | ||
|
||
it('should show the original element when Edit is clicked', function () { | ||
var target = this.element.slugPreview(); | ||
target.find('button').click(); | ||
assert.ok(this.element.css('display') === 'block'); | ||
}); | ||
|
||
it('should hide the preview element when Edit is clicked', function () { | ||
var target = this.element.slugPreview(); | ||
target.find('button').click(); | ||
assert.ok(target.css('display') === 'none'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters