From df96c3e615919c008c113187ef07530a3bdc9f6f Mon Sep 17 00:00:00 2001 From: Adrien Jarthon Date: Sun, 29 Mar 2015 14:59:21 +0200 Subject: Added non-regression test & fixed existing one --- js/tests/unit/tooltip.js | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) (limited to 'js/tests/unit') diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index 57a59db18..21d264195 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -362,23 +362,19 @@ $(function () { assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom') }) - QUnit.test('should be placed dynamically with the dynamic placement option', function (assert) { + QUnit.test('should be placed dynamically to viewport with the dynamic placement option', function (assert) { assert.expect(6) - var $style = $('') + var $style = $('').appendTo('head') var $container = $('
') .css({ - position: 'absolute', - overflow: 'hidden', - width: 600, - height: 400, - top: 0, - left: 0 + position: 'relative', + height: '100%' }) - .appendTo(document.body) + .appendTo('#qunit-fixture') var $topTooltip = $('
Top Dynamic Tooltip
') .appendTo($container) - .bootstrapTooltip({ placement: 'auto' }) + .bootstrapTooltip({ placement: 'auto', viewport: '#qunit-fixture' }) $topTooltip.bootstrapTooltip('show') assert.ok($('.tooltip').is('.bottom'), 'top positioned tooltip is dynamically positioned to bottom') @@ -388,7 +384,7 @@ $(function () { var $rightTooltip = $('
Right Dynamic Tooltip
') .appendTo($container) - .bootstrapTooltip({ placement: 'right auto' }) + .bootstrapTooltip({ placement: 'right auto', viewport: '#qunit-fixture' }) $rightTooltip.bootstrapTooltip('show') assert.ok($('.tooltip').is('.left'), 'right positioned tooltip is dynamically positioned left') @@ -398,7 +394,7 @@ $(function () { var $leftTooltip = $('
Left Dynamic Tooltip
') .appendTo($container) - .bootstrapTooltip({ placement: 'auto left' }) + .bootstrapTooltip({ placement: 'auto left', viewport: '#qunit-fixture' }) $leftTooltip.bootstrapTooltip('show') assert.ok($('.tooltip').is('.right'), 'left positioned tooltip is dynamically positioned right') @@ -436,6 +432,31 @@ $(function () { $styles.remove() }) + QUnit.test('should position tip on top if viewport has enough space and is not parent', function (assert) { + assert.expect(2) + var styles = '' + var $styles = $(styles).appendTo('head') + + var $container = $('
').appendTo('#qunit-fixture') + var $target = $('
') + .appendTo($container) + .bootstrapTooltip({ + placement: 'auto top', + viewport: '#qunit-fixture' + }) + + $target.bootstrapTooltip('show') + assert.ok($('.tooltip').is('.top'), 'top positioned tooltip is dynamically positioned to top') + + $target.bootstrapTooltip('hide') + assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom') + + $styles.remove() + }) + QUnit.test('should position tip on bottom if the tip\'s dimension exceeds the viewport area and placement is "auto top"', function (assert) { assert.expect(2) var styles = '').appendTo('head') + var $style = $('').appendTo('head') var $container = $('
') .css({ position: 'relative', -- cgit v1.2.3 From 3d71eae3011b10daa558baf494b019925fee5f60 Mon Sep 17 00:00:00 2001 From: Johann-S Date: Tue, 24 Mar 2015 20:47:35 +0100 Subject: Add event after template inserted --- js/tests/unit/popover.js | 17 +++++++++++++++++ js/tests/unit/tooltip.js | 14 ++++++++++++++ 2 files changed, 31 insertions(+) (limited to 'js/tests/unit') diff --git a/js/tests/unit/popover.js b/js/tests/unit/popover.js index fbabab9e3..2c3fd0cb0 100644 --- a/js/tests/unit/popover.js +++ b/js/tests/unit/popover.js @@ -259,4 +259,21 @@ $(function () { assert.strictEqual($popover.data('bs.popover'), undefined, 'should not initialize the popover') }) + QUnit.test('should fire inserted event', function (assert) { + assert.expect(2) + var done = assert.async() + + $('@Johann-S') + .appendTo('#qunit-fixture') + .on('inserted.bs.popover', function () { + assert.notEqual($('.popover').length, 0, 'popover was inserted') + assert.ok(true, 'inserted event fired') + done() + }) + .bootstrapPopover({ + title: 'Test', + content: 'Test' + }) + .bootstrapPopover('show') + }) }) diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index 57a59db18..8086631c8 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -139,6 +139,20 @@ $(function () { .bootstrapTooltip('show') }) + QUnit.test('should fire inserted event', function (assert) { + assert.expect(2) + var done = assert.async() + + $('
') + .appendTo('#qunit-fixture') + .on('inserted.bs.tooltip', function () { + assert.notEqual($('.tooltip').length, 0, 'tooltip was inserted') + assert.ok(true, 'inserted event fired') + done() + }) + .bootstrapTooltip('show') + }) + QUnit.test('should fire shown event', function (assert) { assert.expect(1) var done = assert.async() -- cgit v1.2.3 From 66d71136e668cf7bc8a311299fad9b773b76285a Mon Sep 17 00:00:00 2001 From: "Patrick H. Lauke" Date: Sat, 11 Apr 2015 19:24:21 +0200 Subject: Fix existing radio button unit test --- js/tests/unit/button.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/tests/unit') diff --git a/js/tests/unit/button.js b/js/tests/unit/button.js index 02312ebaf..ed7b248d4 100644 --- a/js/tests/unit/button.js +++ b/js/tests/unit/button.js @@ -167,13 +167,13 @@ $(function () { assert.ok(!$btn2.find('input').prop('checked'), 'btn2 is not checked') $btn2.find('input').trigger('click') assert.ok(!$btn1.hasClass('active'), 'btn1 does not have active class') - assert.ok(!$btn1.find('input').prop('checked'), 'btn1 is checked') + assert.ok(!$btn1.find('input').prop('checked'), 'btn1 is not checked') assert.ok($btn2.hasClass('active'), 'btn2 has active class') assert.ok($btn2.find('input').prop('checked'), 'btn2 is checked') $btn2.find('input').trigger('click') // clicking an already checked radio should not un-check it assert.ok(!$btn1.hasClass('active'), 'btn1 does not have active class') - assert.ok(!$btn1.find('input').prop('checked'), 'btn1 is checked') + assert.ok(!$btn1.find('input').prop('checked'), 'btn1 is not checked') assert.ok($btn2.hasClass('active'), 'btn2 has active class') assert.ok($btn2.find('input').prop('checked'), 'btn2 is checked') }) -- cgit v1.2.3 From e949505b89ca146e3af0cf735e100c82703f1cda Mon Sep 17 00:00:00 2001 From: Adrien Siami Date: Wed, 25 Mar 2015 14:46:21 +0100 Subject: Allow viewport option to be a function Closes #16151 by merging a rebased version of it that adds docs and 1 more assertion. --- js/tests/unit/tooltip.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'js/tests/unit') diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index 8086631c8..0cb964e9b 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -733,6 +733,37 @@ $(function () { $styles.remove() }) + QUnit.test('should get viewport element from function', function (assert) { + assert.expect(3) + var styles = '' + var $styles = $(styles).appendTo('head') + + var $container = $('
').appendTo(document.body) + var $target = $('').appendTo($container) + $target + .bootstrapTooltip({ + placement: 'bottom', + viewport: function ($element) { + assert.strictEqual($element[0], $target[0], 'viewport function was passed target as argument') + return ($element.closest('.container-viewport')) + } + }) + + $target.bootstrapTooltip('show') + var $tooltip = $container.find('.tooltip') + assert.strictEqual(Math.round($tooltip.offset().left), Math.round(60 + $container.width() - $tooltip[0].offsetWidth)) + + $target.bootstrapTooltip('hide') + assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom') + + $container.remove() + $styles.remove() + }) + QUnit.test('should not error when trying to show an auto-placed tooltip that has been removed from the dom', function (assert) { assert.expect(1) var passed = true -- cgit v1.2.3 From fc372952e2983934dda338ffefd705112db8008a Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Tue, 21 Apr 2015 17:41:06 -0700 Subject: Throw error when tooltip/popover template has multiple top-level elements Closes #16219. --- js/tests/unit/popover.js | 11 +++++++++++ js/tests/unit/tooltip.js | 10 ++++++++++ 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 2c3fd0cb0..a25df3a58 100644 --- a/js/tests/unit/popover.js +++ b/js/tests/unit/popover.js @@ -259,6 +259,16 @@ $(function () { assert.strictEqual($popover.data('bs.popover'), undefined, 'should not initialize the popover') }) + QUnit.test('should throw an error when template contains multiple top-level elements', function (assert) { + assert.expect(1) + assert.throws(function () { + $('some text') + .appendTo('#qunit-fixture') + .bootstrapPopover({ template: '
Foo
Bar
' }) + .bootstrapPopover('show') + }, new Error('popover `template` option must consist of exactly 1 top-level element!')) + }) + QUnit.test('should fire inserted event', function (assert) { assert.expect(2) var done = assert.async() @@ -276,4 +286,5 @@ $(function () { }) .bootstrapPopover('show') }) + }) diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index 0cb964e9b..2c492a92b 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -1225,4 +1225,14 @@ $(function () { assert.strictEqual($tooltip.data('bs.tooltip'), undefined, 'should not initialize the tooltip') }) + QUnit.test('should throw an error when template contains multiple top-level elements', function (assert) { + assert.expect(1) + assert.throws(function () { + $('
') + .appendTo('#qunit-fixture') + .bootstrapTooltip({ template: '
Foo
Bar
' }) + .bootstrapTooltip('show') + }, new Error('tooltip `template` option must consist of exactly 1 top-level element!')) + }) + }) -- cgit v1.2.3 From 37a10d37c17c051830cdd2ecec698d28c0984603 Mon Sep 17 00:00:00 2001 From: Adrien Date: Tue, 24 Mar 2015 17:12:52 +0100 Subject: Compare tooltip right offset to viewport right offset (and not width) Closes #16142 by merging it. --- 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 2c492a92b..711eba8ec 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -764,6 +764,33 @@ $(function () { $styles.remove() }) + QUnit.test('should not misplace the tip when the right edge offset is greater or equal than the viewport width', function (assert) { + assert.expect(2) + var styles = '' + var $styles = $(styles).appendTo('head') + + var $container = $('
').appendTo(document.body) + var $target = $('foobar') + .appendTo($container) + .bootstrapTooltip({ + viewport: '.container-viewport' + }) + + $target.bootstrapTooltip('show') + var $tooltip = $container.find('.tooltip') + assert.strictEqual(Math.round($tooltip.offset().left), Math.round($target.position().left + $target.width() / 2 - $tooltip[0].offsetWidth / 2)) + + $target.bootstrapTooltip('hide') + assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom') + + $container.remove() + $styles.remove() + }) + QUnit.test('should not error when trying to show an auto-placed tooltip that has been removed from the dom', function (assert) { assert.expect(1) var passed = true -- cgit v1.2.3 From cdb37dce3a85c07790e73b7e2c809860db6b0cad Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Mon, 27 Apr 2015 01:22:07 -0700 Subject: Set `box-sizing: border-box` on .container-viewport in #16142 testcase Otherwise, the test doesn't properly fail when the fix is reverted. --- js/tests/unit/tooltip.js | 1 + 1 file changed, 1 insertion(+) (limited to 'js/tests/unit') diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index 711eba8ec..51cfcb933 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -768,6 +768,7 @@ $(function () { assert.expect(2) var styles = '' -- cgit v1.2.3 From 4b269037cb42cce7898d57890db40ef0cc3bd5f8 Mon Sep 17 00:00:00 2001 From: "Braden M. Kelley" Date: Fri, 6 Mar 2015 17:52:59 -0800 Subject: Multiple tooltip triggers don't play well together Fixes issue #16008 --- js/tests/unit/tooltip.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'js/tests/unit') diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index bdcf0bbd0..27ce6208e 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -1284,4 +1284,42 @@ $(function () { }, new Error('tooltip `template` option must consist of exactly 1 top-level element!')) }) + QUnit.test('should not remove tooltip if multiple triggers are set and one is still active', function (assert) { + assert.expect(41) + var $el = $('') + .appendTo('#qunit-fixture') + .bootstrapTooltip({ trigger: 'click hover focus', animation: false }) + var tooltip = $el.data('bs.tooltip') + var $tooltip = tooltip.tip() + + function showingTooltip() { return $tooltip.hasClass('in') || tooltip.hoverState == 'in' } + + var tests = [ + ['mouseenter', 'mouseleave'], + + ['focusin', 'focusout'], + + ['click', 'click'], + + ['mouseenter', 'focusin', 'focusout', 'mouseleave'], + ['mouseenter', 'focusin', 'mouseleave', 'focusout'], + + ['focusin', 'mouseenter', 'mouseleave', 'focusout'], + ['focusin', 'mouseenter', 'focusout', 'mouseleave'], + + ['click', 'focusin', 'mouseenter', 'focusout', 'mouseleave', 'click'], + ['mouseenter', 'click', 'focusin', 'focusout', 'mouseleave', 'click'], + ['mouseenter', 'focusin', 'click', 'click', 'mouseleave', 'focusout'] + ] + + assert.ok(!showingTooltip()) + + $.each(tests, function (idx, triggers) { + for (var i = 0, len = triggers.length; i < len; i++) { + $el.trigger(triggers[i]); + assert.equal(i < (len - 1), showingTooltip()) + } + }) + }) + }) -- cgit v1.2.3 From 0c1daaf2cec70778fb093280becb0627155fbef4 Mon Sep 17 00:00:00 2001 From: "Patrick H. Lauke" Date: Fri, 1 May 2015 12:55:58 +0100 Subject: Remove broken/vestigial unit test Overall logic for this test appears broken, possibly relating to an older version of Bootstrap that did not require explicit `data-toggle="button"` on single toggle buttons? --- js/tests/unit/button.js | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'js/tests/unit') diff --git a/js/tests/unit/button.js b/js/tests/unit/button.js index ed7b248d4..691796c42 100644 --- a/js/tests/unit/button.js +++ b/js/tests/unit/button.js @@ -130,19 +130,6 @@ $(function () { assert.strictEqual($btn.attr('aria-pressed'), 'true', 'btn aria-pressed state is true') }) - QUnit.test('should toggle active when btn children are clicked within btn-group', function (assert) { - assert.expect(2) - var $btngroup = $('
') - var $btn = $('') - var $inner = $('') - $btngroup - .append($btn.append($inner)) - .appendTo('#qunit-fixture') - assert.ok(!$btn.hasClass('active'), 'btn does not have active class') - $inner.trigger('click') - assert.ok($btn.hasClass('active'), 'btn has class active') - }) - QUnit.test('should check for closest matching toggle', function (assert) { assert.expect(12) var groupHTML = '
' -- cgit v1.2.3 From 49c45563546af97eaab0c6f083d68fbc3b4a0ce6 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Wed, 29 Apr 2015 12:11:58 +0300 Subject: Comply to the new JSCS rules. --- js/tests/unit/modal.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'js/tests/unit') diff --git a/js/tests/unit/modal.js b/js/tests/unit/modal.js index 3c51c2fe2..217e4d7f7 100644 --- a/js/tests/unit/modal.js +++ b/js/tests/unit/modal.js @@ -166,16 +166,16 @@ $(function () { assert.expect(3) var done = assert.async() - var div = $('