From c7b48513fb2cb0cdd0e4ec0050b8dbcbddc698f5 Mon Sep 17 00:00:00 2001 From: hardythe1 Date: Tue, 22 Oct 2013 17:31:15 +0530 Subject: Adding the project initial commit --- tbc/static/js/tests/index.html | 56 + tbc/static/js/tests/phantom.js | 63 + tbc/static/js/tests/server.js | 14 + tbc/static/js/tests/unit/bootstrap-affix.js | 25 + tbc/static/js/tests/unit/bootstrap-alert.js | 62 + tbc/static/js/tests/unit/bootstrap-button.js | 102 ++ tbc/static/js/tests/unit/bootstrap-carousel.js | 81 ++ tbc/static/js/tests/unit/bootstrap-collapse.js | 94 ++ tbc/static/js/tests/unit/bootstrap-dropdown.js | 151 +++ tbc/static/js/tests/unit/bootstrap-modal.js | 137 ++ tbc/static/js/tests/unit/bootstrap-phantom.js | 21 + tbc/static/js/tests/unit/bootstrap-popover.js | 113 ++ tbc/static/js/tests/unit/bootstrap-scrollspy.js | 37 + tbc/static/js/tests/unit/bootstrap-tab.js | 86 ++ tbc/static/js/tests/unit/bootstrap-tooltip.js | 294 +++++ tbc/static/js/tests/unit/bootstrap-transition.js | 13 + tbc/static/js/tests/unit/bootstrap-typeahead.js | 236 ++++ tbc/static/js/tests/vendor/jquery.js | 5 + tbc/static/js/tests/vendor/qunit.css | 232 ++++ tbc/static/js/tests/vendor/qunit.js | 1510 ++++++++++++++++++++++ 20 files changed, 3332 insertions(+) create mode 100755 tbc/static/js/tests/index.html create mode 100755 tbc/static/js/tests/phantom.js create mode 100755 tbc/static/js/tests/server.js create mode 100755 tbc/static/js/tests/unit/bootstrap-affix.js create mode 100755 tbc/static/js/tests/unit/bootstrap-alert.js create mode 100755 tbc/static/js/tests/unit/bootstrap-button.js create mode 100755 tbc/static/js/tests/unit/bootstrap-carousel.js create mode 100755 tbc/static/js/tests/unit/bootstrap-collapse.js create mode 100755 tbc/static/js/tests/unit/bootstrap-dropdown.js create mode 100755 tbc/static/js/tests/unit/bootstrap-modal.js create mode 100755 tbc/static/js/tests/unit/bootstrap-phantom.js create mode 100755 tbc/static/js/tests/unit/bootstrap-popover.js create mode 100755 tbc/static/js/tests/unit/bootstrap-scrollspy.js create mode 100755 tbc/static/js/tests/unit/bootstrap-tab.js create mode 100755 tbc/static/js/tests/unit/bootstrap-tooltip.js create mode 100755 tbc/static/js/tests/unit/bootstrap-transition.js create mode 100755 tbc/static/js/tests/unit/bootstrap-typeahead.js create mode 100755 tbc/static/js/tests/vendor/jquery.js create mode 100755 tbc/static/js/tests/vendor/qunit.css create mode 100755 tbc/static/js/tests/vendor/qunit.js (limited to 'tbc/static/js/tests') diff --git a/tbc/static/js/tests/index.html b/tbc/static/js/tests/index.html new file mode 100755 index 0000000..976ca16 --- /dev/null +++ b/tbc/static/js/tests/index.html @@ -0,0 +1,56 @@ + + + + Bootstrap Plugin Test Suite + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

Bootstrap Plugin Test Suite

+

+

