aboutsummaryrefslogtreecommitdiff
path: root/js/tests/unit
diff options
context:
space:
mode:
authorMark Otto <[email protected]>2011-12-21 18:39:02 -0600
committerMark Otto <[email protected]>2011-12-21 18:39:02 -0600
commit9fb380151d477f1741b7609ade7a9e7fd5450b2c (patch)
treea749f2b6917c09770af1586ae9f83e46115de7eb /js/tests/unit
parent12a0d69454a2831031035d19237d36d38bb2c2a9 (diff)
parenta5a98a8a984512011dac1216b432b86c6eff96a4 (diff)
downloadbootstrap-9fb380151d477f1741b7609ade7a9e7fd5450b2c.tar.xz
bootstrap-9fb380151d477f1741b7609ade7a9e7fd5450b2c.zip
Merge branch '2.0-wip' of github.com:twitter/bootstrap into 2.0-wip
Conflicts: bootstrap.css docs/javascript.html
Diffstat (limited to 'js/tests/unit')
-rw-r--r--js/tests/unit/bootstrap-alert.js (renamed from js/tests/unit/bootstrap-alerts.js)10
-rw-r--r--js/tests/unit/bootstrap-button.js54
-rw-r--r--js/tests/unit/bootstrap-collapse.js25
-rw-r--r--js/tests/unit/bootstrap-dropdown.js21
-rw-r--r--js/tests/unit/bootstrap-modal.js28
-rw-r--r--js/tests/unit/bootstrap-popover.js12
-rw-r--r--js/tests/unit/bootstrap-scrollspy.js6
-rw-r--r--js/tests/unit/bootstrap-tab.js46
-rw-r--r--js/tests/unit/bootstrap-tabs.js49
-rw-r--r--js/tests/unit/bootstrap-transition.js13
-rw-r--r--js/tests/unit/bootstrap-twipsy.js36
11 files changed, 177 insertions, 123 deletions
diff --git a/js/tests/unit/bootstrap-alerts.js b/js/tests/unit/bootstrap-alert.js
index 152d97ab7..8eecaff0d 100644
--- a/js/tests/unit/bootstrap-alerts.js
+++ b/js/tests/unit/bootstrap-alert.js
@@ -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, you’re 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, you’re 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')
})
}) \ No newline at end of file
diff --git a/js/tests/unit/bootstrap-button.js b/js/tests/unit/bootstrap-button.js
new file mode 100644
index 000000000..59e8f33bc
--- /dev/null
+++ b/js/tests/unit/bootstrap-button.js
@@ -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')
+ })
+
+}) \ No newline at end of file
diff --git a/js/tests/unit/bootstrap-collapse.js b/js/tests/unit/bootstrap-collapse.js
new file mode 100644
index 000000000..698238d96
--- /dev/null
+++ b/js/tests/unit/bootstrap-collapse.js
@@ -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')
+ })
+
+}) \ No newline at end of file
diff --git a/js/tests/unit/bootstrap-dropdown.js b/js/tests/unit/bootstrap-dropdown.js
index 2c2acb9bb..368ced2a5 100644
--- a/js/tests/unit/bootstrap-dropdown.js
+++ b/js/tests/unit/bootstrap-dropdown.js
@@ -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()
})
diff --git a/js/tests/unit/bootstrap-modal.js b/js/tests/unit/bootstrap-modal.js
index 4bbb3313c..22f5781ea 100644
--- a/js/tests/unit/bootstrap-modal.js
+++ b/js/tests/unit/bootstrap-modal.js
@@ -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")
})
diff --git a/js/tests/unit/bootstrap-popover.js b/js/tests/unit/bootstrap-popover.js
index 3e13d2fd2..9180c043e 100644
--- a/js/tests/unit/bootstrap-popover.js
+++ b/js/tests/unit/bootstrap-popover.js
@@ -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()
})
}) \ No newline at end of file
diff --git a/js/tests/unit/bootstrap-scrollspy.js b/js/tests/unit/bootstrap-scrollspy.js
index b9b309062..bee46a925 100644
--- a/js/tests/unit/bootstrap-scrollspy.js
+++ b/js/tests/unit/bootstrap-scrollspy.js
@@ -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))
})
}) \ No newline at end of file
diff --git a/js/tests/unit/bootstrap-tab.js b/js/tests/unit/bootstrap-tab.js
new file mode 100644
index 000000000..f32649078
--- /dev/null
+++ b/js/tests/unit/bootstrap-tab.js
@@ -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")
+ })
+
+}) \ No newline at end of file
diff --git a/js/tests/unit/bootstrap-tabs.js b/js/tests/unit/bootstrap-tabs.js
deleted file mode 100644
index 2ee6761ed..000000000
--- a/js/tests/unit/bootstrap-tabs.js
+++ /dev/null
@@ -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()
- })
-
-}) \ No newline at end of file
diff --git a/js/tests/unit/bootstrap-transition.js b/js/tests/unit/bootstrap-transition.js
new file mode 100644
index 000000000..ff4a0f0c3
--- /dev/null
+++ b/js/tests/unit/bootstrap-transition.js
@@ -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')
+ })
+
+}) \ No newline at end of file
diff --git a/js/tests/unit/bootstrap-twipsy.js b/js/tests/unit/bootstrap-twipsy.js
index 04000696a..7a88ab2f1 100644
--- a/js/tests/unit/bootstrap-twipsy.js
+++ b/js/tests/unit/bootstrap-twipsy.js
@@ -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 () {
- $.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 () {
+ 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({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()
})
}) \ No newline at end of file