From 8d085d36509553e5459d2c52a6af4fd6cb2f3934 Mon Sep 17 00:00:00 2001 From: Aron Carroll Date: Mon, 2 Jul 2012 15:05:37 +0100 Subject: [PATCH] [#2525] Add tests for jQuery.url.slugify() --- .../spec/plugins/jquery.url-helpers.spec.js | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) 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'); + }); + }); });