1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-08-15 01:55:46 +02:00

giant refactor - all spec passing again...

This commit is contained in:
Jacob Thornton
2011-12-20 18:02:47 -08:00
parent 7df0d1c7d1
commit 1ef5fa7d6b
27 changed files with 9618 additions and 390 deletions

View File

@@ -4,28 +4,36 @@
<title>Bootstrap Plugin Test Suite</title>
<!-- jquery -->
<script src="http://code.jquery.com/jquery-1.5.2.min.js"></script>
<!--<script src="http://code.jquery.com/jquery-1.7.min.js"></script>-->
<script src="vendor/jquery.js"></script>
<!-- qunit -->
<link rel="stylesheet" href="vendor/qunit.css" type="text/css" media="screen" />
<script src="vendor/qunit.js"></script>
<!-- plugin sources -->
<script src="../../js/bootstrap-transitions.js"></script>
<script src="../../js/bootstrap-alerts.js"></script>
<script src="../../js/bootstrap-transition.js"></script>
<script src="../../js/bootstrap-alert.js"></script>
<script src="../../js/bootstrap-button.js"></script>
<script src="../../js/bootstrap-collapse.js"></script>
<script src="../../js/bootstrap-dropdown.js"></script>
<script src="../../js/bootstrap-modal.js"></script>
<script src="../../js/bootstrap-tabs.js"></script>
<script src="../../js/bootstrap-scrollspy.js"></script>
<script src="../../js/bootstrap-tab.js"></script>
<script src="../../js/bootstrap-twipsy.js"></script>
<script src="../../js/bootstrap-popover.js"></script>
<!-- unit tests -->
<script src="unit/bootstrap-alerts.js"></script>
<script src="unit/bootstrap-transition.js"></script>
<script src="unit/bootstrap-alert.js"></script>
<script src="unit/bootstrap-button.js"></script>
<script src="unit/bootstrap-collapse.js"></script>
<script src="unit/bootstrap-dropdown.js"></script>
<script src="unit/bootstrap-modal.js"></script>
<script src="unit/bootstrap-popover.js"></script>
<script src="unit/bootstrap-tabs.js"></script>
<script src="unit/bootstrap-scrollspy.js"></script>
<script src="unit/bootstrap-tab.js"></script>
<script src="unit/bootstrap-twipsy.js"></script>
<script src="unit/bootstrap-popover.js"></script>
<body>
<div>
@@ -33,7 +41,7 @@
<h2 id="qunit-banner"></h2>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-runoff"></div>
<div id="qunit-fixture"></div>
</div>
</body>
</html>

View File

