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 From ea2346197075a30f0200665fcd2836b217f33fb3 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Thu, 22 Dec 2011 19:28:58 -0800 Subject: fix unit test for twipsy --- js/tests/unit/bootstrap-twipsy.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/tests/unit') diff --git a/js/tests/unit/bootstrap-twipsy.js b/js/tests/unit/bootstrap-twipsy.js index 7a88ab2f1..6623fc026 100644 --- a/js/tests/unit/bootstrap-twipsy.js +++ b/js/tests/unit/bootstrap-twipsy.js @@ -30,10 +30,10 @@ $(function () { $.support.transition = false var twipsy = $('') .appendTo('#qunit-fixture') - .twipsy({placement: 'below'}) + .twipsy({placement: 'bottom'}) .twipsy('show') - ok($(".twipsy").hasClass('fade below in'), 'has correct classes applied') + ok($(".twipsy").hasClass('fade bottom in'), 'has correct classes applied') twipsy.twipsy('hide') }) -- cgit v1.2.3 From 969fbe71504f6a8159688634cce774d7ffc7ac67 Mon Sep 17 00:00:00 2001 From: Nicklas Ansman Giertz Date: Fri, 6 Jan 2012 11:32:11 +0100 Subject: Add a test case for issue #908 (twipsy doesn't respect custom classes) The test case verifies that a custom class is respected. --- js/tests/unit/bootstrap-twipsy.js | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'js/tests/unit') diff --git a/js/tests/unit/bootstrap-twipsy.js b/js/tests/unit/bootstrap-twipsy.js index 6623fc026..08512ca97 100644 --- a/js/tests/unit/bootstrap-twipsy.js +++ b/js/tests/unit/bootstrap-twipsy.js @@ -48,4 +48,15 @@ $(function () { ok(!$(".twipsy").length, 'twipsy removed') }) + test("should respect custom classes", function () { + var twipsy = $('') + .appendTo('#qunit-fixture') + .twipsy({ template: '
'}) + .twipsy('show') + + ok($('.twipsy').hasClass('some-class'), 'custom class is present') + twipsy.twipsy('hide') + ok(!$(".twipsy").length, 'twipsy removed') + }) + }) \ No newline at end of file -- cgit v1.2.3 From dd99e2d0488c503d929909e431a544e472782178 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Fri, 6 Jan 2012 18:30:32 -0800 Subject: start of autocomplete plugin --- js/tests/unit/bootstrap-typeahead.js | 122 +++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 js/tests/unit/bootstrap-typeahead.js (limited to 'js/tests/unit') diff --git a/js/tests/unit/bootstrap-typeahead.js b/js/tests/unit/bootstrap-typeahead.js new file mode 100644 index 000000000..dc46a7990 --- /dev/null +++ b/js/tests/unit/bootstrap-typeahead.js @@ -0,0 +1,122 @@ +$(function () { + + module("bootstrap-typeahead") + + test("should be defined on jquery object", function () { + ok($(document.body).typeahead, 'alert method is defined') + }) + + test("should return element", function () { + ok($(document.body).typeahead()[0] == document.body, 'document.body returned') + }) + + test("should listen to an input", function () { + var $input = $('') + $input.typeahead() + ok($input.data('events').focus, 'has a focus event') + 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') + ok($input.data('events').change, 'has a change 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') + } + }) + + test("should create a menu", function () { + var $input = $('') + ok($input.typeahead().data('typeahead').$menu, 'has a menu') + }) + + test("should listen to the menu", function () { + var $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') + }) + + test("should show menu when query entered", function () { + var $input = $('').typeahead({ + data: ['aa', 'ab', 'ac'] + }) + , typeahead = $input.data('typeahead') + + $input.val('a').change() + + 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 hide menu when query entered", function () { + var $input = $('').typeahead({ + data: ['aa', 'ab', 'ac'] + }) + , typeahead = $input.data('typeahead') + + $input.val('a').change() + + 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') + + $input.blur() + + ok(!typeahead.$menu.is(":visible"), "typeahead is no longer visible") + + typeahead.$menu.remove() + }) + + test("should set next item when down arrow is pressed", function () { + var $input = $('').typeahead({ + data: ['aa', 'ab', 'ac'] + }) + , typeahead = $input.data('typeahead') + + $input.val('a').change() + + 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') + ok(typeahead.$menu.find('li').first().hasClass('active'), "first item is active") + + $input.trigger({ + type: 'keypress' + , keyCode: 40 + }) + + ok(typeahead.$menu.find('li').first().next().hasClass('active'), "second item is active") + + + $input.trigger({ + type: 'keypress' + , keyCode: 38 + }) + + ok(typeahead.$menu.find('li').first().hasClass('active'), "first item is active") + + typeahead.$menu.remove() + }) + + + test("should set input value to selected item", function () { + var $input = $('').typeahead({ + data: ['aa', 'ab', 'ac'] + }) + , typeahead = $input.data('typeahead') + + $input.val('a').change() + + $(typeahead.$menu.find('li')[2]).trigger('click') + + equals($input.val(), 'ac', 'input value was correctly set') + ok(!typeahead.$menu.is(':visible'), 'the menu was hidden') + + typeahead.$menu.remove() + }) +}) \ No newline at end of file -- cgit v1.2.3 From 4478df768168fe41599508688046612bf5f1e526 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Sun, 8 Jan 2012 00:49:38 -0800 Subject: first pass at ultra basic autocomplete --- js/tests/unit/bootstrap-typeahead.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'js/tests/unit') diff --git a/js/tests/unit/bootstrap-typeahead.js b/js/tests/unit/bootstrap-typeahead.js index dc46a7990..10b2a3f17 100644 --- a/js/tests/unit/bootstrap-typeahead.js +++ b/js/tests/unit/bootstrap-typeahead.js @@ -13,11 +13,9 @@ $(function () { test("should listen to an input", function () { var $input = $('') $input.typeahead() - ok($input.data('events').focus, 'has a focus event') 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') - ok($input.data('events').change, 'has a change event') if ($.browser.webkit || $.browser.msie) { ok($input.data('events').keydown, 'has a keydown event') } else { @@ -44,7 +42,8 @@ $(function () { }) , typeahead = $input.data('typeahead') - $input.val('a').change() + $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') @@ -54,12 +53,14 @@ $(function () { }) test("should hide menu when query entered", function () { + stop() var $input = $('').typeahead({ data: ['aa', 'ab', 'ac'] }) , typeahead = $input.data('typeahead') - $input.val('a').change() + $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') @@ -67,7 +68,10 @@ $(function () { $input.blur() - ok(!typeahead.$menu.is(":visible"), "typeahead is no longer visible") + setTimeout(function () { + ok(!typeahead.$menu.is(":visible"), "typeahead is no longer visible") + start() + }, 200) typeahead.$menu.remove() }) @@ -78,7 +82,8 @@ $(function () { }) , typeahead = $input.data('typeahead') - $input.val('a').change() + $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') @@ -110,9 +115,10 @@ $(function () { }) , typeahead = $input.data('typeahead') - $input.val('a').change() + $input.val('a') + typeahead.lookup() - $(typeahead.$menu.find('li')[2]).trigger('click') + $(typeahead.$menu.find('li')[2]).mouseover().click() equals($input.val(), 'ac', 'input value was correctly set') ok(!typeahead.$menu.is(':visible'), 'the menu was hidden') -- cgit v1.2.3 From 6f2f947a4309a8fdeb7067612447c0f1a15dcfd9 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Wed, 11 Jan 2012 21:42:55 -0800 Subject: add build tool for js + rename twipsy to tooltip + lots of little doc cleanup --- js/tests/unit/bootstrap-twipsy.js | 48 +++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'js/tests/unit') diff --git a/js/tests/unit/bootstrap-twipsy.js b/js/tests/unit/bootstrap-twipsy.js index 08512ca97..8543162c6 100644 --- a/js/tests/unit/bootstrap-twipsy.js +++ b/js/tests/unit/bootstrap-twipsy.js @@ -1,62 +1,62 @@ $(function () { - module("bootstrap-twipsy") + module("bootstrap-tooltip") test("should be defined on jquery object", function () { var div = $("
") - ok(div.twipsy, 'popover method is defined') + ok(div.tooltip, 'popover method is defined') }) test("should return element", function () { var div = $("
") - ok(div.twipsy() == div, 'document.body returned') + ok(div.tooltip() == div, 'document.body returned') }) test("should expose default settings", function () { - ok(!!$.fn.twipsy.defaults, 'defaults is defined') + ok(!!$.fn.tooltip.defaults, 'defaults is defined') }) test("should remove title attribute", function () { - var twipsy = $('').twipsy() - ok(!twipsy.attr('title'), 'title tag was removed') + var tooltip = $('').tooltip() + ok(!tooltip.attr('title'), 'title tag was removed') }) test("should add data attribute for referencing original title", function () { - var twipsy = $('').twipsy() - equals(twipsy.attr('data-original-title'), 'Another twipsy', 'original title preserved in data attribute') + var tooltip = $('').tooltip() + equals(tooltip.attr('data-original-title'), 'Another tooltip', 'original title preserved in data attribute') }) test("should place tooltips relative to placement option", function () { $.support.transition = false - var twipsy = $('') + var tooltip = $('') .appendTo('#qunit-fixture') - .twipsy({placement: 'bottom'}) - .twipsy('show') + .tooltip({placement: 'bottom'}) + .tooltip('show') - ok($(".twipsy").hasClass('fade bottom in'), 'has correct classes applied') - twipsy.twipsy('hide') + ok($(".tooltip").hasClass('fade bottom in'), 'has correct classes applied') + tooltip.tooltip('hide') }) test("should always allow html entities", function () { $.support.transition = false - var twipsy = $('') + var tooltip = $('') .appendTo('#qunit-fixture') - .twipsy('show') + .tooltip('show') - ok($('.twipsy b').length, 'b tag was inserted') - twipsy.twipsy('hide') - ok(!$(".twipsy").length, 'twipsy removed') + ok($('.tooltip b').length, 'b tag was inserted') + tooltip.tooltip('hide') + ok(!$(".tooltip").length, 'tooltip removed') }) test("should respect custom classes", function () { - var twipsy = $('') + var tooltip = $('') .appendTo('#qunit-fixture') - .twipsy({ template: '
'}) - .twipsy('show') + .tooltip({ template: '
'}) + .tooltip('show') - ok($('.twipsy').hasClass('some-class'), 'custom class is present') - twipsy.twipsy('hide') - ok(!$(".twipsy").length, 'twipsy removed') + ok($('.tooltip').hasClass('some-class'), 'custom class is present') + tooltip.tooltip('hide') + ok(!$(".tooltip").length, 'tooltip removed') }) }) \ No newline at end of file -- cgit v1.2.3 From 05fdd43e41bae02c8d4006c075b6360599b4467c Mon Sep 17 00:00:00 2001 From: Nicklas Ansman Giertz Date: Sun, 22 Jan 2012 12:32:37 +0100 Subject: Add testcase to popover This test case verifies that custom classes are respected. --- js/tests/unit/bootstrap-popover.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'js/tests/unit') diff --git a/js/tests/unit/bootstrap-popover.js b/js/tests/unit/bootstrap-popover.js index 9180c043e..462db8b3e 100644 --- a/js/tests/unit/bootstrap-popover.js +++ b/js/tests/unit/bootstrap-popover.js @@ -70,5 +70,24 @@ $(function () { ok(!$('.popover').length, 'popover was removed') $('#qunit-fixture').empty() }) + + test("should respect custom classes", function() { + $.support.transition = false + var popover = $('@fat') + .appendTo('#qunit-fixture') + .popover({ + title: 'Test' + , content: 'Test' + , template: '

' + }) + + popover.popover('show') + console.log(popover) + ok($('.popover').length, 'popover was inserted') + ok($('.popover').hasClass('foobar'), 'custom class is present') + popover.popover('hide') + ok(!$('.popover').length, 'popover was removed') + $('#qunit-fixture').empty() + }) }) \ No newline at end of file -- cgit v1.2.3 From 4882e6da2f887c1e8baad96f777b151882adaed8 Mon Sep 17 00:00:00 2001 From: Nicklas Ansman Giertz Date: Sun, 22 Jan 2012 12:33:30 +0100 Subject: Rename the tooltip test file It had not been renamed when twipsys became tooltips. --- js/tests/unit/bootstrap-tooltip.js | 62 ++++++++++++++++++++++++++++++++++++++ js/tests/unit/bootstrap-twipsy.js | 62 -------------------------------------- 2 files changed, 62 insertions(+), 62 deletions(-) create mode 100644 js/tests/unit/bootstrap-tooltip.js delete mode 100644 js/tests/unit/bootstrap-twipsy.js (limited to 'js/tests/unit') diff --git a/js/tests/unit/bootstrap-tooltip.js b/js/tests/unit/bootstrap-tooltip.js new file mode 100644 index 000000000..8543162c6 --- /dev/null +++ b/js/tests/unit/bootstrap-tooltip.js @@ -0,0 +1,62 @@ +$(function () { + + module("bootstrap-tooltip") + + test("should be defined on jquery object", function () { + var div = $("
") + ok(div.tooltip, 'popover method is defined') + }) + + test("should return element", function () { + var div = $("
") + ok(div.tooltip() == div, 'document.body returned') + }) + + test("should expose default settings", function () { + ok(!!$.fn.tooltip.defaults, 'defaults is defined') + }) + + test("should remove title attribute", function () { + var tooltip = $('').tooltip() + ok(!tooltip.attr('title'), 'title tag was removed') + }) + + test("should add data attribute for referencing original title", function () { + var tooltip = $('').tooltip() + equals(tooltip.attr('data-original-title'), 'Another tooltip', 'original title preserved in data attribute') + }) + + test("should place tooltips relative to placement option", function () { + $.support.transition = false + var tooltip = $('') + .appendTo('#qunit-fixture') + .tooltip({placement: 'bottom'}) + .tooltip('show') + + ok($(".tooltip").hasClass('fade bottom in'), 'has correct classes applied') + tooltip.tooltip('hide') + }) + + test("should always allow html entities", function () { + $.support.transition = false + var tooltip = $('') + .appendTo('#qunit-fixture') + .tooltip('show') + + ok($('.tooltip b').length, 'b tag was inserted') + tooltip.tooltip('hide') + ok(!$(".tooltip").length, 'tooltip removed') + }) + + test("should respect custom classes", function () { + var tooltip = $('') + .appendTo('#qunit-fixture') + .tooltip({ template: '
'}) + .tooltip('show') + + ok($('.tooltip').hasClass('some-class'), 'custom class is present') + tooltip.tooltip('hide') + ok(!$(".tooltip").length, 'tooltip removed') + }) + +}) \ No newline at end of file diff --git a/js/tests/unit/bootstrap-twipsy.js b/js/tests/unit/bootstrap-twipsy.js deleted file mode 100644 index 8543162c6..000000000 --- a/js/tests/unit/bootstrap-twipsy.js +++ /dev/null @@ -1,62 +0,0 @@ -$(function () { - - module("bootstrap-tooltip") - - test("should be defined on jquery object", function () { - var div = $("
") - ok(div.tooltip, 'popover method is defined') - }) - - test("should return element", function () { - var div = $("
") - ok(div.tooltip() == div, 'document.body returned') - }) - - test("should expose default settings", function () { - ok(!!$.fn.tooltip.defaults, 'defaults is defined') - }) - - test("should remove title attribute", function () { - var tooltip = $('').tooltip() - ok(!tooltip.attr('title'), 'title tag was removed') - }) - - test("should add data attribute for referencing original title", function () { - var tooltip = $('').tooltip() - equals(tooltip.attr('data-original-title'), 'Another tooltip', 'original title preserved in data attribute') - }) - - test("should place tooltips relative to placement option", function () { - $.support.transition = false - var tooltip = $('') - .appendTo('#qunit-fixture') - .tooltip({placement: 'bottom'}) - .tooltip('show') - - ok($(".tooltip").hasClass('fade bottom in'), 'has correct classes applied') - tooltip.tooltip('hide') - }) - - test("should always allow html entities", function () { - $.support.transition = false - var tooltip = $('') - .appendTo('#qunit-fixture') - .tooltip('show') - - ok($('.tooltip b').length, 'b tag was inserted') - tooltip.tooltip('hide') - ok(!$(".tooltip").length, 'tooltip removed') - }) - - test("should respect custom classes", function () { - var tooltip = $('') - .appendTo('#qunit-fixture') - .tooltip({ template: '
'}) - .tooltip('show') - - ok($('.tooltip').hasClass('some-class'), 'custom class is present') - tooltip.tooltip('hide') - ok(!$(".tooltip").length, 'tooltip removed') - }) - -}) \ No newline at end of file -- cgit v1.2.3 From 3451dcbc2816e86fc649d30bd9d6813ef5466b58 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Sat, 28 Jan 2012 00:03:26 -0800 Subject: fix failing typeahead tests --- js/tests/unit/bootstrap-typeahead.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'js/tests/unit') diff --git a/js/tests/unit/bootstrap-typeahead.js b/js/tests/unit/bootstrap-typeahead.js index 10b2a3f17..455ed415b 100644 --- a/js/tests/unit/bootstrap-typeahead.js +++ b/js/tests/unit/bootstrap-typeahead.js @@ -38,7 +38,7 @@ $(function () { test("should show menu when query entered", function () { var $input = $('').typeahead({ - data: ['aa', 'ab', 'ac'] + source: ['aa', 'ab', 'ac'] }) , typeahead = $input.data('typeahead') @@ -55,7 +55,7 @@ $(function () { test("should hide menu when query entered", function () { stop() var $input = $('').typeahead({ - data: ['aa', 'ab', 'ac'] + source: ['aa', 'ab', 'ac'] }) , typeahead = $input.data('typeahead') @@ -78,7 +78,7 @@ $(function () { test("should set next item when down arrow is pressed", function () { var $input = $('').typeahead({ - data: ['aa', 'ab', 'ac'] + source: ['aa', 'ab', 'ac'] }) , typeahead = $input.data('typeahead') @@ -111,7 +111,7 @@ $(function () { test("should set input value to selected item", function () { var $input = $('').typeahead({ - data: ['aa', 'ab', 'ac'] + source: ['aa', 'ab', 'ac'] }) , typeahead = $input.data('typeahead') -- cgit v1.2.3 From e61164e67a048c20c512e99335e3adfcc3b63604 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Sat, 28 Jan 2012 01:35:13 -0800 Subject: all unit tests passing in ie7 --- js/tests/unit/bootstrap-popover.js | 2 +- js/tests/unit/bootstrap-tab.js | 1 - js/tests/unit/bootstrap-transition.js | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) (limited to 'js/tests/unit') diff --git a/js/tests/unit/bootstrap-popover.js b/js/tests/unit/bootstrap-popover.js index 462db8b3e..08cabae42 100644 --- a/js/tests/unit/bootstrap-popover.js +++ b/js/tests/unit/bootstrap-popover.js @@ -82,7 +82,7 @@ $(function () { }) popover.popover('show') - console.log(popover) + ok($('.popover').length, 'popover was inserted') ok($('.popover').hasClass('foobar'), 'custom class is present') diff --git a/js/tests/unit/bootstrap-tab.js b/js/tests/unit/bootstrap-tab.js index f32649078..18f490fa5 100644 --- a/js/tests/unit/bootstrap-tab.js +++ b/js/tests/unit/bootstrap-tab.js @@ -17,7 +17,6 @@ $(function () { + '
  • Profile
  • ' + '' - $('
    ').appendTo("#qunit-fixture") $(tabsHTML).find('li:last a').tab('show') diff --git a/js/tests/unit/bootstrap-transition.js b/js/tests/unit/bootstrap-transition.js index ff4a0f0c3..3f28d2676 100644 --- a/js/tests/unit/bootstrap-transition.js +++ b/js/tests/unit/bootstrap-transition.js @@ -7,7 +7,7 @@ $(function () { }) test("should provide an end object", function () { - ok($.support.transition.end, 'end string is defined') + ok($.support.transition ? $.support.transition.end : true, 'end string is defined') }) }) \ No newline at end of file -- cgit v1.2.3 From 160a0bf5608c00cc99465199d41c45177634b585 Mon Sep 17 00:00:00 2001 From: Mark Otto Date: Mon, 30 Jan 2012 01:30:18 -0800 Subject: update tests for popover to use proper classes --- js/tests/unit/bootstrap-popover.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'js/tests/unit') diff --git a/js/tests/unit/bootstrap-popover.js b/js/tests/unit/bootstrap-popover.js index 08cabae42..afd6b170b 100644 --- a/js/tests/unit/bootstrap-popover.js +++ b/js/tests/unit/bootstrap-popover.js @@ -47,8 +47,8 @@ $(function () { popover.popover('show') ok($('.popover').length, 'popover was inserted') - equals($('.popover .title').text(), '@fat', 'title correctly inserted') - equals($('.popover .content').text(), 'loves writing tests (╯°□°)╯︵ ┻━┻', 'content correctly inserted') + equals($('.popover .popover-title').text(), '@fat', 'title correctly inserted') + equals($('.popover .popover-content').text(), 'loves writing tests (╯°□°)╯︵ ┻━┻', 'content correctly inserted') popover.popover('hide') ok(!$('.popover').length, 'popover was removed') @@ -63,8 +63,8 @@ $(function () { .popover('show') ok($('.popover').length, 'popover was inserted') - equals($('.popover .title').text(), '@mdo', 'title correctly inserted') - equals($('.popover .content').text(), "loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻", 'content correctly inserted') + equals($('.popover .popover-title').text(), '@mdo', 'title correctly inserted') + equals($('.popover .popover-content').text(), "loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻", 'content correctly inserted') popover.popover('hide') ok(!$('.popover').length, 'popover was removed') -- cgit v1.2.3