From 1ef5fa7d6b4e50230c0c12919b0a06a9a2ac07f1 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Tue, 20 Dec 2011 18:02:47 -0800 Subject: giant refactor - all spec passing again... --- js/tests/unit/bootstrap-alert.js | 41 ++++++++++++++++++++++++++ js/tests/unit/bootstrap-alerts.js | 41 -------------------------- js/tests/unit/bootstrap-button.js | 54 +++++++++++++++++++++++++++++++++++ js/tests/unit/bootstrap-collapse.js | 25 ++++++++++++++++ js/tests/unit/bootstrap-dropdown.js | 21 +++++++------- js/tests/unit/bootstrap-modal.js | 28 ++++++++---------- js/tests/unit/bootstrap-popover.js | 12 ++++---- js/tests/unit/bootstrap-scrollspy.js | 6 ++-- js/tests/unit/bootstrap-tab.js | 46 +++++++++++++++++++++++++++++ js/tests/unit/bootstrap-tabs.js | 49 ------------------------------- js/tests/unit/bootstrap-transition.js | 13 +++++++++ js/tests/unit/bootstrap-twipsy.js | 36 ++--------------------- 12 files changed, 213 insertions(+), 159 deletions(-) create mode 100644 js/tests/unit/bootstrap-alert.js delete mode 100644 js/tests/unit/bootstrap-alerts.js create mode 100644 js/tests/unit/bootstrap-button.js create mode 100644 js/tests/unit/bootstrap-collapse.js create mode 100644 js/tests/unit/bootstrap-tab.js delete mode 100644 js/tests/unit/bootstrap-tabs.js create mode 100644 js/tests/unit/bootstrap-transition.js (limited to 'js/tests/unit') diff --git a/js/tests/unit/bootstrap-alert.js b/js/tests/unit/bootstrap-alert.js new file mode 100644 index 000000000..8eecaff0d --- /dev/null +++ b/js/tests/unit/bootstrap-alert.js @@ -0,0 +1,41 @@ +$(function () { + + module("bootstrap-alerts") + + 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') + }) + +}) \ No newline at end of file diff --git a/js/tests/unit/bootstrap-alerts.js b/js/tests/unit/bootstrap-alerts.js deleted file mode 100644 index 152d97ab7..000000000 --- a/js/tests/unit/bootstrap-alerts.js +++ /dev/null @@ -1,41 +0,0 @@ -$(function () { - - module("bootstrap-alerts") - - 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-runoff').alert() - - ok($('#qunit-runoff').find('.alert-message').length, 'element added to dom') - - alert.find('.close').click() - - ok(!$('#qunit-runoff').find('.alert-message').length, 'element removed from dom') - }) - -}) \ No newline at end of file diff --git a/js/tests/unit/bootstrap-button.js b/js/tests/unit/bootstrap-button.js new file mode 100644 index 000000000..59e8f33bc --- /dev/null +++ b/js/tests/unit/bootstrap-button.js @@ -0,0 +1,54 @@ +$(function () { + + module("bootstrap-buttons") + + test("should be defined on jquery object", function () { + ok($(document.body).button, 'tabs 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') + }) + +}) \ No newline at end of file diff --git a/js/tests/unit/bootstrap-collapse.js b/js/tests/unit/bootstrap-collapse.js new file mode 100644 index 000000000..698238d96 --- /dev/null +++ b/js/tests/unit/bootstrap-collapse.js @@ -0,0 +1,25 @@ +$(function () { + + module("bootstrap-collapse") + + test("should be defined on jquery object", function () { + ok($(document.body).collapse, 'collapse method is defined') + }) + + test("should return element", function () { + ok($(document.body).collapse()[0] == document.body, 'document.body returned') + }) + + test("should show a collapsed element", function () { + var el = $('
').collapse('show') + ok(el.hasClass('in'), 'has class in') + ok(/height/.test(el.attr('style')), 'has height set') + }) + + test("should hide a collapsed element", function () { + var el = $('
').collapse('hide') + ok(!el.hasClass('in'), 'does not have class in') + ok(/height/.test(el.attr('style')), 'has height set') + }) + +}) \ No newline at end of file diff --git a/js/tests/unit/bootstrap-dropdown.js b/js/tests/unit/bootstrap-dropdown.js index 2c2acb9bb..368ced2a5 100644 --- a/js/tests/unit/bootstrap-dropdown.js +++ b/js/tests/unit/bootstrap-dropdown.js @@ -13,7 +13,7 @@ $(function () { test("should add class open to menu if clicked", function () { var dropdownHTML = '' - , dropdown = $(dropdownHTML).dropdown() + , dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').dropdown().click() - dropdown.find('.dropdown-toggle').click() - ok(dropdown.find('.dropdown').hasClass('open'), 'open class added on click') + ok(dropdown.parent('.dropdown').hasClass('open'), 'open class added on click') }) test("should remove open class if body clicked", function () { var dropdownHTML = '' - , dropdown = $(dropdownHTML).dropdown().appendTo('#qunit-runoff') - - dropdown.find('.dropdown-toggle').click() - ok(dropdown.find('.dropdown').hasClass('open'), 'open class added on click') + , dropdown = $(dropdownHTML) + .appendTo('#qunit-fixture') + .find('[data-toggle="dropdown"]') + .dropdown() + .click() + ok(dropdown.parent('.dropdown').hasClass('open'), 'open class added on click') $('body').click() - ok(!dropdown.find('.dropdown').hasClass('open'), 'open class removed') + ok(!dropdown.parent('.dropdown').hasClass('open'), 'open class removed') dropdown.remove() }) diff --git a/js/tests/unit/bootstrap-modal.js b/js/tests/unit/bootstrap-modal.js index 4bbb3313c..22f5781ea 100644 --- a/js/tests/unit/bootstrap-modal.js +++ b/js/tests/unit/bootstrap-modal.js @@ -10,6 +10,7 @@ $(function () { test("should return element", function () { var div = $("") ok(div.modal() == div, 'document.body returned') + $('#modal-test').remove() }) test("should expose defaults var for settings", function () { @@ -19,32 +20,29 @@ $(function () { test("should insert into dom when show method is called", function () { stop() $.support.transition = false - var div = $("") - div - .modal() - .modal("show") + $("") .bind("shown", function () { ok($('#modal-test').length, 'modal insterted into dom') + $(this).remove() start() - div.remove() }) + .modal("show") }) test("should hide modal when hide is called", function () { stop() $.support.transition = false - var div = $("") - div - .modal() + + $("") .bind("shown", function () { ok($('#modal-test').is(":visible"), 'modal visible') ok($('#modal-test').length, 'modal insterted into dom') - div.modal("hide") + $(this).modal("hide") }) .bind("hidden", function() { ok(!$('#modal-test').is(":visible"), 'modal hidden') + $('#modal-test').remove() start() - div.remove() }) .modal("show") }) @@ -54,7 +52,6 @@ $(function () { $.support.transition = false var div = $("") div - .modal() .bind("shown", function () { ok($('#modal-test').is(":visible"), 'modal visible') ok($('#modal-test').length, 'modal insterted into dom') @@ -62,18 +59,17 @@ $(function () { }) .bind("hidden", function() { ok(!$('#modal-test').is(":visible"), 'modal hidden') - start() div.remove() + start() }) .modal("toggle") }) - test("should remove from dom when click .close", function () { + test("should remove from dom when click [data-dismiss=modal]", function () { stop() $.support.transition = false - var div = $("") + var div = $("") div - .modal() .bind("shown", function () { ok($('#modal-test').is(":visible"), 'modal visible') ok($('#modal-test').length, 'modal insterted into dom') @@ -81,8 +77,8 @@ $(function () { }) .bind("hidden", function() { ok(!$('#modal-test').is(":visible"), 'modal hidden') - start() div.remove() + start() }) .modal("toggle") }) diff --git a/js/tests/unit/bootstrap-popover.js b/js/tests/unit/bootstrap-popover.js index 3e13d2fd2..9180c043e 100644 --- a/js/tests/unit/bootstrap-popover.js +++ b/js/tests/unit/bootstrap-popover.js @@ -15,14 +15,12 @@ $(function () { test("should render popover element", function () { $.support.transition = false var popover = $('@mdo') - .appendTo('#qunit-runoff') - .popover() + .appendTo('#qunit-fixture') .popover('show') ok($('.popover').length, 'popover was inserted') popover.popover('hide') ok(!$(".popover").length, 'popover removed') - $('#qunit-runoff').empty() }) test("should store popover instance in popover data object", function () { @@ -36,7 +34,7 @@ $(function () { test("should get title and content from options", function () { $.support.transition = false var popover = $('@fat') - .appendTo('#qunit-runoff') + .appendTo('#qunit-fixture') .popover({ title: function () { return '@fat' @@ -54,13 +52,13 @@ $(function () { popover.popover('hide') ok(!$('.popover').length, 'popover was removed') - $('#qunit-runoff').empty() + $('#qunit-fixture').empty() }) test("should get title and content from attributes", function () { $.support.transition = false var popover = $('@mdo') - .appendTo('#qunit-runoff') + .appendTo('#qunit-fixture') .popover() .popover('show') @@ -70,7 +68,7 @@ $(function () { popover.popover('hide') ok(!$('.popover').length, 'popover was removed') - $('#qunit-runoff').empty() + $('#qunit-fixture').empty() }) }) \ No newline at end of file diff --git a/js/tests/unit/bootstrap-scrollspy.js b/js/tests/unit/bootstrap-scrollspy.js index b9b309062..bee46a925 100644 --- a/js/tests/unit/bootstrap-scrollspy.js +++ b/js/tests/unit/bootstrap-scrollspy.js @@ -12,7 +12,7 @@ $(function () { test("should switch active class on scroll", function () { var sectionHTML = '
' - , $section = $(sectionHTML).append('#qunit-runoff') + , $section = $(sectionHTML).append('#qunit-fixture') , topbarHTML ='
' + '
' + '
' @@ -23,9 +23,9 @@ $(function () { + '
' + '
' + '
' - , $topbar = $(topbarHTML).topbar() + , $topbar = $(topbarHTML).scrollspy() - ok(topbar.find('.active', true) + ok($topbar.find('.active', true)) }) }) \ No newline at end of file diff --git a/js/tests/unit/bootstrap-tab.js b/js/tests/unit/bootstrap-tab.js new file mode 100644 index 000000000..f32649078 --- /dev/null +++ b/js/tests/unit/bootstrap-tab.js @@ -0,0 +1,46 @@ +$(function () { + + module("bootstrap-tabs") + + test("should be defined on jquery object", function () { + ok($(document.body).tab, 'tabs method is defined') + }) + + test("should return element", function () { + ok($(document.body).tab()[0] == document.body, 'document.body returned') + }) + + test("should activate element by tab id", function () { + var tabsHTML = + '' + + + $('').appendTo("#qunit-fixture") + + $(tabsHTML).find('li:last a').tab('show') + equals($("#qunit-fixture").find('.active').attr('id'), "profile") + + $(tabsHTML).find('li:first a').tab('show') + equals($("#qunit-fixture").find('.active').attr('id'), "home") + }) + + test("should activate element by tab id", function () { + var pillsHTML = + '' + + $('').appendTo("#qunit-fixture") + + $(pillsHTML).find('li:last a').tab('show') + equals($("#qunit-fixture").find('.active').attr('id'), "profile") + + $(pillsHTML).find('li:first a').tab('show') + equals($("#qunit-fixture").find('.active').attr('id'), "home") + }) + +}) \ No newline at end of file diff --git a/js/tests/unit/bootstrap-tabs.js b/js/tests/unit/bootstrap-tabs.js deleted file mode 100644 index 2ee6761ed..000000000 --- a/js/tests/unit/bootstrap-tabs.js +++ /dev/null @@ -1,49 +0,0 @@ -$(function () { - - module("bootstrap-tabs") - - test("should be defined on jquery object", function () { - ok($(document.body).tabs, 'tabs method is defined') - }) - - test("should return element", function () { - ok($(document.body).tabs()[0] == document.body, 'document.body returned') - }) - - test("should activate element by tab id", function () { - var tabsHTML = '' - - - $('').appendTo("#qunit-runoff") - - $(tabsHTML).tabs().find('a').last().click() - equals($("#qunit-runoff").find('.active').attr('id'), "profile") - - $(tabsHTML).tabs().find('a').first().click() - equals($("#qunit-runoff").find('.active').attr('id'), "home") - - $("#qunit-runoff").empty() - }) - - test("should activate element by pill id", function () { - var pillsHTML = '' - - - $('').appendTo("#qunit-runoff") - - $(pillsHTML).pills().find('a').last().click() - equals($("#qunit-runoff").find('.active').attr('id'), "profile") - - $(pillsHTML).pills().find('a').first().click() - equals($("#qunit-runoff").find('.active').attr('id'), "home") - - $("#qunit-runoff").empty() - }) - -}) \ No newline at end of file diff --git a/js/tests/unit/bootstrap-transition.js b/js/tests/unit/bootstrap-transition.js new file mode 100644 index 000000000..ff4a0f0c3 --- /dev/null +++ b/js/tests/unit/bootstrap-transition.js @@ -0,0 +1,13 @@ +$(function () { + + module("bootstrap-transition") + + test("should be defined on jquery support object", function () { + ok($.support.transition != undefined, 'transition object is defined') + }) + + test("should provide an end object", function () { + ok($.support.transition.end, 'end string is defined') + }) + +}) \ No newline at end of file diff --git a/js/tests/unit/bootstrap-twipsy.js b/js/tests/unit/bootstrap-twipsy.js index 04000696a..7a88ab2f1 100644 --- a/js/tests/unit/bootstrap-twipsy.js +++ b/js/tests/unit/bootstrap-twipsy.js @@ -29,53 +29,23 @@ $(function () { test("should place tooltips relative to placement option", function () { $.support.transition = false var twipsy = $('') - .appendTo('#qunit-runoff') + .appendTo('#qunit-fixture') .twipsy({placement: 'below'}) .twipsy('show') ok($(".twipsy").hasClass('fade below in'), 'has correct classes applied') twipsy.twipsy('hide') - ok(!$(".twipsy").length, 'twipsy removed') - $('#qunit-runoff').empty() - }) - - test("should add a fallback in cases where elements have no title tag", function () { - $.support.transition = false - var twipsy = $('') - .appendTo('#qunit-runoff') - .twipsy({fallback: '@fat'}) - .twipsy('show') - - equals($(".twipsy").text(), "@fat", 'has correct default text') - twipsy.twipsy('hide') - ok(!$(".twipsy").length, 'twipsy removed') - $('#qunit-runoff').empty() - }) - - test("should not allow html entities", function () { - $.support.transition = false - var twipsy = $('') - .appendTo('#qunit-runoff') - .twipsy() - .twipsy('show') - - ok(!$('.twipsy b').length, 'b tag was not inserted') - twipsy.twipsy('hide') - ok(!$(".twipsy").length, 'twipsy removed') - $('#qunit-runoff').empty() }) - test("should allow html entities if html option set to true", function () { + test("should always allow html entities", function () { $.support.transition = false var twipsy = $('') - .appendTo('#qunit-runoff') - .twipsy({html: true}) + .appendTo('#qunit-fixture') .twipsy('show') ok($('.twipsy b').length, 'b tag was inserted') twipsy.twipsy('hide') ok(!$(".twipsy").length, 'twipsy removed') - $('#qunit-runoff').empty() }) }) \ No newline at end of file -- cgit v1.2.3