Skip to content

Commit

Permalink
[#2525] Add tests for jQuery.url.slugify()
Browse files Browse the repository at this point in the history
  • Loading branch information
aron committed Jul 2, 2012
1 parent ac79236 commit 8d085d3
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions ckan/public/base/test/spec/plugins/jquery.url-helpers.spec.js
@@ -1,3 +1,4 @@
/*globals describe it assert jQuery*/
describe('jQuery.url', function () {
describe('jQuery.url.escape', function () {
it('should escape special characters', function () {
Expand All @@ -10,4 +11,37 @@ describe('jQuery.url', function () {
assert.equal(target, '+');
});
});

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

it('should lowecase all characters', function () {
var target = jQuery.url.slugify('APPLES AND PEARS');
assert.equal(target, 'apples-and-pears');
});

it('should convert unknown characters to hyphens', function () {
var target = jQuery.url.slugify('apples & pears');
assert.equal(target, 'apples-pears');
});

it('should nomalise hyphens', function () {
var target = jQuery.url.slugify('apples---pears');
assert.equal(target, 'apples-pears', 'remove duplicate hyphens');

target = jQuery.url.slugify('--apples-pears');
assert.equal(target, 'apples-pears', 'strip preceding hyphens');

target = jQuery.url.slugify('apples-pears--');
assert.equal(target, 'apples-pears', 'strip trailing hyphens');
});

it('should try and asciify unicode characters', function () {
var target = jQuery.url.slugify('éåøç');
assert.equal(target, 'eaoc');
});
});
});

0 comments on commit 8d085d3

Please sign in to comment.