aboutsummaryrefslogtreecommitdiff
path: root/js/tests/unit
diff options
context:
space:
mode:
authorPierre-Denis Vanduynslager <[email protected]>2017-01-04 12:22:06 -0500
committerPierre-Denis Vanduynslager <[email protected]>2017-01-04 12:22:06 -0500
commitc4867cfedb6235708967aa8518c59ffed2816f0b (patch)
treec7be6d18ee7c7a61f319bccacc035b9952171db1 /js/tests/unit
parent425d156df27fa6c18e979aa000bfe5a346ee3450 (diff)
parent1b194c06607f6cc3d087d25d6d49e1698771f3a1 (diff)
downloadbootstrap-c4867cfedb6235708967aa8518c59ffed2816f0b.tar.xz
bootstrap-c4867cfedb6235708967aa8518c59ffed2816f0b.zip
Merge branch 'twbs/v4-dev' into dropdown-keyboard
# Conflicts: # js/src/dropdown.js
Diffstat (limited to 'js/tests/unit')
-rw-r--r--js/tests/unit/dropdown.js60
-rw-r--r--js/tests/unit/modal.js8
-rw-r--r--js/tests/unit/popover.js32
-rw-r--r--js/tests/unit/tab.js16
-rw-r--r--js/tests/unit/tooltip.js30
5 files changed, 142 insertions, 4 deletions
diff --git a/js/tests/unit/dropdown.js b/js/tests/unit/dropdown.js
index 53455c2a6..9a34fc0c9 100644
--- a/js/tests/unit/dropdown.js
+++ b/js/tests/unit/dropdown.js
@@ -192,6 +192,30 @@ $(function () {
assert.ok(!$dropdown.parent('.dropdown').hasClass('show'), '"show" class removed')
})
+ QUnit.test('should remove "show" class if body is focused', function (assert) {
+ assert.expect(2)
+ var dropdownHTML = '<div class="tabs">'
+ + '<div class="dropdown">'
+ + '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>'
+ + '<div class="dropdown-menu">'
+ + '<a class="dropdown-item" href="#">Secondary link</a>'
+ + '<a class="dropdown-item" href="#">Something else here</a>'
+ + '<div class="dropdown-divider"/>'
+ + '<a class="dropdown-item" href="#">Another link</a>'
+ + '</div>'
+ + '</div>'
+ + '</div>'
+ var $dropdown = $(dropdownHTML)
+ .appendTo('#qunit-fixture')
+ .find('[data-toggle="dropdown"]')
+ .bootstrapDropdown()
+ .trigger('click')
+
+ assert.ok($dropdown.parent('.dropdown').hasClass('show'), '"show" class added on click')
+ $(document.body).trigger('focusin')
+ assert.ok(!$dropdown.parent('.dropdown').hasClass('show'), '"show" class removed')
+ })
+
QUnit.test('should remove "show" class if body is clicked, with multiple dropdowns', function (assert) {
assert.expect(7)
var dropdownHTML = '<ul class="nav">'
@@ -229,6 +253,42 @@ $(function () {
assert.strictEqual($('#qunit-fixture .show').length, 0, '"show" class removed')
})
+ QUnit.test('should remove "show" class if body is focused, with multiple dropdowns', function (assert) {
+ assert.expect(7)
+ var dropdownHTML = '<div class="nav">'
+ + '<div class="dropdown" id="testmenu">'
+ + '<a class="dropdown-toggle" data-toggle="dropdown" href="#testmenu">Test menu <span class="caret"/></a>'
+ + '<div class="dropdown-menu">'
+ + '<a class="dropdown-item" href="#sub1">Submenu 1</a>'
+ + '</div>'
+ + '</div>'
+ + '</div>'
+ + '<div class="btn-group">'
+ + '<button class="btn">Actions</button>'
+ + '<button class="btn dropdown-toggle" data-toggle="dropdown"><span class="caret"/></button>'
+ + '<div class="dropdown-menu">'
+ + '<a class="dropdown-item" href="#">Action 1</a>'
+ + '</div>'
+ + '</div>'
+ var $dropdowns = $(dropdownHTML).appendTo('#qunit-fixture').find('[data-toggle="dropdown"]')
+ var $first = $dropdowns.first()
+ var $last = $dropdowns.last()
+
+ assert.strictEqual($dropdowns.length, 2, 'two dropdowns')
+
+ $first.trigger('click')
+ assert.strictEqual($first.parents('.show').length, 1, '"show" class added on click')
+ assert.strictEqual($('#qunit-fixture .show').length, 1, 'only one dropdown is show')
+ $(document.body).trigger('focusin')
+ assert.strictEqual($('#qunit-fixture .show').length, 0, '"show" class removed')
+
+ $last.trigger('click')
+ assert.strictEqual($last.parent('.show').length, 1, '"show" class added on click')
+ assert.strictEqual($('#qunit-fixture .show').length, 1, 'only one dropdown is show')
+ $(document.body).trigger('focusin')
+ assert.strictEqual($('#qunit-fixture .show').length, 0, '"show" class removed')
+ })
+
QUnit.test('should fire show and hide event', function (assert) {
assert.expect(2)
var dropdownHTML = '<ul class="tabs">'
diff --git a/js/tests/unit/modal.js b/js/tests/unit/modal.js
index 7af5aeb27..84492cec2 100644
--- a/js/tests/unit/modal.js
+++ b/js/tests/unit/modal.js
@@ -379,8 +379,8 @@ $(function () {
QUnit.test('should have a paddingRight when the modal is taller than the viewport', function (assert) {
assert.expect(2)
var done = assert.async()
- $('<div class="navbar-fixed-top navbar-fixed-bottom is-fixed">@Johann-S</div>').appendTo('#qunit-fixture')
- $('.navbar-fixed-top, .navbar-fixed-bottom, .is-fixed').css('padding-right', '10px')
+ $('<div class="fixed-top fixed-bottom sticky-top is-fixed">@Johann-S</div>').appendTo('#qunit-fixture')
+ $('.fixed-top, .fixed-bottom, .is-fixed, .sticky-top').css('padding-right', '10px')
$('<div id="modal-test"/>')
.on('shown.bs.modal', function () {
@@ -396,8 +396,8 @@ $(function () {
QUnit.test('should remove padding-right on modal after closing', function (assert) {
assert.expect(3)
var done = assert.async()
- $('<div class="navbar-fixed-top navbar-fixed-bottom is-fixed">@Johann-S</div>').appendTo('#qunit-fixture')
- $('.navbar-fixed-top, .navbar-fixed-bottom, .is-fixed').css('padding-right', '10px')
+ $('<div class="fixed-top fixed-bottom is-fixed sticky-top">@Johann-S</div>').appendTo('#qunit-fixture')
+ $('.fixed-top, .fixed-bottom, .is-fixed, .sticky-top').css('padding-right', '10px')
$('<div id="modal-test"/>')
.on('shown.bs.modal', function () {
diff --git a/js/tests/unit/popover.js b/js/tests/unit/popover.js
index 5452def58..64c8c556a 100644
--- a/js/tests/unit/popover.js
+++ b/js/tests/unit/popover.js
@@ -332,4 +332,36 @@ $(function () {
done()
}
})
+
+ QUnit.test('should hide popovers when their containing modal is closed', function (assert) {
+ assert.expect(1)
+ var done = assert.async()
+ var templateHTML = '<div id="modal-test" class="modal">' +
+ '<div class="modal-dialog" role="document">' +
+ '<div class="modal-content">' +
+ '<div class="modal-body">' +
+ '<button id="popover-test" type="button" class="btn btn-secondary" data-toggle="popover" data-placement="top" data-content="Popover">' +
+ 'Popover on top' +
+ '</button>' +
+ '</div>' +
+ '</div>' +
+ '</div>' +
+ '</div>'
+
+ $(templateHTML).appendTo('#qunit-fixture')
+ $('#popover-test')
+ .on('shown.bs.popover', function () {
+ $('#modal-test').modal('hide')
+ })
+ .on('hide.bs.popover', function () {
+ assert.ok(true, 'popover hide')
+ done()
+ })
+
+ $('#modal-test')
+ .on('shown.bs.modal', function () {
+ $('#popover-test').bootstrapPopover('show')
+ })
+ .modal('show')
+ })
})
diff --git a/js/tests/unit/tab.js b/js/tests/unit/tab.js
index 62eece896..734648e9e 100644
--- a/js/tests/unit/tab.js
+++ b/js/tests/unit/tab.js
@@ -92,6 +92,22 @@ $(function () {
assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'home')
})
+ QUnit.test('should activate element by tab id in nav list', function (assert) {
+ assert.expect(2)
+ var tabsHTML = '<nav class="nav">' +
+ '<a href="#home">Home</a>' +
+ '<a href="#profile">Profile</a>' +
+ '</nav>'
+
+ $('<nav><div id="home"></div><div id="profile"></div></nav>').appendTo('#qunit-fixture')
+
+ $(tabsHTML).find('a:last').bootstrapTab('show')
+ assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'profile')
+
+ $(tabsHTML).find('a:first').bootstrapTab('show')
+ assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'home')
+ })
+
QUnit.test('should not fire shown when show is prevented', function (assert) {
assert.expect(1)
var done = assert.async()
diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js
index 7ff967fab..e1aec5551 100644
--- a/js/tests/unit/tooltip.js
+++ b/js/tests/unit/tooltip.js
@@ -839,4 +839,34 @@ $(function () {
assert.ok(showingTooltip(), 'tooltip is faded in again')
})
+ QUnit.test('should hide tooltip when their containing modal is closed', function (assert) {
+ assert.expect(1)
+ var done = assert.async()
+ var templateHTML = '<div id="modal-test" class="modal">' +
+ '<div class="modal-dialog" role="document">' +
+ '<div class="modal-content">' +
+ '<div class="modal-body">' +
+ '<a id="tooltipTest" href="#" data-toggle="tooltip" title="Some tooltip text!">Tooltip</a>' +
+ '</div>' +
+ '</div>' +
+ '</div>' +
+ '</div>'
+
+ $(templateHTML).appendTo('#qunit-fixture')
+ $('#tooltipTest')
+ .bootstrapTooltip({ trigger: 'manuel' })
+ .on('shown.bs.tooltip', function () {
+ $('#modal-test').modal('hide')
+ })
+ .on('hide.bs.tooltip', function () {
+ assert.ok(true, 'tooltip hide')
+ done()
+ })
+
+ $('#modal-test')
+ .on('shown.bs.modal', function () {
+ $('#tooltipTest').bootstrapTooltip('show')
+ })
+ .modal('show')
+ })
})