diff options
| author | fat <[email protected]> | 2013-02-07 22:13:13 -0800 |
|---|---|---|
| committer | fat <[email protected]> | 2013-02-07 22:13:13 -0800 |
| commit | 8c7f9c66a7d12f47f50618ef420868fe836d0c33 (patch) | |
| tree | 552f251d1637a1749c34fcdbb3390653d2fdb8ae /js/tests/unit/bootstrap-tooltip.js | |
| parent | ee91afba63bc6e9687397b9052858fca242c2ff5 (diff) | |
| parent | c4d47fb1ea45ed2fc3cf382d087ed87b87c69288 (diff) | |
| download | bootstrap-2.3.0.tar.xz bootstrap-2.3.0.zip | |
Merge branch '2.3.0-wip'v2.3.0
Diffstat (limited to 'js/tests/unit/bootstrap-tooltip.js')
| -rw-r--r-- | js/tests/unit/bootstrap-tooltip.js | 137 |
1 files changed, 136 insertions, 1 deletions
diff --git a/js/tests/unit/bootstrap-tooltip.js b/js/tests/unit/bootstrap-tooltip.js index eb8beeb6f..5b37b4e68 100644 --- a/js/tests/unit/bootstrap-tooltip.js +++ b/js/tests/unit/bootstrap-tooltip.js @@ -66,6 +66,83 @@ $(function () { ok(!$(".tooltip").length, 'tooltip removed') }) + test("should fire show event", function () { + stop() + var tooltip = $('<div title="tooltip title"></div>') + .bind("show", function() { + ok(true, "show was called") + start() + }) + .tooltip('show') + }) + + test("should fire shown event", function () { + stop() + var tooltip = $('<div title="tooltip title"></div>') + .bind("shown", function() { + ok(true, "shown was called") + start() + }) + .tooltip('show') + }) + + test("should not fire shown event when default prevented", function () { + stop() + var tooltip = $('<div title="tooltip title"></div>') + .bind("show", function(e) { + e.preventDefault() + ok(true, "show was called") + start() + }) + .bind("shown", function() { + ok(false, "shown was called") + }) + .tooltip('show') + }) + + test("should fire hide event", function () { + stop() + var tooltip = $('<div title="tooltip title"></div>') + .bind("shown", function() { + $(this).tooltip('hide') + }) + .bind("hide", function() { + ok(true, "hide was called") + start() + }) + .tooltip('show') + }) + + test("should fire hidden event", function () { + stop() + var tooltip = $('<div title="tooltip title"></div>') + .bind("shown", function() { + $(this).tooltip('hide') + }) + .bind("hidden", function() { + ok(true, "hidden was called") + start() + }) + .tooltip('show') + }) + + test("should not fire hidden event when default prevented", function () { + stop() + var tooltip = $('<div title="tooltip title"></div>') + .bind("shown", function() { + $(this).tooltip('hide') + }) + .bind("hide", function(e) { + e.preventDefault() + ok(true, "hide was called") + start() + }) + .bind("hidden", function() { + ok(false, "hidden was called") + }) + .tooltip('show') + }) + test("should not show tooltip if leave event occurs before delay expires", function () { var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>') .appendTo('#qunit-fixture') @@ -156,4 +233,62 @@ $(function () { div.find('a').trigger('click') ok($(".tooltip").is('.fade.in'), 'tooltip is faded in') }) -})
\ No newline at end of file + + test("should show tooltip when toggle is called", function () { + var tooltip = $('<a href="#" rel="tooltip" title="tooltip on toggle"></a>') + .appendTo('#qunit-fixture') + .tooltip({trigger: 'manual'}) + .tooltip('toggle') + ok($(".tooltip").is('.fade.in'), 'tooltip should be toggled in') + }) + + test("should place tooltips inside the body", function () { + var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>') + .appendTo('#qunit-fixture') + .tooltip({container:'body'}) + .tooltip('show') + ok($("body > .tooltip").length, 'inside the body') + ok(!$("#qunit-fixture > .tooltip").length, 'not found in parent') + tooltip.tooltip('hide') + }) + + test("should place tooltip inside window", function(){ + var container = $("<div />").appendTo("body") + .css({position: "absolute", width: 200, height: 200, bottom: 0, left: 0}) + , tooltip = $("<a href='#' title='Very very very very very very very very long tooltip'>Hover me</a>") + .css({position: "absolute", top:0, left: 0}) + .appendTo(container) + .tooltip({placement: "top", animate: false}) + .tooltip("show") + + stop() + + setTimeout(function(){ + ok($(".tooltip").offset().left >= 0) + + start() + container.remove() + }, 100) + }) + + test("should place tooltip on top of element", function(){ + var container = $("<div />").appendTo("body") + .css({position: "absolute", bottom: 0, left: 0, textAlign: "right", width: 300, height: 300}) + , p = $("<p style='margin-top:200px' />").appendTo(container) + , tooltiped = $("<a href='#' title='very very very very very very very long tooltip'>Hover me</a>") + .css({marginTop: 200}) + .appendTo(p) + .tooltip({placement: "top", animate: false}) + .tooltip("show") + + stop() + + setTimeout(function(){ + var tooltip = container.find(".tooltip") + + start() + ok(tooltip.offset().top + tooltip.outerHeight() <= tooltiped.offset().top) + container.remove() + }, 100) + }) +}) |
