From 7976b08451029c71f0f8dcf86d59533a2f013e54 Mon Sep 17 00:00:00 2001 From: Aron Carroll Date: Mon, 2 Jul 2012 15:22:15 +0100 Subject: [PATCH] [#2525] Add tests for jQuery.fn.slug() --- ckan/public/base/test/index.html | 13 ++++++- .../test/spec/plugins/jquery.slug.spec.js | 34 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 ckan/public/base/test/spec/plugins/jquery.slug.spec.js diff --git a/ckan/public/base/test/index.html b/ckan/public/base/test/index.html index a569ba4818d..43a94f95087 100644 --- a/ckan/public/base/test/index.html +++ b/ckan/public/base/test/index.html @@ -7,23 +7,34 @@
+
+ + diff --git a/ckan/public/base/test/spec/plugins/jquery.slug.spec.js b/ckan/public/base/test/spec/plugins/jquery.slug.spec.js new file mode 100644 index 00000000000..7c96c881820 --- /dev/null +++ b/ckan/public/base/test/spec/plugins/jquery.slug.spec.js @@ -0,0 +1,34 @@ +/*globals beforeEach describe it assert jQuery*/ +describe('jQuery.slug()', function () { + beforeEach(function () { + this.input = jQuery('').slug(); + this.fixture.append(this.input); + }); + + it('should slugify and append the pressed key', function () { + var e = jQuery.Event('keypress', {charCode: 97 /* a */}); + this.input.trigger(e); + + assert(this.input.val(), 'a', 'append an "a"'); + + e = jQuery.Event('keypress', {charCode: 38 /* & */}); + this.input.trigger(e); + + assert(this.input.val(), 'a-', 'append an "-"'); + }); + + it('should do nothing if a non character key is pressed', function () { + var e = jQuery.Event('keypress', {charCode: 0}); + this.input.val('some other string').trigger(e); + + assert(this.input.val(), 'some other string'); + }); + + it('should slugify the input contents on "blur" and "change" events', function () { + this.input.val('apples & pears').trigger(jQuery.Event('blur')); + assert(this.input.val(), 'apples-pears', 'on blur'); + + this.input.val('apples & pears').trigger(jQuery.Event('change')); + assert(this.input.val(), 'apples-pears', 'on change'); + }); +});