diff --git a/ckan/public/base/test/spec/plugins/jquery.url-helpers.spec.js b/ckan/public/base/test/spec/plugins/jquery.url-helpers.spec.js index 456610c0fec..a16ca561af7 100644 --- a/ckan/public/base/test/spec/plugins/jquery.url-helpers.spec.js +++ b/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 () { @@ -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'); + }); + }); });