Skip to content

Commit

Permalink
[#2525] Add tests for jQuery.fn.slugPreview()
Browse files Browse the repository at this point in the history
  • Loading branch information
aron committed Jul 2, 2012
1 parent 7976b08 commit b53c105
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
2 changes: 2 additions & 0 deletions ckan/public/base/test/index.html
Expand Up @@ -21,10 +21,12 @@
<script src="../javascript/vendor/jquery.js"></script>
<script src="../javascript/plugins/jquery.url-helpers.js"></script>
<script src="../javascript/plugins/jquery.slug.js"></script>
<script src="../javascript/plugins/jquery.slug-preview.js"></script>

<!-- Suite -->
<script src="./spec/plugins/jquery.url-helpers.spec.js"></script>
<script src="./spec/plugins/jquery.slug.spec.js"></script>
<script src="./spec/plugins/jquery.slug-preview.spec.js"></script>

<script>
beforeEach(function () {
Expand Down
65 changes: 65 additions & 0 deletions ckan/public/base/test/spec/plugins/jquery.slug-preview.spec.js
@@ -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');
});
});
4 changes: 2 additions & 2 deletions ckan/public/base/test/spec/plugins/jquery.url-helpers.spec.js
@@ -1,6 +1,6 @@
/*globals describe it assert jQuery*/
describe('jQuery.url', function () {
describe('jQuery.url.escape', function () {
describe('.escape()', function () {
it('should escape special characters', function () {
var target = jQuery.url.escape('&<>=?#/');
assert.equal(target, '%26%3C%3E%3D%3F%23%2F');
Expand All @@ -12,7 +12,7 @@ describe('jQuery.url', function () {
});
});

describe('jQuery.url.slugify', function () {
describe('.slugify()', function () {
it('should replace spaces with hyphens', function () {
var target = jQuery.url.slugify('apples and pears');
assert.equal(target, 'apples-and-pears');
Expand Down

0 comments on commit b53c105

Please sign in to comment.