From 1041977d0acedfcbd0d2a0d4a007496ccad10991 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Sat, 10 Sep 2011 13:17:08 -0700 Subject: [PATCH] finish up rounding out tests for all js plugins --- js/bootstrap-popover.js | 4 +- js/bootstrap-twipsy.js | 19 ++++--- js/tests/unit/bootstrap-popover.js | 84 +++++++++++++++++++++++++----- 3 files changed, 82 insertions(+), 25 deletions(-) diff --git a/js/bootstrap-popover.js b/js/bootstrap-popover.js index 646b22b644..5928fe8caf 100644 --- a/js/bootstrap-popover.js +++ b/js/bootstrap-popover.js @@ -59,10 +59,10 @@ $.fn.popover = function (options) { if (typeof options == 'object') options = $.extend({}, $.fn.popover.defaults, options) - $.fn.twipsy.initWith.call(this, options, Popover) + $.fn.twipsy.initWith.call(this, options, Popover, 'popover') return this } - $.fn.popover.defaults = $.extend({}, $.fn.twipsy.defaults, { content: '', placement: 'right'}) + $.fn.popover.defaults = $.extend({} , $.fn.twipsy.defaults, { content: 'content', placement: 'right'}) })( jQuery || ender ) \ No newline at end of file diff --git a/js/bootstrap-twipsy.js b/js/bootstrap-twipsy.js index 24c422cb52..ac2f562414 100644 --- a/js/bootstrap-twipsy.js +++ b/js/bootstrap-twipsy.js @@ -187,35 +187,34 @@ * ======================== */ $.fn.twipsy = function (options) { - $.fn.twipsy.initWith.call(this, options, Twipsy) + $.fn.twipsy.initWith.call(this, options, Twipsy, 'twipsy') return this } - $.fn.twipsy.initWith = function (options, Constructor) { - + $.fn.twipsy.initWith = function (options, Constructor, name) { var twipsy , binder , eventIn , eventOut if (options === true) { - return this.data('twipsy') + return this.data(name) } else if (typeof options == 'string') { - twipsy = this.data('twipsy') + twipsy = this.data(name) if (twipsy) { twipsy[options]() } return this } - options = $.extend({}, $.fn.twipsy.defaults, options) + options = $.extend({}, $.fn[name].defaults, options) function get(ele) { - var twipsy = $.data(ele, 'twipsy') + var twipsy = $.data(ele, name) if (!twipsy) { twipsy = new Constructor(ele, $.fn.twipsy.elementOptions(ele, options)) - $.data(ele, 'twipsy', twipsy) + $.data(ele, name, twipsy) } return twipsy @@ -264,8 +263,8 @@ this[binder](eventIn, enter)[binder](eventOut, leave) } - this.bind('twipsy:show', enter) - this.bind('twipsy:hide', leave) + this.bind(name + ':show', enter) + this.bind(name + ':hide', leave) return this } diff --git a/js/tests/unit/bootstrap-popover.js b/js/tests/unit/bootstrap-popover.js index e81e349b12..42ecd70ae5 100644 --- a/js/tests/unit/bootstrap-popover.js +++ b/js/tests/unit/bootstrap-popover.js @@ -1,13 +1,71 @@ -// $(function () { -// -// module("bootstrap-popover") -// -// test("should be defined on jquery object", function () { -// ok($(document.body).popover, 'popover method is defined') -// }) -// -// test("should return element", function () { -// ok($(document.body).popover()[0] == document.body, 'document.body returned') -// }) -// -// }) \ No newline at end of file +$(function () { + + module("bootstrap-popover") + + test("should be defined on jquery object", function () { + var div = $('
') + ok(div.popover, 'popover method is defined') + }) + + test("should return element", function () { + var div = $('
') + ok(div.popover() == div, 'document.body returned') + }) + + test("should render popover element", function () { + $.support.transition = false + var popover = $('@mdo') + .appendTo('#qunit-runoff') + .popover() + .trigger('popover:show') + + ok($('.popover').length, 'popover was inserted') + popover.trigger('popover:hide') + ok(!$(".popover").length, 'popover removed') + $('#qunit-runoff').empty() + }) + + test("should store popover instance in popover data object", function () { + $.support.transition = false + var popover = $('@mdo') + .popover() + + ok(!!popover.data('popover'), 'popover instance exists') + }) + + test("should get title and content from options", function () { + $.support.transition = false + var popover = $('@fat') + .appendTo('#qunit-runoff') + .popover({ + title: '@fat' + , content: 'loves writing tests (╯°□°)╯︵ ┻━┻' + }) + .trigger('popover:show') + + ok($('.popover').length, 'popover was inserted') + equals($('.popover .title').text(), '@fat', 'title correctly inserted') + equals($('.popover .content').text(), 'loves writing tests (╯°□°)╯︵ ┻━┻', 'content correctly inserted') + + popover.trigger('popover:hide') + ok(!$('.popover').length, 'popover was removed') + $('#qunit-runoff').empty() + }) + + test("should get title and content from attributes", function () { + $.support.transition = false + var popover = $('@mdo') + .appendTo('#qunit-runoff') + .popover() + .trigger('popover:show') + + ok($('.popover').length, 'popover was inserted') + equals($('.popover .title').text(), '@mdo', 'title correctly inserted') + equals($('.popover .content').text(), "loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻", 'content correctly inserted') + + popover.trigger('popover:hide') + ok(!$('.popover').length, 'popover was removed') + $('#qunit-runoff').empty() + }) + +}) \ No newline at end of file -- 2.47.2