diff options
| author | Johann-S <[email protected]> | 2018-07-25 11:29:16 +0200 |
|---|---|---|
| committer | XhmikosR <[email protected]> | 2019-02-20 22:05:45 +0200 |
| commit | c44db783bf17c907dd46f53fdaa917ec74ffbded (patch) | |
| tree | 69a380068b58961b01e5cd465e118dbda4d376dd /js/tests/unit | |
| parent | cf821e1d4d1d67f6b4ce9651ae64c72a502c40ba (diff) | |
| download | bootstrap-c44db783bf17c907dd46f53fdaa917ec74ffbded.tar.xz bootstrap-c44db783bf17c907dd46f53fdaa917ec74ffbded.zip | |
chore(update): bump to 4.1.3
Diffstat (limited to 'js/tests/unit')
| -rw-r--r-- | js/tests/unit/carousel.js | 25 | ||||
| -rw-r--r-- | js/tests/unit/dropdown.js | 67 | ||||
| -rw-r--r-- | js/tests/unit/modal.js | 85 | ||||
| -rw-r--r-- | js/tests/unit/tooltip.js | 4 |
4 files changed, 54 insertions, 127 deletions
diff --git a/js/tests/unit/carousel.js b/js/tests/unit/carousel.js index 9016f61ab..3db83eaa3 100644 --- a/js/tests/unit/carousel.js +++ b/js/tests/unit/carousel.js @@ -541,16 +541,19 @@ $(function () { '<a class="left carousel-control" href="#myCarousel" data-slide="prev">‹</a>' + '<a class="right carousel-control" href="#myCarousel" data-slide="next">›</a>' + '</div>' - var $carousel = $(templateHTML) - $carousel.appendTo('body') + var $carousel = $(templateHTML).appendTo('#qunit-fixture') $carousel.bootstrapCarousel(1) - assert.strictEqual($carousel.data('bs.carousel')._config.interval, 3814) + var carousel = Carousel._getInstance($carousel[0]) + assert.strictEqual(carousel._config.interval, 3814) + carousel.dispose() $carousel.remove() - $carousel.appendTo('body') + $carousel = $carousel.appendTo('#qunit-fixture') $carousel.bootstrapCarousel(2) - assert.strictEqual($carousel.data('bs.carousel')._config.interval, 1814, 'reverts to default interval if no data-interval is set') + carousel = Carousel._getInstance($carousel[0]) + + assert.strictEqual(carousel._config.interval, 1814, 'reverts to default interval if no data-interval is set') $carousel.remove() }) @@ -1080,7 +1083,7 @@ $(function () { var $carousel = $(carouselHTML).appendTo('#qunit-fixture') var $item = $('#item') $carousel.bootstrapCarousel() - var carousel = $carousel.data('bs.carousel') + var carousel = Carousel._getInstance($carousel[0]) var spy = sinon.spy(carousel, 'prev') $carousel.one('slid.bs.carousel', function () { @@ -1122,7 +1125,7 @@ $(function () { $carousel.appendTo('#qunit-fixture') var $item = $('#item') $carousel.bootstrapCarousel() - var carousel = $carousel.data('bs.carousel') + var carousel = Carousel._getInstance($carousel[0]) var spy = sinon.spy(carousel, 'prev') $carousel.one('slid.bs.carousel', function () { @@ -1169,7 +1172,7 @@ $(function () { $carousel.appendTo('#qunit-fixture') var $item = $('#item') $carousel.bootstrapCarousel() - var carousel = $carousel.data('bs.carousel') + var carousel = Carousel._getInstance($carousel[0]) var spy = sinon.spy(carousel, 'next') $carousel.one('slid.bs.carousel', function () { @@ -1212,7 +1215,7 @@ $(function () { $carousel.appendTo('#qunit-fixture') var $item = $('#item') $carousel.bootstrapCarousel() - var carousel = $carousel.data('bs.carousel') + var carousel = Carousel._getInstance($carousel[0]) var spy = sinon.spy(carousel, 'next') $carousel.one('slid.bs.carousel', function () { @@ -1264,7 +1267,7 @@ $(function () { $carousel.appendTo('#qunit-fixture') $carousel.bootstrapCarousel() - var carousel = $carousel.data('bs.carousel') + var carousel = Carousel._getInstance($carousel[0]) var spy = sinon.spy(carousel, '_slide') @@ -1283,7 +1286,7 @@ $(function () { $carousel.appendTo('#qunit-fixture') $carousel.bootstrapCarousel() - var carousel = $carousel.data('bs.carousel') + var carousel = Carousel._getInstance($carousel[0]) var spy = sinon.spy(carousel, 'next') var sandbox = sinon.createSandbox() diff --git a/js/tests/unit/dropdown.js b/js/tests/unit/dropdown.js index a9a5773e6..3c1c9d03d 100644 --- a/js/tests/unit/dropdown.js +++ b/js/tests/unit/dropdown.js @@ -517,7 +517,7 @@ $(function () { $(document.body).trigger('click') }) - $dropdown.trigger('click') + $dropdown[0].click() }) QUnit.test('should fire hide and hidden event without a clickEvent if event type is not click', function (assert) { @@ -547,12 +547,13 @@ $(function () { }) .on('shown.bs.dropdown', function () { assert.ok(true, 'shown was fired') - $dropdown.trigger($.Event('keydown', { - which: 27 - })) + + var keyDown = new Event('keydown') + keyDown.which = 27 + $dropdown[0].dispatchEvent(keyDown) }) - $dropdown.trigger('click') + $dropdown[0].click() }) QUnit.test('should ignore keyboard events within <input>s and <textarea>s', function (assert) { @@ -1132,7 +1133,7 @@ $(function () { assert.ok(dropdown._element === null) }) - QUnit.test('should show dropdown', function (assert) { + QUnit.test('should hide dropdown', function (assert) { assert.expect(2) var dropdownHTML = @@ -1148,44 +1149,14 @@ $(function () { .find('[data-toggle="dropdown"]') .bootstrapDropdown() - var dropdown = $dropdown.data('bs.dropdown') + var dropdown = Dropdown._getInstance($dropdown[0]) var done = assert.async() $dropdown .parent('.dropdown') - .on('show.bs.dropdown', function () { - assert.ok(true, 'show was fired') - }) .on('shown.bs.dropdown', function () { - assert.ok($dropdown.parent('.dropdown').hasClass('show'), 'dropdown menu is shown') - done() + dropdown.hide() }) - - dropdown.show() - }) - - QUnit.test('should hide dropdown', function (assert) { - assert.expect(2) - - var dropdownHTML = - '<div class="dropdown">' + - ' <a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>' + - ' <div class="dropdown-menu">' + - ' <a class="dropdown-item" href="#">Another link</a>' + - ' </div>' + - '</div>' - - var $dropdown = $(dropdownHTML) - .appendTo('#qunit-fixture') - .find('[data-toggle="dropdown"]') - .bootstrapDropdown() - - var dropdown = $dropdown.data('bs.dropdown') - var done = assert.async() - $dropdown.trigger('click') - - $dropdown - .parent('.dropdown') .on('hide.bs.dropdown', function () { assert.ok(true, 'hide was fired') }) @@ -1194,7 +1165,7 @@ $(function () { done() }) - dropdown.hide() + dropdown.show() }) QUnit.test('should not hide dropdown', function (assert) { @@ -1213,7 +1184,7 @@ $(function () { .find('[data-toggle="dropdown"]') .bootstrapDropdown() - var dropdown = $dropdown.data('bs.dropdown') + var dropdown = Dropdown._getInstance($dropdown[0]) $dropdown.trigger('click') dropdown.show() @@ -1236,7 +1207,7 @@ $(function () { .find('[data-toggle="dropdown"]') .bootstrapDropdown() - var dropdown = $dropdown.data('bs.dropdown') + var dropdown = Dropdown._getInstance($dropdown[0]) dropdown.hide() assert.ok(!$dropdown.parent('.dropdown').hasClass('show'), 'dropdown menu is still hidden') }) @@ -1257,7 +1228,7 @@ $(function () { .find('[data-toggle="dropdown"]') .bootstrapDropdown() - var dropdown = $dropdown.data('bs.dropdown') + var dropdown = Dropdown._getInstance($dropdown[0]) var done = assert.async() $dropdown @@ -1289,7 +1260,7 @@ $(function () { .find('[data-toggle="dropdown"]') .bootstrapDropdown() - var dropdown = $dropdown.data('bs.dropdown') + var dropdown = Dropdown._getInstance($dropdown[0]) var done = assert.async() $dropdown @@ -1319,19 +1290,21 @@ $(function () { .find('[data-toggle="dropdown"]') .bootstrapDropdown() - var dropdown = $dropdown.data('bs.dropdown') + var dropdown = Dropdown._getInstance($dropdown[0]) var done = assert.async() - $dropdown.trigger('click') $dropdown .parent('.dropdown') + .on('shown.bs.dropdown', function () { + dropdown.hide() + }) .on('hide.bs.dropdown', function (event) { event.preventDefault() + assert.ok($dropdown.parent('.dropdown').hasClass('show'), 'dropdown menu is shown') done() }) - dropdown.hide() - assert.ok($dropdown.parent('.dropdown').hasClass('show'), 'dropdown menu is shown') + dropdown.show() }) QUnit.test('should not open dropdown via show method if target is disabled via attribute', function (assert) { diff --git a/js/tests/unit/modal.js b/js/tests/unit/modal.js index 0739f0378..dacb1fb8d 100644 --- a/js/tests/unit/modal.js +++ b/js/tests/unit/modal.js @@ -2,6 +2,7 @@ $(function () { 'use strict' window.Util = typeof bootstrap !== 'undefined' ? bootstrap.Util : Util + var Modal = typeof window.bootstrap !== 'undefined' ? window.bootstrap.Modal : window.Modal QUnit.module('modal plugin') @@ -624,43 +625,6 @@ $(function () { assert.ok(evt.defaultPrevented, 'model shown instead of navigating to href') }) - QUnit.test('should not parse target as html', function (assert) { - assert.expect(1) - var done = assert.async() - - var $toggleBtn = $('<button data-toggle="modal" data-target="<div id="modal-test"><div class="contents"<div<div id="close" data-dismiss="modal"/></div></div>"/>') - .appendTo('#qunit-fixture') - - $toggleBtn.trigger('click') - setTimeout(function () { - assert.strictEqual($('#modal-test').length, 0, 'target has not been parsed and added to the document') - done() - }, 0) - }) - - QUnit.test('should not execute js from target', function (assert) { - assert.expect(0) - var done = assert.async() - - // This toggle button contains XSS payload in its data-target - // Note: it uses the onerror handler of an img element to execute the js, because a simple script element does not work here - // a script element works in manual tests though, so here it is likely blocked by the qunit framework - var $toggleBtn = $('<button data-toggle="modal" data-target="<div><image src="missing.png" onerror="$('#qunit-fixture button.control').trigger('click')"></div>"/>') - .appendTo('#qunit-fixture') - // The XSS payload above does not have a closure over this function and cannot access the assert object directly - // However, it can send a click event to the following control button, which will then fail the assert - $('<button>') - .addClass('control') - .on('click', function () { - assert.notOk(true, 'XSS payload is not executed as js') - }) - .appendTo('#qunit-fixture') - - $toggleBtn.trigger('click') - - setTimeout(done, 500) - }) - QUnit.test('should not try to open a modal which is already visible', function (assert) { assert.expect(1) var done = assert.async() @@ -717,7 +681,7 @@ $(function () { }) QUnit.test('should dispose modal', function (assert) { - assert.expect(3) + assert.expect(2) var done = assert.async() var $modal = $([ @@ -731,31 +695,19 @@ $(function () { ].join('')).appendTo('#qunit-fixture') $modal.on('shown.bs.modal', function () { - var spy = sinon.spy($.fn, 'off') - - $(this).bootstrapModal('dispose') + var modal = Modal._getInstance($modal[0]) + var spy = sinon.spy($modal[0], 'removeEventListener') - var modalDataApiEvent = [] - $._data(document, 'events').click - .forEach(function (e) { - if (e.namespace === 'bs.data-api.modal') { - modalDataApiEvent.push(e) - } - }) + modal.dispose() - assert.ok(typeof $(this).data('bs.modal') === 'undefined', 'modal data object was disposed') - - assert.ok(spy.callCount === 4, '`jQuery.off` was called') - - assert.ok(modalDataApiEvent.length === 1, '`Event.CLICK_DATA_API` on `document` was not removed') - - $.fn.off.restore() + assert.ok(!Modal._getInstance($modal[0]), 'modal data object was disposed') + assert.ok(spy.called) done() }).bootstrapModal('show') }) QUnit.test('should enforce focus', function (assert) { - assert.expect(4) + assert.expect(2) var done = assert.async() var $modal = $([ @@ -770,27 +722,26 @@ $(function () { .bootstrapModal() .appendTo('#qunit-fixture') - var modal = $modal.data('bs.modal') + var modal = Modal._getInstance($modal[0]) var spy = sinon.spy(modal, '_enforceFocus') - var spyDocOff = sinon.spy($(document), 'off') - var spyDocOn = sinon.spy($(document), 'on') $modal.one('shown.bs.modal', function () { assert.ok(spy.called, '_enforceFocus called') - assert.ok(spyDocOff.withArgs('focusin.bs.modal')) - assert.ok(spyDocOn.withArgs('focusin.bs.modal')) - var spyFocus = sinon.spy(modal._element, 'focus') - var event = $.Event('focusin', { - target: $('#qunit-fixture')[0] - }) - $(document).one('focusin', function () { + function focusInListener() { assert.ok(spyFocus.called) + document.removeEventListener('focusin', focusInListener) done() + } + document.addEventListener('focusin', focusInListener) + + var focusInEvent = new Event('focusin') + Object.defineProperty(focusInEvent, 'target', { + value: $('#qunit-fixture')[0] }) - $(document).trigger(event) + document.dispatchEvent(focusInEvent) }) .bootstrapModal('show') }) diff --git a/js/tests/unit/tooltip.js b/js/tests/unit/tooltip.js index 23cd0cafd..47425dd57 100644 --- a/js/tests/unit/tooltip.js +++ b/js/tests/unit/tooltip.js @@ -1034,7 +1034,7 @@ $(function () { var $tipTest = $('<div class="bs-tooltip" />') .appendTo('#qunit-fixture') - var tooltip = $tooltip.data('bs.tooltip') + var tooltip = Tooltip._getInstance($tooltip[0]) tooltip.tip = null tooltip._handlePopperPlacementChange({ @@ -1054,7 +1054,7 @@ $(function () { .appendTo('#qunit-fixture') .bootstrapTooltip() - var tooltip = $tooltip.data('bs.tooltip') + var tooltip = Tooltip._getInstance($tooltip[0]) assert.strictEqual(tooltip._isEnabled, true) |
