diff options
Diffstat (limited to 'js/tests/unit')
-rw-r--r-- | js/tests/unit/bootstrap-carousel.js | 23 | ||||
-rw-r--r-- | js/tests/unit/bootstrap-dropdown.js | 42 | ||||
-rw-r--r-- | js/tests/unit/bootstrap-popover.js | 8 | ||||
-rw-r--r-- | js/tests/unit/bootstrap-tab.js | 19 | ||||
-rw-r--r-- | js/tests/unit/bootstrap-tooltip.js | 25 | ||||
-rw-r--r-- | js/tests/unit/bootstrap-typeahead.js | 17 |
6 files changed, 109 insertions, 25 deletions
diff --git a/js/tests/unit/bootstrap-carousel.js b/js/tests/unit/bootstrap-carousel.js index 4c93c7b18c..8bd1b62ba0 100644 --- a/js/tests/unit/bootstrap-carousel.js +++ b/js/tests/unit/bootstrap-carousel.js @@ -26,7 +26,7 @@ $(function () { }) 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>' + var template = '<div id="myCarousel" class="carousel slide"><div class="carousel-inner"><div class="item active"><img 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 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 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) @@ -39,4 +39,25 @@ $(function () { .carousel('next') }) + test("should set interval from data attribute", 3,function () { + var template = $('<div id="myCarousel" class="carousel slide"> <div class="carousel-inner"> <div class="item active"> <img 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 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 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>'); + template.attr("data-interval", 1814); + + template.appendTo("body"); + $('[data-slide]').first().click(); + ok($('#myCarousel').data('carousel').options.interval == 1814); + $('#myCarousel').remove(); + + template.appendTo("body").attr("data-modal", "foobar"); + $('[data-slide]').first().click(); + ok($('#myCarousel').data('carousel').options.interval == 1814, "even if there is an data-modal attribute set"); + $('#myCarousel').remove(); + + template.appendTo("body"); + $('[data-slide]').first().click(); + $('#myCarousel').attr('data-interval', 1860); + $('[data-slide]').first().click(); + ok($('#myCarousel').data('carousel').options.interval == 1814, "attributes should be read only on intitialization"); + $('#myCarousel').remove(); + }) })
\ No newline at end of file diff --git a/js/tests/unit/bootstrap-dropdown.js b/js/tests/unit/bootstrap-dropdown.js index 3a617692b3..3788209ecc 100644 --- a/js/tests/unit/bootstrap-dropdown.js +++ b/js/tests/unit/bootstrap-dropdown.js @@ -7,7 +7,8 @@ $(function () { }) test("should return element", function () { - ok($(document.body).dropdown()[0] == document.body, 'document.body returned') + var el = $("<div />") + ok(el.dropdown()[0] === el[0], 'same element returned') }) test("should not open dropdown if target is disabled", function () { @@ -102,4 +103,43 @@ $(function () { dropdown.remove() }) + test("should remove open class if body clicked, with multiple drop downs", function () { + var dropdownHTML = + '<ul class="nav">' + + ' <li><a href="#menu1">Menu 1</a></li>' + + ' <li class="dropdown" id="testmenu">' + + ' <a class="dropdown-toggle" data-toggle="dropdown" href="#testmenu">Test menu <b class="caret"></b></a>' + + ' <ul class="dropdown-menu" role="menu">' + + ' <li><a href="#sub1">Submenu 1</a></li>' + + ' </ul>' + + ' </li>' + + '</ul>' + + '<div class="btn-group">' + + ' <button class="btn">Actions</button>' + + ' <button class="btn dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></button>' + + ' <ul class="dropdown-menu">' + + ' <li><a href="#">Action 1</a></li>' + + ' </ul>' + + '</div>' + , dropdowns = $(dropdownHTML).appendTo('#qunit-fixture').find('[data-toggle="dropdown"]') + , first = dropdowns.first() + , last = dropdowns.last() + + ok(dropdowns.length == 2, "Should be two dropdowns") + + first.click() + ok(first.parents('.open').length == 1, 'open class added on click') + ok($('#qunit-fixture .open').length == 1, 'only one object is open') + $('body').click() + ok($("#qunit-fixture .open").length === 0, 'open class removed') + + last.click() + ok(last.parent('.open').length == 1, 'open class added on click') + ok($('#qunit-fixture .open').length == 1, 'only one object is open') + $('body').click() + ok($("#qunit-fixture .open").length === 0, 'open class removed') + + $("#qunit-fixture").html("") + }) + })
\ No newline at end of file diff --git a/js/tests/unit/bootstrap-popover.js b/js/tests/unit/bootstrap-popover.js index 04d5279d24..6a5f0bdcfe 100644 --- a/js/tests/unit/bootstrap-popover.js +++ b/js/tests/unit/bootstrap-popover.js @@ -94,14 +94,14 @@ $(function () { 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') + ok($._data(popover[0], 'events').mouseover && $._data(popover[0], 'events').mouseout, 'popover has hover event') + ok($._data(popover[0], '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') + ok($._data(popover[0],'events').click[0].namespace == 'foo', 'popover still has click.foo') + ok(!$._data(popover[0], 'events').mouseover && !$._data(popover[0], 'events').mouseout, 'popover does not have any events') }) })
\ No newline at end of file diff --git a/js/tests/unit/bootstrap-tab.js b/js/tests/unit/bootstrap-tab.js index 9878047810..40f9a7406d 100644 --- a/js/tests/unit/bootstrap-tab.js +++ b/js/tests/unit/bootstrap-tab.js @@ -58,4 +58,23 @@ $(function () { .tab('show') }) + test("show and shown events should reference correct relatedTarget", function () { + var dropHTML = + '<ul class="drop">' + + '<li class="dropdown"><a data-toggle="dropdown" href="#">1</a>' + + '<ul class="dropdown-menu">' + + '<li><a href="#1-1" data-toggle="tab">1-1</a></li>' + + '<li><a href="#1-2" data-toggle="tab">1-2</a></li>' + + '</ul>' + + '</li>' + + '</ul>' + + $(dropHTML).find('ul>li:first a').tab('show').end() + .find('ul>li:last a').on('show', function(event){ + equals(event.relatedTarget.hash, "#1-1") + }).on('shown', function(event){ + equals(event.relatedTarget.hash, "#1-1") + }).tab('show') + }) + })
\ No newline at end of file diff --git a/js/tests/unit/bootstrap-tooltip.js b/js/tests/unit/bootstrap-tooltip.js index 9844d6460f..bbdf3ce80f 100644 --- a/js/tests/unit/bootstrap-tooltip.js +++ b/js/tests/unit/bootstrap-tooltip.js @@ -37,10 +37,11 @@ $(function () { tooltip.tooltip('hide') }) - test("should always allow html entities", function () { + test("should allow html entities", function () { $.support.transition = false var tooltip = $('<a href="#" rel="tooltip" title="<b>@fat</b>"></a>') .appendTo('#qunit-fixture') + .tooltip({html: true}) .tooltip('show') ok($('.tooltip b').length, 'b tag was inserted') @@ -113,7 +114,7 @@ $(function () { }, 50) }) - test("should show tooltip if leave event hasn't occurred before delay expires", function () { + test("should show tooltip if leave event hasn't occured before delay expires", function () { var tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"></a>') .appendTo('#qunit-fixture') .tooltip({ delay: 150 }) @@ -131,14 +132,22 @@ $(function () { 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') + ok($._data(tooltip[0], 'events').mouseover && $._data(tooltip[0], 'events').mouseout, 'tooltip has hover event') + ok($._data(tooltip[0], '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') + ok(!$._data(tooltip[0], 'tooltip'), 'tooltip does not have data') + ok($._data(tooltip[0], 'events').click[0].namespace == 'foo', 'tooltip still has click.foo') + ok(!$._data(tooltip[0], 'events').mouseover && !$._data(tooltip[0], 'events').mouseout, 'tooltip does not have any events') }) -}) + test("should show tooltip with delegate selector on click", function () { + var div = $('<div><a href="#" rel="tooltip" title="Another tooltip"></a></div>') + var tooltip = div.appendTo('#qunit-fixture') + .tooltip({ selector: 'a[rel=tooltip]', + trigger: 'click' }) + div.find('a').trigger('click') + ok($(".tooltip").is('.fade.in'), 'tooltip is faded in') + }) +})
\ No newline at end of file diff --git a/js/tests/unit/bootstrap-typeahead.js b/js/tests/unit/bootstrap-typeahead.js index eb447aaa6e..16bdb91948 100644 --- a/js/tests/unit/bootstrap-typeahead.js +++ b/js/tests/unit/bootstrap-typeahead.js @@ -13,14 +13,9 @@ $(function () { 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') - } + ok($._data($input[0], 'events').blur, 'has a blur event') + ok($._data($input[0], 'events').keypress, 'has a keypress event') + ok($._data($input[0], 'events').keyup, 'has a keyup event') }) test("should create a menu", function () { @@ -32,8 +27,8 @@ $(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') + ok($._data($menu[0], 'events').mouseover, 'has a mouseover(pseudo: mouseenter)') + ok($._data($menu[0], 'events').click, 'has a click') }) test("should show menu when query entered", function () { @@ -201,4 +196,4 @@ $(function () { typeahead.$menu.remove() }) -}) +})
\ No newline at end of file |