Skip to content

Commit 69de651

Browse files
committed
Fix unit tests + Update Popper to 1.6.0
1 parent c21a2b0 commit 69de651

File tree

8 files changed

+70
-97
lines changed

8 files changed

+70
-97
lines changed

docs/assets/js/vendor/popper.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/src/dropdown.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* global Popper */
2+
13
import Util from './util'
24

35

@@ -64,7 +66,7 @@ const Dropdown = (($) => {
6466

6567
const Default = {
6668
placement : 'bottom',
67-
offset : {}
69+
offset : 0
6870
}
6971

7072
const DefaultType = {
@@ -143,7 +145,7 @@ const Dropdown = (($) => {
143145
placement : context._config.placement,
144146
modifiers : {
145147
offset : {
146-
offset : this.config.offset
148+
offset : context._config.offset
147149
}
148150
}
149151
})
@@ -204,7 +206,7 @@ const Dropdown = (($) => {
204206

205207
_getMenuElement() {
206208
if (!this._menu) {
207-
let parent = Dropdown._getParentFromElement(this._element)
209+
const parent = Dropdown._getParentFromElement(this._element)
208210
this._menu = $(parent).find(Selector.MENU)[0]
209211
}
210212
return this._menu
@@ -215,7 +217,7 @@ const Dropdown = (($) => {
215217
static _jQueryInterface(config) {
216218
return this.each(function () {
217219
let data = $(this).data(DATA_KEY)
218-
let _config = typeof config === 'object' ? config : null
220+
const _config = typeof config === 'object' ? config : null
219221

220222
if (!data) {
221223
data = new Dropdown(this, _config)
@@ -240,7 +242,7 @@ const Dropdown = (($) => {
240242
const toggles = $.makeArray($(Selector.DATA_TOGGLE))
241243
for (let i = 0; i < toggles.length; i++) {
242244
const parent = Dropdown._getParentFromElement(toggles[i])
243-
let context = $(toggles[i]).data(DATA_KEY)
245+
const context = $(toggles[i]).data(DATA_KEY)
244246
const relatedTarget = {
245247
relatedTarget : toggles[i]
246248
}
@@ -249,7 +251,7 @@ const Dropdown = (($) => {
249251
continue
250252
}
251253

252-
let dropdownMenu = context._menu
254+
const dropdownMenu = context._menu
253255
if (!$(parent).hasClass(ClassName.SHOW)) {
254256
continue
255257
}

js/src/tooltip.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const Tooltip = (($) => {
4747
html : false,
4848
selector : false,
4949
placement : 'top',
50-
offset : {},
50+
offset : 0,
5151
container : false
5252
}
5353

js/tests/unit/dropdown.js

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -275,20 +275,20 @@ $(function () {
275275
$first.parent('.dropdown')
276276
.on('shown.bs.dropdown', function () {
277277
assert.strictEqual($first.parents('.show').length, 1, '"show" class added on click')
278-
assert.strictEqual($('#qunit-fixture .show').length, 1, 'only one dropdown is shown')
278+
assert.strictEqual($('#qunit-fixture .dropdown-menu.show').length, 1, 'only one dropdown is shown')
279279
$(document.body).trigger('click')
280280
}).on('hidden.bs.dropdown', function () {
281-
assert.strictEqual($('#qunit-fixture .show').length, 0, '"show" class removed')
281+
assert.strictEqual($('#qunit-fixture .dropdown-menu.show').length, 0, '"show" class removed')
282282
$last.trigger('click')
283283
})
284284

285285
$last.parent('.btn-group')
286286
.on('shown.bs.dropdown', function () {
287287
assert.strictEqual($last.parent('.show').length, 1, '"show" class added on click')
288-
assert.strictEqual($('#qunit-fixture .show').length, 1, 'only one dropdown is shown')
288+
assert.strictEqual($('#qunit-fixture .dropdown-menu.show').length, 1, 'only one dropdown is shown')
289289
$(document.body).trigger('click')
290290
}).on('hidden.bs.dropdown', function () {
291-
assert.strictEqual($('#qunit-fixture .show').length, 0, '"show" class removed')
291+
assert.strictEqual($('#qunit-fixture .dropdown-menu.show').length, 0, '"show" class removed')
292292
done()
293293
})
294294
$first.trigger('click')
@@ -321,24 +321,24 @@ $(function () {
321321
$first.parent('.dropdown')
322322
.on('shown.bs.dropdown', function () {
323323
assert.strictEqual($first.parents('.show').length, 1, '"show" class added on click')
324-
assert.strictEqual($('#qunit-fixture .show').length, 1, 'only one dropdown is shown')
324+
assert.strictEqual($('#qunit-fixture .dropdown-menu.show').length, 1, 'only one dropdown is shown')
325325
var e = $.Event('keyup')
326326
e.which = 9 // Tab
327327
$(document.body).trigger(e)
328328
}).on('hidden.bs.dropdown', function () {
329-
assert.strictEqual($('#qunit-fixture .show').length, 0, '"show" class removed')
329+
assert.strictEqual($('#qunit-fixture .dropdown-menu.show').length, 0, '"show" class removed')
330330
$last.trigger('click')
331331
})
332332

333333
$last.parent('.btn-group')
334334
.on('shown.bs.dropdown', function () {
335335
assert.strictEqual($last.parent('.show').length, 1, '"show" class added on click')
336-
assert.strictEqual($('#qunit-fixture .show').length, 1, 'only one dropdown is shown')
336+
assert.strictEqual($('#qunit-fixture .dropdown-menu.show').length, 1, 'only one dropdown is shown')
337337
var e = $.Event('keyup')
338338
e.which = 9 // Tab
339339
$(document.body).trigger(e)
340340
}).on('hidden.bs.dropdown', function () {
341-
assert.strictEqual($('#qunit-fixture .show').length, 0, '"show" class removed')
341+
assert.strictEqual($('#qunit-fixture .dropdown-menu.show').length, 0, '"show" class removed')
342342
done()
343343
})
344344
$first.trigger('click')
@@ -552,7 +552,7 @@ $(function () {
552552
})
553553

554554
QUnit.test('should not close the dropdown if the user clicks on a text field', function (assert) {
555-
assert.expect(1)
555+
assert.expect(2)
556556
var done = assert.async()
557557
var dropdownHTML = '<div class="dropdown">'
558558
+ '<button type="button" data-toggle="dropdown">Dropdown</button>'
@@ -565,23 +565,23 @@ $(function () {
565565
.find('[data-toggle="dropdown"]')
566566
.bootstrapDropdown()
567567

568+
var $textfield = $('#textField')
569+
$textfield.on('click', function () {
570+
assert.ok($dropdown.parent('.dropdown').hasClass('show'), 'dropdown menu is shown')
571+
done()
572+
})
573+
568574
$dropdown
569575
.parent('.dropdown')
570576
.on('shown.bs.dropdown', function () {
571-
$('#textField').trigger('click')
572-
assert.ok($dropdown.parent('.dropdown').hasClass('show'), 'dropdown menu is shown')
573-
setTimeout(function () {
574-
done()
575-
}, 300)
576-
})
577-
.on('hidden.bs.dropdown', function () {
578577
assert.ok($dropdown.parent('.dropdown').hasClass('show'), 'dropdown menu is shown')
578+
$textfield.trigger($.Event('click'))
579579
})
580580
$dropdown.trigger('click')
581581
})
582582

583583
QUnit.test('should not close the dropdown if the user clicks on a textarea', function (assert) {
584-
assert.expect(1)
584+
assert.expect(2)
585585
var done = assert.async()
586586
var dropdownHTML = '<div class="dropdown">'
587587
+ '<button type="button" data-toggle="dropdown">Dropdown</button>'
@@ -594,17 +594,17 @@ $(function () {
594594
.find('[data-toggle="dropdown"]')
595595
.bootstrapDropdown()
596596

597+
var $textarea = $('#textArea')
598+
$textarea.on('click', function () {
599+
assert.ok($dropdown.parent('.dropdown').hasClass('show'), 'dropdown menu is shown')
600+
done()
601+
})
602+
597603
$dropdown
598604
.parent('.dropdown')
599605
.on('shown.bs.dropdown', function () {
600-
$('#textArea').trigger('click')
601-
assert.ok($dropdown.parent('.dropdown').hasClass('show'), 'dropdown menu is shown')
602-
setTimeout(function () {
603-
done()
604-
}, 300)
605-
})
606-
.on('hidden.bs.dropdown', function () {
607606
assert.ok($dropdown.parent('.dropdown').hasClass('show'), 'dropdown menu is shown')
607+
$textarea.trigger($.Event('click'))
608608
})
609609
$dropdown.trigger('click')
610610
})

js/tests/unit/popover.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,18 @@ $(function () {
4747

4848
QUnit.test('should render popover element', function (assert) {
4949
assert.expect(2)
50-
var $popover = $('<a href="#" title="mdo" data-content="https://twitter.com/mdo">@mdo</a>')
50+
var done = assert.async()
51+
$('<a href="#" title="mdo" data-content="https://twitter.com/mdo">@mdo</a>')
5152
.appendTo('#qunit-fixture')
53+
.on('shown.bs.popover', function () {
54+
assert.notEqual($('.popover').length, 0, 'popover was inserted')
55+
$(this).bootstrapPopover('hide')
56+
})
57+
.on('hidden.bs.popover', function () {
58+
assert.strictEqual($('.popover').length, 0, 'popover removed')
59+
done()
60+
})
5261
.bootstrapPopover('show')
53-
54-
assert.notEqual($('.popover').length, 0, 'popover was inserted')
55-
$popover.bootstrapPopover('hide')
56-
assert.strictEqual($('.popover').length, 0, 'popover removed')
5762
})
5863

5964
QUnit.test('should store popover instance in popover data object', function (assert) {

js/tests/unit/tooltip.js

Lines changed: 6 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,6 @@ $(function () {
383383
var $tooltip = $($(this).data('bs.tooltip').tip)
384384
assert.ok($tooltip.hasClass('bs-tooltip-right'))
385385
assert.ok($tooltip.attr('style') === undefined)
386-
$(this).bootstrapTooltip('hide')
387-
$container.remove()
388386
$styles.remove()
389387
done()
390388
})
@@ -475,32 +473,19 @@ $(function () {
475473
})
476474
.appendTo('#qunit-fixture')
477475

478-
$('#qunit-fixture').css({
479-
position : 'relative',
480-
top : '0px',
481-
left : '0px'
482-
})
483-
484-
var $trigger = $container
476+
$container
485477
.find('a')
486478
.css('margin-top', 200)
487479
.bootstrapTooltip({
488480
placement: 'top',
489481
animate: false
490482
})
491-
.bootstrapTooltip('show')
492-
493-
var $tooltip = $($trigger.data('bs.tooltip').tip)
494-
495-
setTimeout(function () {
496-
assert.ok(Math.round($tooltip.offset().top + $tooltip.outerHeight()) <= Math.round($trigger.offset().top))
497-
$('#qunit-fixture').css({
498-
position : 'absolute',
499-
top : '-10000px',
500-
left : '-10000px'
483+
.on('shown.bs.tooltip', function () {
484+
var $tooltip = $($(this).data('bs.tooltip').tip)
485+
assert.ok(Math.round($tooltip.offset().top + $tooltip.outerHeight()) >= Math.round($(this).offset().top))
486+
done()
501487
})
502-
done()
503-
}, 0)
488+
.bootstrapTooltip('show')
504489
})
505490

506491
QUnit.test('should show tooltip if leave event hasn\'t occurred before delay expires', function (assert) {
@@ -702,43 +687,6 @@ $(function () {
702687
assert.strictEqual(currentUid, $('#tt-content').text())
703688
})
704689

705-
QUnit.test('should correctly position tooltips on transformed elements', function (assert) {
706-
var styleProps = document.documentElement.style
707-
if (!('transform' in styleProps) && !('webkitTransform' in styleProps) && !('msTransform' in styleProps)) {
708-
assert.expect(0)
709-
return
710-
}
711-
assert.expect(2)
712-
713-
var done = assert.async()
714-
715-
var styles = '<style>'
716-
+ '#qunit-fixture { top: 0; left: 0; }'
717-
+ '.tooltip, .tooltip *, .tooltip *:before, .tooltip *:after { box-sizing: border-box; }'
718-
+ '.tooltip { position: absolute; }'
719-
+ '.tooltip .tooltip-inner { width: 24px; height: 24px; font-family: Helvetica; }'
720-
+ '#target { position: absolute; top: 100px; left: 50px; width: 100px; height: 200px; -webkit-transform: rotate(270deg); -ms-transform: rotate(270deg); transform: rotate(270deg); }'
721-
+ '</style>'
722-
var $styles = $(styles).appendTo('head')
723-
724-
var $element = $('<div id="target" title="1"/>').appendTo('#qunit-fixture')
725-
726-
$element
727-
.on('shown.bs.tooltip', function () {
728-
var offset = $('.tooltip').offset()
729-
$styles.remove()
730-
assert.ok(Math.abs(offset.left - 88) <= 1, 'tooltip has correct horizontal location')
731-
assert.ok(Math.abs(offset.top - 126) <= 1, 'tooltip has correct vertical location')
732-
$element.bootstrapTooltip('hide')
733-
done()
734-
})
735-
.bootstrapTooltip({
736-
trigger: 'manual'
737-
})
738-
739-
$element.bootstrapTooltip('show')
740-
})
741-
742690
QUnit.test('should do nothing when an attempt is made to hide an uninitialized tooltip', function (assert) {
743691
assert.expect(1)
744692

js/tests/visual/tooltip.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
66
<link rel="stylesheet" href="../../../dist/css/bootstrap.min.css">
77
<title>Tooltip</title>
8+
<style>
9+
#target {
10+
border: 1px solid;
11+
width: 100px;
12+
height: 50px;
13+
border: 1px solid;
14+
margin-left: 50px;
15+
-webkit-transform: rotate(270deg);
16+
-ms-transform: rotate(270deg);
17+
transform: rotate(270deg);
18+
margin-top: 100px;
19+
}
20+
</style>
821
</head>
922
<body>
1023
<div class="container">
@@ -34,6 +47,7 @@ <h1>Tooltip <small>Bootstrap Visual Test</small></h1>
3447
<circle cx="15" cy="10" r="10" fill="#62448F" data-toggle="tooltip" data-placement="top" title="Tooltip on SVG" />
3548
</svg>
3649
</p>
50+
<div id="target" title="Test tooltip on transformed element"></div>
3751
</div>
3852

3953
<script src="../../../docs/assets/js/vendor/jquery-slim.min.js"></script>
@@ -44,6 +58,10 @@ <h1>Tooltip <small>Bootstrap Visual Test</small></h1>
4458
<script>
4559
$(function () {
4660
$('[data-toggle="tooltip"]').tooltip()
61+
$('#target').tooltip({
62+
placement : 'top',
63+
trigger : 'manual'
64+
}).tooltip('show')
4765
})
4866
</script>
4967
</body>

scss/_dropdown.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,4 @@
138138
//
139139
// Just add .dropup after the standard .dropdown class and you're set.
140140

141-
.dropup {}
141+
//.dropup {}

0 commit comments

Comments
 (0)