]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
finish up rounding out tests for all js plugins
authorJacob Thornton <jacobthornton@gmail.com>
Sat, 10 Sep 2011 20:17:08 +0000 (13:17 -0700)
committerJacob Thornton <jacobthornton@gmail.com>
Sat, 10 Sep 2011 20:17:08 +0000 (13:17 -0700)
js/bootstrap-popover.js
js/bootstrap-twipsy.js
js/tests/unit/bootstrap-popover.js

index 646b22b644152a3103fe1ebf20530c4256995339..5928fe8caf5290a851eb2b1c36690547d5f05dc0 100644 (file)
 
   $.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
index 24c422cb526c94f80e92497aa9b2bc18c8ad661f..ac2f562414275dd91f619bcce9ff20ce05ccf07e 100644 (file)
   * ======================== */
 
   $.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
       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
   }
index e81e349b1218f800932d73fc76067c5ebdf5a1b9..42ecd70ae5589da9af29767f1ecd4b4b875f69de 100644 (file)
@@ -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 = $('<div></div>')
+        ok(div.popover, 'popover method is defined')
+      })
+
+      test("should return element", function () {
+        var div = $('<div></div>')
+        ok(div.popover() == div, 'document.body returned')
+      })
+
+      test("should render popover element", function () {
+        $.support.transition = false
+        var popover = $('<a href="#" data-title="mdo" data-content="http://twitter.com/mdo">@mdo</a>')
+          .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 = $('<a href="#" data-title="mdo" data-content="http://twitter.com/mdo">@mdo</a>')
+          .popover()
+
+        ok(!!popover.data('popover'), 'popover instance exists')
+      })
+
+      test("should get title and content from options", function () {
+        $.support.transition = false
+        var popover = $('<a href="#">@fat</a>')
+          .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 = $('<a href="#" data-title="@mdo" data-content="loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻" >@mdo</a>')
+          .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