diff options
| author | Jacob Thornton <[email protected]> | 2012-04-24 02:21:45 -0700 |
|---|---|---|
| committer | Jacob Thornton <[email protected]> | 2012-04-24 02:21:45 -0700 |
| commit | e659dc7e1be2e09cec34703dce8c737496e3504e (patch) | |
| tree | be3caed12a3de1218e1fd548f2564302e6c8193a /js/tests | |
| parent | 6506ede6323ee60d4d7f8171937d92141a64e09e (diff) | |
| parent | 839ef3a030b355d0f0c35d6c9e42ecba8b072036 (diff) | |
| download | bootstrap-e659dc7e1be2e09cec34703dce8c737496e3504e.tar.xz bootstrap-e659dc7e1be2e09cec34703dce8c737496e3504e.zip | |
Merge branch '2.0.3-wip'
Conflicts:
Makefile
docs/assets/js/bootstrap.js
docs/assets/js/bootstrap.min.js
Diffstat (limited to 'js/tests')
| -rw-r--r-- | js/tests/index.html | 7 | ||||
| -rw-r--r-- | js/tests/phantom.js | 63 | ||||
| -rw-r--r-- | js/tests/server.js | 14 | ||||
| -rw-r--r-- | js/tests/unit/bootstrap-alert.js | 15 | ||||
| -rw-r--r-- | js/tests/unit/bootstrap-carousel.js | 28 | ||||
| -rw-r--r-- | js/tests/unit/bootstrap-collapse.js | 15 | ||||
| -rw-r--r-- | js/tests/unit/bootstrap-dropdown.js | 34 | ||||
| -rw-r--r-- | js/tests/unit/bootstrap-modal.js | 29 | ||||
| -rw-r--r-- | js/tests/unit/bootstrap-phantom.js | 21 | ||||
| -rw-r--r-- | js/tests/unit/bootstrap-tab.js | 16 | ||||
| -rw-r--r-- | js/tests/unit/bootstrap-tooltip.js | 74 | ||||
| -rw-r--r-- | js/tests/unit/bootstrap-transition.js | 2 | ||||
| -rw-r--r-- | js/tests/unit/bootstrap-typeahead.js | 20 |
13 files changed, 334 insertions, 4 deletions
diff --git a/js/tests/index.html b/js/tests/index.html index 8c710de36..2f8f71b12 100644 --- a/js/tests/index.html +++ b/js/tests/index.html @@ -11,10 +11,14 @@ <link rel="stylesheet" href="vendor/qunit.css" type="text/css" media="screen" /> <script src="vendor/qunit.js"></script> + <!-- phantomjs logging script--> + <script src="unit/bootstrap-phantom.js"></script> + <!-- plugin sources --> <script src="../../js/bootstrap-transition.js"></script> <script src="../../js/bootstrap-alert.js"></script> <script src="../../js/bootstrap-button.js"></script> + <script src="../../js/bootstrap-carousel.js"></script> <script src="../../js/bootstrap-collapse.js"></script> <script src="../../js/bootstrap-dropdown.js"></script> <script src="../../js/bootstrap-modal.js"></script> @@ -28,6 +32,7 @@ <script src="unit/bootstrap-transition.js"></script> <script src="unit/bootstrap-alert.js"></script> <script src="unit/bootstrap-button.js"></script> + <script src="unit/bootstrap-carousel.js"></script> <script src="unit/bootstrap-collapse.js"></script> <script src="unit/bootstrap-dropdown.js"></script> <script src="unit/bootstrap-modal.js"></script> @@ -36,7 +41,7 @@ <script src="unit/bootstrap-tooltip.js"></script> <script src="unit/bootstrap-popover.js"></script> <script src="unit/bootstrap-typeahead.js"></script> - +</head> <body> <div> <h1 id="qunit-header">Bootstrap Plugin Test Suite</h1> diff --git a/js/tests/phantom.js b/js/tests/phantom.js new file mode 100644 index 000000000..4105bf529 --- /dev/null +++ b/js/tests/phantom.js @@ -0,0 +1,63 @@ +// Simple phantom.js integration script +// Adapted from Modernizr + +function waitFor(testFx, onReady, timeOutMillis) { + var maxtimeOutMillis = timeOutMillis ? timeOutMillis : 5001 //< Default Max Timout is 5s + , start = new Date().getTime() + , condition = false + , interval = setInterval(function () { + if ((new Date().getTime() - start < maxtimeOutMillis) && !condition) { + // If not time-out yet and condition not yet fulfilled + condition = (typeof(testFx) === "string" ? eval(testFx) : testFx()) //< defensive code + } else { + if (!condition) { + // If condition still not fulfilled (timeout but condition is 'false') + console.log("'waitFor()' timeout") + phantom.exit(1) + } else { + // Condition fulfilled (timeout and/or condition is 'true') + typeof(onReady) === "string" ? eval(onReady) : onReady() //< Do what it's supposed to do once the condition is fulfilled + clearInterval(interval) //< Stop this interval + } + } + }, 100) //< repeat check every 100ms +} + + +if (phantom.args.length === 0 || phantom.args.length > 2) { + console.log('Usage: phantom.js URL') + phantom.exit() +} + +var page = new WebPage() + +// Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this") +page.onConsoleMessage = function(msg) { + console.log(msg) +}; + +page.open(phantom.args[0], function(status){ + if (status !== "success") { + console.log("Unable to access network") + phantom.exit() + } else { + waitFor(function(){ + return page.evaluate(function(){ + var el = document.getElementById('qunit-testresult') + if (el && el.innerText.match('completed')) { + return true + } + return false + }) + }, function(){ + var failedNum = page.evaluate(function(){ + var el = document.getElementById('qunit-testresult') + try { + return el.getElementsByClassName('failed')[0].innerHTML + } catch (e) { } + return 10000 + }); + phantom.exit((parseInt(failedNum, 10) > 0) ? 1 : 0) + }) + } +})
\ No newline at end of file diff --git a/js/tests/server.js b/js/tests/server.js new file mode 100644 index 000000000..7c8445feb --- /dev/null +++ b/js/tests/server.js @@ -0,0 +1,14 @@ +/* + * Simple connect server for phantom.js + * Adapted from Modernizr + */ + +var connect = require('connect') + , http = require('http') + , fs = require('fs') + , app = connect() + .use(connect.static(__dirname + '/../../')); + +http.createServer(app).listen(3000); + +fs.writeFileSync(__dirname + '/pid.txt', process.pid, 'utf-8')
\ No newline at end of file diff --git a/js/tests/unit/bootstrap-alert.js b/js/tests/unit/bootstrap-alert.js index e607f4340..7f24e0e6b 100644 --- a/js/tests/unit/bootstrap-alert.js +++ b/js/tests/unit/bootstrap-alert.js @@ -38,4 +38,19 @@ $(function () { ok(!$('#qunit-fixture').find('.alert-message').length, 'element removed from dom') }) + test("should not fire closed when close is prevented", function () { + $.support.transition = false + stop(); + $('<div class="alert"/>') + .bind('close', function (e) { + e.preventDefault(); + ok(true); + start(); + }) + .bind('closed', function () { + ok(false); + }) + .alert('close') + }) + })
\ No newline at end of file diff --git a/js/tests/unit/bootstrap-carousel.js b/js/tests/unit/bootstrap-carousel.js new file mode 100644 index 000000000..92c23e227 --- /dev/null +++ b/js/tests/unit/bootstrap-carousel.js @@ -0,0 +1,28 @@ +$(function () { + + module("bootstrap-carousel") + + test("should be defined on jquery object", function () { + ok($(document.body).carousel, 'carousel method is defined') + }) + + test("should return element", function () { + ok($(document.body).carousel()[0] == document.body, 'document.body returned') + }) + + test("should not fire sliden when slide is prevented", function () { + $.support.transition = false + stop(); + $('<div class="carousel"/>') + .bind('slide', function (e) { + e.preventDefault(); + ok(true); + start(); + }) + .bind('slid', function () { + ok(false); + }) + .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 698238d96..8e52898b5 100644 --- a/js/tests/unit/bootstrap-collapse.js +++ b/js/tests/unit/bootstrap-collapse.js @@ -22,4 +22,19 @@ $(function () { ok(/height/.test(el.attr('style')), 'has height set') }) + test("should not fire shown when show is prevented", function () { + $.support.transition = false + stop(); + $('<div class="collapse"/>') + .bind('show', function (e) { + e.preventDefault(); + ok(true); + start(); + }) + .bind('shown', function () { + ok(false); + }) + .collapse('show') + }) + })
\ No newline at end of file diff --git a/js/tests/unit/bootstrap-dropdown.js b/js/tests/unit/bootstrap-dropdown.js index 368ced2a5..4e52c8485 100644 --- a/js/tests/unit/bootstrap-dropdown.js +++ b/js/tests/unit/bootstrap-dropdown.js @@ -10,6 +10,40 @@ $(function () { ok($(document.body).dropdown()[0] == document.body, 'document.body returned') }) + test("should not open dropdown if target is disabled", function () { + var dropdownHTML = '<ul class="tabs">' + + '<li class="dropdown">' + + '<button disabled href="#" class="btn dropdown-toggle" data-toggle="dropdown">Dropdown</button>' + + '<ul class="dropdown-menu">' + + '<li><a href="#">Secondary link</a></li>' + + '<li><a href="#">Something else here</a></li>' + + '<li class="divider"></li>' + + '<li><a href="#">Another link</a></li>' + + '</ul>' + + '</li>' + + '</ul>' + , dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').dropdown().click() + + ok(!dropdown.parent('.dropdown').hasClass('open'), 'open class added on click') + }) + + test("should not open dropdown if target is disabled", function () { + var dropdownHTML = '<ul class="tabs">' + + '<li class="dropdown">' + + '<button href="#" class="btn dropdown-toggle disabled" data-toggle="dropdown">Dropdown</button>' + + '<ul class="dropdown-menu">' + + '<li><a href="#">Secondary link</a></li>' + + '<li><a href="#">Something else here</a></li>' + + '<li class="divider"></li>' + + '<li><a href="#">Another link</a></li>' + + '</ul>' + + '</li>' + + '</ul>' + , dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').dropdown().click() + + ok(!dropdown.parent('.dropdown').hasClass('open'), 'open class added on click') + }) + test("should add class open to menu if clicked", function () { var dropdownHTML = '<ul class="tabs">' + '<li class="dropdown">' diff --git a/js/tests/unit/bootstrap-modal.js b/js/tests/unit/bootstrap-modal.js index 22f5781ea..0851f64a7 100644 --- a/js/tests/unit/bootstrap-modal.js +++ b/js/tests/unit/bootstrap-modal.js @@ -29,6 +29,35 @@ $(function () { .modal("show") }) + test("should fire show event", function () { + stop() + $.support.transition = false + $("<div id='modal-test'></div>") + .bind("show", function () { + ok(true, "show was called") + }) + .bind("shown", function () { + $(this).remove() + start() + }) + .modal("show") + }) + + test("should not fire shown when default prevented", function () { + stop() + $.support.transition = false + $("<div id='modal-test'></div>") + .bind("show", function (e) { + e.preventDefault() + ok(true, "show was called") + start() + }) + .bind("shown", function () { + ok(false, "shown was called") + }) + .modal("show") + }) + test("should hide modal when hide is called", function () { stop() $.support.transition = false diff --git a/js/tests/unit/bootstrap-phantom.js b/js/tests/unit/bootstrap-phantom.js new file mode 100644 index 000000000..a04aeaa87 --- /dev/null +++ b/js/tests/unit/bootstrap-phantom.js @@ -0,0 +1,21 @@ +// Logging setup for phantom integration +// adapted from Modernizr + +QUnit.begin = function () { + console.log("Starting test suite") + console.log("================================================\n") +} + +QUnit.moduleDone = function (opts) { + if (opts.failed === 0) { + console.log("\u2714 All tests passed in '" + opts.name + "' module") + } else { + console.log("\u2716 " + opts.failed + " tests failed in '" + opts.name + "' module") + } +} + +QUnit.done = function (opts) { + console.log("\n================================================") + console.log("Tests completed in " + opts.runtime + " milliseconds") + console.log(opts.passed + " tests of " + opts.total + " passed, " + opts.failed + " failed.") +}
\ No newline at end of file diff --git a/js/tests/unit/bootstrap-tab.js b/js/tests/unit/bootstrap-tab.js index 18f490fa5..987804781 100644 --- a/js/tests/unit/bootstrap-tab.js +++ b/js/tests/unit/bootstrap-tab.js @@ -42,4 +42,20 @@ $(function () { equals($("#qunit-fixture").find('.active').attr('id'), "home") }) + + test("should not fire closed when close is prevented", function () { + $.support.transition = false + stop(); + $('<div class="tab"/>') + .bind('show', function (e) { + e.preventDefault(); + ok(true); + start(); + }) + .bind('shown', function () { + ok(false); + }) + .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 8543162c6..63f4f0b07 100644 --- a/js/tests/unit/bootstrap-tooltip.js +++ b/js/tests/unit/bootstrap-tooltip.js @@ -59,4 +59,78 @@ $(function () { ok(!$(".tooltip").length, 'tooltip removed') }) + 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') + .tooltip({ delay: 200 }) + + stop() + + tooltip.trigger('mouseenter') + + setTimeout(function () { + ok(!$(".tooltip").hasClass('fade in'), 'tooltip is not faded in') + tooltip.trigger('mouseout') + setTimeout(function () { + ok(!$(".tooltip").hasClass('fade in'), 'tooltip is not faded in') + start() + }, 200) + }, 100) + }) + + 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') + .tooltip({ delay: 100 }) + stop() + tooltip.trigger('mouseenter') + setTimeout(function () { + ok(!$(".tooltip").hasClass('fade in'), 'tooltip is not faded in') + tooltip.trigger('mouseout') + setTimeout(function () { + ok(!$(".tooltip").hasClass('fade in'), 'tooltip is not faded in') + start() + }, 100) + }, 50) + }) + + 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: 200 }) + stop() + tooltip.trigger('mouseenter') + setTimeout(function () { + ok(!$(".tooltip").hasClass('fade in'), 'tooltip is not faded in') + setTimeout(function () { + ok(!$(".tooltip").hasClass('fade in'), 'tooltip has faded in') + start() + }, 200) + }, 100) + }) + + 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') + }) + })
\ No newline at end of file diff --git a/js/tests/unit/bootstrap-transition.js b/js/tests/unit/bootstrap-transition.js index 3f28d2676..086773fa2 100644 --- a/js/tests/unit/bootstrap-transition.js +++ b/js/tests/unit/bootstrap-transition.js @@ -3,7 +3,7 @@ $(function () { module("bootstrap-transition") test("should be defined on jquery support object", function () { - ok($.support.transition != undefined, 'transition object is defined') + ok($.support.transition !== undefined, 'transition object is defined') }) test("should provide an end object", function () { diff --git a/js/tests/unit/bootstrap-typeahead.js b/js/tests/unit/bootstrap-typeahead.js index 96ea7c45f..4e2428d6a 100644 --- a/js/tests/unit/bootstrap-typeahead.js +++ b/js/tests/unit/bootstrap-typeahead.js @@ -52,6 +52,22 @@ $(function () { typeahead.$menu.remove() }) + test("should not explode when regex chars are entered", function () { + var $input = $('<input />').typeahead({ + source: ['aa', 'ab', 'ac', 'mdo*', 'fat+'] + }) + , typeahead = $input.data('typeahead') + + $input.val('+') + typeahead.lookup() + + ok(typeahead.$menu.is(":visible"), 'typeahead is visible') + equals(typeahead.$menu.find('li').length, 1, 'has 1 item 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({ @@ -91,7 +107,7 @@ $(function () { ok(typeahead.$menu.find('li').first().hasClass('active'), "first item is active") $input.trigger({ - type: 'keypress' + type: 'keydown' , keyCode: 40 }) @@ -99,7 +115,7 @@ $(function () { $input.trigger({ - type: 'keypress' + type: 'keydown' , keyCode: 38 }) |
