diff options
| author | Jacob Thornton <[email protected]> | 2012-01-31 13:18:34 -0800 |
|---|---|---|
| committer | Jacob Thornton <[email protected]> | 2012-01-31 13:18:34 -0800 |
| commit | 0bfbe5058d61ae93d82b09f1dff7eb30dc22426e (patch) | |
| tree | 6ccf3dd9c36ff4b1f6cde5edbce21cdf0de78497 /js/tests/unit | |
| parent | 43cbc9440425b7c97c943690eefd14520de708e1 (diff) | |
| parent | 4bd1ba4e0dc44d1d16161306576548f378ab1f8a (diff) | |
| download | bootstrap-0bfbe5058d61ae93d82b09f1dff7eb30dc22426e.tar.xz bootstrap-0bfbe5058d61ae93d82b09f1dff7eb30dc22426e.zip | |
Merge branch '2.0-wip'
Conflicts:
.gitignore
LICENSE
Makefile
bootstrap.css
bootstrap.min.css
docs/assets/js/application.js
docs/assets/js/google-code-prettify/prettify.css
docs/index.html
docs/javascript.html
examples/container-app.html
examples/fluid.html
examples/hero.html
js/bootstrap-alerts.js
js/bootstrap-dropdown.js
js/bootstrap-modal.js
js/bootstrap-popover.js
js/bootstrap-scrollspy.js
js/bootstrap-tabs.js
js/bootstrap-twipsy.js
js/tests/index.html
js/tests/unit/bootstrap-modal.js
js/tests/unit/bootstrap-popover.js
js/tests/unit/bootstrap-tabs.js
lib/forms.less
lib/mixins.less
lib/patterns.less
lib/scaffolding.less
lib/tables.less
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.js (renamed from js/tests/unit/bootstrap-buttons.js) | 18 | ||||
| -rw-r--r-- | js/tests/unit/bootstrap-collapse.js | 25 | ||||
| -rw-r--r-- | js/tests/unit/bootstrap-dropdown.js | 21 | ||||
| -rw-r--r-- | js/tests/unit/bootstrap-modal.js | 216 | ||||
| -rw-r--r-- | js/tests/unit/bootstrap-popover.js | 41 | ||||
| -rw-r--r-- | js/tests/unit/bootstrap-scrollspy.js | 6 | ||||
| -rw-r--r-- | js/tests/unit/bootstrap-tab.js | 45 | ||||
| -rw-r--r-- | js/tests/unit/bootstrap-tabs.js | 77 | ||||
| -rw-r--r-- | js/tests/unit/bootstrap-tooltip.js | 62 | ||||
| -rw-r--r-- | js/tests/unit/bootstrap-transition.js | 13 | ||||
| -rw-r--r-- | js/tests/unit/bootstrap-twipsy.js | 81 | ||||
| -rw-r--r-- | js/tests/unit/bootstrap-typeahead.js | 128 |
13 files changed, 407 insertions, 336 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-buttons.js b/js/tests/unit/bootstrap-button.js index 9554bf2d4..59e8f33bc 100644 --- a/js/tests/unit/bootstrap-buttons.js +++ b/js/tests/unit/bootstrap-button.js @@ -16,10 +16,10 @@ $(function () { btn.button('loading') equals(btn.html(), 'fat', 'btn text equals fat') stop() - setTimeout(function() { - start() + setTimeout(function () { ok(btn.attr('disabled'), 'btn is disabled') ok(btn.hasClass('disabled'), 'btn has disabled class') + start() }, 0) }) @@ -29,15 +29,19 @@ $(function () { btn.button('loading') equals(btn.html(), 'fat', 'btn text equals fat') stop() - setTimeout(function() { + setTimeout(function () { + ok(btn.attr('disabled'), 'btn is disabled') + ok(btn.hasClass('disabled'), 'btn has disabled class') start() - ok(btn.attr('disabled'), 'btn is disabled') - ok(btn.hasClass('disabled'), 'btn is disabled') + stop() }, 0) btn.button('reset') equals(btn.html(), 'mdo', 'btn text equals mdo') - ok(!btn.attr('disabled'), 'btn is not disabled') - ok(!btn.hasClass('disabled'), 'btn does not have disabled class') + 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 () { 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 e96f678be..22f5781ea 100644 --- a/js/tests/unit/bootstrap-modal.js +++ b/js/tests/unit/bootstrap-modal.js @@ -1,151 +1,85 @@ $(function () { - module("bootstrap-modal") + module("bootstrap-modal") - test("should be defined on jquery object", function () { - var div = $("<div id='modal-test'></div>") - ok(div.modal, 'modal method is defined') - }) + test("should be defined on jquery object", function () { + var div = $("<div id='modal-test'></div>") + ok(div.modal, 'modal method is defined') + }) - test("should return element", function () { - var div = $("<div id='modal-test'></div>") - ok(div.modal() == div, 'div element returned') - }) + 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 () { - ok($.fn.modal.defaults, 'default object exposed') - }) + test("should expose defaults var for settings", function () { + ok($.fn.modal.defaults, 'default object exposed') + }) - test("should insert into dom when show method is called", function () { - stop() - $.support.transition = false - var div = $("<div id='modal-test'></div>") - div - .modal() - .bind("shown", function () { - ok($('#modal-test').length, 'modal insterted into dom') - start() - div.remove() - }) - .modal("show") - }) + test("should insert into dom when show method is called", function () { + stop() + $.support.transition = false + $("<div id='modal-test'></div>") + .bind("shown", function () { + ok($('#modal-test').length, 'modal insterted into dom') + $(this).remove() + start() + }) + .modal("show") + }) - test("should hide modal when hide is called", function () { - stop() - $.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') - div.modal("hide") - }) - .bind("hidden", function() { - ok(!$('#modal-test').is(":visible"), 'modal hidden') - start() - div.remove() - }) - .modal("show") - }) + test("should hide modal when hide is called", function () { + stop() + $.support.transition = false - test("should toggle when toggle is called", function () { - stop() - $.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') - div.modal("toggle") - }) - .bind("hidden", function() { - ok(!$('#modal-test').is(":visible"), 'modal hidden') - start() - div.remove() - }) - .modal("toggle") - }) + $("<div id='modal-test'></div>") + .bind("shown", function () { + ok($('#modal-test').is(":visible"), 'modal visible') + ok($('#modal-test').length, 'modal insterted into dom') + $(this).modal("hide") + }) + .bind("hidden", function() { + ok(!$('#modal-test').is(":visible"), 'modal hidden') + $('#modal-test').remove() + start() + }) + .modal("show") + }) - test("should remove from dom when click .close", function () { - stop() - $.support.transition = false - var div = $("<div id='modal-test'><span class='close'></span></div>") - div - .modal() - .bind("shown", function () { - ok($('#modal-test').is(":visible"), 'modal visible') - ok($('#modal-test').length, 'modal insterted into dom') - div.find('.close').click() - }) - .bind("hidden", function() { - ok(!$('#modal-test').is(":visible"), 'modal hidden') - start() - div.remove() - }) - .modal("toggle") - }) + test("should toggle when toggle is called", function () { + stop() + $.support.transition = false + var div = $("<div id='modal-test'></div>") + div + .bind("shown", function () { + ok($('#modal-test').is(":visible"), 'modal visible') + ok($('#modal-test').length, 'modal insterted into dom') + div.modal("toggle") + }) + .bind("hidden", function() { + ok(!$('#modal-test').is(":visible"), 'modal hidden') + div.remove() + start() + }) + .modal("toggle") + }) - test("should add backdrop when desired", function () { - stop() - $.support.transition = false - var div = $("<div id='modal-test'></div>") - div - .modal({ backdrop:true }) - .bind("shown", function () { - equal($('.modal-backdrop').length, 1, 'modal backdrop inserted into dom') - start() - div.remove() - $('.modal-backdrop').remove() - }) - .modal("show") - }) - - test("should not add backdrop when not desired", function () { - stop() - $.support.transition = false - var div = $("<div id='modal-test'></div>") - div - .modal({backdrop:false}) - .bind("shown", function () { - equal($('.modal-backdrop').length, 0, 'modal backdrop not inserted into dom') - start() - div.remove() - }) - .modal("show") - }) - - test("should close backdrop when clicked", function () { - stop() - $.support.transition = false - var div = $("<div id='modal-test'></div>") - div - .modal({backdrop:true}) - .bind("shown", function () { - equal($('.modal-backdrop').length, 1, 'modal backdrop inserted into dom') - $('.modal-backdrop').click() - equal($('.modal-backdrop').length, 0, 'modal backdrop removed from dom') - start() - div.remove() - }) - .modal("show") - }) - - test("should not close backdrop when click disabled", function () { - stop() - $.support.transition = false - var div = $("<div id='modal-test'></div>") - div - .modal({backdrop: 'static'}) - .bind("shown", function () { - equal($('.modal-backdrop').length, 1, 'modal backdrop inserted into dom') - $('.modal-backdrop').click() - equal($('.modal-backdrop').length, 1, 'modal backdrop still in dom') - start() - div.remove() - $('.modal-backdrop').remove() - }) - .modal("show") - }) -}) + test("should remove from dom when click [data-dismiss=modal]", function () { + stop() + $.support.transition = false + var div = $("<div id='modal-test'><span class='close' data-dismiss='modal'></span></div>") + div + .bind("shown", function () { + ok($('#modal-test').is(":visible"), 'modal visible') + ok($('#modal-test').length, 'modal insterted into dom') + div.find('.close').click() + }) + .bind("hidden", function() { + ok(!$('#modal-test').is(":visible"), 'modal hidden') + div.remove() + start() + }) + .modal("toggle") + }) +})
\ No newline at end of file diff --git a/js/tests/unit/bootstrap-popover.js b/js/tests/unit/bootstrap-popover.js index 2c1483435..afd6b170b 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' @@ -49,28 +47,47 @@ $(function () { popover.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') + equals($('.popover .popover-title').text(), '@fat', 'title correctly inserted') + equals($('.popover .popover-content').text(), 'loves writing tests (╯°□°)╯︵ ┻━┻', 'content correctly inserted') 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') ok($('.popover').length, 'popover was inserted') - equals($('.popover .title').text(), '@mdo', 'title correctly inserted') - equals($('.popover .content').text(), "loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻", 'content correctly inserted') + equals($('.popover .popover-title').text(), '@mdo', 'title correctly inserted') + equals($('.popover .popover-content').text(), "loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻", 'content correctly inserted') popover.popover('hide') ok(!$('.popover').length, 'popover was removed') - $('#qunit-runoff').empty() + $('#qunit-fixture').empty() }) + + test("should respect custom classes", function() { + $.support.transition = false + var popover = $('<a href="#">@fat</a>') + .appendTo('#qunit-fixture') + .popover({ + title: 'Test' + , content: 'Test' + , template: '<div class="popover foobar"><div class="arrow"></div><div class="inner"><h3 class="title"></h3><div class="content"><p></p></div></div></div>' + }) + + popover.popover('show') -}) + ok($('.popover').length, 'popover was inserted') + ok($('.popover').hasClass('foobar'), 'custom class is present') + + popover.popover('hide') + ok(!$('.popover').length, 'popover was removed') + $('#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..18f490fa5 --- /dev/null +++ b/js/tests/unit/bootstrap-tab.js @@ -0,0 +1,45 @@ +$(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 1d024ecbb..000000000 --- a/js/tests/unit/bootstrap-tabs.js +++ /dev/null @@ -1,77 +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() - }) - - test( "should trigger change event on activate", function () { - var $tabsHTML = $('<ul class="tabs">' - + '<li class="active"><a href="#home">Home</a></li>' - + '<li><a href="#profile">Profile</a></li>' - + '</ul>') - , $target - , count = 0 - , relatedTarget - , target - - $tabsHTML - .tabs() - .bind( "change", function (e) { - target = e.target - relatedTarget = e.relatedTarget - count++ - }) - - $target = $tabsHTML - .find('a') - .last() - .click() - - equals(relatedTarget, $tabsHTML.find('a').first()[0]) - equals(target, $target[0]) - equals(count, 1) - }) - -})
\ No newline at end of file diff --git a/js/tests/unit/bootstrap-tooltip.js b/js/tests/unit/bootstrap-tooltip.js new file mode 100644 index 000000000..8543162c6 --- /dev/null +++ b/js/tests/unit/bootstrap-tooltip.js @@ -0,0 +1,62 @@ +$(function () { + + module("bootstrap-tooltip") + + test("should be defined on jquery object", function () { + var div = $("<div></div>") + ok(div.tooltip, 'popover method is defined') + }) + + test("should return element", function () { + var div = $("<div></div>") + ok(div.tooltip() == div, 'document.body returned') + }) + + test("should expose default settings", function () { + ok(!!$.fn.tooltip.defaults, 'defaults is defined') + }) + + test("should remove title attribute", function () { + var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>').tooltip() + ok(!tooltip.attr('title'), 'title tag was removed') + }) + + test("should add data attribute for referencing original title", function () { + var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>').tooltip() + equals(tooltip.attr('data-original-title'), 'Another tooltip', 'original title preserved in data attribute') + }) + + test("should place tooltips relative to placement option", function () { + $.support.transition = false + var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>') + .appendTo('#qunit-fixture') + .tooltip({placement: 'bottom'}) + .tooltip('show') + + ok($(".tooltip").hasClass('fade bottom in'), 'has correct classes applied') + tooltip.tooltip('hide') + }) + + test("should always allow html entities", function () { + $.support.transition = false + var tooltip = $('<a href="#" rel="tooltip" title="<b>@fat</b>"></a>') + .appendTo('#qunit-fixture') + .tooltip('show') + + ok($('.tooltip b').length, 'b tag was inserted') + tooltip.tooltip('hide') + ok(!$(".tooltip").length, 'tooltip removed') + }) + + test("should respect custom classes", function () { + var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>') + .appendTo('#qunit-fixture') + .tooltip({ template: '<div class="tooltip some-class"><div class="tooltip-arrow"/><div class="tooltip-inner"/></div>'}) + .tooltip('show') + + ok($('.tooltip').hasClass('some-class'), 'custom class is present') + tooltip.tooltip('hide') + ok(!$(".tooltip").length, 'tooltip removed') + }) + +})
\ 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..3f28d2676 --- /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 ? $.support.transition.end : true, '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 deleted file mode 100644 index 04000696a..000000000 --- a/js/tests/unit/bootstrap-twipsy.js +++ /dev/null @@ -1,81 +0,0 @@ -$(function () { - - module("bootstrap-twipsy") - - test("should be defined on jquery object", function () { - var div = $("<div></div>") - ok(div.twipsy, 'popover method is defined') - }) - - test("should return element", function () { - var div = $("<div></div>") - ok(div.twipsy() == div, 'document.body returned') - }) - - test("should expose default settings", function () { - ok(!!$.fn.twipsy.defaults, 'defaults is defined') - }) - - test("should remove title attribute", function () { - var twipsy = $('<a href="#" rel="twipsy" title="Another twipsy"></a>').twipsy() - ok(!twipsy.attr('title'), 'title tag was removed') - }) - - test("should add data attribute for referencing original title", function () { - var twipsy = $('<a href="#" rel="twipsy" title="Another twipsy"></a>').twipsy() - equals(twipsy.attr('data-original-title'), 'Another twipsy', 'original title preserved in data attribute') - }) - - 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') - .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 () { - $.support.transition = false - var twipsy = $('<a href="#" rel="twipsy" title="<b>@fat</b>"></a>') - .appendTo('#qunit-runoff') - .twipsy({html: true}) - .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 diff --git a/js/tests/unit/bootstrap-typeahead.js b/js/tests/unit/bootstrap-typeahead.js new file mode 100644 index 000000000..455ed415b --- /dev/null +++ b/js/tests/unit/bootstrap-typeahead.js @@ -0,0 +1,128 @@ +$(function () { + + module("bootstrap-typeahead") + + test("should be defined on jquery object", function () { + ok($(document.body).typeahead, 'alert method is defined') + }) + + test("should return element", function () { + ok($(document.body).typeahead()[0] == document.body, 'document.body returned') + }) + + test("should listen to an input", function () { + var $input = $('<input />') + $input.typeahead() + ok($input.data('events').blur, 'has a blur event') + ok($input.data('events').keypress, 'has a keypress event') + ok($input.data('events').keyup, 'has a keyup event') + if ($.browser.webkit || $.browser.msie) { + ok($input.data('events').keydown, 'has a keydown event') + } else { + ok($input.data('events').keydown, 'does not have a keydown event') + } + }) + + test("should create a menu", function () { + var $input = $('<input />') + ok($input.typeahead().data('typeahead').$menu, 'has a menu') + }) + + test("should listen to the menu", function () { + var $input = $('<input />') + , $menu = $input.typeahead().data('typeahead').$menu + + ok($menu.data('events').mouseover, 'has a mouseover(pseudo: mouseenter)') + ok($menu.data('events').click, 'has a click') + }) + + test("should show menu when query entered", function () { + var $input = $('<input />').typeahead({ + source: ['aa', 'ab', 'ac'] + }) + , typeahead = $input.data('typeahead') + + $input.val('a') + typeahead.lookup() + + ok(typeahead.$menu.is(":visible"), 'typeahead is visible') + equals(typeahead.$menu.find('li').length, 3, 'has 3 items in menu') + equals(typeahead.$menu.find('.active').length, 1, 'one item is active') + + typeahead.$menu.remove() + }) + + test("should hide menu when query entered", function () { + stop() + var $input = $('<input />').typeahead({ + source: ['aa', 'ab', 'ac'] + }) + , typeahead = $input.data('typeahead') + + $input.val('a') + typeahead.lookup() + + ok(typeahead.$menu.is(":visible"), 'typeahead is visible') + equals(typeahead.$menu.find('li').length, 3, 'has 3 items in menu') + equals(typeahead.$menu.find('.active').length, 1, 'one item is active') + + $input.blur() + + setTimeout(function () { + ok(!typeahead.$menu.is(":visible"), "typeahead is no longer visible") + start() + }, 200) + + typeahead.$menu.remove() + }) + + test("should set next item when down arrow is pressed", function () { + var $input = $('<input />').typeahead({ + source: ['aa', 'ab', 'ac'] + }) + , typeahead = $input.data('typeahead') + + $input.val('a') + typeahead.lookup() + + ok(typeahead.$menu.is(":visible"), 'typeahead is visible') + equals(typeahead.$menu.find('li').length, 3, 'has 3 items in menu') + equals(typeahead.$menu.find('.active').length, 1, 'one item is active') + ok(typeahead.$menu.find('li').first().hasClass('active'), "first item is active") + + $input.trigger({ + type: 'keypress' + , keyCode: 40 + }) + + ok(typeahead.$menu.find('li').first().next().hasClass('active'), "second item is active") + + + $input.trigger({ + type: 'keypress' + , keyCode: 38 + }) + + ok(typeahead.$menu.find('li').first().hasClass('active'), "first item is active") + + typeahead.$menu.remove() + }) + + + test("should set input value to selected item", function () { + var $input = $('<input />').typeahead({ + source: ['aa', 'ab', 'ac'] + }) + , typeahead = $input.data('typeahead') + + $input.val('a') + typeahead.lookup() + + $(typeahead.$menu.find('li')[2]).mouseover().click() + + equals($input.val(), 'ac', 'input value was correctly set') + ok(!typeahead.$menu.is(':visible'), 'the menu was hidden') + + typeahead.$menu.remove() + }) +})
\ No newline at end of file |
