1
0
Fork 0
mirror of https://github.com/twbs/bootstrap.git synced 2022-11-09 12:25:43 -05:00

finish up rounding out tests for all js plugins

This commit is contained in:
Jacob Thornton 2011-09-10 13:17:08 -07:00
parent 48aa209348
commit 1041977d0a
3 changed files with 82 additions and 25 deletions

View file

@ -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 )

View file

@ -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
}

View 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')
// })
//
// })
$(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()
})
})