diff options
| author | Jacob Thornton <[email protected]> | 2012-08-20 16:13:46 -0700 |
|---|---|---|
| committer | Jacob Thornton <[email protected]> | 2012-08-20 16:13:46 -0700 |
| commit | 5d63e8e2a84468351b4c1ee6cc21f48e95ea27bf (patch) | |
| tree | 2d760c794e61c15850d14d5eee1c565ab4f9a871 /js/tests/unit | |
| parent | 5df1e2c00a295c45db7fa75dba333dc9464b128c (diff) | |
| parent | aa2cec6f2f706f8c1754f8bf79a8c9f094445bd8 (diff) | |
| download | bootstrap-5d63e8e2a84468351b4c1ee6cc21f48e95ea27bf.tar.xz bootstrap-5d63e8e2a84468351b4c1ee6cc21f48e95ea27bf.zip | |
fMerge branch '2.1.0-wip'
Conflicts:
docs/index.html
Diffstat (limited to 'js/tests/unit')
| -rw-r--r-- | js/tests/unit/bootstrap-affix.js | 19 | ||||
| -rw-r--r-- | js/tests/unit/bootstrap-carousel.js | 16 | ||||
| -rw-r--r-- | js/tests/unit/bootstrap-collapse.js | 38 | ||||
| -rw-r--r-- | js/tests/unit/bootstrap-popover.js | 14 | ||||
| -rw-r--r-- | js/tests/unit/bootstrap-tooltip.js | 33 | ||||
| -rw-r--r-- | js/tests/unit/bootstrap-typeahead.js | 56 |
6 files changed, 151 insertions, 25 deletions
diff --git a/js/tests/unit/bootstrap-affix.js b/js/tests/unit/bootstrap-affix.js new file mode 100644 index 000000000..bc25df991 --- /dev/null +++ b/js/tests/unit/bootstrap-affix.js @@ -0,0 +1,19 @@ +$(function () { + + module("bootstrap-affix") + + test("should be defined on jquery object", function () { + ok($(document.body).affix, 'affix method is defined') + }) + + test("should return element", function () { + ok($(document.body).affix()[0] == document.body, 'document.body returned') + }) + + test("should exit early if element is not visible", function () { + var $affix = $('<div style="display: none"></div>').affix() + $affix.data('affix').checkPosition() + ok(!$affix.hasClass('affix'), 'affix class was not added') + }) + +})
\ No newline at end of file diff --git a/js/tests/unit/bootstrap-carousel.js b/js/tests/unit/bootstrap-carousel.js index 92c23e227..4c93c7b18 100644 --- a/js/tests/unit/bootstrap-carousel.js +++ b/js/tests/unit/bootstrap-carousel.js @@ -12,7 +12,7 @@ $(function () { test("should not fire sliden when slide is prevented", function () { $.support.transition = false - stop(); + stop() $('<div class="carousel"/>') .bind('slide', function (e) { e.preventDefault(); @@ -25,4 +25,18 @@ $(function () { .carousel('next') }) + test("should fire slide event with relatedTarget", function () { + var template = '<div id="myCarousel" class="carousel slide"><div class="carousel-inner"><div class="item active"><img src="assets/img/bootstrap-mdo-sfmoma-01.jpg" alt=""><div class="carousel-caption"><h4>{{_i}}First Thumbnail label{{/i}}</h4><p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p></div></div><div class="item"><img src="assets/img/bootstrap-mdo-sfmoma-02.jpg" alt=""><div class="carousel-caption"><h4>{{_i}}Second Thumbnail label{{/i}}</h4><p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p></div></div><div class="item"><img src="assets/img/bootstrap-mdo-sfmoma-03.jpg" alt=""><div class="carousel-caption"><h4>{{_i}}Third Thumbnail label{{/i}}</h4><p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p></div></div></div><a class="left carousel-control" href="#myCarousel" data-slide="prev">‹</a><a class="right carousel-control" href="#myCarousel" data-slide="next">›</a></div>' + $.support.transition = false + stop() + $(template) + .on('slide', function (e) { + e.preventDefault(); + ok(e.relatedTarget); + ok($(e.relatedTarget).hasClass('item')); + start(); + }) + .carousel('next') + }) + })
\ No newline at end of file diff --git a/js/tests/unit/bootstrap-collapse.js b/js/tests/unit/bootstrap-collapse.js index fb66135db..6cc7ac7a4 100644 --- a/js/tests/unit/bootstrap-collapse.js +++ b/js/tests/unit/bootstrap-collapse.js @@ -24,7 +24,7 @@ $(function () { test("should not fire shown when show is prevented", function () { $.support.transition = false - stop(); + stop() $('<div class="collapse"/>') .bind('show', function (e) { e.preventDefault(); @@ -39,7 +39,7 @@ $(function () { test("should reset style to auto after finishing opening collapse", function () { $.support.transition = false - stop(); + stop() $('<div class="collapse" style="height: 0px"/>') .bind('show', function () { ok(this.style.height == '0px') @@ -51,4 +51,38 @@ $(function () { .collapse('show') }) + test("should add active class to target when collapse shown", function () { + $.support.transition = false + stop() + + var target = $('<a data-toggle="collapse" href="#test1"></a>') + .appendTo($('#qunit-fixture')) + + var collapsible = $('<div id="test1"></div>') + .appendTo($('#qunit-fixture')) + .on('show', function () { + ok(!target.hasClass('collapsed')) + start() + }) + + target.click() + }) + + test("should remove active class to target when collapse hidden", function () { + $.support.transition = false + stop() + + var target = $('<a data-toggle="collapse" href="#test1"></a>') + .appendTo($('#qunit-fixture')) + + var collapsible = $('<div id="test1" class="in"></div>') + .appendTo($('#qunit-fixture')) + .on('hide', function () { + ok(target.hasClass('collapsed')) + start() + }) + + target.click() + }) + })
\ No newline at end of file diff --git a/js/tests/unit/bootstrap-popover.js b/js/tests/unit/bootstrap-popover.js index afd6b170b..04d5279d2 100644 --- a/js/tests/unit/bootstrap-popover.js +++ b/js/tests/unit/bootstrap-popover.js @@ -90,4 +90,18 @@ $(function () { ok(!$('.popover').length, 'popover was removed') $('#qunit-fixture').empty() }) + + test("should destroy popover", function () { + var popover = $('<div/>').popover({trigger: 'hover'}).on('click.foo', function(){}) + ok(popover.data('popover'), 'popover has data') + ok(popover.data('events').mouseover && popover.data('events').mouseout, 'popover has hover event') + ok(popover.data('events').click[0].namespace == 'foo', 'popover has extra click.foo event') + popover.popover('show') + popover.popover('destroy') + ok(!popover.hasClass('in'), 'popover is hidden') + ok(!popover.data('popover'), 'popover does not have data') + ok(popover.data('events').click[0].namespace == 'foo', 'popover still has click.foo') + ok(!popover.data('events').mouseover && !popover.data('events').mouseout, 'popover does not have any events') + }) + })
\ No newline at end of file diff --git a/js/tests/unit/bootstrap-tooltip.js b/js/tests/unit/bootstrap-tooltip.js index 7b0c10de0..2eb8c8f7c 100644 --- a/js/tests/unit/bootstrap-tooltip.js +++ b/js/tests/unit/bootstrap-tooltip.js @@ -128,28 +128,17 @@ $(function () { }, 200) }) - test("should detect if title string is html or text: foo", function () { - ok(!$.fn.tooltip.Constructor.prototype.isHTML('foo'), 'correctly detected html') - }) - - test("should detect if title string is html or text: &lt;foo&gt;", function () { - ok(!$.fn.tooltip.Constructor.prototype.isHTML('<foo>'), 'correctly detected html') - }) - - test("should detect if title string is html or text: <div>foo</div>", function () { - ok($.fn.tooltip.Constructor.prototype.isHTML('<div>foo</div>'), 'correctly detected html') - }) - - test("should detect if title string is html or text: asdfa<div>foo</div>asdfasdf", function () { - ok($.fn.tooltip.Constructor.prototype.isHTML('asdfa<div>foo</div>asdfasdf'), 'correctly detected html') - }) - - test("should detect if title string is html or text: document.createElement('div')", function () { - ok($.fn.tooltip.Constructor.prototype.isHTML(document.createElement('div')), 'correctly detected html') - }) - - test("should detect if title string is html or text: $('<div />)", function () { - ok($.fn.tooltip.Constructor.prototype.isHTML($('<div></div>')), 'correctly detected html') + test("should destroy tooltip", function () { + var tooltip = $('<div/>').tooltip().on('click.foo', function(){}) + ok(tooltip.data('tooltip'), 'tooltip has data') + ok(tooltip.data('events').mouseover && tooltip.data('events').mouseout, 'tooltip has hover event') + ok(tooltip.data('events').click[0].namespace == 'foo', 'tooltip has extra click.foo event') + tooltip.tooltip('show') + tooltip.tooltip('destroy') + ok(!tooltip.hasClass('in'), 'tooltip is hidden') + ok(!tooltip.data('tooltip'), 'tooltip does not have data') + ok(tooltip.data('events').click[0].namespace == 'foo', 'tooltip still has click.foo') + ok(!tooltip.data('events').mouseover && !tooltip.data('events').mouseout, 'tooltip does not have any events') }) }) diff --git a/js/tests/unit/bootstrap-typeahead.js b/js/tests/unit/bootstrap-typeahead.js index 4e2428d6a..eb447aaa6 100644 --- a/js/tests/unit/bootstrap-typeahead.js +++ b/js/tests/unit/bootstrap-typeahead.js @@ -52,6 +52,42 @@ $(function () { typeahead.$menu.remove() }) + test("should accept data source via synchronous function", function () { + var $input = $('<input />').typeahead({ + source: function () { + return ['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 accept data source via asynchronous function", function () { + var $input = $('<input />').typeahead({ + source: function (query, process) { + process(['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 not explode when regex chars are entered", function () { var $input = $('<input />').typeahead({ source: ['aa', 'ab', 'ac', 'mdo*', 'fat+'] @@ -145,4 +181,24 @@ $(function () { typeahead.$menu.remove() }) + + test("should start querying when minLength is met", function () { + var $input = $('<input />').typeahead({ + source: ['aaaa', 'aaab', 'aaac'], + minLength: 3 + }) + , typeahead = $input.data('typeahead') + + $input.val('aa') + typeahead.lookup() + + equals(typeahead.$menu.find('li').length, 0, 'has 0 items in menu') + + $input.val('aaa') + typeahead.lookup() + + equals(typeahead.$menu.find('li').length, 3, 'has 3 items in menu') + + typeahead.$menu.remove() + }) }) |
