From 8534e12523c7156b53e76393cc8d016ffdcf5b4f Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Mon, 20 Jan 2014 11:54:22 -0800 Subject: Add tooltip `viewport` option, respect bounds of the viewport --- js/tests/unit/tooltip.js | 81 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 79 insertions(+), 2 deletions(-) (limited to 'js/tests/unit') diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index 9df234236..e670883e3 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -337,12 +337,12 @@ $(function () { }) test('should add position class before positioning so that position-specific styles are taken into account', function () { - $('head').append('') + $('head').append('') var container = $('
').appendTo('body'), target = $('') .appendTo(container) - .tooltip({placement: 'right'}) + .tooltip({placement: 'right', viewport: null}) .tooltip('show'), tooltip = container.find('.tooltip') @@ -352,6 +352,7 @@ $(function () { var topDiff = top - top2 ok(topDiff <= 1 && topDiff >= -1) target.tooltip('hide') + $('head #test').remove() }) test('tooltip title test #1', function () { @@ -428,4 +429,80 @@ $(function () { ttContainer.remove() }) + test('should adjust the tip\'s top when up against the top of the viewport', function () { + $('head').append('') + + var container = $('
').appendTo('body'), + target = $('') + .appendTo(container) + .tooltip({placement: 'right', viewport: {selector: 'body', padding: 12}}) + .tooltip('show'), + tooltip = container.find('.tooltip') + + ok( Math.round(tooltip.offset().top) === 12 ) + target.tooltip('hide') + $('head #test').remove() + }) + + test('should adjust the tip\'s top when up against the bottom of the viewport', function () { + $('head').append('') + + var container = $('
').appendTo('body'), + target = $('') + .appendTo(container) + .tooltip({placement: 'right', viewport: {selector: 'body', padding: 12}}) + .tooltip('show'), + tooltip = container.find('.tooltip') + + ok( Math.round(tooltip.offset().top) === Math.round($(window).height() - 12 - tooltip[0].offsetHeight) ) + target.tooltip('hide') + $('head #test').remove() + }) + + test('should adjust the tip\'s left when up against the left of the viewport', function () { + $('head').append('') + + var container = $('
').appendTo('body'), + target = $('') + .appendTo(container) + .tooltip({placement: 'bottom', viewport: {selector: 'body', padding: 12}}) + .tooltip('show'), + tooltip = container.find('.tooltip') + + ok( Math.round(tooltip.offset().left) === 12 ) + target.tooltip('hide') + $('head #test').remove() + }) + + test('should adjust the tip\'s left when up against the right of the viewport', function () { + $('head').append('') + + var container = $('
').appendTo('body'), + target = $('') + .appendTo(container) + .tooltip({placement: 'bottom', viewport: {selector: 'body', padding: 12}}) + .tooltip('show'), + tooltip = container.find('.tooltip') + + ok( Math.round(tooltip.offset().left) === Math.round($(window).width() - 12 - tooltip[0].offsetWidth) ) + target.tooltip('hide') + $('head #test').remove() + }) + + test('should adjust the tip when up against the right of an arbitrary viewport', function () { + $('head').append('') + $('head').append('') + + var container = $('
', {class: 'container-viewport'}).appendTo('body'), + target = $('') + .appendTo(container) + .tooltip({placement: 'bottom', viewport: '.container-viewport'}) + .tooltip('show'), + tooltip = container.find('.tooltip') + + ok( Math.round(tooltip.offset().left) === Math.round(60 + container.width() - tooltip[0].offsetWidth) ) + target.tooltip('hide') + $('head #test').remove() + $('head #viewport-style').remove() + }) }) -- cgit v1.2.3 From 674b41dd632d4911d291a593a23a5563a1a67811 Mon Sep 17 00:00:00 2001 From: Stefan Neculai Date: Mon, 24 Mar 2014 19:49:06 +0200 Subject: Add test for popover. --- js/tests/unit/popover.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'js/tests/unit') diff --git a/js/tests/unit/popover.js b/js/tests/unit/popover.js index c08b6d8ef..24f2f6f03 100644 --- a/js/tests/unit/popover.js +++ b/js/tests/unit/popover.js @@ -61,6 +61,35 @@ $(function () { $('#qunit-fixture').empty() }) + test('should not duplicate HTML object', function () { + $.support.transition = false + + $div = $('
').html('loves writing tests (╯°□°)╯︵ ┻━┻') + + var popover = $('@fat') + .appendTo('#qunit-fixture') + .popover({ + content: function () { + return $div + } + }) + + popover.popover('show') + ok($('.popover').length, 'popover was inserted') + equal($('.popover .popover-content').html(), $div, 'content correctly inserted') + + popover.popover('hide') + ok(!$('.popover').length, 'popover was removed') + + popover.popover('show') + ok($('.popover').length, 'popover was inserted') + equal($('.popover .popover-content').html(), $div, 'content correctly inserted') + + popover.popover('hide') + ok(!$('.popover').length, 'popover was removed') + $('#qunit-fixture').empty() + }) + test('should get title and content from attributes', function () { $.support.transition = false var popover = $('@mdo') -- cgit v1.2.3 From 4a2d337bf5f329eac1ca16208414ec1ebfe0546e Mon Sep 17 00:00:00 2001 From: fat Date: Mon, 24 Mar 2014 19:15:58 -0700 Subject: fixes #9461 - Make carousel ignore non-items in carousel-inner --- js/tests/unit/carousel.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'js/tests/unit') diff --git a/js/tests/unit/carousel.js b/js/tests/unit/carousel.js index 6f69855c7..562e30255 100644 --- a/js/tests/unit/carousel.js +++ b/js/tests/unit/carousel.js @@ -107,4 +107,32 @@ $(function () { ok($('#myCarousel').data('bs.carousel').options.interval === false, 'data attribute has higher priority than default options') $('#myCarousel').remove() }) + + test('should skip over non-items', function () { + $.support.transition = false + + var $template = $( + '' + ) + + $template.carousel() + + equal($template.find('.item')[0], $template.find('.active')[0], 'the first carousel item should be active') + + $template.carousel(1) + + equal($template.find('.item')[1], $template.find('.active')[0], 'the second carousel item should be active') + }) }) -- cgit v1.2.3 From 5ef634dab9bb39b9dc5beb10a568a05952a519ff Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Thu, 3 Apr 2014 18:13:16 -0700 Subject: replace $.bind() with $.on() in unit tests; per #13272 --- js/tests/unit/dropdown.js | 8 ++++---- js/tests/unit/modal.js | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'js/tests/unit') diff --git a/js/tests/unit/dropdown.js b/js/tests/unit/dropdown.js index 8597426cd..2d2e7c51d 100644 --- a/js/tests/unit/dropdown.js +++ b/js/tests/unit/dropdown.js @@ -169,10 +169,10 @@ $(function () { dropdown .parent('.dropdown') - .bind('show.bs.dropdown', function () { + .on('show.bs.dropdown', function () { ok(true, 'show was called') }) - .bind('hide.bs.dropdown', function () { + .on('hide.bs.dropdown', function () { ok(true, 'hide was called') start() }) @@ -203,10 +203,10 @@ $(function () { dropdown .parent('.dropdown') - .bind('shown.bs.dropdown', function () { + .on('shown.bs.dropdown', function () { ok(true, 'show was called') }) - .bind('hidden.bs.dropdown', function () { + .on('hidden.bs.dropdown', function () { ok(true, 'hide was called') start() }) diff --git a/js/tests/unit/modal.js b/js/tests/unit/modal.js index b026d18c4..34912c2e9 100644 --- a/js/tests/unit/modal.js +++ b/js/tests/unit/modal.js @@ -140,13 +140,13 @@ $(function () { $.support.transition = false var div = $('') div - .bind('shown.bs.modal', function () { + .on('shown.bs.modal', function () { ok($('#modal-test').length, 'modal insterted into dom') $('.contents').click() ok($('#modal-test').is(':visible'), 'modal visible') $('#modal-test').click() }) - .bind('hidden.bs.modal', function () { + .on('hidden.bs.modal', function () { ok(!$('#modal-test').is(':visible'), 'modal hidden') div.remove() start() @@ -162,11 +162,11 @@ $(function () { var div = $('') div - .bind('shown.bs.modal', function () { + .on('shown.bs.modal', function () { triggered = 0 $('#modal-test').click() }) - .bind('hide.bs.modal', function () { + .on('hide.bs.modal', function () { triggered += 1 ok(triggered === 1, 'modal hide triggered once') start() @@ -179,7 +179,7 @@ $(function () { $.support.transition = false var div = $('') div - .bind('shown.bs.modal', function () { + .on('shown.bs.modal', function () { $('#close').click() ok(!$('#modal-test').is(':visible'), 'modal hidden') }) -- cgit v1.2.3 From 45b476bdbff7ac38518deb7898529bb9510f648f Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Sat, 1 Mar 2014 18:19:50 +0200 Subject: JS: remove unused variables. --- js/tests/unit/affix.js | 6 +++--- js/tests/unit/button.js | 1 - js/tests/unit/collapse.js | 16 ++++++++-------- js/tests/unit/scrollspy.js | 2 +- js/tests/unit/tooltip.js | 20 ++++++++++---------- 5 files changed, 22 insertions(+), 23 deletions(-) (limited to 'js/tests/unit') diff --git a/js/tests/unit/affix.js b/js/tests/unit/affix.js index b348ecf2b..673026b8c 100644 --- a/js/tests/unit/affix.js +++ b/js/tests/unit/affix.js @@ -28,14 +28,14 @@ $(function () { var template = $('
  • Please affix
  • And unaffix
') template.appendTo('body') - var affixer = $('#affixTarget').affix({ + $('#affixTarget').affix({ offset: $('#affixTarget ul').position() }) $('#affixTarget') - .on('affix.bs.affix', function (e) { + .on('affix.bs.affix', function () { ok(true, 'affix event triggered') - }).on('affixed.bs.affix', function (e) { + }).on('affixed.bs.affix', function () { ok(true,'affixed event triggered') $('#affixTarget').remove() $('#affixAfter').remove() diff --git a/js/tests/unit/button.js b/js/tests/unit/button.js index 73420863c..ea1236478 100644 --- a/js/tests/unit/button.js +++ b/js/tests/unit/button.js @@ -98,7 +98,6 @@ $(function () { var btn1 = $(group.children()[0]) var btn2 = $(group.children()[1]) - var btn3 = $(group.children()[2]) group.appendTo($('#qunit-fixture')) diff --git a/js/tests/unit/collapse.js b/js/tests/unit/collapse.js index 7948b3ab4..bead36f91 100644 --- a/js/tests/unit/collapse.js +++ b/js/tests/unit/collapse.js @@ -64,7 +64,7 @@ $(function () { var target = $('') .appendTo($('#qunit-fixture')) - var collapsible = $('
') + $('
') .appendTo($('#qunit-fixture')) .on('show.bs.collapse', function () { ok(!target.hasClass('collapsed')) @@ -81,7 +81,7 @@ $(function () { var target = $('') .appendTo($('#qunit-fixture')) - var collapsible = $('
') + $('
') .appendTo($('#qunit-fixture')) .on('hide.bs.collapse', function () { ok(target.hasClass('collapsed')) @@ -101,19 +101,19 @@ $(function () { var target1 = $('') .appendTo(accordion.find('.accordion-group').eq(0)) - var collapsible1 = $('
') + $('
') .appendTo(accordion.find('.accordion-group').eq(0)) var target2 = $('') .appendTo(accordion.find('.accordion-group').eq(1)) - var collapsible2 = $('
') + $('
') .appendTo(accordion.find('.accordion-group').eq(1)) var target3 = $('') .appendTo(accordion.find('.accordion-group').eq(2)) - var collapsible3 = $('
') + $('
') .appendTo(accordion.find('.accordion-group').eq(2)) .on('show.bs.collapse', function () { ok(target1.hasClass('collapsed')) @@ -136,19 +136,19 @@ $(function () { var target1 = $('') .appendTo(accordion.find('.accordion-group').eq(0)) - var collapsible1 = $('
') + $('
') .appendTo(accordion.find('.accordion-group').eq(0)) var target2 = $('') .appendTo(accordion.find('.accordion-group').eq(1)) - var collapsible2 = $('
') + $('
') .appendTo(accordion.find('.accordion-group').eq(1)) var target3 = $('') .appendTo(accordion.find('.accordion-group').eq(2)) - var collapsible3 = $('
') + $('
') .appendTo(accordion.find('.accordion-group').eq(2)) .on('show.bs.collapse', function () { ok(target1.hasClass('collapsed')) diff --git a/js/tests/unit/scrollspy.js b/js/tests/unit/scrollspy.js index d91b6b313..670735a46 100644 --- a/js/tests/unit/scrollspy.js +++ b/js/tests/unit/scrollspy.js @@ -18,7 +18,6 @@ $(function () { test('should switch active class on scroll', function () { var sectionHTML = '
', - $section = $(sectionHTML).append('#qunit-fixture'), topbarHTML = '
' + '
' + '
' + @@ -30,6 +29,7 @@ $(function () { '
', $topbar = $(topbarHTML).scrollspy() + $(sectionHTML).append('#qunit-fixture') ok($topbar.find('.active', true)) }) diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index e670883e3..e6ae11993 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -68,7 +68,7 @@ $(function () { test('should fire show event', function () { stop() - var tooltip = $('
') + $('
') .on('show.bs.tooltip', function () { ok(true, 'show was called') start() @@ -78,7 +78,7 @@ $(function () { test('should fire shown event', function () { stop() - var tooltip = $('
') + $('
') .on('shown.bs.tooltip', function () { ok(true, 'shown was called') start() @@ -88,7 +88,7 @@ $(function () { test('should not fire shown event when default prevented', function () { stop() - var tooltip = $('
') + $('
') .on('show.bs.tooltip', function (e) { e.preventDefault() ok(true, 'show was called') @@ -102,7 +102,7 @@ $(function () { test('should fire hide event', function () { stop() - var tooltip = $('
') + $('
') .on('shown.bs.tooltip', function () { $(this).tooltip('hide') }) @@ -115,7 +115,7 @@ $(function () { test('should fire hidden event', function () { stop() - var tooltip = $('
') + $('
') .on('shown.bs.tooltip', function () { $(this).tooltip('hide') }) @@ -128,7 +128,7 @@ $(function () { test('should not fire hidden event when default prevented', function () { stop() - var tooltip = $('
') + $('
') .on('shown.bs.tooltip', function () { $(this).tooltip('hide') }) @@ -272,14 +272,14 @@ $(function () { test('should show tooltip with delegate selector on click', function () { var div = $('
') - var tooltip = div.appendTo('#qunit-fixture') + 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') }) test('should show tooltip when toggle is called', function () { - var tooltip = $('') + $('') .appendTo('#qunit-fixture') .tooltip({trigger: 'manual'}) .tooltip('toggle') @@ -298,8 +298,8 @@ $(function () { test('should place tooltip inside window', function () { var container = $('
').appendTo('body') - .css({position: 'absolute', width: 200, height: 200, bottom: 0, left: 0}), - tooltip = $('Hover me') + .css({position: 'absolute', width: 200, height: 200, bottom: 0, left: 0}) + $('Hover me') .css({position: 'absolute', top: 0, left: 0}) .appendTo(container) .tooltip({placement: 'top', animate: false}) -- cgit v1.2.3 From cd4696f7231cbf6f0478a3bfc1b5c4551e3a290e Mon Sep 17 00:00:00 2001 From: fat Date: Tue, 15 Apr 2014 20:28:08 -0700 Subject: fixes #11099 - $.collapse() overrides the original dimension of the coll... --- js/tests/unit/collapse.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/tests/unit') diff --git a/js/tests/unit/collapse.js b/js/tests/unit/collapse.js index bead36f91..66b2dc1a7 100644 --- a/js/tests/unit/collapse.js +++ b/js/tests/unit/collapse.js @@ -19,7 +19,7 @@ $(function () { 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') + ok(!/height/.test(el.attr('style')), 'has height reset') }) test('should hide a collapsed element', function () { @@ -51,7 +51,7 @@ $(function () { ok(this.style.height == '0px') }) .on('shown.bs.collapse', function () { - ok(this.style.height == 'auto') + ok(this.style.height === '') start() }) .collapse('show') -- cgit v1.2.3 From 0aaf2cdd3a715b08bd41197b361ecd2af99cba0b Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Sat, 19 Apr 2014 17:45:56 -0700 Subject: quote attribute values in selectors in JS unit tests for consistency --- js/tests/unit/modal.js | 4 ++-- js/tests/unit/tooltip.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'js/tests/unit') diff --git a/js/tests/unit/modal.js b/js/tests/unit/modal.js index 34912c2e9..33952eba5 100644 --- a/js/tests/unit/modal.js +++ b/js/tests/unit/modal.js @@ -100,7 +100,7 @@ $(function () { .modal('toggle') }) - test('should remove from dom when click [data-dismiss=modal]', function () { + test('should remove from dom when click [data-dismiss="modal"]', function () { stop() $.support.transition = false var div = $('') @@ -174,7 +174,7 @@ $(function () { .modal('show') }) - test('should close reopened modal with [data-dismiss=modal] click', function () { + test('should close reopened modal with [data-dismiss="modal"] click', function () { stop() $.support.transition = false var div = $('') diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index e6ae11993..9a5f36f7b 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -273,7 +273,7 @@ $(function () { test('should show tooltip with delegate selector on click', function () { var div = $('
') div.appendTo('#qunit-fixture') - .tooltip({ selector: 'a[rel=tooltip]', trigger: 'click' }) + .tooltip({ selector: 'a[rel="tooltip"]', trigger: 'click' }) div.find('a').trigger('click') ok($('.tooltip').is('.fade.in'), 'tooltip is faded in') }) -- cgit v1.2.3 From 9c4afc577253ada54d3ff27965e380a5c9f4e60e Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Mon, 21 Apr 2014 13:08:16 -0700 Subject: spelling fixes in Carousel unit tests --- js/tests/unit/carousel.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'js/tests/unit') diff --git a/js/tests/unit/carousel.js b/js/tests/unit/carousel.js index 562e30255..065354451 100644 --- a/js/tests/unit/carousel.js +++ b/js/tests/unit/carousel.js @@ -4,11 +4,11 @@ $(function () { test('should provide no conflict', function () { var carousel = $.fn.carousel.noConflict() - ok(!$.fn.carousel, 'carousel was set back to undefined (org value)') + ok(!$.fn.carousel, 'carousel was set back to undefined (orig value)') $.fn.carousel = carousel }) - test('should be defined on jquery object', function () { + test('should be defined on jQuery object', function () { ok($(document.body).carousel, 'carousel method is defined') }) @@ -98,7 +98,7 @@ $(function () { $('[data-slide]').first().click() $('#myCarousel').attr('data-interval', 1860) $('[data-slide]').first().click() - ok($('#myCarousel').data('bs.carousel').options.interval == 1814, 'attributes should be read only on intitialization') + ok($('#myCarousel').data('bs.carousel').options.interval == 1814, 'attributes should be read only on initialization') $('#myCarousel').remove() template.attr('data-interval', false) -- cgit v1.2.3 From f66a747615c5216b8cd81c699149f993e8f28608 Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Mon, 21 Apr 2014 13:14:53 -0700 Subject: add unit tests for Carousel slid events --- js/tests/unit/carousel.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'js/tests/unit') diff --git a/js/tests/unit/carousel.js b/js/tests/unit/carousel.js index 065354451..a4008bb0c 100644 --- a/js/tests/unit/carousel.js +++ b/js/tests/unit/carousel.js @@ -66,6 +66,18 @@ $(function () { }).carousel('next') }) + test('should fire slid event with direction', function () { + var template = '' + $.support.transition = false + stop() + $(template).on('slid.bs.carousel', function (e) { + e.preventDefault() + ok(e.direction) + ok(e.direction === 'right' || e.direction === 'left') + start() + }).carousel('next') + }) + test('should fire slide event with relatedTarget', function () { var template = '' $.support.transition = false @@ -80,6 +92,20 @@ $(function () { .carousel('next') }) + test('should fire slid event with relatedTarget', function () { + var template = '' + $.support.transition = false + stop() + $(template) + .on('slid.bs.carousel', function (e) { + e.preventDefault() + ok(e.relatedTarget) + ok($(e.relatedTarget).hasClass('item')) + start() + }) + .carousel('next') + }) + test('should set interval from data attribute', 4, function () { var template = $('') template.attr('data-interval', 1814) -- cgit v1.2.3 From a9f2b6ce0fb2ac059e30da259f7ae25282803c09 Mon Sep 17 00:00:00 2001 From: Collin Donahue-Oponski Date: Mon, 21 Apr 2014 23:03:33 -0600 Subject: #11464 - Fix JS noConflict mode - Refactor all plugins to use an internal reference to the jQuery plugin, because in noConflict mode you can never expect to be defined on the jQuery object --- js/tests/unit/affix.js | 29 +++++--- js/tests/unit/alert.js | 31 +++++--- js/tests/unit/button.js | 33 ++++++--- js/tests/unit/carousel.js | 41 +++++++---- js/tests/unit/collapse.js | 33 ++++++--- js/tests/unit/dropdown.js | 39 ++++++---- js/tests/unit/modal.js | 55 ++++++++------ js/tests/unit/popover.js | 71 ++++++++++-------- js/tests/unit/scrollspy.js | 29 +++++--- js/tests/unit/tab.js | 39 ++++++---- js/tests/unit/tooltip.js | 177 ++++++++++++++++++++++++--------------------- 11 files changed, 338 insertions(+), 239 deletions(-) (limited to 'js/tests/unit') diff --git a/js/tests/unit/affix.js b/js/tests/unit/affix.js index 673026b8c..404c6605b 100644 --- a/js/tests/unit/affix.js +++ b/js/tests/unit/affix.js @@ -1,23 +1,32 @@ $(function () { - module('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 - }) + module('affix plugin') test('should be defined on jquery object', function () { ok($(document.body).affix, 'affix method is defined') }) + module('affix', { + setup: function() { + // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode + $.fn.bootstrapAffix = $.fn.affix.noConflict() + }, + teardown: function() { + $.fn.affix = $.fn.bootstrapAffix + delete $.fn.bootstrapAffix + } + }) + + test('should provide no conflict', function () { + ok(!$.fn.affix, 'affix was set back to undefined (org value)') + }) + test('should return element', function () { - ok($(document.body).affix()[0] == document.body, 'document.body returned') + ok($(document.body).bootstrapAffix()[0] == document.body, 'document.body returned') }) test('should exit early if element is not visible', function () { - var $affix = $('
').affix() + var $affix = $('
').bootstrapAffix() $affix.data('bs.affix').checkPosition() ok(!$affix.hasClass('affix'), 'affix class was not added') }) @@ -28,7 +37,7 @@ $(function () { var template = $('
  • Please affix
  • And unaffix
') template.appendTo('body') - $('#affixTarget').affix({ + $('#affixTarget').bootstrapAffix({ offset: $('#affixTarget ul').position() }) diff --git a/js/tests/unit/alert.js b/js/tests/unit/alert.js index 1de46e06f..f5d6075f5 100644 --- a/js/tests/unit/alert.js +++ b/js/tests/unit/alert.js @@ -1,19 +1,28 @@ $(function () { - module('alert') - - 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 - }) + module('alert plugin') test('should be defined on jquery object', function () { ok($(document.body).alert, 'alert method is defined') }) + module('alert', { + setup: function() { + // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode + $.fn.bootstrapAlert = $.fn.alert.noConflict() + }, + teardown: function() { + $.fn.alert = $.fn.bootstrapAlert + delete $.fn.bootstrapAlert + } + }) + + test('should provide no conflict', function () { + ok(!$.fn.alert, 'alert was set back to undefined (org value)') + }) + test('should return element', function () { - ok($(document.body).alert()[0] == document.body, 'document.body returned') + ok($(document.body).bootstrapAlert()[0] == document.body, 'document.body returned') }) test('should fade element out on clicking .close', function () { @@ -21,7 +30,7 @@ $(function () { '×' + '

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

' + '
', - alert = $(alertHTML).alert() + alert = $(alertHTML).bootstrapAlert() alert.find('.close').click() @@ -35,7 +44,7 @@ $(function () { '×' + '

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

' + '
', - alert = $(alertHTML).appendTo('#qunit-fixture').alert() + alert = $(alertHTML).appendTo('#qunit-fixture').bootstrapAlert() ok($('#qunit-fixture').find('.alert-message').length, 'element added to dom') @@ -56,7 +65,7 @@ $(function () { .on('closed.bs.alert', function () { ok(false) }) - .alert('close') + .bootstrapAlert('close') }) }) diff --git a/js/tests/unit/button.js b/js/tests/unit/button.js index ea1236478..10bff1442 100644 --- a/js/tests/unit/button.js +++ b/js/tests/unit/button.js @@ -1,25 +1,34 @@ $(function () { - module('button') - - 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 - }) + module('button plugin') test('should be defined on jquery object', function () { ok($(document.body).button, 'button method is defined') }) + module('button', { + setup: function() { + // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode + $.fn.bootstrapButton = $.fn.button.noConflict() + }, + teardown: function() { + $.fn.button = $.fn.bootstrapButton + delete $.fn.bootstrapButton + } + }) + + test('should provide no conflict', function () { + ok(!$.fn.button, 'button was set back to undefined (org value)') + }) + test('should return element', function () { - ok($(document.body).button()[0] == document.body, 'document.body returned') + ok($(document.body).bootstrapButton()[0] == document.body, 'document.body returned') }) test('should return set state to loading', function () { var btn = $('') equal(btn.html(), 'mdo', 'btn text equals mdo') - btn.button('loading') + btn.bootstrapButton('loading') equal(btn.html(), 'fat', 'btn text equals fat') stop() setTimeout(function () { @@ -32,7 +41,7 @@ $(function () { test('should return reset state', function () { var btn = $('') equal(btn.html(), 'mdo', 'btn text equals mdo') - btn.button('loading') + btn.bootstrapButton('loading') equal(btn.html(), 'fat', 'btn text equals fat') stop() setTimeout(function () { @@ -40,7 +49,7 @@ $(function () { ok(btn.hasClass('disabled'), 'btn has disabled class') start() stop() - btn.button('reset') + btn.bootstrapButton('reset') equal(btn.html(), 'mdo', 'btn text equals mdo') setTimeout(function () { ok(!btn.attr('disabled'), 'btn is not disabled') @@ -54,7 +63,7 @@ $(function () { test('should toggle active', function () { var btn = $('') ok(!btn.hasClass('active'), 'btn does not have active class') - btn.button('toggle') + btn.bootstrapButton('toggle') ok(btn.hasClass('active'), 'btn has class active') }) diff --git a/js/tests/unit/carousel.js b/js/tests/unit/carousel.js index 065354451..ece18553e 100644 --- a/js/tests/unit/carousel.js +++ b/js/tests/unit/carousel.js @@ -1,19 +1,28 @@ $(function () { - module('carousel') - - test('should provide no conflict', function () { - var carousel = $.fn.carousel.noConflict() - ok(!$.fn.carousel, 'carousel was set back to undefined (orig value)') - $.fn.carousel = carousel - }) + module('carousel plugin') test('should be defined on jQuery object', function () { ok($(document.body).carousel, 'carousel method is defined') }) + module('carousel', { + setup: function() { + // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode + $.fn.bootstrapCarousel = $.fn.carousel.noConflict() + }, + teardown: function() { + $.fn.carousel = $.fn.bootstrapCarousel + delete $.fn.bootstrapCarousel + } + }) + + test('should provide no conflict', function () { + ok(!$.fn.carousel, 'carousel was set back to undefined (orig value)') + }) + test('should return element', function () { - ok($(document.body).carousel()[0] == document.body, 'document.body returned') + ok($(document.body).bootstrapCarousel()[0] == document.body, 'document.body returned') }) test('should not fire slide when slide is prevented', function () { @@ -28,7 +37,7 @@ $(function () { .on('slid.bs.carousel', function () { ok(false) }) - .carousel('next') + .bootstrapCarousel('next') }) test('should reset when slide is prevented', function () { @@ -41,7 +50,7 @@ $(function () { setTimeout(function () { ok($carousel.find('.item:eq(0)').is('.active')) ok($carousel.find('.carousel-indicators li:eq(0)').is('.active')) - $carousel.carousel('next') + $carousel.bootstrapCarousel('next') }, 1) }) $carousel.one('slid.bs.carousel', function () { @@ -51,7 +60,7 @@ $(function () { start() }, 1) }) - $carousel.carousel('next') + $carousel.bootstrapCarousel('next') }) test('should fire slide event with direction', function () { @@ -63,7 +72,7 @@ $(function () { ok(e.direction) ok(e.direction === 'right' || e.direction === 'left') start() - }).carousel('next') + }).bootstrapCarousel('next') }) test('should fire slide event with relatedTarget', function () { @@ -77,7 +86,7 @@ $(function () { ok($(e.relatedTarget).hasClass('item')) start() }) - .carousel('next') + .bootstrapCarousel('next') }) test('should set interval from data attribute', 4, function () { @@ -103,7 +112,7 @@ $(function () { template.attr('data-interval', false) template.appendTo('body') - $('#myCarousel').carousel(1) + $('#myCarousel').bootstrapCarousel(1) ok($('#myCarousel').data('bs.carousel').options.interval === false, 'data attribute has higher priority than default options') $('#myCarousel').remove() }) @@ -127,11 +136,11 @@ $(function () { + '
' ) - $template.carousel() + $template.bootstrapCarousel() equal($template.find('.item')[0], $template.find('.active')[0], 'the first carousel item should be active') - $template.carousel(1) + $template.bootstrapCarousel(1) equal($template.find('.item')[1], $template.find('.active')[0], 'the second carousel item should be active') }) diff --git a/js/tests/unit/collapse.js b/js/tests/unit/collapse.js index 66b2dc1a7..a8c6e38a5 100644 --- a/js/tests/unit/collapse.js +++ b/js/tests/unit/collapse.js @@ -1,29 +1,38 @@ $(function () { - module('collapse') - - test('should provide no conflict', function () { - var collapse = $.fn.collapse.noConflict() - ok(!$.fn.collapse, 'collapse was set back to undefined (org value)') - $.fn.collapse = collapse - }) + module('collapse plugin') test('should be defined on jquery object', function () { ok($(document.body).collapse, 'collapse method is defined') }) + module('collapse', { + setup: function() { + // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode + $.fn.bootstrapCollapse = $.fn.collapse.noConflict() + }, + teardown: function() { + $.fn.collapse = $.fn.bootstrapCollapse + delete $.fn.bootstrapCollapse + } + }) + + test('should provide no conflict', function () { + ok(!$.fn.collapse, 'collapse was set back to undefined (org value)') + }) + test('should return element', function () { - ok($(document.body).collapse()[0] == document.body, 'document.body returned') + ok($(document.body).bootstrapCollapse()[0] == document.body, 'document.body returned') }) test('should show a collapsed element', function () { - var el = $('
').collapse('show') + var el = $('
').bootstrapCollapse('show') ok(el.hasClass('in'), 'has class in') ok(!/height/.test(el.attr('style')), 'has height reset') }) test('should hide a collapsed element', function () { - var el = $('
').collapse('hide') + var el = $('
').bootstrapCollapse('hide') ok(!el.hasClass('in'), 'does not have class in') ok(/height/.test(el.attr('style')), 'has height set') }) @@ -40,7 +49,7 @@ $(function () { .on('shown.bs.collapse', function () { ok(false) }) - .collapse('show') + .bootstrapCollapse('show') }) test('should reset style to auto after finishing opening collapse', function () { @@ -54,7 +63,7 @@ $(function () { ok(this.style.height === '') start() }) - .collapse('show') + .bootstrapCollapse('show') }) test('should add active class to target when collapse shown', function () { diff --git a/js/tests/unit/dropdown.js b/js/tests/unit/dropdown.js index 2d2e7c51d..f074c5598 100644 --- a/js/tests/unit/dropdown.js +++ b/js/tests/unit/dropdown.js @@ -1,20 +1,29 @@ $(function () { - module('dropdowns') - - test('should provide no conflict', function () { - var dropdown = $.fn.dropdown.noConflict() - ok(!$.fn.dropdown, 'dropdown was set back to undefined (org value)') - $.fn.dropdown = dropdown - }) + module('dropdowns plugin') test('should be defined on jquery object', function () { ok($(document.body).dropdown, 'dropdown method is defined') }) + module('dropdowns', { + setup: function() { + // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode + $.fn.bootstrapDropdown = $.fn.dropdown.noConflict() + }, + teardown: function() { + $.fn.dropdown = $.fn.bootstrapDropdown + delete $.fn.bootstrapDropdown + } + }) + + test('should provide no conflict', function () { + ok(!$.fn.dropdown, 'dropdown was set back to undefined (org value)') + }) + test('should return element', function () { var el = $('
') - ok(el.dropdown()[0] === el[0], 'same element returned') + ok(el.bootstrapDropdown()[0] === el[0], 'same element returned') }) test('should not open dropdown if target is disabled', function () { @@ -29,7 +38,7 @@ $(function () { '' + '' + '', - dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').dropdown().click() + dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().click() ok(!dropdown.parent('.dropdown').hasClass('open'), 'open class added on click') }) @@ -46,7 +55,7 @@ $(function () { '' + '' + '', - dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').dropdown().click() + dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().click() ok(!dropdown.parent('.dropdown').hasClass('open'), 'open class added on click') }) @@ -63,7 +72,7 @@ $(function () { '' + '' + '', - dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').dropdown().click() + dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().click() ok(dropdown.parent('.dropdown').hasClass('open'), 'open class added on click') }) @@ -80,7 +89,7 @@ $(function () { '' + '' + '', - dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').dropdown().click() + dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().click() ok(dropdown.parent('.dropdown').hasClass('open'), 'open class added on click') }) @@ -101,7 +110,7 @@ $(function () { dropdown = $(dropdownHTML) .appendTo('#qunit-fixture') .find('[data-toggle="dropdown"]') - .dropdown() + .bootstrapDropdown() .click() ok(dropdown.parent('.dropdown').hasClass('open'), 'open class added on click') @@ -163,7 +172,7 @@ $(function () { dropdown = $(dropdownHTML) .appendTo('#qunit-fixture') .find('[data-toggle="dropdown"]') - .dropdown() + .bootstrapDropdown() stop() @@ -197,7 +206,7 @@ $(function () { dropdown = $(dropdownHTML) .appendTo('#qunit-fixture') .find('[data-toggle="dropdown"]') - .dropdown() + .bootstrapDropdown() stop() diff --git a/js/tests/unit/modal.js b/js/tests/unit/modal.js index 33952eba5..c1dc895e3 100644 --- a/js/tests/unit/modal.js +++ b/js/tests/unit/modal.js @@ -1,26 +1,35 @@ $(function () { - module('modal') - - test('should provide no conflict', function () { - var modal = $.fn.modal.noConflict() - ok(!$.fn.modal, 'modal was set back to undefined (org value)') - $.fn.modal = modal - }) + module('modal plugin') test('should be defined on jquery object', function () { var div = $('') ok(div.modal, 'modal method is defined') }) + module('modal', { + setup: function() { + // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode + $.fn.bootstrapModal = $.fn.modal.noConflict() + }, + teardown: function() { + $.fn.modal = $.fn.bootstrapModal + delete $.fn.bootstrapModal + } + }) + + test('should provide no conflict', function () { + ok(!$.fn.modal, 'modal was set back to undefined (org value)') + }) + test('should return element', function () { var div = $('') - ok(div.modal() == div, 'document.body returned') + ok(div.bootstrapModal() == div, 'document.body returned') $('#modal-test').remove() }) test('should expose defaults var for settings', function () { - ok($.fn.modal.Constructor.DEFAULTS, 'default object exposed') + ok($.fn.bootstrapModal.Constructor.DEFAULTS, 'default object exposed') }) test('should insert into dom when show method is called', function () { @@ -32,7 +41,7 @@ $(function () { $(this).remove() start() }) - .modal('show') + .bootstrapModal('show') }) test('should fire show event', function () { @@ -46,7 +55,7 @@ $(function () { $(this).remove() start() }) - .modal('show') + .bootstrapModal('show') }) test('should not fire shown when default prevented', function () { @@ -61,7 +70,7 @@ $(function () { .on('shown.bs.modal', function () { ok(false, 'shown was called') }) - .modal('show') + .bootstrapModal('show') }) test('should hide modal when hide is called', function () { @@ -72,14 +81,14 @@ $(function () { .on('shown.bs.modal', function () { ok($('#modal-test').is(':visible'), 'modal visible') ok($('#modal-test').length, 'modal inserted into dom') - $(this).modal('hide') + $(this).bootstrapModal('hide') }) .on('hidden.bs.modal', function () { ok(!$('#modal-test').is(':visible'), 'modal hidden') $('#modal-test').remove() start() }) - .modal('show') + .bootstrapModal('show') }) test('should toggle when toggle is called', function () { @@ -90,14 +99,14 @@ $(function () { .on('shown.bs.modal', function () { ok($('#modal-test').is(':visible'), 'modal visible') ok($('#modal-test').length, 'modal inserted into dom') - div.modal('toggle') + div.bootstrapModal('toggle') }) .on('hidden.bs.modal', function () { ok(!$('#modal-test').is(':visible'), 'modal hidden') div.remove() start() }) - .modal('toggle') + .bootstrapModal('toggle') }) test('should remove from dom when click [data-dismiss="modal"]', function () { @@ -115,7 +124,7 @@ $(function () { div.remove() start() }) - .modal('toggle') + .bootstrapModal('toggle') }) test('should allow modal close with "backdrop:false"', function () { @@ -125,14 +134,14 @@ $(function () { div .on('shown.bs.modal', function () { ok($('#modal-test').is(':visible'), 'modal visible') - div.modal('hide') + div.bootstrapModal('hide') }) .on('hidden.bs.modal', function () { ok(!$('#modal-test').is(':visible'), 'modal hidden') div.remove() start() }) - .modal('show') + .bootstrapModal('show') }) test('should close modal when clicking outside of modal-content', function () { @@ -151,7 +160,7 @@ $(function () { div.remove() start() }) - .modal('show') + .bootstrapModal('show') }) test('should trigger hide event once when clicking outside of modal-content', function () { @@ -171,7 +180,7 @@ $(function () { ok(triggered === 1, 'modal hide triggered once') start() }) - .modal('show') + .bootstrapModal('show') }) test('should close reopened modal with [data-dismiss="modal"] click', function () { @@ -186,9 +195,9 @@ $(function () { .one('hidden.bs.modal', function () { div.one('hidden.bs.modal', function () { start() - }).modal('show') + }).bootstrapModal('show') }) - .modal('show') + .bootstrapModal('show') div.remove() }) diff --git a/js/tests/unit/popover.js b/js/tests/unit/popover.js index 24f2f6f03..1a095564b 100644 --- a/js/tests/unit/popover.js +++ b/js/tests/unit/popover.js @@ -1,38 +1,47 @@ $(function () { - module('popover') - - test('should provide no conflict', function () { - var popover = $.fn.popover.noConflict() - ok(!$.fn.popover, 'popover was set back to undefined (org value)') - $.fn.popover = popover - }) + module('popover plugin') test('should be defined on jquery object', function () { var div = $('
') ok(div.popover, 'popover method is defined') }) + module('popover', { + setup: function() { + // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode + $.fn.bootstrapPopover = $.fn.popover.noConflict() + }, + teardown: function() { + $.fn.popover = $.fn.bootstrapPopover + delete $.fn.bootstrapPopover + } + }) + + test('should provide no conflict', function () { + ok(!$.fn.popover, 'popover was set back to undefined (org value)') + }) + test('should return element', function () { var div = $('
') - ok(div.popover() == div, 'document.body returned') + ok(div.bootstrapPopover() == div, 'document.body returned') }) test('should render popover element', function () { $.support.transition = false var popover = $('@mdo') .appendTo('#qunit-fixture') - .popover('show') + .bootstrapPopover('show') ok($('.popover').length, 'popover was inserted') - popover.popover('hide') + popover.bootstrapPopover('hide') ok(!$('.popover').length, 'popover removed') }) test('should store popover instance in popover data object', function () { $.support.transition = false var popover = $('@mdo') - .popover() + .bootstrapPopover() ok(!!popover.data('bs.popover'), 'popover instance exists') }) @@ -41,7 +50,7 @@ $(function () { $.support.transition = false var popover = $('@fat') .appendTo('#qunit-fixture') - .popover({ + .bootstrapPopover({ title: function () { return '@fat' }, @@ -50,13 +59,13 @@ $(function () { } }) - popover.popover('show') + popover.bootstrapPopover('show') ok($('.popover').length, 'popover was inserted') equal($('.popover .popover-title').text(), '@fat', 'title correctly inserted') equal($('.popover .popover-content').text(), 'loves writing tests (╯°□°)╯︵ ┻━┻', 'content correctly inserted') - popover.popover('hide') + popover.bootstrapPopover('hide') ok(!$('.popover').length, 'popover was removed') $('#qunit-fixture').empty() }) @@ -68,24 +77,24 @@ $(function () { var popover = $('@fat') .appendTo('#qunit-fixture') - .popover({ + .bootstrapPopover({ content: function () { return $div } }) - popover.popover('show') + popover.bootstrapPopover('show') ok($('.popover').length, 'popover was inserted') equal($('.popover .popover-content').html(), $div, 'content correctly inserted') - popover.popover('hide') + popover.bootstrapPopover('hide') ok(!$('.popover').length, 'popover was removed') - popover.popover('show') + popover.bootstrapPopover('show') ok($('.popover').length, 'popover was inserted') equal($('.popover .popover-content').html(), $div, 'content correctly inserted') - popover.popover('hide') + popover.bootstrapPopover('hide') ok(!$('.popover').length, 'popover was removed') $('#qunit-fixture').empty() }) @@ -94,14 +103,14 @@ $(function () { $.support.transition = false var popover = $('@mdo') .appendTo('#qunit-fixture') - .popover() - .popover('show') + .bootstrapPopover() + .bootstrapPopover('show') ok($('.popover').length, 'popover was inserted') equal($('.popover .popover-title').text(), '@mdo', 'title correctly inserted') equal($('.popover .popover-content').text(), 'loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻', 'content correctly inserted') - popover.popover('hide') + popover.bootstrapPopover('hide') ok(!$('.popover').length, 'popover was removed') $('#qunit-fixture').empty() }) @@ -111,17 +120,17 @@ $(function () { $.support.transition = false var popover = $('@mdo') .appendTo('#qunit-fixture') - .popover({ + .bootstrapPopover({ title: 'ignored title option', content: 'ignored content option' }) - .popover('show') + .bootstrapPopover('show') ok($('.popover').length, 'popover was inserted') equal($('.popover .popover-title').text(), '@mdo', 'title correctly inserted') equal($('.popover .popover-content').text(), 'loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻', 'content correctly inserted') - popover.popover('hide') + popover.bootstrapPopover('hide') ok(!$('.popover').length, 'popover was removed') $('#qunit-fixture').empty() }) @@ -130,29 +139,29 @@ $(function () { $.support.transition = false var popover = $('@fat') .appendTo('#qunit-fixture') - .popover({ + .bootstrapPopover({ title: 'Test', content: 'Test', template: '

' }) - popover.popover('show') + popover.bootstrapPopover('show') ok($('.popover').length, 'popover was inserted') ok($('.popover').hasClass('foobar'), 'custom class is present') - popover.popover('hide') + popover.bootstrapPopover('hide') ok(!$('.popover').length, 'popover was removed') $('#qunit-fixture').empty() }) test('should destroy popover', function () { - var popover = $('
').popover({trigger: 'hover'}).on('click.foo', function () {}) + var popover = $('
').bootstrapPopover({trigger: 'hover'}).on('click.foo', function () {}) ok(popover.data('bs.popover'), 'popover has data') 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') + popover.bootstrapPopover('show') + popover.bootstrapPopover('destroy') ok(!popover.hasClass('in'), 'popover is hidden') ok(!popover.data('popover'), 'popover does not have data') ok($._data(popover[0],'events').click[0].namespace == 'foo', 'popover still has click.foo') diff --git a/js/tests/unit/scrollspy.js b/js/tests/unit/scrollspy.js index 670735a46..90c95d769 100644 --- a/js/tests/unit/scrollspy.js +++ b/js/tests/unit/scrollspy.js @@ -1,19 +1,28 @@ $(function () { - module('scrollspy') - - test('should provide no conflict', function () { - var scrollspy = $.fn.scrollspy.noConflict() - ok(!$.fn.scrollspy, 'scrollspy was set back to undefined (org value)') - $.fn.scrollspy = scrollspy - }) + module('scrollspy plugin') test('should be defined on jquery object', function () { ok($(document.body).scrollspy, 'scrollspy method is defined') }) + module('scrollspy', { + setup: function() { + // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode + $.fn.bootstrapScrollspy = $.fn.scrollspy.noConflict() + }, + teardown: function() { + $.fn.scrollspy = $.fn.bootstrapScrollspy + delete $.fn.bootstrapScrollspy + } + }) + + test('should provide no conflict', function () { + ok(!$.fn.scrollspy, 'scrollspy was set back to undefined (org value)') + }) + test('should return element', function () { - ok($(document.body).scrollspy()[0] == document.body, 'document.body returned') + ok($(document.body).bootstrapScrollspy()[0] == document.body, 'document.body returned') }) test('should switch active class on scroll', function () { @@ -27,7 +36,7 @@ $(function () { '
' + '
' + '
', - $topbar = $(topbarHTML).scrollspy() + $topbar = $(topbarHTML).bootstrapScrollspy() $(sectionHTML).append('#qunit-fixture') ok($topbar.find('.active', true)) @@ -64,7 +73,7 @@ $(function () { $scrollSpy = $section .show() .find('#scrollspy-example') - .scrollspy({target: '#ss-target'}) + .bootstrapScrollspy({target: '#ss-target'}) $scrollSpy.scrollTop(350); ok($section.hasClass('active'), 'Active class still on root node') diff --git a/js/tests/unit/tab.js b/js/tests/unit/tab.js index 08f6e3cfd..7372b7a17 100644 --- a/js/tests/unit/tab.js +++ b/js/tests/unit/tab.js @@ -1,19 +1,28 @@ $(function () { - module('tabs') - - test('should provide no conflict', function () { - var tab = $.fn.tab.noConflict() - ok(!$.fn.tab, 'tab was set back to undefined (org value)') - $.fn.tab = tab - }) + module('tabs plugin') test('should be defined on jquery object', function () { ok($(document.body).tab, 'tabs method is defined') }) + module('tabs', { + setup: function() { + // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode + $.fn.bootstrapTab = $.fn.tab.noConflict() + }, + teardown: function() { + $.fn.tab = $.fn.bootstrapTab + delete $.fn.bootstrapTab + } + }) + + test('should provide no conflict', function () { + ok(!$.fn.tab, 'tab was set back to undefined (org value)') + }) + test('should return element', function () { - ok($(document.body).tab()[0] == document.body, 'document.body returned') + ok($(document.body).bootstrapTab()[0] == document.body, 'document.body returned') }) test('should activate element by tab id', function () { @@ -24,10 +33,10 @@ $(function () { $('
').appendTo('#qunit-fixture') - $(tabsHTML).find('li:last a').tab('show') + $(tabsHTML).find('li:last a').bootstrapTab('show') equal($('#qunit-fixture').find('.active').attr('id'), 'profile') - $(tabsHTML).find('li:first a').tab('show') + $(tabsHTML).find('li:first a').bootstrapTab('show') equal($('#qunit-fixture').find('.active').attr('id'), 'home') }) @@ -39,10 +48,10 @@ $(function () { $('
').appendTo('#qunit-fixture') - $(pillsHTML).find('li:last a').tab('show') + $(pillsHTML).find('li:last a').bootstrapTab('show') equal($('#qunit-fixture').find('.active').attr('id'), 'profile') - $(pillsHTML).find('li:first a').tab('show') + $(pillsHTML).find('li:first a').bootstrapTab('show') equal($('#qunit-fixture').find('.active').attr('id'), 'home') }) @@ -59,7 +68,7 @@ $(function () { .on('shown.bs.tab', function () { ok(false) }) - .tab('show') + .bootstrapTab('show') }) test('show and shown events should reference correct relatedTarget', function () { @@ -72,7 +81,7 @@ $(function () { '' + '' - $(dropHTML).find('ul>li:first a').tab('show').end() + $(dropHTML).find('ul>li:first a').bootstrapTab('show').end() .find('ul>li:last a') .on('show.bs.tab', function (event) { equal(event.relatedTarget.hash, '#1-1') @@ -80,7 +89,7 @@ $(function () { .on('show.bs.tab', function (event) { equal(event.relatedTarget.hash, '#1-1') }) - .tab('show') + .bootstrapTab('show') }) }) diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index 9a5f36f7b..e579a9ef7 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -1,34 +1,43 @@ $(function () { - module('tooltip') - - test('should provide no conflict', function () { - var tooltip = $.fn.tooltip.noConflict() - ok(!$.fn.tooltip, 'tooltip was set back to undefined (org value)') - $.fn.tooltip = tooltip - }) + module('tooltip plugin') test('should be defined on jquery object', function () { var div = $('
') ok(div.tooltip, 'popover method is defined') }) + module('tooltip', { + setup: function() { + // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode + $.fn.bootstrapTooltip = $.fn.tooltip.noConflict() + }, + teardown: function() { + $.fn.tooltip = $.fn.bootstrapTooltip + delete $.fn.bootstrapTooltip + } + }) + + test('should provide no conflict', function () { + ok(!$.fn.tooltip, 'tooltip was set back to undefined (org value)') + }) + test('should return element', function () { var div = $('
') - ok(div.tooltip() == div, 'document.body returned') + ok(div.bootstrapTooltip() == div, 'document.body returned') }) test('should expose default settings', function () { - ok(!!$.fn.tooltip.Constructor.DEFAULTS, 'defaults is defined') + ok(!!$.fn.bootstrapTooltip.Constructor.DEFAULTS, 'defaults is defined') }) test('should empty title attribute', function () { - var tooltip = $('').tooltip() + var tooltip = $('').bootstrapTooltip() ok(tooltip.attr('title') === '', 'title attribute was emptied') }) test('should add data attribute for referencing original title', function () { - var tooltip = $('').tooltip() + var tooltip = $('').bootstrapTooltip() equal(tooltip.attr('data-original-title'), 'Another tooltip', 'original title preserved in data attribute') }) @@ -36,33 +45,33 @@ $(function () { $.support.transition = false var tooltip = $('') .appendTo('#qunit-fixture') - .tooltip({placement: 'bottom'}) - .tooltip('show') + .bootstrapTooltip({placement: 'bottom'}) + .bootstrapTooltip('show') ok($('.tooltip').is('.fade.bottom.in'), 'has correct classes applied') - tooltip.tooltip('hide') + tooltip.bootstrapTooltip('hide') }) test('should allow html entities', function () { $.support.transition = false var tooltip = $('') .appendTo('#qunit-fixture') - .tooltip({html: true}) - .tooltip('show') + .bootstrapTooltip({html: true}) + .bootstrapTooltip('show') ok($('.tooltip b').length, 'b tag was inserted') - tooltip.tooltip('hide') + tooltip.bootstrapTooltip('hide') ok(!$('.tooltip').length, 'tooltip removed') }) test('should respect custom classes', function () { var tooltip = $('') .appendTo('#qunit-fixture') - .tooltip({ template: '
'}) - .tooltip('show') + .bootstrapTooltip({ template: '
'}) + .bootstrapTooltip('show') ok($('.tooltip').hasClass('some-class'), 'custom class is present') - tooltip.tooltip('hide') + tooltip.bootstrapTooltip('hide') ok(!$('.tooltip').length, 'tooltip removed') }) @@ -73,7 +82,7 @@ $(function () { ok(true, 'show was called') start() }) - .tooltip('show') + .bootstrapTooltip('show') }) test('should fire shown event', function () { @@ -83,7 +92,7 @@ $(function () { ok(true, 'shown was called') start() }) - .tooltip('show') + .bootstrapTooltip('show') }) test('should not fire shown event when default prevented', function () { @@ -97,40 +106,40 @@ $(function () { .on('shown.bs.tooltip', function () { ok(false, 'shown was called') }) - .tooltip('show') + .bootstrapTooltip('show') }) test('should fire hide event', function () { stop() $('
') .on('shown.bs.tooltip', function () { - $(this).tooltip('hide') + $(this).bootstrapTooltip('hide') }) .on('hide.bs.tooltip', function () { ok(true, 'hide was called') start() }) - .tooltip('show') + .bootstrapTooltip('show') }) test('should fire hidden event', function () { stop() $('
') .on('shown.bs.tooltip', function () { - $(this).tooltip('hide') + $(this).bootstrapTooltip('hide') }) .on('hidden.bs.tooltip', function () { ok(true, 'hidden was called') start() }) - .tooltip('show') + .bootstrapTooltip('show') }) test('should not fire hidden event when default prevented', function () { stop() $('
') .on('shown.bs.tooltip', function () { - $(this).tooltip('hide') + $(this).bootstrapTooltip('hide') }) .on('hide.bs.tooltip', function (e) { e.preventDefault() @@ -140,13 +149,13 @@ $(function () { .on('hidden.bs.tooltip', function () { ok(false, 'hidden was called') }) - .tooltip('show') + .bootstrapTooltip('show') }) test('should not show tooltip if leave event occurs before delay expires', function () { var tooltip = $('') .appendTo('#qunit-fixture') - .tooltip({ delay: 200 }) + .bootstrapTooltip({ delay: 200 }) stop() @@ -165,7 +174,7 @@ $(function () { test('should not show tooltip if leave event occurs before delay expires, even if hide delay is 0', function () { var tooltip = $('') .appendTo('#qunit-fixture') - .tooltip({ delay: { show: 200, hide: 0} }) + .bootstrapTooltip({ delay: { show: 200, hide: 0} }) stop() @@ -184,7 +193,7 @@ $(function () { test('should wait 200 ms before hiding the tooltip', 3, function () { var tooltip = $('') .appendTo('#qunit-fixture') - .tooltip({ delay: { show: 0, hide: 200} }) + .bootstrapTooltip({ delay: { show: 0, hide: 200} }) stop() @@ -206,7 +215,7 @@ $(function () { test('should not hide tooltip if leave event occurs, then tooltip is show immediately again', function () { var tooltip = $('') .appendTo('#qunit-fixture') - .tooltip({ delay: { show: 0, hide: 200} }) + .bootstrapTooltip({ delay: { show: 0, hide: 200} }) stop() @@ -229,7 +238,7 @@ $(function () { test('should not show tooltip if leave event occurs before delay expires', function () { var tooltip = $('') .appendTo('#qunit-fixture') - .tooltip({ delay: 100 }) + .bootstrapTooltip({ delay: 100 }) stop() tooltip.trigger('mouseenter') setTimeout(function () { @@ -245,7 +254,7 @@ $(function () { test('should show tooltip if leave event hasn\'t occured before delay expires', function () { var tooltip = $('') .appendTo('#qunit-fixture') - .tooltip({ delay: 150 }) + .bootstrapTooltip({ delay: 150 }) stop() tooltip.trigger('mouseenter') setTimeout(function () { @@ -258,12 +267,12 @@ $(function () { }) test('should destroy tooltip', function () { - var tooltip = $('
').tooltip().on('click.foo', function () {}) + var tooltip = $('
').bootstrapTooltip().on('click.foo', function () {}) ok(tooltip.data('bs.tooltip'), 'tooltip has data') 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') + tooltip.bootstrapTooltip('show') + tooltip.bootstrapTooltip('destroy') ok(!tooltip.hasClass('in'), 'tooltip is hidden') ok(!$._data(tooltip[0], 'bs.tooltip'), 'tooltip does not have data') ok($._data(tooltip[0], 'events').click[0].namespace == 'foo', 'tooltip still has click.foo') @@ -273,7 +282,7 @@ $(function () { test('should show tooltip with delegate selector on click', function () { var div = $('
') div.appendTo('#qunit-fixture') - .tooltip({ selector: 'a[rel="tooltip"]', trigger: 'click' }) + .bootstrapTooltip({ selector: 'a[rel="tooltip"]', trigger: 'click' }) div.find('a').trigger('click') ok($('.tooltip').is('.fade.in'), 'tooltip is faded in') }) @@ -281,19 +290,19 @@ $(function () { test('should show tooltip when toggle is called', function () { $('') .appendTo('#qunit-fixture') - .tooltip({trigger: 'manual'}) - .tooltip('toggle') + .bootstrapTooltip({trigger: 'manual'}) + .bootstrapTooltip('toggle') ok($('.tooltip').is('.fade.in'), 'tooltip should be toggled in') }) test('should place tooltips inside the body', function () { var tooltip = $('') .appendTo('#qunit-fixture') - .tooltip({container: 'body'}) - .tooltip('show') + .bootstrapTooltip({container: 'body'}) + .bootstrapTooltip('show') ok($('body > .tooltip').length, 'inside the body') ok(!$('#qunit-fixture > .tooltip').length, 'not found in parent') - tooltip.tooltip('hide') + tooltip.bootstrapTooltip('hide') }) test('should place tooltip inside window', function () { @@ -302,8 +311,8 @@ $(function () { $('Hover me') .css({position: 'absolute', top: 0, left: 0}) .appendTo(container) - .tooltip({placement: 'top', animate: false}) - .tooltip('show') + .bootstrapTooltip({placement: 'top', animate: false}) + .bootstrapTooltip('show') stop() @@ -322,8 +331,8 @@ $(function () { tooltiped = $('Hover me') .css({marginTop: 200}) .appendTo(p) - .tooltip({placement: 'top', animate: false}) - .tooltip('show') + .bootstrapTooltip({placement: 'top', animate: false}) + .bootstrapTooltip('show') stop() @@ -342,8 +351,8 @@ $(function () { var container = $('
').appendTo('body'), target = $('') .appendTo(container) - .tooltip({placement: 'right', viewport: null}) - .tooltip('show'), + .bootstrapTooltip({placement: 'right', viewport: null}) + .bootstrapTooltip('show'), tooltip = container.find('.tooltip') // this is some dumb hack shit because sub pixels in firefox @@ -351,41 +360,41 @@ $(function () { var top2 = Math.round(tooltip.offset().top) var topDiff = top - top2 ok(topDiff <= 1 && topDiff >= -1) - target.tooltip('hide') + target.bootstrapTooltip('hide') $('head #test').remove() }) test('tooltip title test #1', function () { var tooltip = $('') .appendTo('#qunit-fixture') - .tooltip({}) - .tooltip('show') + .bootstrapTooltip({}) + .bootstrapTooltip('show') equal($('.tooltip').children('.tooltip-inner').text(), 'Simple tooltip', 'title from title attribute is set') - tooltip.tooltip('hide') + tooltip.bootstrapTooltip('hide') ok(!$('.tooltip').length, 'tooltip removed') }) test('tooltip title test #2', function () { var tooltip = $('') .appendTo('#qunit-fixture') - .tooltip({ + .bootstrapTooltip({ title: 'This is a tooltip with some content' }) - .tooltip('show') + .bootstrapTooltip('show') equal($('.tooltip').children('.tooltip-inner').text(), 'Simple tooltip', 'title is set from title attribute while prefered over title option') - tooltip.tooltip('hide') + tooltip.bootstrapTooltip('hide') ok(!$('.tooltip').length, 'tooltip removed') }) test('tooltip title test #3', function () { var tooltip = $('') .appendTo('#qunit-fixture') - .tooltip({ + .bootstrapTooltip({ title: 'This is a tooltip with some content' }) - .tooltip('show') + .bootstrapTooltip('show') equal($('.tooltip').children('.tooltip-inner').text(), 'This is a tooltip with some content', 'title from title option is set') - tooltip.tooltip('hide') + tooltip.bootstrapTooltip('hide') ok(!$('.tooltip').length, 'tooltip removed') }) @@ -403,28 +412,28 @@ $(function () { var topTooltip = $('
Top Dynamic Tooltip
') .appendTo('#dynamic-tt-test') - .tooltip({placement: 'auto'}) - .tooltip('show') + .bootstrapTooltip({placement: 'auto'}) + .bootstrapTooltip('show') ok($('.tooltip').is('.bottom'), 'top positioned tooltip is dynamically positioned bottom') - topTooltip.tooltip('hide') + topTooltip.bootstrapTooltip('hide') var rightTooltip = $('
Right Dynamic Tooltip
') .appendTo('#dynamic-tt-test') - .tooltip({placement: 'right auto'}) - .tooltip('show') + .bootstrapTooltip({placement: 'right auto'}) + .bootstrapTooltip('show') ok($('.tooltip').is('.left'), 'right positioned tooltip is dynamically positioned left') - rightTooltip.tooltip('hide') + rightTooltip.bootstrapTooltip('hide') var leftTooltip = $('
Left Dynamic Tooltip
') .appendTo('#dynamic-tt-test') - .tooltip({placement: 'auto left'}) - .tooltip('show') + .bootstrapTooltip({placement: 'auto left'}) + .bootstrapTooltip('show') ok($('.tooltip').is('.right'), 'left positioned tooltip is dynamically positioned right') - leftTooltip.tooltip('hide') + leftTooltip.bootstrapTooltip('hide') ttContainer.remove() }) @@ -435,12 +444,12 @@ $(function () { var container = $('
').appendTo('body'), target = $('') .appendTo(container) - .tooltip({placement: 'right', viewport: {selector: 'body', padding: 12}}) - .tooltip('show'), + .bootstrapTooltip({placement: 'right', viewport: {selector: 'body', padding: 12}}) + .bootstrapTooltip('show'), tooltip = container.find('.tooltip') ok( Math.round(tooltip.offset().top) === 12 ) - target.tooltip('hide') + target.bootstrapTooltip('hide') $('head #test').remove() }) @@ -450,12 +459,12 @@ $(function () { var container = $('
').appendTo('body'), target = $('') .appendTo(container) - .tooltip({placement: 'right', viewport: {selector: 'body', padding: 12}}) - .tooltip('show'), + .bootstrapTooltip({placement: 'right', viewport: {selector: 'body', padding: 12}}) + .bootstrapTooltip('show'), tooltip = container.find('.tooltip') ok( Math.round(tooltip.offset().top) === Math.round($(window).height() - 12 - tooltip[0].offsetHeight) ) - target.tooltip('hide') + target.bootstrapTooltip('hide') $('head #test').remove() }) @@ -465,12 +474,12 @@ $(function () { var container = $('
').appendTo('body'), target = $('') .appendTo(container) - .tooltip({placement: 'bottom', viewport: {selector: 'body', padding: 12}}) - .tooltip('show'), + .bootstrapTooltip({placement: 'bottom', viewport: {selector: 'body', padding: 12}}) + .bootstrapTooltip('show'), tooltip = container.find('.tooltip') ok( Math.round(tooltip.offset().left) === 12 ) - target.tooltip('hide') + target.bootstrapTooltip('hide') $('head #test').remove() }) @@ -480,12 +489,12 @@ $(function () { var container = $('
').appendTo('body'), target = $('') .appendTo(container) - .tooltip({placement: 'bottom', viewport: {selector: 'body', padding: 12}}) - .tooltip('show'), + .bootstrapTooltip({placement: 'bottom', viewport: {selector: 'body', padding: 12}}) + .bootstrapTooltip('show'), tooltip = container.find('.tooltip') ok( Math.round(tooltip.offset().left) === Math.round($(window).width() - 12 - tooltip[0].offsetWidth) ) - target.tooltip('hide') + target.bootstrapTooltip('hide') $('head #test').remove() }) @@ -496,12 +505,12 @@ $(function () { var container = $('
', {class: 'container-viewport'}).appendTo('body'), target = $('') .appendTo(container) - .tooltip({placement: 'bottom', viewport: '.container-viewport'}) - .tooltip('show'), + .bootstrapTooltip({placement: 'bottom', viewport: '.container-viewport'}) + .bootstrapTooltip('show'), tooltip = container.find('.tooltip') ok( Math.round(tooltip.offset().left) === Math.round(60 + container.width() - tooltip[0].offsetWidth) ) - target.tooltip('hide') + target.bootstrapTooltip('hide') $('head #test').remove() $('head #viewport-style').remove() }) -- cgit v1.2.3 From d9edf28c5f8607a217ec2b7945ca98f66938b623 Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Thu, 1 May 2014 13:37:44 -0700 Subject: make new Carousel tests compatible with noConflict mode --- js/tests/unit/carousel.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/tests/unit') diff --git a/js/tests/unit/carousel.js b/js/tests/unit/carousel.js index 8657ee00a..5fd875c8c 100644 --- a/js/tests/unit/carousel.js +++ b/js/tests/unit/carousel.js @@ -84,7 +84,7 @@ $(function () { ok(e.direction) ok(e.direction === 'right' || e.direction === 'left') start() - }).carousel('next') + }).bootstrapCarousel('next') }) test('should fire slide event with relatedTarget', function () { @@ -112,7 +112,7 @@ $(function () { ok($(e.relatedTarget).hasClass('item')) start() }) - .carousel('next') + .bootstrapCarousel('next') }) test('should set interval from data attribute', 4, function () { -- cgit v1.2.3 From 7627b24c1e6aa5301ee3f525dd931c2852e7ff0a Mon Sep 17 00:00:00 2001 From: breaddevil Date: Sun, 4 May 2014 11:24:31 +0200 Subject: replace js scrollspy test for default behavior --- js/tests/unit/scrollspy.js | 54 +++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 17 deletions(-) (limited to 'js/tests/unit') diff --git a/js/tests/unit/scrollspy.js b/js/tests/unit/scrollspy.js index 90c95d769..a36749f2e 100644 --- a/js/tests/unit/scrollspy.js +++ b/js/tests/unit/scrollspy.js @@ -25,23 +25,6 @@ $(function () { ok($(document.body).bootstrapScrollspy()[0] == document.body, 'document.body returned') }) - test('should switch active class on scroll', function () { - var sectionHTML = '
', - topbarHTML = '
' + - '
' + - '
' + - '

Bootstrap

' + - '
  • Overview
  • ' + - '' + - '
    ' + - '
    ' + - '
    ', - $topbar = $(topbarHTML).bootstrapScrollspy() - - $(sectionHTML).append('#qunit-fixture') - ok($topbar.find('.active', true)) - }) - test('should only switch active class on current target', function () { var sectionHTML = '
    ' + '
    ' + @@ -78,4 +61,41 @@ $(function () { $scrollSpy.scrollTop(350); ok($section.hasClass('active'), 'Active class still on root node') }) + + test('should add the active class to the correct element', function () { + var navbarHtml = + '' + var contentHtml = + '
    ' + + '
    div 1
    ' + + '
    div 2
    ' + + '
    ' + + $(navbarHtml).appendTo('#qunit-fixture') + var $content = $(contentHtml) + .appendTo('#qunit-fixture') + .bootstrapScrollspy({offset: 0, target: '.navbar'}) + + var testElementIsActiveAfterScroll = function (element, target) { + var deferred = $.Deferred() + var scrollHeight = $content.scrollTop() + $(target).position().top + stop() + $content.one('scroll', function () { + ok($(element).hasClass('active'), 'target:' + target + ', element' + element) + start() + deferred.resolve() + }) + $content.scrollTop(scrollHeight) + return deferred.promise() + } + + $.when(testElementIsActiveAfterScroll('#li-1', '#div-1')) + .then(function () { return testElementIsActiveAfterScroll('#li-2', '#div-2') }) + }) + }) -- cgit v1.2.3 From d8ee1ba9b61ef4ba5b0494433e3a6eac414ef782 Mon Sep 17 00:00:00 2001 From: Heinrich Fenkart Date: Mon, 5 May 2014 12:11:59 +0200 Subject: Allow for resetText of a button to be a falsey value; fixes #13466 --- js/tests/unit/button.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'js/tests/unit') diff --git a/js/tests/unit/button.js b/js/tests/unit/button.js index 10bff1442..da65ae383 100644 --- a/js/tests/unit/button.js +++ b/js/tests/unit/button.js @@ -57,7 +57,27 @@ $(function () { start() }, 0) }, 0) + }) + test('should work with an empty string as reset state', function () { + var btn = $('') + equal(btn.html(), '', 'btn text equals ""') + btn.bootstrapButton('loading') + equal(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() + btn.bootstrapButton('reset') + equal(btn.html(), '', 'btn text equals ""') + setTimeout(function () { + ok(!btn.attr('disabled'), 'btn is not disabled') + ok(!btn.hasClass('disabled'), 'btn does not have disabled class') + start() + }, 0) + }, 0) }) test('should toggle active', function () { -- cgit v1.2.3 From c2e94eba8da462ba8cacbc1558f7fdf6b3e28007 Mon Sep 17 00:00:00 2001 From: Mike Robinet Date: Tue, 13 May 2014 12:20:18 -0500 Subject: Add Scrollspy maxScroll with offset test. --- js/tests/unit/scrollspy.js | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'js/tests/unit') diff --git a/js/tests/unit/scrollspy.js b/js/tests/unit/scrollspy.js index 90c95d769..9a00221fd 100644 --- a/js/tests/unit/scrollspy.js +++ b/js/tests/unit/scrollspy.js @@ -42,7 +42,8 @@ $(function () { ok($topbar.find('.active', true)) }) - test('should only switch active class on current target', function () { + asyncTest('should only switch active class on current target', function () { + expect(1); var sectionHTML = '
    ' + '
    ' + '
    ' + @@ -75,7 +76,40 @@ $(function () { .find('#scrollspy-example') .bootstrapScrollspy({target: '#ss-target'}) + $scrollSpy.on('scroll.bs.scrollspy', function () { + ok($section.hasClass('active'), 'Active class still on root node') + start() + }) $scrollSpy.scrollTop(350); - ok($section.hasClass('active'), 'Active class still on root node') + }) + + asyncTest('middle navigation option correctly selected when large offset is used', function () { + expect(3); + var sectionHTML = '' + + '' + + '
    ' + + '
    ' + + '
    ' + + '
    ' + + '
    ', + $section = $(sectionHTML).appendTo('#qunit-fixture'), + $scrollSpy = $section + .show() + .filter('#content') + $scrollSpy.bootstrapScrollspy({target: '#navigation', offset: $scrollSpy.position().top}) + + $scrollSpy.on('scroll.bs.scrollspy', function () { + ok(!$section.find('#one-link').parent().hasClass('active'), 'Active class removed from first section') + ok($section.find('#two-link').parent().hasClass('active'), 'Active class on middle section') + ok(!$section.find('#three-link').parent().hasClass('active'), 'Active class not on last section') + start() + }) + $scrollSpy.scrollTop(550); }) }) -- cgit v1.2.3 From 122c05dbd87d9708086da4d097f7e715233f3b2c Mon Sep 17 00:00:00 2001 From: "j.corns" Date: Wed, 14 May 2014 10:36:32 -0700 Subject: Add tooltip self-reference to address #12320 primarily adds a data- attribute to the tooltip (and thus, the popover) to create a self-reference. --- js/tests/unit/popover.js | 10 ++++++++++ js/tests/unit/tooltip.js | 11 +++++++++++ 2 files changed, 21 insertions(+) (limited to 'js/tests/unit') diff --git a/js/tests/unit/popover.js b/js/tests/unit/popover.js index 1a095564b..b28e1f3a7 100644 --- a/js/tests/unit/popover.js +++ b/js/tests/unit/popover.js @@ -46,6 +46,16 @@ $(function () { ok(!!popover.data('bs.popover'), 'popover instance exists') }) + test('should store popover trigger in popover instance data object', function () { + $.support.transition = false + var popover = $('@ResentedHook') + .appendTo('#qunit-fixture') + .bootstrapPopover() + popover.bootstrapPopover('show') + ok(!!$('.popover').data('bs.popover'), 'popover trigger stored in instance data') + $('#qunit-fixture').empty() + }) + test('should get title and content from options', function () { $.support.transition = false var popover = $('@fat') diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index e579a9ef7..6c24111b8 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -295,6 +295,17 @@ $(function () { ok($('.tooltip').is('.fade.in'), 'tooltip should be toggled in') }) + test('should hide shown tooltip when toggle is called on tooltip', function () { + var tooltip = $('@ResentedHook') + .appendTo('#qunit-fixture') + .bootstrapTooltip({trigger: 'manual'}) + .bootstrapTooltip('toggle') + $('.tooltip', '#qunit-fixture').bootstrapTooltip('toggle') + ok($('.tooltip').not('.fade.in'), 'tooltip should be toggled out') + tooltip.bootstrapTooltip('hide') + $('#qunit-fixture').empty() + }) + test('should place tooltips inside the body', function () { var tooltip = $('') .appendTo('#qunit-fixture') -- cgit v1.2.3 From a70da16f6fb8c665f22b78b49a1dff998f1da8a7 Mon Sep 17 00:00:00 2001 From: Steven Bassett Date: Thu, 8 May 2014 20:19:12 -0700 Subject: Adds aria described by to tooltip plugin for accessibility Generates a unique id for tooltip and adds [aria-describedby] to the element it is called on. Resolves issue #13480 - set up test - linted the code styles - passed the tests - integrated feedback from @cvrebert --- js/tests/unit/tooltip.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'js/tests/unit') diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index e579a9ef7..e95b91cbb 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -41,6 +41,36 @@ $(function () { equal(tooltip.attr('data-original-title'), 'Another tooltip', 'original title preserved in data attribute') }) + test('should add set set aria describedby to the element called on show', function() { + var tooltip = $('').bootstrapTooltip() + .appendTo('#qunit-fixture') + .bootstrapTooltip('show') + ok(tooltip.attr('aria-describedby'), 'has the right attributes') + var id = $('.tooltip').attr('id') + + ok($('#' + id).length == 1, 'has a unique id') + ok($('.tooltip').attr('aria-describedby') === tooltip.attr('id'), 'they match!') + ok(tooltip.attr('aria-describedby') !== undefined, 'has the right attributes') + }) + + test('should remove the aria-describedby attributes on hide', function() { + var tooltip = $('').bootstrapTooltip() + .appendTo('#qunit-fixture') + .bootstrapTooltip('show') + ok(tooltip.attr('aria-describedby'), 'has the right attributes') + tooltip.bootstrapTooltip('hide') + ok(!tooltip.attr('aria-describedby'), 'removed the attributes on hide') + }) + + test('should assign a unique id tooltip element', function () { + $('') + .appendTo('#qunit-fixture') + .bootstrapTooltip('show'), + id = $('.tooltip').attr('id') + + ok( $('#' + id).length == 1 && id.indexOf('tooltip') === 0, 'generated prefixed and unique tooltip id') + }) + test('should place tooltips relative to placement option', function () { $.support.transition = false var tooltip = $('') -- cgit v1.2.3 From e9b99d475cdc635d6e1435b5101500b84e0ef615 Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Mon, 19 May 2014 00:47:06 -0700 Subject: fix typo in assertion description --- js/tests/unit/modal.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/tests/unit') diff --git a/js/tests/unit/modal.js b/js/tests/unit/modal.js index c1dc895e3..d8bef3ea1 100644 --- a/js/tests/unit/modal.js +++ b/js/tests/unit/modal.js @@ -19,7 +19,7 @@ $(function () { }) test('should provide no conflict', function () { - ok(!$.fn.modal, 'modal was set back to undefined (org value)') + ok(!$.fn.modal, 'modal was set back to undefined (orig value)') }) test('should return element', function () { -- cgit v1.2.3 From b058c018eba059811f0c26074b813b843cfb5cb7 Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Mon, 19 May 2014 01:25:52 -0700 Subject: Hopefully a fix for #12364 * register the callback before invoking the toggling * listen for `hidden` instead of `hide` * account for the possibility of the associated `show` event being preventDefault-ed Adds relevant unit tests. --- js/tests/unit/modal.js | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'js/tests/unit') diff --git a/js/tests/unit/modal.js b/js/tests/unit/modal.js index c1dc895e3..6db29ebb2 100644 --- a/js/tests/unit/modal.js +++ b/js/tests/unit/modal.js @@ -201,4 +201,55 @@ $(function () { div.remove() }) + + test('should restore focus to toggling element when modal is hidden after having been opened via data-api', function () { + stop() + $.support.transition = false + var toggleBtn = $('').appendTo('#qunit-fixture') + var div = $('') + div + .on('hidden.bs.modal', function () { + window.setTimeout(function () { // give the focus restoration callback a chance to run + equal(document.activeElement, toggleBtn[0], 'toggling element is once again focused') + div.remove() + toggleBtn.remove() + start() + }, 0) + }) + .on('shown.bs.modal', function () { + $('#close').click() + }) + .appendTo('#qunit-fixture') + toggleBtn.click() + }) + + test('should not restore focus to toggling element if the associated show event gets prevented', function () { + stop() + $.support.transition = false + var toggleBtn = $('').appendTo('#qunit-fixture') + var otherBtn = $('').appendTo('#qunit-fixture') + var div = $('') + div + .one('show.bs.modal', function (e) { + e.preventDefault() + otherBtn.focus() + window.setTimeout(function () { // give the focus event from the previous line a chance to run + div.bootstrapModal('show') + }, 0) + }) + .on('hidden.bs.modal', function () { + window.setTimeout(function () { // give the focus restoration callback a chance to run (except it shouldn't run in this case) + equal(document.activeElement, otherBtn[0], 'show was prevented, so focus should not have been restored to toggling element') + div.remove() + toggleBtn.remove() + otherBtn.remove() + start() + }, 0) + }) + .on('shown.bs.modal', function () { + $('#close').click() + }) + .appendTo('#qunit-fixture') + toggleBtn.click() + }) }) -- cgit v1.2.3 From 5ef9383f5388ba7a701c4377b43ebdbedb0bf748 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Mon, 17 Mar 2014 09:07:21 +0200 Subject: Tweak JSHint and JSCS checks. Be more consistent across the whole codebase. Also, make use of JSHint's 2.5.1 `extends` and `qunit` options. This way we set our basis options in js/.jshintrc and override the rest. --- js/tests/unit/.jshintrc | 5 +++++ js/tests/unit/phantom.js | 1 - 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 js/tests/unit/.jshintrc (limited to 'js/tests/unit') diff --git a/js/tests/unit/.jshintrc b/js/tests/unit/.jshintrc new file mode 100644 index 000000000..682a49af1 --- /dev/null +++ b/js/tests/unit/.jshintrc @@ -0,0 +1,5 @@ +{ + "extends" : "../../.jshintrc", + "devel" : true, + "qunit" : true +} diff --git a/js/tests/unit/phantom.js b/js/tests/unit/phantom.js index cd184c2f4..b5f0c67a6 100644 --- a/js/tests/unit/phantom.js +++ b/js/tests/unit/phantom.js @@ -6,7 +6,6 @@ * Licensed under the MIT license. */ -/*global QUnit:true, alert:true*/ (function () { 'use strict'; -- cgit v1.2.3 From 7b0acf14d8a7c7c6089035a848cba540ed963f36 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Mon, 17 Mar 2014 09:12:55 +0200 Subject: Comply to the new style. --- js/tests/unit/affix.js | 11 ++-- js/tests/unit/alert.js | 13 ++--- js/tests/unit/button.js | 15 +++--- js/tests/unit/carousel.js | 5 +- js/tests/unit/collapse.js | 5 +- js/tests/unit/dropdown.js | 41 ++++++++------- js/tests/unit/modal.js | 5 +- js/tests/unit/popover.js | 11 ++-- js/tests/unit/scrollspy.js | 30 ++++++----- js/tests/unit/tab.js | 5 +- js/tests/unit/tooltip.js | 127 +++++++++++++++++++++++---------------------- 11 files changed, 140 insertions(+), 128 deletions(-) (limited to 'js/tests/unit') diff --git a/js/tests/unit/affix.js b/js/tests/unit/affix.js index 404c6605b..03f25eb59 100644 --- a/js/tests/unit/affix.js +++ b/js/tests/unit/affix.js @@ -1,4 +1,5 @@ $(function () { + 'use strict'; module('affix plugin') @@ -7,11 +8,11 @@ $(function () { }) module('affix', { - setup: function() { + setup: function () { // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode $.fn.bootstrapAffix = $.fn.affix.noConflict() }, - teardown: function() { + teardown: function () { $.fn.affix = $.fn.bootstrapAffix delete $.fn.bootstrapAffix } @@ -45,7 +46,7 @@ $(function () { .on('affix.bs.affix', function () { ok(true, 'affix event triggered') }).on('affixed.bs.affix', function () { - ok(true,'affixed event triggered') + ok(true, 'affixed event triggered') $('#affixTarget').remove() $('#affixAfter').remove() start() @@ -53,7 +54,7 @@ $(function () { setTimeout(function () { window.scrollTo(0, document.body.scrollHeight) - setTimeout(function () { window.scroll(0,0) }, 0) - },0) + setTimeout(function () { window.scroll(0, 0) }, 0) + }, 0) }) }) diff --git a/js/tests/unit/alert.js b/js/tests/unit/alert.js index f5d6075f5..31116cce2 100644 --- a/js/tests/unit/alert.js +++ b/js/tests/unit/alert.js @@ -1,4 +1,5 @@ $(function () { + 'use strict'; module('alert plugin') @@ -7,11 +8,11 @@ $(function () { }) module('alert', { - setup: function() { + setup: function () { // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode $.fn.bootstrapAlert = $.fn.alert.noConflict() }, - teardown: function() { + teardown: function () { $.fn.alert = $.fn.bootstrapAlert delete $.fn.bootstrapAlert } @@ -29,8 +30,8 @@ $(function () { var alertHTML = '
    ' + '×' + '

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

    ' + - '
    ', - alert = $(alertHTML).bootstrapAlert() + '
    ' + var alert = $(alertHTML).bootstrapAlert() alert.find('.close').click() @@ -43,8 +44,8 @@ $(function () { var alertHTML = '
    ' + '×' + '

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

    ' + - '
    ', - alert = $(alertHTML).appendTo('#qunit-fixture').bootstrapAlert() + '
    ' + var alert = $(alertHTML).appendTo('#qunit-fixture').bootstrapAlert() ok($('#qunit-fixture').find('.alert-message').length, 'element added to dom') diff --git a/js/tests/unit/button.js b/js/tests/unit/button.js index da65ae383..671a93891 100644 --- a/js/tests/unit/button.js +++ b/js/tests/unit/button.js @@ -1,4 +1,5 @@ $(function () { + 'use strict'; module('button plugin') @@ -7,11 +8,11 @@ $(function () { }) module('button', { - setup: function() { + setup: function () { // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode $.fn.bootstrapButton = $.fn.button.noConflict() }, - teardown: function() { + teardown: function () { $.fn.button = $.fn.bootstrapButton delete $.fn.bootstrapButton } @@ -88,8 +89,8 @@ $(function () { }) test('should toggle active when btn children are clicked', function () { - var btn = $(''), - inner = $('') + var btn = $('') + var inner = $('') btn .append(inner) .appendTo($('#qunit-fixture')) @@ -99,9 +100,9 @@ $(function () { }) test('should toggle active when btn children are clicked within btn-group', function () { - var btngroup = $('
    '), - btn = $(''), - inner = $('') + var btngroup = $('
    ') + var btn = $('') + var inner = $('') btngroup .append(btn.append(inner)) .appendTo($('#qunit-fixture')) diff --git a/js/tests/unit/carousel.js b/js/tests/unit/carousel.js index 5fd875c8c..474cfb40c 100644 --- a/js/tests/unit/carousel.js +++ b/js/tests/unit/carousel.js @@ -1,4 +1,5 @@ $(function () { + 'use strict'; module('carousel plugin') @@ -7,11 +8,11 @@ $(function () { }) module('carousel', { - setup: function() { + setup: function () { // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode $.fn.bootstrapCarousel = $.fn.carousel.noConflict() }, - teardown: function() { + teardown: function () { $.fn.carousel = $.fn.bootstrapCarousel delete $.fn.bootstrapCarousel } diff --git a/js/tests/unit/collapse.js b/js/tests/unit/collapse.js index a8c6e38a5..4a0cf2b2e 100644 --- a/js/tests/unit/collapse.js +++ b/js/tests/unit/collapse.js @@ -1,4 +1,5 @@ $(function () { + 'use strict'; module('collapse plugin') @@ -7,11 +8,11 @@ $(function () { }) module('collapse', { - setup: function() { + setup: function () { // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode $.fn.bootstrapCollapse = $.fn.collapse.noConflict() }, - teardown: function() { + teardown: function () { $.fn.collapse = $.fn.bootstrapCollapse delete $.fn.bootstrapCollapse } diff --git a/js/tests/unit/dropdown.js b/js/tests/unit/dropdown.js index f074c5598..f21aa98fc 100644 --- a/js/tests/unit/dropdown.js +++ b/js/tests/unit/dropdown.js @@ -1,4 +1,5 @@ $(function () { + 'use strict'; module('dropdowns plugin') @@ -7,11 +8,11 @@ $(function () { }) module('dropdowns', { - setup: function() { + setup: function () { // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode $.fn.bootstrapDropdown = $.fn.dropdown.noConflict() }, - teardown: function() { + teardown: function () { $.fn.dropdown = $.fn.bootstrapDropdown delete $.fn.bootstrapDropdown } @@ -37,8 +38,8 @@ $(function () { '
  • Another link
  • ' + '' + '' + - '', - dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().click() + '' + var dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().click() ok(!dropdown.parent('.dropdown').hasClass('open'), 'open class added on click') }) @@ -54,8 +55,8 @@ $(function () { '
  • Another link
  • ' + '' + '' + - '', - dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().click() + '' + var dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().click() ok(!dropdown.parent('.dropdown').hasClass('open'), 'open class added on click') }) @@ -71,8 +72,8 @@ $(function () { '
  • Another link
  • ' + '' + '' + - '', - dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().click() + '' + var dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().click() ok(dropdown.parent('.dropdown').hasClass('open'), 'open class added on click') }) @@ -88,8 +89,8 @@ $(function () { '
  • Another link
  • ' + '' + '' + - '', - dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().click() + '' + var dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().click() ok(dropdown.parent('.dropdown').hasClass('open'), 'open class added on click') }) @@ -106,8 +107,8 @@ $(function () { '
  • Another link
  • ' + '' + '' + - '', - dropdown = $(dropdownHTML) + '' + var dropdown = $(dropdownHTML) .appendTo('#qunit-fixture') .find('[data-toggle="dropdown"]') .bootstrapDropdown() @@ -135,10 +136,10 @@ $(function () { ' ' + - '
    ', - dropdowns = $(dropdownHTML).appendTo('#qunit-fixture').find('[data-toggle="dropdown"]'), - first = dropdowns.first(), - last = dropdowns.last() + '
    ' + var dropdowns = $(dropdownHTML).appendTo('#qunit-fixture').find('[data-toggle="dropdown"]') + var first = dropdowns.first() + var last = dropdowns.last() ok(dropdowns.length == 2, 'Should be two dropdowns') @@ -168,8 +169,8 @@ $(function () { '
  • Another link
  • ' + '' + '' + - '', - dropdown = $(dropdownHTML) + '' + var dropdown = $(dropdownHTML) .appendTo('#qunit-fixture') .find('[data-toggle="dropdown"]') .bootstrapDropdown() @@ -202,8 +203,8 @@ $(function () { '
  • Another link
  • ' + '' + '' + - '', - dropdown = $(dropdownHTML) + '' + var dropdown = $(dropdownHTML) .appendTo('#qunit-fixture') .find('[data-toggle="dropdown"]') .bootstrapDropdown() diff --git a/js/tests/unit/modal.js b/js/tests/unit/modal.js index d8bef3ea1..782af9221 100644 --- a/js/tests/unit/modal.js +++ b/js/tests/unit/modal.js @@ -1,4 +1,5 @@ $(function () { + 'use strict'; module('modal plugin') @@ -8,11 +9,11 @@ $(function () { }) module('modal', { - setup: function() { + setup: function () { // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode $.fn.bootstrapModal = $.fn.modal.noConflict() }, - teardown: function() { + teardown: function () { $.fn.modal = $.fn.bootstrapModal delete $.fn.bootstrapModal } diff --git a/js/tests/unit/popover.js b/js/tests/unit/popover.js index b28e1f3a7..2ccf2cbbf 100644 --- a/js/tests/unit/popover.js +++ b/js/tests/unit/popover.js @@ -1,4 +1,5 @@ $(function () { + 'use strict'; module('popover plugin') @@ -8,11 +9,11 @@ $(function () { }) module('popover', { - setup: function() { + setup: function () { // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode $.fn.bootstrapPopover = $.fn.popover.noConflict() }, - teardown: function() { + teardown: function () { $.fn.popover = $.fn.bootstrapPopover delete $.fn.bootstrapPopover } @@ -83,7 +84,7 @@ $(function () { test('should not duplicate HTML object', function () { $.support.transition = false - $div = $('
    ').html('loves writing tests (╯°□°)╯︵ ┻━┻') + var $div = $('
    ').html('loves writing tests (╯°□°)╯︵ ┻━┻') var popover = $('@fat') .appendTo('#qunit-fixture') @@ -166,7 +167,7 @@ $(function () { }) test('should destroy popover', function () { - var popover = $('
    ').bootstrapPopover({trigger: 'hover'}).on('click.foo', function () {}) + var popover = $('
    ').bootstrapPopover({ trigger: 'hover' }).on('click.foo', function () {}) ok(popover.data('bs.popover'), 'popover has data') 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') @@ -174,7 +175,7 @@ $(function () { popover.bootstrapPopover('destroy') ok(!popover.hasClass('in'), 'popover is hidden') ok(!popover.data('popover'), 'popover does not have data') - ok($._data(popover[0],'events').click[0].namespace == 'foo', 'popover still has click.foo') + 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') }) diff --git a/js/tests/unit/scrollspy.js b/js/tests/unit/scrollspy.js index 9a00221fd..2ec51fc24 100644 --- a/js/tests/unit/scrollspy.js +++ b/js/tests/unit/scrollspy.js @@ -1,4 +1,5 @@ $(function () { + 'use strict'; module('scrollspy plugin') @@ -7,11 +8,11 @@ $(function () { }) module('scrollspy', { - setup: function() { + setup: function () { // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode $.fn.bootstrapScrollspy = $.fn.scrollspy.noConflict() }, - teardown: function() { + teardown: function () { $.fn.scrollspy = $.fn.bootstrapScrollspy delete $.fn.bootstrapScrollspy } @@ -26,8 +27,9 @@ $(function () { }) test('should switch active class on scroll', function () { - var sectionHTML = '
    ', - topbarHTML = '
    ' + + var sectionHTML = '
    ' + $(sectionHTML).append('#qunit-fixture') + var topbarHTML = '
    ' + '
    ' + '
    ' + '

    Bootstrap

    ' + @@ -35,8 +37,8 @@ $(function () { '' + '
    ' + '
    ' + - '
    ', - $topbar = $(topbarHTML).bootstrapScrollspy() + '
    ' + var $topbar = $(topbarHTML).bootstrapScrollspy() $(sectionHTML).append('#qunit-fixture') ok($topbar.find('.active', true)) @@ -69,12 +71,12 @@ $(function () { '

    ' + '
    ' + '
    ' + - '
    ', - $section = $(sectionHTML).appendTo('#qunit-fixture'), - $scrollSpy = $section + '
    ' + var $section = $(sectionHTML).appendTo('#qunit-fixture') + var $scrollSpy = $section .show() .find('#scrollspy-example') - .bootstrapScrollspy({target: '#ss-target'}) + .bootstrapScrollspy({ target: '#ss-target' }) $scrollSpy.on('scroll.bs.scrollspy', function () { ok($section.hasClass('active'), 'Active class still on root node') @@ -97,12 +99,12 @@ $(function () { '
    ' + '
    ' + '
    ' + - '
    ', - $section = $(sectionHTML).appendTo('#qunit-fixture'), - $scrollSpy = $section + '
    ' + var $section = $(sectionHTML).appendTo('#qunit-fixture') + var $scrollSpy = $section .show() .filter('#content') - $scrollSpy.bootstrapScrollspy({target: '#navigation', offset: $scrollSpy.position().top}) + $scrollSpy.bootstrapScrollspy({ target: '#navigation', offset: $scrollSpy.position().top }) $scrollSpy.on('scroll.bs.scrollspy', function () { ok(!$section.find('#one-link').parent().hasClass('active'), 'Active class removed from first section') diff --git a/js/tests/unit/tab.js b/js/tests/unit/tab.js index 7372b7a17..0c49feeaf 100644 --- a/js/tests/unit/tab.js +++ b/js/tests/unit/tab.js @@ -1,4 +1,5 @@ $(function () { + 'use strict'; module('tabs plugin') @@ -7,11 +8,11 @@ $(function () { }) module('tabs', { - setup: function() { + setup: function () { // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode $.fn.bootstrapTab = $.fn.tab.noConflict() }, - teardown: function() { + teardown: function () { $.fn.tab = $.fn.bootstrapTab delete $.fn.bootstrapTab } diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index 79e120691..466f88a64 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -1,4 +1,5 @@ $(function () { + 'use strict'; module('tooltip plugin') @@ -8,11 +9,11 @@ $(function () { }) module('tooltip', { - setup: function() { + setup: function () { // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode $.fn.bootstrapTooltip = $.fn.tooltip.noConflict() }, - teardown: function() { + teardown: function () { $.fn.tooltip = $.fn.bootstrapTooltip delete $.fn.bootstrapTooltip } @@ -41,7 +42,7 @@ $(function () { equal(tooltip.attr('data-original-title'), 'Another tooltip', 'original title preserved in data attribute') }) - test('should add set set aria describedby to the element called on show', function() { + test('should add set set aria describedby to the element called on show', function () { var tooltip = $('').bootstrapTooltip() .appendTo('#qunit-fixture') .bootstrapTooltip('show') @@ -53,7 +54,7 @@ $(function () { ok(tooltip.attr('aria-describedby') !== undefined, 'has the right attributes') }) - test('should remove the aria-describedby attributes on hide', function() { + test('should remove the aria-describedby attributes on hide', function () { var tooltip = $('').bootstrapTooltip() .appendTo('#qunit-fixture') .bootstrapTooltip('show') @@ -65,17 +66,17 @@ $(function () { test('should assign a unique id tooltip element', function () { $('') .appendTo('#qunit-fixture') - .bootstrapTooltip('show'), - id = $('.tooltip').attr('id') + .bootstrapTooltip('show') + var id = $('.tooltip').attr('id') - ok( $('#' + id).length == 1 && id.indexOf('tooltip') === 0, 'generated prefixed and unique tooltip id') + ok($('#' + id).length == 1 && id.indexOf('tooltip') === 0, 'generated prefixed and unique tooltip id') }) test('should place tooltips relative to placement option', function () { $.support.transition = false var tooltip = $('') .appendTo('#qunit-fixture') - .bootstrapTooltip({placement: 'bottom'}) + .bootstrapTooltip({ placement: 'bottom' }) .bootstrapTooltip('show') ok($('.tooltip').is('.fade.bottom.in'), 'has correct classes applied') @@ -86,7 +87,7 @@ $(function () { $.support.transition = false var tooltip = $('') .appendTo('#qunit-fixture') - .bootstrapTooltip({html: true}) + .bootstrapTooltip({ html: true }) .bootstrapTooltip('show') ok($('.tooltip b').length, 'b tag was inserted') @@ -97,7 +98,7 @@ $(function () { test('should respect custom classes', function () { var tooltip = $('') .appendTo('#qunit-fixture') - .bootstrapTooltip({ template: '
    '}) + .bootstrapTooltip({ template: '
    ' }) .bootstrapTooltip('show') ok($('.tooltip').hasClass('some-class'), 'custom class is present') @@ -204,7 +205,7 @@ $(function () { test('should not show tooltip if leave event occurs before delay expires, even if hide delay is 0', function () { var tooltip = $('') .appendTo('#qunit-fixture') - .bootstrapTooltip({ delay: { show: 200, hide: 0} }) + .bootstrapTooltip({ delay: { show: 200, hide: 0 }}) stop() @@ -223,7 +224,7 @@ $(function () { test('should wait 200 ms before hiding the tooltip', 3, function () { var tooltip = $('') .appendTo('#qunit-fixture') - .bootstrapTooltip({ delay: { show: 0, hide: 200} }) + .bootstrapTooltip({ delay: { show: 0, hide: 200 }}) stop() @@ -245,7 +246,7 @@ $(function () { test('should not hide tooltip if leave event occurs, then tooltip is show immediately again', function () { var tooltip = $('') .appendTo('#qunit-fixture') - .bootstrapTooltip({ delay: { show: 0, hide: 200} }) + .bootstrapTooltip({ delay: { show: 0, hide: 200 }}) stop() @@ -320,7 +321,7 @@ $(function () { test('should show tooltip when toggle is called', function () { $('') .appendTo('#qunit-fixture') - .bootstrapTooltip({trigger: 'manual'}) + .bootstrapTooltip({ trigger: 'manual' }) .bootstrapTooltip('toggle') ok($('.tooltip').is('.fade.in'), 'tooltip should be toggled in') }) @@ -328,7 +329,7 @@ $(function () { test('should hide shown tooltip when toggle is called on tooltip', function () { var tooltip = $('@ResentedHook') .appendTo('#qunit-fixture') - .bootstrapTooltip({trigger: 'manual'}) + .bootstrapTooltip({ trigger: 'manual' }) .bootstrapTooltip('toggle') $('.tooltip', '#qunit-fixture').bootstrapTooltip('toggle') ok($('.tooltip').not('.fade.in'), 'tooltip should be toggled out') @@ -339,7 +340,7 @@ $(function () { test('should place tooltips inside the body', function () { var tooltip = $('') .appendTo('#qunit-fixture') - .bootstrapTooltip({container: 'body'}) + .bootstrapTooltip({ container: 'body' }) .bootstrapTooltip('show') ok($('body > .tooltip').length, 'inside the body') ok(!$('#qunit-fixture > .tooltip').length, 'not found in parent') @@ -348,11 +349,11 @@ $(function () { test('should place tooltip inside window', function () { var container = $('
    ').appendTo('body') - .css({position: 'absolute', width: 200, height: 200, bottom: 0, left: 0}) + .css({ position: 'absolute', width: 200, height: 200, bottom: 0, left: 0 }) $('Hover me') - .css({position: 'absolute', top: 0, left: 0}) + .css({ position: 'absolute', top: 0, left: 0 }) .appendTo(container) - .bootstrapTooltip({placement: 'top', animate: false}) + .bootstrapTooltip({ placement: 'top', animate: false }) .bootstrapTooltip('show') stop() @@ -367,12 +368,12 @@ $(function () { test('should place tooltip on top of element', function () { var container = $('
    ').appendTo('body') - .css({position: 'absolute', bottom: 0, left: 0, textAlign: 'right', width: 300, height: 300}), - p = $('

    ').appendTo(container), - tooltiped = $('Hover me') - .css({marginTop: 200}) + .css({ position: 'absolute', bottom: 0, left: 0, textAlign: 'right', width: 300, height: 300 }) + var p = $('

    ').appendTo(container) + var tooltiped = $('Hover me') + .css({ marginTop: 200 }) .appendTo(p) - .bootstrapTooltip({placement: 'top', animate: false}) + .bootstrapTooltip({ placement: 'top', animate: false }) .bootstrapTooltip('show') stop() @@ -389,17 +390,17 @@ $(function () { test('should add position class before positioning so that position-specific styles are taken into account', function () { $('head').append('') - var container = $('

    ').appendTo('body'), - target = $('') + var container = $('
    ').appendTo('body') + var target = $('') .appendTo(container) - .bootstrapTooltip({placement: 'right', viewport: null}) - .bootstrapTooltip('show'), - tooltip = container.find('.tooltip') + .bootstrapTooltip({ placement: 'right', viewport: null }) + .bootstrapTooltip('show') + var tooltip = container.find('.tooltip') // this is some dumb hack shit because sub pixels in firefox var top = Math.round(target.offset().top + (target[0].offsetHeight / 2) - (tooltip[0].offsetHeight / 2)) var top2 = Math.round(tooltip.offset().top) - var topDiff = top - top2 + var topDiff = top - top2 ok(topDiff <= 1 && topDiff >= -1) target.bootstrapTooltip('hide') $('head #test').remove() @@ -453,7 +454,7 @@ $(function () { var topTooltip = $('
    Top Dynamic Tooltip
    ') .appendTo('#dynamic-tt-test') - .bootstrapTooltip({placement: 'auto'}) + .bootstrapTooltip({ placement: 'auto' }) .bootstrapTooltip('show') ok($('.tooltip').is('.bottom'), 'top positioned tooltip is dynamically positioned bottom') @@ -462,7 +463,7 @@ $(function () { var rightTooltip = $('
    Right Dynamic Tooltip
    ') .appendTo('#dynamic-tt-test') - .bootstrapTooltip({placement: 'right auto'}) + .bootstrapTooltip({ placement: 'right auto' }) .bootstrapTooltip('show') ok($('.tooltip').is('.left'), 'right positioned tooltip is dynamically positioned left') @@ -470,7 +471,7 @@ $(function () { var leftTooltip = $('
    Left Dynamic Tooltip
    ') .appendTo('#dynamic-tt-test') - .bootstrapTooltip({placement: 'auto left'}) + .bootstrapTooltip({ placement: 'auto left' }) .bootstrapTooltip('show') ok($('.tooltip').is('.right'), 'left positioned tooltip is dynamically positioned right') @@ -482,14 +483,14 @@ $(function () { test('should adjust the tip\'s top when up against the top of the viewport', function () { $('head').append('') - var container = $('
    ').appendTo('body'), - target = $('') + var container = $('
    ').appendTo('body') + var target = $('') .appendTo(container) - .bootstrapTooltip({placement: 'right', viewport: {selector: 'body', padding: 12}}) - .bootstrapTooltip('show'), - tooltip = container.find('.tooltip') + .bootstrapTooltip({ placement: 'right', viewport: { selector: 'body', padding: 12 }}) + .bootstrapTooltip('show') + var tooltip = container.find('.tooltip') - ok( Math.round(tooltip.offset().top) === 12 ) + ok(Math.round(tooltip.offset().top) === 12) target.bootstrapTooltip('hide') $('head #test').remove() }) @@ -497,14 +498,14 @@ $(function () { test('should adjust the tip\'s top when up against the bottom of the viewport', function () { $('head').append('') - var container = $('
    ').appendTo('body'), - target = $('') + var container = $('
    ').appendTo('body') + var target = $('') .appendTo(container) - .bootstrapTooltip({placement: 'right', viewport: {selector: 'body', padding: 12}}) - .bootstrapTooltip('show'), - tooltip = container.find('.tooltip') + .bootstrapTooltip({ placement: 'right', viewport: { selector: 'body', padding: 12 }}) + .bootstrapTooltip('show') + var tooltip = container.find('.tooltip') - ok( Math.round(tooltip.offset().top) === Math.round($(window).height() - 12 - tooltip[0].offsetHeight) ) + ok(Math.round(tooltip.offset().top) === Math.round($(window).height() - 12 - tooltip[0].offsetHeight)) target.bootstrapTooltip('hide') $('head #test').remove() }) @@ -512,14 +513,14 @@ $(function () { test('should adjust the tip\'s left when up against the left of the viewport', function () { $('head').append('') - var container = $('
    ').appendTo('body'), - target = $('') + var container = $('
    ').appendTo('body') + var target = $('') .appendTo(container) - .bootstrapTooltip({placement: 'bottom', viewport: {selector: 'body', padding: 12}}) - .bootstrapTooltip('show'), - tooltip = container.find('.tooltip') + .bootstrapTooltip({ placement: 'bottom', viewport: { selector: 'body', padding: 12 }}) + .bootstrapTooltip('show') + var tooltip = container.find('.tooltip') - ok( Math.round(tooltip.offset().left) === 12 ) + ok(Math.round(tooltip.offset().left) === 12) target.bootstrapTooltip('hide') $('head #test').remove() }) @@ -527,14 +528,14 @@ $(function () { test('should adjust the tip\'s left when up against the right of the viewport', function () { $('head').append('') - var container = $('
    ').appendTo('body'), - target = $('') + var container = $('
    ').appendTo('body') + var target = $('') .appendTo(container) - .bootstrapTooltip({placement: 'bottom', viewport: {selector: 'body', padding: 12}}) - .bootstrapTooltip('show'), - tooltip = container.find('.tooltip') + .bootstrapTooltip({ placement: 'bottom', viewport: { selector: 'body', padding: 12 }}) + .bootstrapTooltip('show') + var tooltip = container.find('.tooltip') - ok( Math.round(tooltip.offset().left) === Math.round($(window).width() - 12 - tooltip[0].offsetWidth) ) + ok(Math.round(tooltip.offset().left) === Math.round($(window).width() - 12 - tooltip[0].offsetWidth)) target.bootstrapTooltip('hide') $('head #test').remove() }) @@ -543,14 +544,14 @@ $(function () { $('head').append('') $('head').append('') - var container = $('
    ', {class: 'container-viewport'}).appendTo('body'), - target = $('') + var container = $('
    ', { 'class': 'container-viewport' }).appendTo('body') + var target = $('') .appendTo(container) - .bootstrapTooltip({placement: 'bottom', viewport: '.container-viewport'}) - .bootstrapTooltip('show'), - tooltip = container.find('.tooltip') + .bootstrapTooltip({ placement: 'bottom', viewport: '.container-viewport' }) + .bootstrapTooltip('show') + var tooltip = container.find('.tooltip') - ok( Math.round(tooltip.offset().left) === Math.round(60 + container.width() - tooltip[0].offsetWidth) ) + ok(Math.round(tooltip.offset().left) === Math.round(60 + container.width() - tooltip[0].offsetWidth)) target.bootstrapTooltip('hide') $('head #test').remove() $('head #viewport-style').remove() -- cgit v1.2.3 From e2cabe4971927e3dbbbda4c81ae8f74abdee2d15 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Thu, 29 May 2014 07:35:22 +0300 Subject: Minor style tweaks. --- js/tests/unit/affix.js | 4 +++- js/tests/unit/popover.js | 4 +++- js/tests/unit/tooltip.js | 17 +++++++++-------- 3 files changed, 15 insertions(+), 10 deletions(-) (limited to 'js/tests/unit') diff --git a/js/tests/unit/affix.js b/js/tests/unit/affix.js index 03f25eb59..1cdfc7f90 100644 --- a/js/tests/unit/affix.js +++ b/js/tests/unit/affix.js @@ -54,7 +54,9 @@ $(function () { setTimeout(function () { window.scrollTo(0, document.body.scrollHeight) - setTimeout(function () { window.scroll(0, 0) }, 0) + setTimeout(function () { + window.scroll(0, 0) + }, 0) }, 0) }) }) diff --git a/js/tests/unit/popover.js b/js/tests/unit/popover.js index 2ccf2cbbf..16f94e143 100644 --- a/js/tests/unit/popover.js +++ b/js/tests/unit/popover.js @@ -167,7 +167,9 @@ $(function () { }) test('should destroy popover', function () { - var popover = $('
    ').bootstrapPopover({ trigger: 'hover' }).on('click.foo', function () {}) + var popover = $('
    ').bootstrapPopover({ + trigger: 'hover' + }).on('click.foo', function () {}) ok(popover.data('bs.popover'), 'popover has data') 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') diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index 466f88a64..2e175583e 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -312,8 +312,9 @@ $(function () { test('should show tooltip with delegate selector on click', function () { var div = $('
    ') - div.appendTo('#qunit-fixture') - .bootstrapTooltip({ selector: 'a[rel="tooltip"]', trigger: 'click' }) + div.appendTo('#qunit-fixture').bootstrapTooltip({ + selector: 'a[rel="tooltip"]', trigger: 'click' + }) div.find('a').trigger('click') ok($('.tooltip').is('.fade.in'), 'tooltip is faded in') }) @@ -443,12 +444,12 @@ $(function () { test('tooltips should be placed dynamically, with the dynamic placement option', function () { $.support.transition = false var ttContainer = $('
    ').css({ - height : 400, - overflow : 'hidden', - position : 'absolute', - top : 0, - left : 0, - width : 600 + height: 400, + overflow: 'hidden', + position: 'absolute', + top: 0, + left: 0, + width: 600 }) .appendTo('body') -- cgit v1.2.3 From 20c099d41a0802a7f377e7f996c35cade9e0c431 Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Fri, 6 Jun 2014 14:49:59 -0700 Subject: add failing test for #13268 --- js/tests/unit/tooltip.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'js/tests/unit') diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index 2e175583e..81c0fdf73 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -557,4 +557,31 @@ $(function () { $('head #test').remove() $('head #viewport-style').remove() }) + + test('should not error when trying to show an auto-placed tooltip that has been removed from the dom', function () { + var tooltip = $('').appendTo('#qunit-fixture') + + tooltip + .one('show.bs.tooltip', function () { + tooltip.remove() + }) + .bootstrapTooltip({ placement: 'auto' }) + + var passed = true + try { + tooltip.bootstrapTooltip('show') + } + catch (err) { + passed = false + console.log(err) + } + ok(passed, '.tooltip(\'show\') should not throw an error in this case') + + try { + tooltip.remove() + } + catch (err) { + // tooltip may have already been removed + } + }) }) -- cgit v1.2.3 From b23ed1b034caa90a4f6d0f97674022c80126d078 Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Fri, 6 Jun 2014 15:30:44 -0700 Subject: put the tooltips into the DOM in the tooltip unit tests --- js/tests/unit/tooltip.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'js/tests/unit') diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index 81c0fdf73..f4c840d84 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -118,9 +118,11 @@ $(function () { test('should fire shown event', function () { stop() - $('
    ') + var tooltip = $('
    ').appendTo('#qunit-fixture') + tooltip .on('shown.bs.tooltip', function () { ok(true, 'shown was called') + tooltip.remove() start() }) .bootstrapTooltip('show') @@ -142,12 +144,14 @@ $(function () { test('should fire hide event', function () { stop() - $('
    ') + var tooltip = $('
    ').appendTo('#qunit-fixture') + tooltip .on('shown.bs.tooltip', function () { $(this).bootstrapTooltip('hide') }) .on('hide.bs.tooltip', function () { ok(true, 'hide was called') + tooltip.remove() start() }) .bootstrapTooltip('show') @@ -155,12 +159,14 @@ $(function () { test('should fire hidden event', function () { stop() - $('
    ') + var tooltip = $('
    ').appendTo('#qunit-fixture') + tooltip .on('shown.bs.tooltip', function () { $(this).bootstrapTooltip('hide') }) .on('hidden.bs.tooltip', function () { ok(true, 'hidden was called') + tooltip.remove() start() }) .bootstrapTooltip('show') @@ -168,13 +174,15 @@ $(function () { test('should not fire hidden event when default prevented', function () { stop() - $('
    ') + var tooltip = $('
    ').appendTo('#qunit-fixture') + tooltip .on('shown.bs.tooltip', function () { $(this).bootstrapTooltip('hide') }) .on('hide.bs.tooltip', function (e) { e.preventDefault() ok(true, 'hide was called') + tooltip.remove() start() }) .on('hidden.bs.tooltip', function () { -- cgit v1.2.3 From 121bf6633e8704df0d69a1e44a6fbbc2dbe6f8d2 Mon Sep 17 00:00:00 2001 From: Heinrich Fenkart Date: Thu, 19 Jun 2014 00:50:25 +0200 Subject: Use mousedown instead of click for backdrop click detection; fixes #13816 --- js/tests/unit/modal.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/tests/unit') diff --git a/js/tests/unit/modal.js b/js/tests/unit/modal.js index a415129aa..35a92a33b 100644 --- a/js/tests/unit/modal.js +++ b/js/tests/unit/modal.js @@ -154,7 +154,7 @@ $(function () { ok($('#modal-test').length, 'modal insterted into dom') $('.contents').click() ok($('#modal-test').is(':visible'), 'modal visible') - $('#modal-test').click() + $('#modal-test').mousedown() }) .on('hidden.bs.modal', function () { ok(!$('#modal-test').is(':visible'), 'modal hidden') @@ -174,7 +174,7 @@ $(function () { div .on('shown.bs.modal', function () { triggered = 0 - $('#modal-test').click() + $('#modal-test').mousedown() }) .on('hide.bs.modal', function () { triggered += 1 -- cgit v1.2.3 From 91f329e4488c667c04ea0f3ccc8dc11aaa7124ef Mon Sep 17 00:00:00 2001 From: Heinrich Fenkart Date: Tue, 1 Jul 2014 05:50:31 +0200 Subject: Only close modal if escape was hit with keydown; fixes #13929 --- js/tests/unit/modal.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'js/tests/unit') diff --git a/js/tests/unit/modal.js b/js/tests/unit/modal.js index a415129aa..5ee58616f 100644 --- a/js/tests/unit/modal.js +++ b/js/tests/unit/modal.js @@ -164,6 +164,44 @@ $(function () { .bootstrapModal('show') }) + test('should close modal when escape key is pressed via keydown', function () { + stop() + + var div = $('