+
    +
    +
    + + \ No newline at end of file diff --git a/tbc/static/js/tests/phantom.js b/tbc/static/js/tests/phantom.js new file mode 100755 index 0000000..4105bf5 --- /dev/null +++ b/tbc/static/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/tbc/static/js/tests/server.js b/tbc/static/js/tests/server.js new file mode 100755 index 0000000..7c8445f --- /dev/null +++ b/tbc/static/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/tbc/static/js/tests/unit/bootstrap-affix.js b/tbc/static/js/tests/unit/bootstrap-affix.js new file mode 100755 index 0000000..c978878 --- /dev/null +++ b/tbc/static/js/tests/unit/bootstrap-affix.js @@ -0,0 +1,25 @@ +$(function () { + + module("bootstrap-affix") + + test("should provide no conflict", function () { + var affix = $.fn.affix.noConflict() + ok(!$.fn.affix, 'affix was set back to undefined (org value)') + $.fn.affix = 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 = $('
    ').affix() + $affix.data('affix').checkPosition() + ok(!$affix.hasClass('affix'), 'affix class was not added') + }) + +}) \ No newline at end of file diff --git a/tbc/static/js/tests/unit/bootstrap-alert.js b/tbc/static/js/tests/unit/bootstrap-alert.js new file mode 100755 index 0000000..9a6b514 --- /dev/null +++ b/tbc/static/js/tests/unit/bootstrap-alert.js @@ -0,0 +1,62 @@ +$(function () { + + module("bootstrap-alerts") + + test("should provide no conflict", function () { + var alert = $.fn.alert.noConflict() + ok(!$.fn.alert, 'alert was set back to undefined (org value)') + $.fn.alert = alert + }) + + test("should be defined on jquery object", function () { + ok($(document.body).alert, 'alert method is defined') + }) + + test("should return element", function () { + ok($(document.body).alert()[0] == document.body, 'document.body returned') + }) + + test("should fade element out on clicking .close", function () { + var alertHTML = '
    ' + + '×' + + '

    Holy guacamole! Best check yo self, you\'re not looking too good.

    ' + + '
    ' + , alert = $(alertHTML).alert() + + alert.find('.close').click() + + ok(!alert.hasClass('in'), 'remove .in class on .close click') + }) + + test("should remove element when clicking .close", function () { + $.support.transition = false + + var alertHTML = '
    ' + + '×' + + '

    Holy guacamole! Best check yo self, you\'re not looking too good.

    ' + + '
    ' + , alert = $(alertHTML).appendTo('#qunit-fixture').alert() + + ok($('#qunit-fixture').find('.alert-message').length, 'element added to dom') + + alert.find('.close').click() + + 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(); + $('
    ') + .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/tbc/static/js/tests/unit/bootstrap-button.js b/tbc/static/js/tests/unit/bootstrap-button.js new file mode 100755 index 0000000..e23ff9e --- /dev/null +++ b/tbc/static/js/tests/unit/bootstrap-button.js @@ -0,0 +1,102 @@ +$(function () { + + module("bootstrap-buttons") + + test("should provide no conflict", function () { + var button = $.fn.button.noConflict() + ok(!$.fn.button, 'button was set back to undefined (org value)') + $.fn.button = button + }) + + test("should be defined on jquery object", function () { + ok($(document.body).button, 'button method is defined') + }) + + test("should return element", function () { + ok($(document.body).button()[0] == document.body, 'document.body returned') + }) + + test("should return set state to loading", function () { + var btn = $('') + equals(btn.html(), 'mdo', 'btn text equals mdo') + btn.button('loading') + equals(btn.html(), 'fat', 'btn text equals fat') + stop() + setTimeout(function () { + ok(btn.attr('disabled'), 'btn is disabled') + ok(btn.hasClass('disabled'), 'btn has disabled class') + start() + }, 0) + }) + + test("should return reset state", function () { + var btn = $('') + equals(btn.html(), 'mdo', 'btn text equals mdo') + btn.button('loading') + equals(btn.html(), 'fat', 'btn text equals fat') + stop() + setTimeout(function () { + ok(btn.attr('disabled'), 'btn is disabled') + ok(btn.hasClass('disabled'), 'btn has disabled class') + start() + stop() + }, 0) + btn.button('reset') + equals(btn.html(), 'mdo', 'btn text equals mdo') + setTimeout(function () { + ok(!btn.attr('disabled'), 'btn is not disabled') + ok(!btn.hasClass('disabled'), 'btn does not have disabled class') + start() + }, 0) + }) + + test("should toggle active", function () { + var btn = $('') + ok(!btn.hasClass('active'), 'btn does not have active class') + btn.button('toggle') + ok(btn.hasClass('active'), 'btn has class active') + }) + + test("should toggle active when btn children are clicked", function () { + var btn = $('') + , inner = $('') + btn + .append(inner) + .appendTo($('#qunit-fixture')) + ok(!btn.hasClass('active'), 'btn does not have active class') + inner.click() + ok(btn.hasClass('active'), 'btn has class active') + }) + + test("should toggle active when btn children are clicked within btn-group", function () { + var btngroup = $('
    ') + , btn = $('') + , inner = $('') + btngroup + .append(btn.append(inner)) + .appendTo($('#qunit-fixture')) + ok(!btn.hasClass('active'), 'btn does not have active class') + inner.click() + ok(btn.hasClass('active'), 'btn has class active') + }) + + test("should check for closest matching toggle", function () { + var group = $("
    ") + , btn1 = $("") + , btn2 = $("") + , wrap = $("
    ") + + wrap.append(btn1, btn2) + + group + .append(wrap) + .appendTo($('#qunit-fixture')) + + ok(btn1.hasClass('active'), 'btn1 has active class') + ok(!btn2.hasClass('active'), 'btn2 does not have active class') + btn2.click() + ok(!btn1.hasClass('active'), 'btn1 does not have active class') + ok(btn2.hasClass('active'), 'btn2 has active class') + }) + +}) \ No newline at end of file diff --git a/tbc/static/js/tests/unit/bootstrap-carousel.js b/tbc/static/js/tests/unit/bootstrap-carousel.js new file mode 100755 index 0000000..80b6e13 --- /dev/null +++ b/tbc/static/js/tests/unit/bootstrap-carousel.js @@ -0,0 +1,81 @@ +$(function () { + + module("bootstrap-carousel") + + test("should provide no conflict", function () { + var carousel = $.fn.carousel.noConflict() + ok(!$.fn.carousel, 'carousel was set back to undefined (org value)') + $.fn.carousel = 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() + $('