@@ -12,7 +12,7 @@ $(function () {
test("should fade element out on clicking .close", function () {
var alertHTML = '<div class="alert-message warning fade in">'
+ '<a class="close" href="#">×</a>'
+ '<a class="close" href="#" data-dismiss="alert">×</a>'
+ '<p><strong>Holy guacamole!</strong> Best check yo self, youre not looking too good.</p>'
+ '</div>'
, alert = $(alertHTML).alert()
@@ -26,16 +26,16 @@ $(function () {
$.support.transition = false
var alertHTML = '<div class="alert-message warning fade in">'
+ '<a class="close" href="#">×</a>'
+ '<a class="close" href="#" data-dismiss="alert">×</a>'
+ '<p><strong>Holy guacamole!</strong> Best check yo self, youre not looking too good.</p>'
+ '</div>'
, alert = $(alertHTML).appendTo('#qunit-runoff').alert()
, alert = $(alertHTML).appendTo('#qunit-fixture').alert()
ok($('#qunit-runoff').find('.alert-message').length, 'element added to dom')
ok($('#qunit-fixture').find('.alert-message').length, 'element added to dom')
alert.find('.close').click()
ok(!$('#qunit-runoff').find('.alert-message').length, 'element removed from dom')
ok(!$('#qunit-fixture').find('.alert-message').length, 'element removed from dom')
})
})

54
js/tests/unit/bootstrap-button.js vendored Normal file
View File

@@ -0,0 +1,54 @@
$(function () {
module("bootstrap-buttons")
test("should be defined on jquery object", function () {
ok($(document.body).button, 'tabs method is defined')
})
test("should return element", function () {
ok($(document.body).button()[0] == document.body, 'document.body returned')
})
test("should return set state to loading", function () {
var btn = $('<button class="btn" data-loading-text="fat">mdo</button>')
equals(btn.html(), 'mdo', 'btn text equals mdo')
btn.button('loading')
equals(btn.html(), 'fat', 'btn text equals fat')
stop()
setTimeout(function () {
ok(btn.attr('disabled'), 'btn is disabled')
ok(btn.hasClass('disabled'), 'btn has disabled class')
start()
}, 0)
})
test("should return reset state", function () {
var btn = $('<button class="btn" data-loading-text="fat">mdo</button>')
equals(btn.html(), 'mdo', 'btn text equals mdo')
btn.button('loading')
equals(btn.html(), 'fat', 'btn text equals fat')
stop()
setTimeout(function () {
ok(btn.attr('disabled'), 'btn is disabled')
ok(btn.hasClass('disabled'), 'btn has disabled class')
start()
stop()
}, 0)
btn.button('reset')
equals(btn.html(), 'mdo', 'btn text equals mdo')
setTimeout(function () {
ok(!btn.attr('disabled'), 'btn is not disabled')
ok(!btn.hasClass('disabled'), 'btn does not have disabled class')
start()
}, 0)
})
test("should toggle active", function () {
var btn = $('<button class="btn" data-loading-text="fat">mdo</button>')
ok(!btn.hasClass('active'), 'btn does not have active class')
btn.button('toggle')
ok(btn.hasClass('active'), 'btn has class active')
})
})

25
js/tests/unit/bootstrap-collapse.js vendored Normal file
View File

@@ -0,0 +1,25 @@
$(function () {
module("bootstrap-collapse")
test("should be defined on jquery object", function () {
ok($(document.body).collapse, 'collapse method is defined')
})
test("should return element", function () {
ok($(document.body).collapse()[0] == document.body, 'document.body returned')
})
test("should show a collapsed element", function () {
var el = $('<div class="collapse"></div>').collapse('show')
ok(el.hasClass('in'), 'has class in')
ok(/height/.test(el.attr('style')), 'has height set')
})
test("should hide a collapsed element", function () {
var el = $('<div class="collapse"></div>').collapse('hide')
ok(!el.hasClass('in'), 'does not have class in')
ok(/height/.test(el.attr('style')), 'has height set')
})
})

View File

@@ -13,7 +13,7 @@ $(function () {
test("should add class open to menu if clicked", function () {
var dropdownHTML = '<ul class="tabs">'
+ '<li class="dropdown">'
+ '<a href="#" class="dropdown-toggle">Dropdown</a>'
+ '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>'
+ '<ul class="dropdown-menu">'
+ '<li><a href="#">Secondary link</a></li>'
+ '<li><a href="#">Something else here</a></li>'
@@ -22,16 +22,15 @@ $(function () {
+ '</ul>'
+ '</li>'
+ '</ul>'
, dropdown = $(dropdownHTML).dropdown()
, dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').dropdown().click()
dropdown.find('.dropdown-toggle').click()
ok(dropdown.find('.dropdown').hasClass('open'), 'open class added on click')
ok(dropdown.parent('.dropdown').hasClass('open'), 'open class added on click')
})
test("should remove open class if body clicked", function () {
var dropdownHTML = '<ul class="tabs">'
+ '<li class="dropdown">'
+ '<a href="#" class="dropdown-toggle">Dropdown</a>'
+ '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>'
+ '<ul class="dropdown-menu">'
+ '<li><a href="#">Secondary link</a></li>'
+ '<li><a href="#">Something else here</a></li>'
@@ -40,12 +39,14 @@ $(function () {
+ '</ul>'
+ '</li>'
+ '</ul>'
, dropdown = $(dropdownHTML).dropdown().appendTo('#qunit-runoff')
dropdown.find('.dropdown-toggle').click()
ok(dropdown.find('.dropdown').hasClass('open'), 'open class added on click')
, dropdown = $(dropdownHTML)
.appendTo('#qunit-fixture')
.find('[data-toggle="dropdown"]')
.dropdown()
.click()
ok(dropdown.parent('.dropdown').hasClass('open'), 'open class added on click')
$('body').click()
ok(!dropdown.find('.dropdown').hasClass('open'), 'open class removed')
ok(!dropdown.parent('.dropdown').hasClass('open'), 'open class removed')
dropdown.remove()
})

View File

@@ -10,6 +10,7 @@ $(function () {
test("should return element", function () {
var div = $("<div id='modal-test'></div>")
ok(div.modal() == div, 'document.body returned')
$('#modal-test').remove()
})
test("should expose defaults var for settings", function () {
@@ -19,32 +20,29 @@ $(function () {
test("should insert into dom when show method is called", function () {
stop()
$.support.transition = false
var div = $("<div id='modal-test'></div>")
div
.modal()
.modal("show")
$("<div id='modal-test'></div>")
.bind("shown", function () {
ok($('#modal-test').length, 'modal insterted into dom')
$(this).remove()
start()
div.remove()
})
.modal("show")
})
test("should hide modal when hide is called", function () {
stop()
$.support.transition = false
var div = $("<div id='modal-test'></div>")
div
.modal()
$("<div id='modal-test'></div>")
.bind("shown", function () {
ok($('#modal-test').is(":visible"), 'modal visible')
ok($('#modal-test').length, 'modal insterted into dom')
div.modal("hide")
$(this).modal("hide")
})
.bind("hidden", function() {
ok(!$('#modal-test').is(":visible"), 'modal hidden')
$('#modal-test').remove()
start()
div.remove()
})
.modal("show")
})
@@ -54,7 +52,6 @@ $(function () {
$.support.transition = false
var div = $("<div id='modal-test'></div>")
div
.modal()
.bind("shown", function () {
ok($('#modal-test').is(":visible"), 'modal visible')
ok($('#modal-test').length, 'modal insterted into dom')
@@ -62,18 +59,17 @@ $(function () {
})
.bind("hidden", function() {
ok(!$('#modal-test').is(":visible"), 'modal hidden')
start()
div.remove()
start()
})
.modal("toggle")
})
test("should remove from dom when click .close", function () {
test("should remove from dom when click [data-dismiss=modal]", function () {
stop()
$.support.transition = false
var div = $("<div id='modal-test'><span class='close'></span></div>")
var div = $("<div id='modal-test'><span class='close' data-dismiss='modal'></span></div>")
div
.modal()
.bind("shown", function () {
ok($('#modal-test').is(":visible"), 'modal visible')
ok($('#modal-test').length, 'modal insterted into dom')
@@ -81,8 +77,8 @@ $(function () {
})
.bind("hidden", function() {
ok(!$('#modal-test').is(":visible"), 'modal hidden')
start()
div.remove()
start()
})
.modal("toggle")
})

View File

@@ -15,14 +15,12 @@ $(function () {
test("should render popover element", function () {
$.support.transition = false
var popover = $('<a href="#" title="mdo" data-content="http://twitter.com/mdo">@mdo</a>')
.appendTo('#qunit-runoff')
.popover()
.appendTo('#qunit-fixture')
.popover('show')
ok($('.popover').length, 'popover was inserted')
popover.popover('hide')
ok(!$(".popover").length, 'popover removed')
$('#qunit-runoff').empty()
})
test("should store popover instance in popover data object", function () {
@@ -36,7 +34,7 @@ $(function () {
test("should get title and content from options", function () {
$.support.transition = false
var popover = $('<a href="#">@fat</a>')
.appendTo('#qunit-runoff')
.appendTo('#qunit-fixture')
.popover({
title: function () {
return '@fat'
@@ -54,13 +52,13 @@ $(function () {
popover.popover('hide')
ok(!$('.popover').length, 'popover was removed')
$('#qunit-runoff').empty()
$('#qunit-fixture').empty()
})
test("should get title and content from attributes", function () {
$.support.transition = false
var popover = $('<a href="#" title="@mdo" data-content="loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻" >@mdo</a>')
.appendTo('#qunit-runoff')
.appendTo('#qunit-fixture')
.popover()
.popover('show')
@@ -70,7 +68,7 @@ $(function () {
popover.popover('hide')
ok(!$('.popover').length, 'popover was removed')
$('#qunit-runoff').empty()
$('#qunit-fixture').empty()
})
})

View File

@@ -12,7 +12,7 @@ $(function () {
test("should switch active class on scroll", function () {
var sectionHTML = '<div id="masthead"></div>'
, $section = $(sectionHTML).append('#qunit-runoff')
, $section = $(sectionHTML).append('#qunit-fixture')
, topbarHTML ='<div class="topbar">'
+ '<div class="topbar-inner">'
+ '<div class="container">'
@@ -23,9 +23,9 @@ $(function () {
+ '</div>'
+ '</div>'
+ '</div>'
, $topbar = $(topbarHTML).topbar()
, $topbar = $(topbarHTML).scrollspy()
ok(topbar.find('.active', true)
ok($topbar.find('.active', true))
})
})

46
js/tests/unit/bootstrap-tab.js vendored Normal file
View File

@@ -0,0 +1,46 @@
$(function () {
module("bootstrap-tabs")
test("should be defined on jquery object", function () {
ok($(document.body).tab, 'tabs method is defined')
})
test("should return element", function () {
ok($(document.body).tab()[0] == document.body, 'document.body returned')
})
test("should activate element by tab id", function () {
var tabsHTML =
'<ul class="tabs">'
+ '<li><a href="#home">Home</a></li>'
+ '<li><a href="#profile">Profile</a></li>'
+ '</ul>'
$('<ul><li id="home"></li><li id="profile"></li></ul>').appendTo("#qunit-fixture")
$(tabsHTML).find('li:last a').tab('show')
equals($("#qunit-fixture").find('.active').attr('id'), "profile")
$(tabsHTML).find('li:first a').tab('show')
equals($("#qunit-fixture").find('.active').attr('id'), "home")
})
test("should activate element by tab id", function () {
var pillsHTML =
'<ul class="pills">'
+ '<li><a href="#home">Home</a></li>'
+ '<li><a href="#profile">Profile</a></li>'
+ '</ul>'
$('<ul><li id="home"></li><li id="profile"></li></ul>').appendTo("#qunit-fixture")
$(pillsHTML).find('li:last a').tab('show')
equals($("#qunit-fixture").find('.active').attr('id'), "profile")
$(pillsHTML).find('li:first a').tab('show')
equals($("#qunit-fixture").find('.active').attr('id'), "home")
})
})

View File

@@ -1,49 +0,0 @@
$(function () {
module("bootstrap-tabs")
test("should be defined on jquery object", function () {
ok($(document.body).tabs, 'tabs method is defined')
})
test("should return element", function () {
ok($(document.body).tabs()[0] == document.body, 'document.body returned')
})
test("should activate element by tab id", function () {
var tabsHTML = '<ul class="tabs">'
+ '<li class="active"><a href="#home">Home</a></li>'
+ '<li><a href="#profile">Profile</a></li>'
+ '</ul>'
$('<ul><li id="home"></li><li id="profile"></li></ul>').appendTo("#qunit-runoff")
$(tabsHTML).tabs().find('a').last().click()
equals($("#qunit-runoff").find('.active').attr('id'), "profile")
$(tabsHTML).tabs().find('a').first().click()
equals($("#qunit-runoff").find('.active').attr('id'), "home")
$("#qunit-runoff").empty()
})
test("should activate element by pill id", function () {
var pillsHTML = '<ul class="pills">'
+ '<li class="active"><a href="#home">Home</a></li>'
+ '<li><a href="#profile">Profile</a></li>'
+ '</ul>'
$('<ul><li id="home"></li><li id="profile"></li></ul>').appendTo("#qunit-runoff")
$(pillsHTML).pills().find('a').last().click()
equals($("#qunit-runoff").find('.active').attr('id'), "profile")
$(pillsHTML).pills().find('a').first().click()
equals($("#qunit-runoff").find('.active').attr('id'), "home")
$("#qunit-runoff").empty()
})
})

13
js/tests/unit/bootstrap-transition.js vendored Normal file
View File

@@ -0,0 +1,13 @@
$(function () {
module("bootstrap-transition")
test("should be defined on jquery support object", function () {
ok($.support.transition != undefined, 'transition object is defined')
})
test("should provide an end object", function () {
ok($.support.transition.end, 'end string is defined')
})
})

View File

@@ -29,53 +29,23 @@ $(function () {
test("should place tooltips relative to placement option", function () {
$.support.transition = false
var twipsy = $('<a href="#" rel="twipsy" title="Another twipsy"></a>')
.appendTo('#qunit-runoff')
.appendTo('#qunit-fixture')
.twipsy({placement: 'below'})
.twipsy('show')
ok($(".twipsy").hasClass('fade below in'), 'has correct classes applied')
twipsy.twipsy('hide')
ok(!$(".twipsy").length, 'twipsy removed')
$('#qunit-runoff').empty()
})
test("should add a fallback in cases where elements have no title tag", function () {
$.support.transition = false
var twipsy = $('<a href="#" rel="twipsy"></a>')
.appendTo('#qunit-runoff')
.twipsy({fallback: '@fat'})
.twipsy('show')
equals($(".twipsy").text(), "@fat", 'has correct default text')
twipsy.twipsy('hide')
ok(!$(".twipsy").length, 'twipsy removed')
$('#qunit-runoff').empty()
})
test("should not allow html entities", function () {
test("should always allow html entities", function () {
$.support.transition = false
var twipsy = $('<a href="#" rel="twipsy" title="<b>@fat</b>"></a>')
.appendTo('#qunit-runoff')
.twipsy()
.twipsy('show')
ok(!$('.twipsy b').length, 'b tag was not inserted')
twipsy.twipsy('hide')
ok(!$(".twipsy").length, 'twipsy removed')
$('#qunit-runoff').empty()
})
test("should allow html entities if html option set to true", function () {
$.support.transition = false
var twipsy = $('<a href="#" rel="twipsy" title="<b>@fat</b>"></a>')
.appendTo('#qunit-runoff')
.twipsy({html: true})
.appendTo('#qunit-fixture')
.twipsy('show')
ok($('.twipsy b').length, 'b tag was inserted')
twipsy.twipsy('hide')
ok(!$(".twipsy").length, 'twipsy removed')
$('#qunit-runoff').empty()
})
})

9252
js/tests/vendor/jquery.js vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -227,6 +227,6 @@
/** Runoff */
#qunit-runoff {
#qunit-fixture {
display:none;
}