diff options
| author | Jacob Thornton <[email protected]> | 2011-09-10 12:49:21 -0700 |
|---|---|---|
| committer | Jacob Thornton <[email protected]> | 2011-09-10 12:49:21 -0700 |
| commit | 48aa209348c47df65f4edb0d8a36ccaac357eb0a (patch) | |
| tree | 7dfef7b52a39319c75d6d0fd657b9f9c8f0dfeed /js/tests | |
| parent | 79d5f907130a030963b802647e3ed3bcb6300a46 (diff) | |
| download | bootstrap-48aa209348c47df65f4edb0d8a36ccaac357eb0a.tar.xz bootstrap-48aa209348c47df65f4edb0d8a36ccaac357eb0a.zip | |
more tests, more js goodness
Diffstat (limited to 'js/tests')
| -rw-r--r-- | js/tests/unit/bootstrap-modal.js | 50 | ||||
| -rw-r--r-- | js/tests/unit/bootstrap-popover.js | 13 | ||||
| -rw-r--r-- | js/tests/unit/bootstrap-tabs.js | 49 | ||||
| -rw-r--r-- | js/tests/unit/bootstrap-twipsy.js | 81 |
4 files changed, 180 insertions, 13 deletions
diff --git a/js/tests/unit/bootstrap-modal.js b/js/tests/unit/bootstrap-modal.js index 24510664c..cfdf4064d 100644 --- a/js/tests/unit/bootstrap-modal.js +++ b/js/tests/unit/bootstrap-modal.js @@ -3,30 +3,54 @@ $(function () { module("bootstrap-modal") test("should be defined on jquery object", function () { - ok($(document.body).modal, 'modal method is defined') + var div = $("<div id='modal-test'></div>") + ok(div.modal, 'modal method is defined') }) - test("should not return element", function () { - ok(!$(document.body).modal()[0], 'document.body not returned') + test("should return element", function () { + var div = $("<div id='modal-test'></div>") + ok(div.modal() == div, 'document.body returned') }) - test("should return instance of modal class", function () { - ok($(document.body).modal() instanceof $.fn.modal.Modal, 'document.body returned') + test("should expose defaults var for settings", function () { + ok($.fn.modal.defaults, 'default object exposed') }) - test("should expose defaults var for settings", { - ok(!!$.fn.modal.default, 'default object exposed') + test("should insert into dom when modal:show event is called", function () { + $.support.transition = false + var div = $("<div id='modal-test'></div>") + div.modal().trigger("modal:show") + ok($('#modal-test').length, 'modal insterted into dom') + div.remove() }) - test("should insert into dom when open is called", function () { - var div = $("<div></div>") - div.modal().open() + test("should remove from dom when close is called", function () { + $.support.transition = false + var div = $("<div id='modal-test'></div>") + div.modal().trigger("modal:show") + ok($('#modal-test').length, 'modal insterted into dom') + div.trigger("modal:hide") + ok(!$('#modal-test').length, 'modal removed from dom') + div.remove() }) - test("should remove from dom when close is called", function () { + test("should toggle when toggle is called", function () { $.support.transition = false - re + var div = $("<div id='modal-test'></div>") + div.modal().trigger("modal:toggle") + ok($('#modal-test').length, 'modal insterted into dom') + div.trigger("modal:toggle") + ok(!$('#modal-test').length, 'modal removed from dom') + div.remove() }) - test("should remove from dom when click .close") + test("should remove from dom when click .close", function () { + $.support.transition = false + var div = $("<div id='modal-test'><span class='close'></span></div>") + div.modal().trigger("modal:toggle") + ok($('#modal-test').length, 'modal insterted into dom') + div.find('.close').click() + ok(!$('#modal-test').length, 'modal removed from dom') + div.remove() + }) })
\ No newline at end of file diff --git a/js/tests/unit/bootstrap-popover.js b/js/tests/unit/bootstrap-popover.js index e69de29bb..e81e349b1 100644 --- a/js/tests/unit/bootstrap-popover.js +++ b/js/tests/unit/bootstrap-popover.js @@ -0,0 +1,13 @@ +// $(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 diff --git a/js/tests/unit/bootstrap-tabs.js b/js/tests/unit/bootstrap-tabs.js index e69de29bb..2ee6761ed 100644 --- a/js/tests/unit/bootstrap-tabs.js +++ b/js/tests/unit/bootstrap-tabs.js @@ -0,0 +1,49 @@ +$(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-twipsy.js b/js/tests/unit/bootstrap-twipsy.js index e69de29bb..05de7e938 100644 --- a/js/tests/unit/bootstrap-twipsy.js +++ b/js/tests/unit/bootstrap-twipsy.js @@ -0,0 +1,81 @@ +$(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'}) + .trigger('twipsy:show') + + ok($(".twipsy").hasClass('fade below in'), 'has correct classes applied') + twipsy.trigger('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'}) + .trigger('twipsy:show') + + equals($(".twipsy").text(), "@fat", 'has correct default text') + twipsy.trigger('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() + .trigger('twipsy:show') + + ok(!$('.twipsy b').length, 'b tag was not inserted') + twipsy.trigger('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}) + .trigger('twipsy:show') + + ok($('.twipsy b').length, 'b tag was inserted') + twipsy.trigger('twipsy:hide') + ok(!$(".twipsy").length, 'twipsy removed') + $('#qunit-runoff').empty() + }) + +})
\ No newline at end of file |
