diff options
Diffstat (limited to 'themes/docsy/assets/vendor/bootstrap/js/tests/unit')
12 files changed, 6631 insertions, 0 deletions
diff --git a/themes/docsy/assets/vendor/bootstrap/js/tests/unit/.eslintrc.json b/themes/docsy/assets/vendor/bootstrap/js/tests/unit/.eslintrc.json new file mode 100644 index 0000000..0896f40 --- /dev/null +++ b/themes/docsy/assets/vendor/bootstrap/js/tests/unit/.eslintrc.json @@ -0,0 +1,37 @@ +{ + "env": { + "es6": false, + "jquery": true, + "qunit": true + }, + "globals": { + "bootstrap": false, + "sinon": false, + "Util": false, + "Alert": false, + "Button": false + }, + "parserOptions": { + "ecmaVersion": 5, + "sourceType": "script" + }, + "extends": "../../../.eslintrc.json", + "rules": { + "no-console": "off", + // Best Practices + "consistent-return": "off", + "no-magic-numbers": "off", + "vars-on-top": "off", + + // Stylistic Issues + "func-style": "off", + "spaced-comment": "off", + + // ECMAScript 6 + "no-var": "off", + "object-shorthand": "off", + "prefer-arrow-callback": "off", + "prefer-template": "off", + "prefer-rest-params": "off" + } +} diff --git a/themes/docsy/assets/vendor/bootstrap/js/tests/unit/alert.js b/themes/docsy/assets/vendor/bootstrap/js/tests/unit/alert.js new file mode 100644 index 0000000..65a8f9e --- /dev/null +++ b/themes/docsy/assets/vendor/bootstrap/js/tests/unit/alert.js @@ -0,0 +1,123 @@ +$(function () { + 'use strict' + + QUnit.module('alert plugin') + + QUnit.test('should be defined on jquery object', function (assert) { + assert.expect(1) + assert.ok($(document.body).alert, 'alert method is defined') + }) + + QUnit.module('alert', { + beforeEach: 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() + }, + afterEach: function () { + $.fn.alert = $.fn.bootstrapAlert + delete $.fn.bootstrapAlert + $('#qunit-fixture').html('') + } + }) + + QUnit.test('should provide no conflict', function (assert) { + assert.expect(1) + assert.strictEqual(typeof $.fn.alert, 'undefined', 'alert was set back to undefined (org value)') + }) + + QUnit.test('should return jquery collection containing the element', function (assert) { + assert.expect(2) + var $el = $('<div/>') + var $alert = $el.bootstrapAlert() + assert.ok($alert instanceof $, 'returns jquery collection') + assert.strictEqual($alert[0], $el[0], 'collection contains element') + }) + + QUnit.test('should fade element out on clicking .close', function (assert) { + assert.expect(1) + var alertHTML = '<div class="alert alert-danger fade show">' + + '<a class="close" href="#" data-dismiss="alert">×</a>' + + '<p><strong>Holy guacamole!</strong> Best check yo self, you\'re not looking too good.</p>' + + '</div>' + + var $alert = $(alertHTML).bootstrapAlert().appendTo($('#qunit-fixture')) + + $alert.find('.close').trigger('click') + + assert.strictEqual($alert.hasClass('show'), false, 'remove .show class on .close click') + }) + + QUnit.test('should remove element when clicking .close', function (assert) { + assert.expect(2) + var done = assert.async() + var alertHTML = '<div class="alert alert-danger fade show">' + + '<a class="close" href="#" data-dismiss="alert">×</a>' + + '<p><strong>Holy guacamole!</strong> Best check yo self, you\'re not looking too good.</p>' + + '</div>' + var $alert = $(alertHTML).appendTo('#qunit-fixture').bootstrapAlert() + + assert.notEqual($('#qunit-fixture').find('.alert').length, 0, 'element added to dom') + + $alert + .one('closed.bs.alert', function () { + assert.strictEqual($('#qunit-fixture').find('.alert').length, 0, 'element removed from dom') + done() + }) + .find('.close') + .trigger('click') + }) + + QUnit.test('should not fire closed when close is prevented', function (assert) { + assert.expect(1) + var done = assert.async() + $('<div class="alert"/>') + .on('close.bs.alert', function (e) { + e.preventDefault() + assert.ok(true, 'close event fired') + done() + }) + .on('closed.bs.alert', function () { + assert.ok(false, 'closed event fired') + }) + .bootstrapAlert('close') + }) + + QUnit.test('close should use internal _element if no element provided', function (assert) { + assert.expect(1) + + var done = assert.async() + var $el = $('<div/>') + var $alert = $el.bootstrapAlert() + var alertInstance = $alert.data('bs.alert') + + $alert.one('closed.bs.alert', function () { + assert.ok('alert closed') + done() + }) + + alertInstance.close() + }) + + QUnit.test('dispose should remove data and the element', function (assert) { + assert.expect(2) + + var $el = $('<div/>') + var $alert = $el.bootstrapAlert() + + assert.ok(typeof $alert.data('bs.alert') !== 'undefined') + + $alert.data('bs.alert').dispose() + + assert.ok(typeof $alert.data('bs.button') === 'undefined') + }) + + QUnit.test('should return alert version', function (assert) { + assert.expect(1) + + if (typeof Alert !== 'undefined') { + assert.ok(typeof Alert.VERSION === 'string') + } else { + assert.notOk() + } + }) +}) diff --git a/themes/docsy/assets/vendor/bootstrap/js/tests/unit/button.js b/themes/docsy/assets/vendor/bootstrap/js/tests/unit/button.js new file mode 100644 index 0000000..9576dd2 --- /dev/null +++ b/themes/docsy/assets/vendor/bootstrap/js/tests/unit/button.js @@ -0,0 +1,199 @@ +$(function () { + 'use strict' + + QUnit.module('button plugin') + + QUnit.test('should be defined on jquery object', function (assert) { + assert.expect(1) + assert.ok($(document.body).button, 'button method is defined') + }) + + QUnit.module('button', { + beforeEach: 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() + }, + afterEach: function () { + $.fn.button = $.fn.bootstrapButton + delete $.fn.bootstrapButton + $('#qunit-fixture').html('') + } + }) + + QUnit.test('should provide no conflict', function (assert) { + assert.expect(1) + assert.strictEqual(typeof $.fn.button, 'undefined', 'button was set back to undefined (org value)') + }) + + QUnit.test('should return jquery collection containing the element', function (assert) { + assert.expect(2) + var $el = $('<div/>') + var $button = $el.bootstrapButton() + assert.ok($button instanceof $, 'returns jquery collection') + assert.strictEqual($button[0], $el[0], 'collection contains element') + }) + + QUnit.test('should toggle active', function (assert) { + assert.expect(2) + var $btn = $('<button class="btn" data-toggle="button">mdo</button>') + assert.ok(!$btn.hasClass('active'), 'btn does not have active class') + $btn.bootstrapButton('toggle') + assert.ok($btn.hasClass('active'), 'btn has class active') + }) + + QUnit.test('should toggle active when btn children are clicked', function (assert) { + assert.expect(2) + var $btn = $('<button class="btn" data-toggle="button">mdo</button>') + var $inner = $('<i/>') + $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 toggle aria-pressed', function (assert) { + assert.expect(2) + var $btn = $('<button class="btn" data-toggle="button" aria-pressed="false">redux</button>') + assert.strictEqual($btn.attr('aria-pressed'), 'false', 'btn aria-pressed state is false') + $btn.bootstrapButton('toggle') + assert.strictEqual($btn.attr('aria-pressed'), 'true', 'btn aria-pressed state is true') + }) + + QUnit.test('should toggle aria-pressed on buttons with container', function (assert) { + assert.expect(1) + var groupHTML = '<div class="btn-group" data-toggle="buttons">' + + '<button id="btn1" class="btn btn-secondary" type="button">One</button>' + + '<button class="btn btn-secondary" type="button">Two</button>' + + '</div>' + $('#qunit-fixture').append(groupHTML) + $('#btn1').bootstrapButton('toggle') + assert.strictEqual($('#btn1').attr('aria-pressed'), 'true') + }) + + QUnit.test('should toggle aria-pressed when btn children are clicked', function (assert) { + assert.expect(2) + var $btn = $('<button class="btn" data-toggle="button" aria-pressed="false">redux</button>') + var $inner = $('<i/>') + $btn + .append($inner) + .appendTo('#qunit-fixture') + assert.strictEqual($btn.attr('aria-pressed'), 'false', 'btn aria-pressed state is false') + $inner.trigger('click') + assert.strictEqual($btn.attr('aria-pressed'), 'true', 'btn aria-pressed state is true') + }) + + QUnit.test('should trigger input change event when toggled button has input field', function (assert) { + assert.expect(1) + var done = assert.async() + + var groupHTML = '<div class="btn-group" data-toggle="buttons">' + + '<label class="btn btn-primary">' + + '<input type="radio" id="radio" autocomplete="off">Radio' + + '</label>' + + '</div>' + var $group = $(groupHTML).appendTo('#qunit-fixture') + + $group.find('input').on('change', function (e) { + e.preventDefault() + assert.ok(true, 'change event fired') + done() + }) + + $group.find('label').trigger('click') + }) + + QUnit.test('should check for closest matching toggle', function (assert) { + assert.expect(12) + var groupHTML = '<div class="btn-group" data-toggle="buttons">' + + '<label class="btn btn-primary active">' + + '<input type="radio" name="options" id="option1" checked="true"> Option 1' + + '</label>' + + '<label class="btn btn-primary">' + + '<input type="radio" name="options" id="option2"> Option 2' + + '</label>' + + '<label class="btn btn-primary">' + + '<input type="radio" name="options" id="option3"> Option 3' + + '</label>' + + '</div>' + var $group = $(groupHTML).appendTo('#qunit-fixture') + + var $btn1 = $group.children().eq(0) + var $btn2 = $group.children().eq(1) + + assert.ok($btn1.hasClass('active'), 'btn1 has active class') + assert.ok($btn1.find('input').prop('checked'), 'btn1 is checked') + assert.ok(!$btn2.hasClass('active'), 'btn2 does not have active class') + 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 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 not checked') + assert.ok($btn2.hasClass('active'), 'btn2 has active class') + assert.ok($btn2.find('input').prop('checked'), 'btn2 is checked') + }) + + QUnit.test('should not add aria-pressed on labels for radio/checkbox inputs in a data-toggle="buttons" group', function (assert) { + assert.expect(2) + var groupHTML = '<div class="btn-group" data-toggle="buttons">' + + '<label class="btn btn-primary"><input type="checkbox" autocomplete="off"> Checkbox</label>' + + '<label class="btn btn-primary"><input type="radio" name="options" autocomplete="off"> Radio</label>' + + '</div>' + var $group = $(groupHTML).appendTo('#qunit-fixture') + + var $btn1 = $group.children().eq(0) + var $btn2 = $group.children().eq(1) + + $btn1.find('input').trigger('click') + assert.ok($btn1.is(':not([aria-pressed])'), 'label for nested checkbox input has not been given an aria-pressed attribute') + + $btn2.find('input').trigger('click') + assert.ok($btn2.is(':not([aria-pressed])'), 'label for nested radio input has not been given an aria-pressed attribute') + }) + + QUnit.test('should handle disabled attribute on non-button elements', function (assert) { + assert.expect(2) + var groupHTML = '<div class="btn-group disabled" data-toggle="buttons" aria-disabled="true" disabled>' + + '<label class="btn btn-danger disabled" aria-disabled="true" disabled>' + + '<input type="checkbox" aria-disabled="true" autocomplete="off" disabled class="disabled"/>' + + '</label>' + + '</div>' + var $group = $(groupHTML).appendTo('#qunit-fixture') + + var $btn = $group.children().eq(0) + var $input = $btn.children().eq(0) + + $btn.trigger('click') + assert.ok($btn.is(':not(.active)'), 'button did not become active') + assert.ok(!$input.is(':checked'), 'checkbox did not get checked') + }) + + QUnit.test('dispose should remove data and the element', function (assert) { + assert.expect(2) + + var $el = $('<div/>') + var $button = $el.bootstrapButton() + + assert.ok(typeof $button.data('bs.button') !== 'undefined') + + $button.data('bs.button').dispose() + + assert.ok(typeof $button.data('bs.button') === 'undefined') + }) + + QUnit.test('should return button version', function (assert) { + assert.expect(1) + + if (typeof Button !== 'undefined') { + assert.ok(typeof Button.VERSION === 'string') + } else { + assert.notOk() + } + }) +}) diff --git a/themes/docsy/assets/vendor/bootstrap/js/tests/unit/carousel.js b/themes/docsy/assets/vendor/bootstrap/js/tests/unit/carousel.js new file mode 100644 index 0000000..baabcf4 --- /dev/null +++ b/themes/docsy/assets/vendor/bootstrap/js/tests/unit/carousel.js @@ -0,0 +1,944 @@ +$(function () { + 'use strict' + + QUnit.module('carousel plugin') + + QUnit.test('should be defined on jQuery object', function (assert) { + assert.expect(1) + assert.ok($(document.body).carousel, 'carousel method is defined') + }) + + QUnit.module('carousel', { + beforeEach: 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() + }, + afterEach: function () { + $.fn.carousel = $.fn.bootstrapCarousel + delete $.fn.bootstrapCarousel + $('#qunit-fixture').html('') + } + }) + + QUnit.test('should provide no conflict', function (assert) { + assert.expect(1) + assert.strictEqual(typeof $.fn.carousel, 'undefined', 'carousel was set back to undefined (orig value)') + }) + + QUnit.test('should throw explicit error on undefined method', function (assert) { + assert.expect(1) + var $el = $('<div/>') + $el.bootstrapCarousel() + try { + $el.bootstrapCarousel('noMethod') + } catch (err) { + assert.strictEqual(err.message, 'No method named "noMethod"') + } + }) + + QUnit.test('should return jquery collection containing the element', function (assert) { + assert.expect(2) + var $el = $('<div/>') + var $carousel = $el.bootstrapCarousel() + assert.ok($carousel instanceof $, 'returns jquery collection') + assert.strictEqual($carousel[0], $el[0], 'collection contains element') + }) + + QUnit.test('should type check config options', function (assert) { + assert.expect(2) + + var message + var expectedMessage = 'CAROUSEL: Option "interval" provided type "string" but expected type "(number|boolean)".' + var config = { + interval: 'fat sux' + } + + try { + $('<div/>').bootstrapCarousel(config) + } catch (err) { + message = err.message + } + + assert.ok(message === expectedMessage, 'correct error message') + + config = { + keyboard: document.createElement('div') + } + expectedMessage = 'CAROUSEL: Option "keyboard" provided type "element" but expected type "boolean".' + + try { + $('<div/>').bootstrapCarousel(config) + } catch (err) { + message = err.message + } + + assert.ok(message === expectedMessage, 'correct error message') + }) + + QUnit.test('should not fire slid when slide is prevented', function (assert) { + assert.expect(1) + var done = assert.async() + $('<div class="carousel"/>') + .on('slide.bs.carousel', function (e) { + e.preventDefault() + assert.ok(true, 'slide event fired') + done() + }) + .on('slid.bs.carousel', function () { + assert.ok(false, 'slid event fired') + }) + .bootstrapCarousel('next') + }) + + QUnit.test('should reset when slide is prevented', function (assert) { + assert.expect(6) + var carouselHTML = '<div id="carousel-example-generic" class="carousel slide">' + + '<ol class="carousel-indicators">' + + '<li data-target="#carousel-example-generic" data-slide-to="0" class="active"/>' + + '<li data-target="#carousel-example-generic" data-slide-to="1"/>' + + '<li data-target="#carousel-example-generic" data-slide-to="2"/>' + + '</ol>' + + '<div class="carousel-inner">' + + '<div class="carousel-item active">' + + '<div class="carousel-caption"/>' + + '</div>' + + '<div class="carousel-item">' + + '<div class="carousel-caption"/>' + + '</div>' + + '<div class="carousel-item">' + + '<div class="carousel-caption"/>' + + '</div>' + + '</div>' + + '<a class="left carousel-control" href="#carousel-example-generic" data-slide="prev"/>' + + '<a class="right carousel-control" href="#carousel-example-generic" data-slide="next"/>' + + '</div>' + var $carousel = $(carouselHTML) + + var done = assert.async() + $carousel + .one('slide.bs.carousel', function (e) { + e.preventDefault() + setTimeout(function () { + assert.ok($carousel.find('.carousel-item:nth-child(1)').is('.active'), 'first item still active') + assert.ok($carousel.find('.carousel-indicators li:nth-child(1)').is('.active'), 'first indicator still active') + $carousel.bootstrapCarousel('next') + }, 0) + }) + .one('slid.bs.carousel', function () { + setTimeout(function () { + assert.ok(!$carousel.find('.carousel-item:nth-child(1)').is('.active'), 'first item still active') + assert.ok(!$carousel.find('.carousel-indicators li:nth-child(1)').is('.active'), 'first indicator still active') + assert.ok($carousel.find('.carousel-item:nth-child(2)').is('.active'), 'second item active') + assert.ok($carousel.find('.carousel-indicators li:nth-child(2)').is('.active'), 'second indicator active') + done() + }, 0) + }) + .bootstrapCarousel('next') + }) + + QUnit.test('should fire slide event with direction', function (assert) { + assert.expect(4) + var carouselHTML = '<div id="myCarousel" class="carousel slide">' + + '<div class="carousel-inner">' + + '<div class="carousel-item active">' + + '<img alt="">' + + '<div class="carousel-caption">' + + '<h4>First Thumbnail label</h4>' + + '<p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec ' + + 'id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ' + + 'ultricies vehicula ut id elit.</p>' + + '</div>' + + '</div>' + + '<div class="carousel-item">' + + '<img alt="">' + + '<div class="carousel-caption">' + + '<h4>Second Thumbnail label</h4>' + + '<p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec ' + + 'id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ' + + 'ultricies vehicula ut id elit.</p>' + + '</div>' + + '</div>' + + '<div class="carousel-item">' + + '<img alt="">' + + '<div class="carousel-caption">' + + '<h4>Third Thumbnail label</h4>' + + '<p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec ' + + 'id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ' + + 'ultricies vehicula ut id elit.</p>' + + '</div>' + + '</div>' + + '</div>' + + '<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 = $(carouselHTML) + + var done = assert.async() + + $carousel + .one('slide.bs.carousel', function (e) { + assert.ok(e.direction, 'direction present on next') + assert.strictEqual(e.direction, 'left', 'direction is left on next') + + $carousel + .one('slide.bs.carousel', function (e) { + assert.ok(e.direction, 'direction present on prev') + assert.strictEqual(e.direction, 'right', 'direction is right on prev') + done() + }) + .bootstrapCarousel('prev') + }) + .bootstrapCarousel('next') + }) + + QUnit.test('should fire slid event with direction', function (assert) { + assert.expect(4) + var carouselHTML = '<div id="myCarousel" class="carousel slide">' + + '<div class="carousel-inner">' + + '<div class="carousel-item active">' + + '<img alt="">' + + '<div class="carousel-caption">' + + '<h4>First Thumbnail label</h4>' + + '<p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec ' + + 'id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ' + + 'ultricies vehicula ut id elit.</p>' + + '</div>' + + '</div>' + + '<div class="carousel-item">' + + '<img alt="">' + + '<div class="carousel-caption">' + + '<h4>Second Thumbnail label</h4>' + + '<p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec ' + + 'id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ' + + 'ultricies vehicula ut id elit.</p>' + + '</div>' + + '</div>' + + '<div class="carousel-item">' + + '<img alt="">' + + '<div class="carousel-caption">' + + '<h4>Third Thumbnail label</h4>' + + '<p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec ' + + 'id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ' + + 'ultricies vehicula ut id elit.</p>' + + '</div>' + + '</div>' + + '</div>' + + '<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 = $(carouselHTML) + + var done = assert.async() + + $carousel + .one('slid.bs.carousel', function (e) { + assert.ok(e.direction, 'direction present on next') + assert.strictEqual(e.direction, 'left', 'direction is left on next') + + $carousel + .one('slid.bs.carousel', function (e) { + assert.ok(e.direction, 'direction present on prev') + assert.strictEqual(e.direction, 'right', 'direction is right on prev') + done() + }) + .bootstrapCarousel('prev') + }) + .bootstrapCarousel('next') + }) + + QUnit.test('should fire slide event with relatedTarget', function (assert) { + assert.expect(2) + var template = '<div id="myCarousel" class="carousel slide">' + + '<div class="carousel-inner">' + + '<div class="carousel-item active">' + + '<img alt="">' + + '<div class="carousel-caption">' + + '<h4>First Thumbnail label</h4>' + + '<p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec ' + + 'id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ' + + 'ultricies vehicula ut id elit.</p>' + + '</div>' + + '</div>' + + '<div class="carousel-item">' + + '<img alt="">' + + '<div class="carousel-caption">' + + '<h4>Second Thumbnail label</h4>' + + '<p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec ' + + 'id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ' + + 'ultricies vehicula ut id elit.</p>' + + '</div>' + + '</div>' + + '<div class="carousel-item">' + + '<img alt="">' + + '<div class="carousel-caption">' + + '<h4>Third Thumbnail label</h4>' + + '<p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec ' + + 'id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ' + + 'ultricies vehicula ut id elit.</p>' + + '</div>' + + '</div>' + + '</div>' + + '<a class="left carousel-control" href="#myCarousel" data-slide="prev">‹</a>' + + '<a class="right carousel-control" href="#myCarousel" data-slide="next">›</a>' + + '</div>' + + var done = assert.async() + + $(template) + .on('slide.bs.carousel', function (e) { + assert.ok(e.relatedTarget, 'relatedTarget present') + assert.ok($(e.relatedTarget).hasClass('carousel-item'), 'relatedTarget has class "item"') + done() + }) + .bootstrapCarousel('next') + }) + + QUnit.test('should fire slid event with relatedTarget', function (assert) { + assert.expect(2) + var template = '<div id="myCarousel" class="carousel slide">' + + '<div class="carousel-inner">' + + '<div class="carousel-item active">' + + '<img alt="">' + + '<div class="carousel-caption">' + + '<h4>First Thumbnail label</h4>' + + '<p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec ' + + 'id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ' + + 'ultricies vehicula ut id elit.</p>' + + '</div>' + + '</div>' + + '<div class="carousel-item">' + + '<img alt="">' + + '<div class="carousel-caption">' + + '<h4>Second Thumbnail label</h4>' + + '<p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec ' + + 'id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ' + + 'ultricies vehicula ut id elit.</p>' + + '</div>' + + '</div>' + + '<div class="carousel-item">' + + '<img alt="">' + + '<div class="carousel-caption">' + + '<h4>Third Thumbnail label</h4>' + + '<p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec ' + + 'id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ' + + 'ultricies vehicula ut id elit.</p>' + + '</div>' + + '</div>' + + '</div>' + + '<a class="left carousel-control" href="#myCarousel" data-slide="prev">‹</a>' + + '<a class="right carousel-control" href="#myCarousel" data-slide="next">›</a>' + + '</div>' + + var done = assert.async() + + $(template) + .on('slid.bs.carousel', function (e) { + assert.ok(e.relatedTarget, 'relatedTarget present') + assert.ok($(e.relatedTarget).hasClass('carousel-item'), 'relatedTarget has class "item"') + done() + }) + .bootstrapCarousel('next') + }) + + QUnit.test('should fire slid and slide events with from and to', function (assert) { + assert.expect(4) + var template = '<div id="myCarousel" class="carousel slide">' + + '<div class="carousel-inner">' + + '<div class="carousel-item active">' + + '<img alt="">' + + '<div class="carousel-caption">' + + '<h4>First Thumbnail label</h4>' + + '</div>' + + '</div>' + + '<div class="carousel-item">' + + '<img alt="">' + + '<div class="carousel-caption">' + + '<h4>Second Thumbnail label</h4>' + + '</div>' + + '</div>' + + '<div class="carousel-item">' + + '<img alt="">' + + '<div class="carousel-caption">' + + '<h4>Third Thumbnail label</h4>' + + '</div>' + + '</div>' + + '</div>' + + '<a class="left carousel-control" href="#myCarousel" data-slide="prev">‹</a>' + + '<a class="right carousel-control" href="#myCarousel" data-slide="next">›</a>' + + '</div>' + + var done = assert.async() + $(template) + .on('slid.bs.carousel', function (e) { + assert.ok(typeof e.from !== 'undefined', 'from present') + assert.ok(typeof e.to !== 'undefined', 'to present') + $(this).off() + done() + }) + .on('slide.bs.carousel', function (e) { + assert.ok(typeof e.from !== 'undefined', 'from present') + assert.ok(typeof e.to !== 'undefined', 'to present') + $(this).off('slide.bs.carousel') + }) + .bootstrapCarousel('next') + }) + + QUnit.test('should set interval from data attribute', function (assert) { + assert.expect(4) + var templateHTML = '<div id="myCarousel" class="carousel slide">' + + '<div class="carousel-inner">' + + '<div class="carousel-item active">' + + '<img alt="">' + + '<div class="carousel-caption">' + + '<h4>First Thumbnail label</h4>' + + '<p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec ' + + 'id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ' + + 'ultricies vehicula ut id elit.</p>' + + '</div>' + + '</div>' + + '<div class="carousel-item">' + + '<img alt="">' + + '<div class="carousel-caption">' + + '<h4>Second Thumbnail label</h4>' + + '<p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec ' + + 'id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ' + + 'ultricies vehicula ut id elit.</p>' + + '</div>' + + '</div>' + + '<div class="carousel-item">' + + '<img alt="">' + + '<div class="carousel-caption">' + + '<h4>Third Thumbnail label</h4>' + + '<p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec ' + + 'id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ' + + 'ultricies vehicula ut id elit.</p>' + + '</div>' + + '</div>' + + '</div>' + + '<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.attr('data-interval', 1814) + + $carousel.appendTo('body') + $('[data-slide]').first().trigger('click') + assert.strictEqual($carousel.data('bs.carousel')._config.interval, 1814) + $carousel.remove() + + $carousel.appendTo('body').attr('data-modal', 'foobar') + $('[data-slide]').first().trigger('click') + assert.strictEqual($carousel.data('bs.carousel')._config.interval, 1814, 'even if there is an data-modal attribute set') + $carousel.remove() + + $carousel.appendTo('body') + $('[data-slide]').first().trigger('click') + $carousel.attr('data-interval', 1860) + $('[data-slide]').first().trigger('click') + assert.strictEqual($carousel.data('bs.carousel')._config.interval, 1814, 'attributes should be read only on initialization') + $carousel.remove() + + $carousel.attr('data-interval', false) + $carousel.appendTo('body') + $carousel.bootstrapCarousel(1) + assert.strictEqual($carousel.data('bs.carousel')._config.interval, false, 'data attribute has higher priority than default options') + $carousel.remove() + }) + + QUnit.test('should skip over non-items when using item indices', function (assert) { + assert.expect(2) + var templateHTML = '<div id="myCarousel" class="carousel" data-interval="1814">' + + '<div class="carousel-inner">' + + '<div class="carousel-item active">' + + '<img alt="">' + + '</div>' + + '<script type="text/x-metamorph" id="thingy"/>' + + '<div class="carousel-item">' + + '<img alt="">' + + '</div>' + + '<div class="carousel-item">' + + '</div>' + + '</div>' + + '</div>' + var $template = $(templateHTML) + + $template.bootstrapCarousel() + + assert.strictEqual($template.find('.carousel-item')[0], $template.find('.active')[0], 'first item active') + + $template.bootstrapCarousel(1) + + assert.strictEqual($template.find('.carousel-item')[1], $template.find('.active')[0], 'second item active') + }) + + QUnit.test('should skip over non-items when using next/prev methods', function (assert) { + assert.expect(2) + var templateHTML = '<div id="myCarousel" class="carousel" data-interval="1814">' + + '<div class="carousel-inner">' + + '<div class="carousel-item active">' + + '<img alt="">' + + '</div>' + + '<script type="text/x-metamorph" id="thingy"/>' + + '<div class="carousel-item">' + + '<img alt="">' + + '</div>' + + '<div class="carousel-item">' + + '</div>' + + '</div>' + + '</div>' + var $template = $(templateHTML) + + $template.bootstrapCarousel() + + assert.strictEqual($template.find('.carousel-item')[0], $template.find('.active')[0], 'first item active') + + $template.bootstrapCarousel('next') + + assert.strictEqual($template.find('.carousel-item')[1], $template.find('.active')[0], 'second item active') + }) + + QUnit.test('should go to previous item if left arrow key is pressed', function (assert) { + assert.expect(2) + var templateHTML = '<div id="myCarousel" class="carousel" data-interval="false">' + + '<div class="carousel-inner">' + + '<div id="first" class="carousel-item">' + + '<img alt="">' + + '</div>' + + '<div id="second" class="carousel-item active">' + + '<img alt="">' + + '</div>' + + '<div id="third" class="carousel-item">' + + '<img alt="">' + + '</div>' + + '</div>' + + '</div>' + var $template = $(templateHTML) + + $template.bootstrapCarousel() + + assert.strictEqual($template.find('.carousel-item')[1], $template.find('.active')[0], 'second item active') + + $template.trigger($.Event('keydown', { + which: 37 + })) + + assert.strictEqual($template.find('.carousel-item')[0], $template.find('.active')[0], 'first item active') + }) + + QUnit.test('should go to next item if right arrow key is pressed', function (assert) { + assert.expect(2) + var templateHTML = '<div id="myCarousel" class="carousel" data-interval="false">' + + '<div class="carousel-inner">' + + '<div id="first" class="carousel-item active">' + + '<img alt="">' + + '</div>' + + '<div id="second" class="carousel-item">' + + '<img alt="">' + + '</div>' + + '<div id="third" class="carousel-item">' + + '<img alt="">' + + '</div>' + + '</div>' + + '</div>' + var $template = $(templateHTML) + + $template.bootstrapCarousel() + + assert.strictEqual($template.find('.carousel-item')[0], $template.find('.active')[0], 'first item active') + + $template.trigger($.Event('keydown', { + which: 39 + })) + + assert.strictEqual($template.find('.carousel-item')[1], $template.find('.active')[0], 'second item active') + }) + + QUnit.test('should not prevent keydown if key is not ARROW_LEFT or ARROW_RIGHT', function (assert) { + assert.expect(2) + var templateHTML = '<div id="myCarousel" class="carousel" data-interval="false">' + + '<div class="carousel-inner">' + + '<div id="first" class="carousel-item active">' + + '<img alt="">' + + '</div>' + + '</div>' + + '</div>' + var $template = $(templateHTML) + + $template.bootstrapCarousel() + var done = assert.async() + + var eventArrowDown = $.Event('keydown', { + which: 40 + }) + var eventArrowUp = $.Event('keydown', { + which: 38 + }) + + $template.one('keydown', function (event) { + assert.strictEqual(event.isDefaultPrevented(), false) + }) + + $template.trigger(eventArrowDown) + + $template.one('keydown', function (event) { + assert.strictEqual(event.isDefaultPrevented(), false) + done() + }) + + $template.trigger(eventArrowUp) + }) + + QUnit.test('should support disabling the keyboard navigation', function (assert) { + assert.expect(3) + var templateHTML = '<div id="myCarousel" class="carousel" data-interval="false" data-keyboard="false">' + + '<div class="carousel-inner">' + + '<div id="first" class="carousel-item active">' + + '<img alt="">' + + '</div>' + + '<div id="second" class="carousel-item">' + + '<img alt="">' + + '</div>' + + '<div id="third" class="carousel-item">' + + '<img alt="">' + + '</div>' + + '</div>' + + '</div>' + var $template = $(templateHTML) + + $template.bootstrapCarousel() + + assert.strictEqual($template.find('.carousel-item')[0], $template.find('.active')[0], 'first item active') + + $template.trigger($.Event('keydown', { + which: 39 + })) + + assert.strictEqual($template.find('.carousel-item')[0], $template.find('.active')[0], 'first item still active after right arrow press') + + $template.trigger($.Event('keydown', { + which: 37 + })) + + assert.strictEqual($template.find('.carousel-item')[0], $template.find('.active')[0], 'first item still active after left arrow press') + }) + + QUnit.test('should ignore keyboard events within <input>s and <textarea>s', function (assert) { + assert.expect(7) + var templateHTML = '<div id="myCarousel" class="carousel" data-interval="false">' + + '<div class="carousel-inner">' + + '<div id="first" class="carousel-item active">' + + '<img alt="">' + + '<input type="text" id="in-put">' + + '<textarea id="text-area"></textarea>' + + '</div>' + + '<div id="second" class="carousel-item">' + + '<img alt="">' + + '</div>' + + '<div id="third" class="carousel-item">' + + '<img alt="">' + + '</div>' + + '</div>' + + '</div>' + var $template = $(templateHTML) + var $input = $template.find('#in-put') + var $textarea = $template.find('#text-area') + + assert.strictEqual($input.length, 1, 'found <input>') + assert.strictEqual($textarea.length, 1, 'found <textarea>') + + $template.bootstrapCarousel() + + assert.strictEqual($template.find('.carousel-item')[0], $template.find('.active')[0], 'first item active') + + $input.trigger($.Event('keydown', { + which: 39 + })) + assert.strictEqual($template.find('.carousel-item')[0], $template.find('.active')[0], 'first item still active after right arrow press in <input>') + + $input.trigger($.Event('keydown', { + which: 37 + })) + assert.strictEqual($template.find('.carousel-item')[0], $template.find('.active')[0], 'first item still active after left arrow press in <input>') + + $textarea.trigger($.Event('keydown', { + which: 39 + })) + assert.strictEqual($template.find('.carousel-item')[0], $template.find('.active')[0], 'first item still active after right arrow press in <textarea>') + + $textarea.trigger($.Event('keydown', { + which: 37 + })) + assert.strictEqual($template.find('.carousel-item')[0], $template.find('.active')[0], 'first item still active after left arrow press in <textarea>') + }) + + QUnit.test('should wrap around from end to start when wrap option is true', function (assert) { + assert.expect(3) + var carouselHTML = '<div id="carousel-example-generic" class="carousel slide" data-wrap="true">' + + '<ol class="carousel-indicators">' + + '<li data-target="#carousel-example-generic" data-slide-to="0" class="active"/>' + + '<li data-target="#carousel-example-generic" data-slide-to="1"/>' + + '<li data-target="#carousel-example-generic" data-slide-to="2"/>' + + '</ol>' + + '<div class="carousel-inner">' + + '<div class="carousel-item active" id="one">' + + '<div class="carousel-caption"/>' + + '</div>' + + '<div class="carousel-item" id="two">' + + '<div class="carousel-caption"/>' + + '</div>' + + '<div class="carousel-item" id="three">' + + '<div class="carousel-caption"/>' + + '</div>' + + '</div>' + + '<a class="left carousel-control" href="#carousel-example-generic" data-slide="prev"/>' + + '<a class="right carousel-control" href="#carousel-example-generic" data-slide="next"/>' + + '</div>' + var $carousel = $(carouselHTML) + var getActiveId = function () { + return $carousel.find('.carousel-item.active').attr('id') + } + + var done = assert.async() + + $carousel + .one('slid.bs.carousel', function () { + assert.strictEqual(getActiveId(), 'two', 'carousel slid from 1st to 2nd slide') + $carousel + .one('slid.bs.carousel', function () { + assert.strictEqual(getActiveId(), 'three', 'carousel slid from 2nd to 3rd slide') + $carousel + .one('slid.bs.carousel', function () { + assert.strictEqual(getActiveId(), 'one', 'carousel wrapped around and slid from 3rd to 1st slide') + done() + }) + .bootstrapCarousel('next') + }) + .bootstrapCarousel('next') + }) + .bootstrapCarousel('next') + }) + + QUnit.test('should wrap around from start to end when wrap option is true', function (assert) { + assert.expect(1) + var carouselHTML = '<div id="carousel-example-generic" class="carousel slide" data-wrap="true">' + + '<ol class="carousel-indicators">' + + '<li data-target="#carousel-example-generic" data-slide-to="0" class="active"/>' + + '<li data-target="#carousel-example-generic" data-slide-to="1"/>' + + '<li data-target="#carousel-example-generic" data-slide-to="2"/>' + + '</ol>' + + '<div class="carousel-inner">' + + '<div class="carousel-item active" id="one">' + + '<div class="carousel-caption"/>' + + '</div>' + + '<div class="carousel-item" id="two">' + + '<div class="carousel-caption"/>' + + '</div>' + + '<div class="carousel-item" id="three">' + + '<div class="carousel-caption"/>' + + '</div>' + + '</div>' + + '<a class="left carousel-control" href="#carousel-example-generic" data-slide="prev"/>' + + '<a class="right carousel-control" href="#carousel-example-generic" data-slide="next"/>' + + '</div>' + var $carousel = $(carouselHTML) + + var done = assert.async() + + $carousel + .on('slid.bs.carousel', function () { + assert.strictEqual($carousel.find('.carousel-item.active').attr('id'), 'three', 'carousel wrapped around and slid from 1st to 3rd slide') + done() + }) + .bootstrapCarousel('prev') + }) + + QUnit.test('should stay at the end when the next method is called and wrap is false', function (assert) { + assert.expect(3) + var carouselHTML = '<div id="carousel-example-generic" class="carousel slide" data-wrap="false">' + + '<ol class="carousel-indicators">' + + '<li data-target="#carousel-example-generic" data-slide-to="0" class="active"/>' + + '<li data-target="#carousel-example-generic" data-slide-to="1"/>' + + '<li data-target="#carousel-example-generic" data-slide-to="2"/>' + + '</ol>' + + '<div class="carousel-inner">' + + '<div class="carousel-item active" id="one">' + + '<div class="carousel-caption"/>' + + '</div>' + + '<div class="carousel-item" id="two">' + + '<div class="carousel-caption"/>' + + '</div>' + + '<div class="carousel-item" id="three">' + + '<div class="carousel-caption"/>' + + '</div>' + + '</div>' + + '<a class="left carousel-control" href="#carousel-example-generic" data-slide="prev"/>' + + '<a class="right carousel-control" href="#carousel-example-generic" data-slide="next"/>' + + '</div>' + var $carousel = $(carouselHTML) + var getActiveId = function () { + return $carousel.find('.carousel-item.active').attr('id') + } + + var done = assert.async() + + $carousel + .one('slid.bs.carousel', function () { + assert.strictEqual(getActiveId(), 'two', 'carousel slid from 1st to 2nd slide') + $carousel + .one('slid.bs.carousel', function () { + assert.strictEqual(getActiveId(), 'three', 'carousel slid from 2nd to 3rd slide') + $carousel + .one('slid.bs.carousel', function () { + assert.ok(false, 'carousel slid when it should not have slid') + }) + .bootstrapCarousel('next') + assert.strictEqual(getActiveId(), 'three', 'carousel did not wrap around and stayed on 3rd slide') + done() + }) + .bootstrapCarousel('next') + }) + .bootstrapCarousel('next') + }) + + QUnit.test('should stay at the start when the prev method is called and wrap is false', function (assert) { + assert.expect(1) + var carouselHTML = '<div id="carousel-example-generic" class="carousel slide" data-wrap="false">' + + '<ol class="carousel-indicators">' + + '<li data-target="#carousel-example-generic" data-slide-to="0" class="active"/>' + + '<li data-target="#carousel-example-generic" data-slide-to="1"/>' + + '<li data-target="#carousel-example-generic" data-slide-to="2"/>' + + '</ol>' + + '<div class="carousel-inner">' + + '<div class="carousel-item active" id="one">' + + '<div class="carousel-caption"/>' + + '</div>' + + '<div class="carousel-item" id="two">' + + '<div class="carousel-caption"/>' + + '</div>' + + '<div class="carousel-item" id="three">' + + '<div class="carousel-caption"/>' + + '</div>' + + '</div>' + + '<a class="left carousel-control" href="#carousel-example-generic" data-slide="prev"/>' + + '<a class="right carousel-control" href="#carousel-example-generic" data-slide="next"/>' + + '</div>' + var $carousel = $(carouselHTML) + + $carousel + .on('slid.bs.carousel', function () { + assert.ok(false, 'carousel slid when it should not have slid') + }) + .bootstrapCarousel('prev') + assert.strictEqual($carousel.find('.carousel-item.active').attr('id'), 'one', 'carousel did not wrap around and stayed on 1st slide') + }) + + QUnit.test('should not prevent keydown for inputs and textareas', function (assert) { + assert.expect(2) + var templateHTML = '<div id="myCarousel" class="carousel" data-interval="false">' + + '<div class="carousel-inner">' + + '<div id="first" class="carousel-item">' + + '<input type="text" id="inputText" />' + + '</div>' + + '<div id="second" class="carousel-item active">' + + '<textarea id="txtArea"></textarea>' + + '</div>' + + '</div>' + + '</div>' + var $template = $(templateHTML) + var done = assert.async() + $template.appendTo('#qunit-fixture') + var $inputText = $template.find('#inputText') + var $textArea = $template.find('#txtArea') + $template.bootstrapCarousel() + + var eventKeyDown = $.Event('keydown', { + which: 65 + }) // 65 for "a" + $inputText.on('keydown', function (event) { + assert.strictEqual(event.isDefaultPrevented(), false) + }) + $inputText.trigger(eventKeyDown) + + $textArea.on('keydown', function (event) { + assert.strictEqual(event.isDefaultPrevented(), false) + done() + }) + $textArea.trigger(eventKeyDown) + }) + + QUnit.test('Should not go to the next item when the carousel is not visible', function (assert) { + assert.expect(2) + var done = assert.async() + var html = '<div id="myCarousel" class="carousel slide" data-interval="50" style="display: none;">' + + ' <div class="carousel-inner">' + + ' <div id="firstItem" class="carousel-item active">' + + ' <img alt="">' + + ' </div>' + + ' <div class="carousel-item">' + + ' <img alt="">' + + ' </div>' + + ' <div class="carousel-item">' + + ' <img alt="">' + + ' </div>' + + ' <a class="left carousel-control" href="#myCarousel" data-slide="prev">‹</a>' + + ' <a class="right carousel-control" href="#myCarousel" data-slide="next">›</a>' + + '</div>' + var $html = $(html) + $html + .appendTo('#qunit-fixture') + .bootstrapCarousel() + + var $firstItem = $('#firstItem') + setTimeout(function () { + assert.ok($firstItem.hasClass('active')) + $html + .bootstrapCarousel('dispose') + .attr('style', 'visibility: hidden;') + .bootstrapCarousel() + + setTimeout(function () { + assert.ok($firstItem.hasClass('active')) + done() + }, 80) + }, 80) + }) + + QUnit.test('Should not go to the next item when the parent of the carousel is not visible', function (assert) { + assert.expect(2) + var done = assert.async() + var html = '<div id="parent" style="display: none;">' + + ' <div id="myCarousel" class="carousel slide" data-interval="50" style="display: none;">' + + ' <div class="carousel-inner">' + + ' <div id="firstItem" class="carousel-item active">' + + ' <img alt="">' + + ' </div>' + + ' <div class="carousel-item">' + + ' <img alt="">' + + ' </div>' + + ' <div class="carousel-item">' + + ' <img alt="">' + + ' </div>' + + ' <a class="left carousel-control" href="#myCarousel" data-slide="prev">‹</a>' + + ' <a class="right carousel-control" href="#myCarousel" data-slide="next">›</a>' + + ' </div>' + + '</div>' + var $html = $(html) + $html.appendTo('#qunit-fixture') + var $parent = $html.find('#parent') + var $carousel = $html.find('#myCarousel') + $carousel.bootstrapCarousel() + var $firstItem = $('#firstItem') + + setTimeout(function () { + assert.ok($firstItem.hasClass('active')) + $carousel.bootstrapCarousel('dispose') + $parent.attr('style', 'visibility: hidden;') + $carousel.bootstrapCarousel() + + setTimeout(function () { + assert.ok($firstItem.hasClass('active')) + done() + }, 80) + }, 80) + }) +}) diff --git a/themes/docsy/assets/vendor/bootstrap/js/tests/unit/collapse.js b/themes/docsy/assets/vendor/bootstrap/js/tests/unit/collapse.js new file mode 100644 index 0000000..7f4cedd --- /dev/null +++ b/themes/docsy/assets/vendor/bootstrap/js/tests/unit/collapse.js @@ -0,0 +1,858 @@ +$(function () { + 'use strict' + + QUnit.module('collapse plugin') + + QUnit.test('should be defined on jquery object', function (assert) { + assert.expect(1) + assert.ok($(document.body).collapse, 'collapse method is defined') + }) + + QUnit.module('collapse', { + beforeEach: 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() + }, + afterEach: function () { + $.fn.collapse = $.fn.bootstrapCollapse + delete $.fn.bootstrapCollapse + $('#qunit-fixture').html('') + } + }) + + QUnit.test('should provide no conflict', function (assert) { + assert.expect(1) + assert.strictEqual(typeof $.fn.collapse, 'undefined', 'collapse was set back to undefined (org value)') + }) + + QUnit.test('should throw explicit error on undefined method', function (assert) { + assert.expect(1) + var $el = $('<div/>') + $el.bootstrapCollapse() + try { + $el.bootstrapCollapse('noMethod') + } catch (err) { + assert.strictEqual(err.message, 'No method named "noMethod"') + } + }) + + QUnit.test('should return jquery collection containing the element', function (assert) { + assert.expect(2) + var $el = $('<div/>') + var $collapse = $el.bootstrapCollapse() + assert.ok($collapse instanceof $, 'returns jquery collection') + assert.strictEqual($collapse[0], $el[0], 'collection contains element') + }) + + QUnit.test('should show a collapsed element', function (assert) { + assert.expect(2) + var done = assert.async() + var $el = $('<div class="collapse"/>') + + $el.one('shown.bs.collapse', function () { + assert.ok($el.hasClass('show'), 'has class "show"') + assert.ok(!/height/i.test($el.attr('style')), 'has height reset') + done() + }).bootstrapCollapse('show') + }) + + QUnit.test('should show multiple collapsed elements', function (assert) { + assert.expect(4) + var done = assert.async() + var $target = $('<a role="button" data-toggle="collapse" class="collapsed" href=".multi"/>').appendTo('#qunit-fixture') + var $el = $('<div class="collapse multi"/>').appendTo('#qunit-fixture') + var $el2 = $('<div class="collapse multi"/>').appendTo('#qunit-fixture') + $el.one('shown.bs.collapse', function () { + assert.ok($el.hasClass('show'), 'has class "show"') + assert.ok(!/height/i.test($el.attr('style')), 'has height reset') + }) + $el2.one('shown.bs.collapse', function () { + assert.ok($el2.hasClass('show'), 'has class "show"') + assert.ok(!/height/i.test($el2.attr('style')), 'has height reset') + done() + }) + $target.trigger('click') + }) + + QUnit.test('should collapse only the first collapse', function (assert) { + assert.expect(2) + var done = assert.async() + var html = [ + '<div class="panel-group" id="accordion1">', + '<div class="panel">', + '<div id="collapse1" class="collapse"/>', + '</div>', + '</div>', + '<div class="panel-group" id="accordion2">', + '<div class="panel">', + '<div id="collapse2" class="collapse show"/>', + '</div>', + '</div>' + ].join('') + $(html).appendTo('#qunit-fixture') + var $el1 = $('#collapse1') + var $el2 = $('#collapse2') + $el1.one('shown.bs.collapse', function () { + assert.ok($el1.hasClass('show')) + assert.ok($el2.hasClass('show')) + done() + }).bootstrapCollapse('show') + }) + + QUnit.test('should hide a collapsed element', function (assert) { + assert.expect(1) + var $el = $('<div class="collapse"/>').bootstrapCollapse('hide') + + assert.ok(!$el.hasClass('show'), 'does not have class "show"') + }) + + QUnit.test('should not fire shown when show is prevented', function (assert) { + assert.expect(1) + var done = assert.async() + + $('<div class="collapse"/>') + .on('show.bs.collapse', function (e) { + e.preventDefault() + assert.ok(true, 'show event fired') + done() + }) + .on('shown.bs.collapse', function () { + assert.ok(false, 'shown event fired') + }) + .bootstrapCollapse('show') + }) + + QUnit.test('should reset style to auto after finishing opening collapse', function (assert) { + assert.expect(2) + var done = assert.async() + + $('<div class="collapse" style="height: 0px"/>') + .on('show.bs.collapse', function () { + assert.strictEqual(this.style.height, '0px', 'height is 0px') + }) + .on('shown.bs.collapse', function () { + assert.strictEqual(this.style.height, '', 'height is auto') + done() + }) + .bootstrapCollapse('show') + }) + + QUnit.test('should reset style to auto after finishing closing collapse', function (assert) { + assert.expect(1) + var done = assert.async() + + $('<div class="collapse"/>') + .on('shown.bs.collapse', function () { + $(this).bootstrapCollapse('hide') + }) + .on('hidden.bs.collapse', function () { + assert.strictEqual(this.style.height, '', 'height is auto') + done() + }) + .bootstrapCollapse('show') + }) + + QUnit.test('should remove "collapsed" class from target when collapse is shown', function (assert) { + assert.expect(1) + var done = assert.async() + + var $target = $('<a role="button" data-toggle="collapse" class="collapsed" href="#test1"/>').appendTo('#qunit-fixture') + + $('<div id="test1"/>') + .appendTo('#qunit-fixture') + .on('shown.bs.collapse', function () { + assert.ok(!$target.hasClass('collapsed'), 'target does not have collapsed class') + done() + }) + + $target.trigger('click') + }) + + QUnit.test('should add "collapsed" class to target when collapse is hidden', function (assert) { + assert.expect(1) + var done = assert.async() + + var $target = $('<a role="button" data-toggle="collapse" href="#test1"/>').appendTo('#qunit-fixture') + + $('<div id="test1" class="show"/>') + .appendTo('#qunit-fixture') + .on('hidden.bs.collapse', function () { + assert.ok($target.hasClass('collapsed'), 'target has collapsed class') + done() + }) + + $target.trigger('click') + }) + + QUnit.test('should remove "collapsed" class from all triggers targeting the collapse when the collapse is shown', function (assert) { + assert.expect(2) + var done = assert.async() + + var $target = $('<a role="button" data-toggle="collapse" class="collapsed" href="#test1"/>').appendTo('#qunit-fixture') + var $alt = $('<a role="button" data-toggle="collapse" class="collapsed" href="#test1"/>').appendTo('#qunit-fixture') + + $('<div id="test1"/>') + .appendTo('#qunit-fixture') + .on('shown.bs.collapse', function () { + assert.ok(!$target.hasClass('collapsed'), 'target trigger does not have collapsed class') + assert.ok(!$alt.hasClass('collapsed'), 'alt trigger does not have collapsed class') + done() + }) + + $target.trigger('click') + }) + + QUnit.test('should add "collapsed" class to all triggers targeting the collapse when the collapse is hidden', function (assert) { + assert.expect(2) + var done = assert.async() + + var $target = $('<a role="button" data-toggle="collapse" href="#test1"/>').appendTo('#qunit-fixture') + var $alt = $('<a role="button" data-toggle="collapse" href="#test1"/>').appendTo('#qunit-fixture') + + $('<div id="test1" class="show"/>') + .appendTo('#qunit-fixture') + .on('hidden.bs.collapse', function () { + assert.ok($target.hasClass('collapsed'), 'target has collapsed class') + assert.ok($alt.hasClass('collapsed'), 'alt trigger has collapsed class') + done() + }) + + $target.trigger('click') + }) + + QUnit.test('should not close a collapse when initialized with "show" option if already shown', function (assert) { + assert.expect(0) + var done = assert.async() + + var $test = $('<div id="test1" class="show"/>') + .appendTo('#qunit-fixture') + .on('hide.bs.collapse', function () { + assert.ok(false) + }) + + $test.bootstrapCollapse('show') + + setTimeout(done, 0) + }) + + QUnit.test('should open a collapse when initialized with "show" option if not already shown', function (assert) { + assert.expect(1) + var done = assert.async() + + var $test = $('<div id="test1" />') + .appendTo('#qunit-fixture') + .on('show.bs.collapse', function () { + assert.ok(true) + }) + + $test.bootstrapCollapse('show') + + setTimeout(done, 0) + }) + + QUnit.test('should not show a collapse when initialized with "hide" option if already hidden', function (assert) { + assert.expect(0) + var done = assert.async() + + $('<div class="collapse"></div>') + .appendTo('#qunit-fixture') + .on('show.bs.collapse', function () { + assert.ok(false, 'showing a previously-uninitialized hidden collapse when the "hide" method is called') + }) + .bootstrapCollapse('hide') + + setTimeout(done, 0) + }) + + QUnit.test('should hide a collapse when initialized with "hide" option if not already hidden', function (assert) { + assert.expect(1) + var done = assert.async() + + $('<div class="collapse show"></div>') + .appendTo('#qunit-fixture') + .on('hide.bs.collapse', function () { + assert.ok(true, 'hiding a previously-uninitialized shown collapse when the "hide" method is called') + }) + .bootstrapCollapse('hide') + + setTimeout(done, 0) + }) + + QUnit.test('should remove "collapsed" class from active accordion target', function (assert) { + assert.expect(3) + var done = assert.async() + + var accordionHTML = '<div id="accordion">' + + '<div class="card"/>' + + '<div class="card"/>' + + '<div class="card"/>' + + '</div>' + var $groups = $(accordionHTML).appendTo('#qunit-fixture').find('.card') + + var $target1 = $('<a role="button" data-toggle="collapse" href="#body1" />').appendTo($groups.eq(0)) + + $('<div id="body1" class="show" data-parent="#accordion"/>').appendTo($groups.eq(0)) + + var $target2 = $('<a class="collapsed" data-toggle="collapse" role="button" href="#body2" />').appendTo($groups.eq(1)) + + $('<div id="body2" data-parent="#accordion"/>').appendTo($groups.eq(1)) + + var $target3 = $('<a class="collapsed" data-toggle="collapse" role="button" href="#body3" />').appendTo($groups.eq(2)) + + $('<div id="body3" data-parent="#accordion"/>') + .appendTo($groups.eq(2)) + .on('shown.bs.collapse', function () { + assert.ok($target1.hasClass('collapsed'), 'inactive target 1 does have class "collapsed"') + assert.ok($target2.hasClass('collapsed'), 'inactive target 2 does have class "collapsed"') + assert.ok(!$target3.hasClass('collapsed'), 'active target 3 does not have class "collapsed"') + + done() + }) + + $target3.trigger('click') + }) + + QUnit.test('should allow dots in data-parent', function (assert) { + assert.expect(3) + var done = assert.async() + + var accordionHTML = '<div class="accordion">' + + '<div class="card"/>' + + '<div class="card"/>' + + '<div class="card"/>' + + '</div>' + var $groups = $(accordionHTML).appendTo('#qunit-fixture').find('.card') + + var $target1 = $('<a role="button" data-toggle="collapse" href="#body1"/>').appendTo($groups.eq(0)) + + $('<div id="body1" class="show" data-parent=".accordion"/>').appendTo($groups.eq(0)) + + var $target2 = $('<a class="collapsed" data-toggle="collapse" role="button" href="#body2"/>').appendTo($groups.eq(1)) + + $('<div id="body2" data-parent=".accordion"/>').appendTo($groups.eq(1)) + + var $target3 = $('<a class="collapsed" data-toggle="collapse" role="button" href="#body3"/>').appendTo($groups.eq(2)) + + $('<div id="body3" data-parent=".accordion"/>') + .appendTo($groups.eq(2)) + .on('shown.bs.collapse', function () { + assert.ok($target1.hasClass('collapsed'), 'inactive target 1 does have class "collapsed"') + assert.ok($target2.hasClass('collapsed'), 'inactive target 2 does have class "collapsed"') + assert.ok(!$target3.hasClass('collapsed'), 'active target 3 does not have class "collapsed"') + + done() + }) + + $target3.trigger('click') + }) + + QUnit.test('should set aria-expanded="true" on trigger/control when collapse is shown', function (assert) { + assert.expect(1) + var done = assert.async() + + var $target = $('<a role="button" data-toggle="collapse" class="collapsed" href="#test1" aria-expanded="false"/>').appendTo('#qunit-fixture') + + $('<div id="test1"/>') + .appendTo('#qunit-fixture') + .on('shown.bs.collapse', function () { + assert.strictEqual($target.attr('aria-expanded'), 'true', 'aria-expanded on target is "true"') + done() + }) + + $target.trigger('click') + }) + + QUnit.test('should set aria-expanded="false" on trigger/control when collapse is hidden', function (assert) { + assert.expect(1) + var done = assert.async() + + var $target = $('<a role="button" data-toggle="collapse" href="#test1" aria-expanded="true"/>').appendTo('#qunit-fixture') + + $('<div id="test1" class="show"/>') + .appendTo('#qunit-fixture') + .on('hidden.bs.collapse', function () { + assert.strictEqual($target.attr('aria-expanded'), 'false', 'aria-expanded on target is "false"') + done() + }) + + $target.trigger('click') + }) + + QUnit.test('should set aria-expanded="true" on all triggers targeting the collapse when the collapse is shown', function (assert) { + assert.expect(2) + var done = assert.async() + + var $target = $('<a role="button" data-toggle="collapse" class="collapsed" href="#test1" aria-expanded="false"/>').appendTo('#qunit-fixture') + var $alt = $('<a role="button" data-toggle="collapse" class="collapsed" href="#test1" aria-expanded="false"/>').appendTo('#qunit-fixture') + + $('<div id="test1"/>') + .appendTo('#qunit-fixture') + .on('shown.bs.collapse', function () { + assert.strictEqual($target.attr('aria-expanded'), 'true', 'aria-expanded on trigger/control is "true"') + assert.strictEqual($alt.attr('aria-expanded'), 'true', 'aria-expanded on alternative trigger/control is "true"') + done() + }) + + $target.trigger('click') + }) + + QUnit.test('should set aria-expanded="false" on all triggers targeting the collapse when the collapse is hidden', function (assert) { + assert.expect(2) + var done = assert.async() + + var $target = $('<a role="button" data-toggle="collapse" href="#test1" aria-expanded="true"/>').appendTo('#qunit-fixture') + var $alt = $('<a role="button" data-toggle="collapse" href="#test1" aria-expanded="true"/>').appendTo('#qunit-fixture') + + $('<div id="test1" class="show"/>') + .appendTo('#qunit-fixture') + .on('hidden.bs.collapse', function () { + assert.strictEqual($target.attr('aria-expanded'), 'false', 'aria-expanded on trigger/control is "false"') + assert.strictEqual($alt.attr('aria-expanded'), 'false', 'aria-expanded on alternative trigger/control is "false"') + done() + }) + + $target.trigger('click') + }) + + QUnit.test('should change aria-expanded from active accordion trigger/control to "false" and set the trigger/control for the newly active one to "true"', function (assert) { + assert.expect(3) + var done = assert.async() + + var accordionHTML = '<div id="accordion">' + + '<div class="card"/>' + + '<div class="card"/>' + + '<div class="card"/>' + + '</div>' + var $groups = $(accordionHTML).appendTo('#qunit-fixture').find('.card') + + var $target1 = $('<a role="button" data-toggle="collapse" aria-expanded="true" href="#body1"/>').appendTo($groups.eq(0)) + + $('<div id="body1" class="show" data-parent="#accordion"/>').appendTo($groups.eq(0)) + + var $target2 = $('<a role="button" data-toggle="collapse" aria-expanded="false" href="#body2" class="collapsed" aria-expanded="false" />').appendTo($groups.eq(1)) + + $('<div id="body2" data-parent="#accordion"/>').appendTo($groups.eq(1)) + + var $target3 = $('<a class="collapsed" data-toggle="collapse" aria-expanded="false" role="button" href="#body3"/>').appendTo($groups.eq(2)) + + $('<div id="body3" data-parent="#accordion"/>') + .appendTo($groups.eq(2)) + .on('shown.bs.collapse', function () { + assert.strictEqual($target1.attr('aria-expanded'), 'false', 'inactive trigger/control 1 has aria-expanded="false"') + assert.strictEqual($target2.attr('aria-expanded'), 'false', 'inactive trigger/control 2 has aria-expanded="false"') + assert.strictEqual($target3.attr('aria-expanded'), 'true', 'active trigger/control 3 has aria-expanded="true"') + + done() + }) + + $target3.trigger('click') + }) + + QUnit.test('should not fire show event if show is prevented because other element is still transitioning', function (assert) { + assert.expect(1) + var done = assert.async() + + var accordionHTML = '<div id="accordion">' + + '<div class="card"/>' + + '<div class="card"/>' + + '</div>' + var showFired = false + var $groups = $(accordionHTML).appendTo('#qunit-fixture').find('.card') + + var $target1 = $('<a role="button" data-toggle="collapse" href="#body1"/>').appendTo($groups.eq(0)) + + $('<div id="body1" class="collapse" data-parent="#accordion"/>') + .appendTo($groups.eq(0)) + .on('show.bs.collapse', function () { + showFired = true + }) + + var $target2 = $('<a role="button" data-toggle="collapse" href="#body2"/>').appendTo($groups.eq(1)) + var $body2 = $('<div id="body2" class="collapse" data-parent="#accordion"/>').appendTo($groups.eq(1)) + + $target2.trigger('click') + + $body2 + .toggleClass('show collapsing') + .data('bs.collapse')._isTransitioning = 1 + + $target1.trigger('click') + + setTimeout(function () { + assert.ok(!showFired, 'show event did not fire') + done() + }, 1) + }) + + QUnit.test('should add "collapsed" class to target when collapse is hidden via manual invocation', function (assert) { + assert.expect(1) + var done = assert.async() + + var $target = $('<a role="button" data-toggle="collapse" href="#test1"/>').appendTo('#qunit-fixture') + + $('<div id="test1" class="show"/>') + .appendTo('#qunit-fixture') + .on('hidden.bs.collapse', function () { + assert.ok($target.hasClass('collapsed')) + done() + }) + .bootstrapCollapse('hide') + }) + + QUnit.test('should remove "collapsed" class from target when collapse is shown via manual invocation', function (assert) { + assert.expect(1) + var done = assert.async() + + var $target = $('<a role="button" data-toggle="collapse" class="collapsed" href="#test1"/>').appendTo('#qunit-fixture') + + $('<div id="test1"/>') + .appendTo('#qunit-fixture') + .on('shown.bs.collapse', function () { + assert.ok(!$target.hasClass('collapsed')) + done() + }) + .bootstrapCollapse('show') + }) + + QUnit.test('should allow accordion to use children other than card', function (assert) { + assert.expect(4) + var done = assert.async() + var accordionHTML = '<div id="accordion">' + + '<div class="item">' + + '<a id="linkTrigger" data-toggle="collapse" href="#collapseOne" aria-expanded="false" aria-controls="collapseOne"></a>' + + '<div id="collapseOne" class="collapse" role="tabpanel" aria-labelledby="headingThree" data-parent="#accordion"></div>' + + '</div>' + + '<div class="item">' + + '<a id="linkTriggerTwo" data-toggle="collapse" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo"></a>' + + '<div id="collapseTwo" class="collapse show" role="tabpanel" aria-labelledby="headingTwo" data-parent="#accordion"></div>' + + '</div>' + + '</div>' + + $(accordionHTML).appendTo('#qunit-fixture') + var $trigger = $('#linkTrigger') + var $triggerTwo = $('#linkTriggerTwo') + var $collapseOne = $('#collapseOne') + var $collapseTwo = $('#collapseTwo') + $collapseOne.on('shown.bs.collapse', function () { + assert.ok($collapseOne.hasClass('show'), '#collapseOne is shown') + assert.ok(!$collapseTwo.hasClass('show'), '#collapseTwo is not shown') + $collapseTwo.on('shown.bs.collapse', function () { + assert.ok(!$collapseOne.hasClass('show'), '#collapseOne is not shown') + assert.ok($collapseTwo.hasClass('show'), '#collapseTwo is shown') + done() + }) + $triggerTwo.trigger($.Event('click')) + }) + $trigger.trigger($.Event('click')) + }) + + QUnit.test('should allow accordion to contain nested elements', function (assert) { + assert.expect(4) + var done = assert.async() + var accordionHTML = '<div id="accordion">' + + '<div class="row">' + + '<div class="col-lg-6">' + + '<div class="item">' + + '<a id="linkTrigger" data-toggle="collapse" href="#collapseOne" aria-expanded="false" aria-controls="collapseOne"></a>' + + '<div id="collapseOne" class="collapse" role="tabpanel" aria-labelledby="headingThree" data-parent="#accordion"></div>' + + '</div>' + + '</div>' + + '<div class="col-lg-6">' + + '<div class="item">' + + '<a id="linkTriggerTwo" data-toggle="collapse" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo"></a>' + + '<div id="collapseTwo" class="collapse show" role="tabpanel" aria-labelledby="headingTwo" data-parent="#accordion"></div>' + + '</div>' + + '</div>' + + '</div>' + + '</div>' + + $(accordionHTML).appendTo('#qunit-fixture') + var $trigger = $('#linkTrigger') + var $triggerTwo = $('#linkTriggerTwo') + var $collapseOne = $('#collapseOne') + var $collapseTwo = $('#collapseTwo') + $collapseOne.on('shown.bs.collapse', function () { + assert.ok($collapseOne.hasClass('show'), '#collapseOne is shown') + assert.ok(!$collapseTwo.hasClass('show'), '#collapseTwo is not shown') + $collapseTwo.on('shown.bs.collapse', function () { + assert.ok(!$collapseOne.hasClass('show'), '#collapseOne is not shown') + assert.ok($collapseTwo.hasClass('show'), '#collapseTwo is shown') + done() + }) + $triggerTwo.trigger($.Event('click')) + }) + $trigger.trigger($.Event('click')) + }) + + QUnit.test('should allow accordion to target multiple elements', function (assert) { + assert.expect(8) + var done = assert.async() + var accordionHTML = '<div id="accordion">' + + '<a id="linkTriggerOne" data-toggle="collapse" data-target=".collapseOne" href="#" aria-expanded="false" aria-controls="collapseOne"></a>' + + '<a id="linkTriggerTwo" data-toggle="collapse" data-target=".collapseTwo" href="#" aria-expanded="false" aria-controls="collapseTwo"></a>' + + '<div id="collapseOneOne" class="collapse collapseOne" role="tabpanel" data-parent="#accordion"></div>' + + '<div id="collapseOneTwo" class="collapse collapseOne" role="tabpanel" data-parent="#accordion"></div>' + + '<div id="collapseTwoOne" class="collapse collapseTwo" role="tabpanel" data-parent="#accordion"></div>' + + '<div id="collapseTwoTwo" class="collapse collapseTwo" role="tabpanel" data-parent="#accordion"></div>' + + '</div>' + + $(accordionHTML).appendTo('#qunit-fixture') + var $trigger = $('#linkTriggerOne') + var $triggerTwo = $('#linkTriggerTwo') + var $collapseOneOne = $('#collapseOneOne') + var $collapseOneTwo = $('#collapseOneTwo') + var $collapseTwoOne = $('#collapseTwoOne') + var $collapseTwoTwo = $('#collapseTwoTwo') + var collapsedElements = { + one : false, + two : false + } + + function firstTest() { + assert.ok($collapseOneOne.hasClass('show'), '#collapseOneOne is shown') + assert.ok($collapseOneTwo.hasClass('show'), '#collapseOneTwo is shown') + assert.ok(!$collapseTwoOne.hasClass('show'), '#collapseTwoOne is not shown') + assert.ok(!$collapseTwoTwo.hasClass('show'), '#collapseTwoTwo is not shown') + $triggerTwo.trigger($.Event('click')) + } + + function secondTest() { + assert.ok(!$collapseOneOne.hasClass('show'), '#collapseOneOne is not shown') + assert.ok(!$collapseOneTwo.hasClass('show'), '#collapseOneTwo is not shown') + assert.ok($collapseTwoOne.hasClass('show'), '#collapseTwoOne is shown') + assert.ok($collapseTwoTwo.hasClass('show'), '#collapseTwoTwo is shown') + done() + } + + $collapseOneOne.on('shown.bs.collapse', function () { + if (collapsedElements.one) { + firstTest() + } else { + collapsedElements.one = true + } + }) + + $collapseOneTwo.on('shown.bs.collapse', function () { + if (collapsedElements.one) { + firstTest() + } else { + collapsedElements.one = true + } + }) + + $collapseTwoOne.on('shown.bs.collapse', function () { + if (collapsedElements.two) { + secondTest() + } else { + collapsedElements.two = true + } + }) + + $collapseTwoTwo.on('shown.bs.collapse', function () { + if (collapsedElements.two) { + secondTest() + } else { + collapsedElements.two = true + } + }) + + $trigger.trigger($.Event('click')) + }) + + QUnit.test('should collapse accordion children but not nested accordion children', function (assert) { + assert.expect(9) + var done = assert.async() + $('<div id="accordion">' + + '<div class="item">' + + '<a id="linkTrigger" data-toggle="collapse" href="#collapseOne" aria-expanded="false" aria-controls="collapseOne"></a>' + + '<div id="collapseOne" data-parent="#accordion" class="collapse" role="tabpanel" aria-labelledby="headingThree">' + + '<div id="nestedAccordion">' + + '<div class="item">' + + '<a id="nestedLinkTrigger" data-toggle="collapse" href="#nestedCollapseOne" aria-expanded="false" aria-controls="nestedCollapseOne"></a>' + + '<div id="nestedCollapseOne" data-parent="#nestedAccordion" class="collapse" role="tabpanel" aria-labelledby="headingThree">' + + '</div>' + + '</div>' + + '</div>' + + '</div>' + + '</div>' + + '<div class="item">' + + '<a id="linkTriggerTwo" data-toggle="collapse" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo"></a>' + + '<div id="collapseTwo" data-parent="#accordion" class="collapse show" role="tabpanel" aria-labelledby="headingTwo"></div>' + + '</div>' + + '</div>').appendTo('#qunit-fixture') + var $trigger = $('#linkTrigger') + var $triggerTwo = $('#linkTriggerTwo') + var $nestedTrigger = $('#nestedLinkTrigger') + var $collapseOne = $('#collapseOne') + var $collapseTwo = $('#collapseTwo') + var $nestedCollapseOne = $('#nestedCollapseOne') + + $collapseOne.one('shown.bs.collapse', function () { + assert.ok($collapseOne.hasClass('show'), '#collapseOne is shown') + assert.ok(!$collapseTwo.hasClass('show'), '#collapseTwo is not shown') + assert.ok(!$('#nestedCollapseOne').hasClass('show'), '#nestedCollapseOne is not shown') + $nestedCollapseOne.one('shown.bs.collapse', function () { + assert.ok($collapseOne.hasClass('show'), '#collapseOne is shown') + assert.ok(!$collapseTwo.hasClass('show'), '#collapseTwo is not shown') + assert.ok($nestedCollapseOne.hasClass('show'), '#nestedCollapseOne is shown') + $collapseTwo.one('shown.bs.collapse', function () { + assert.ok(!$collapseOne.hasClass('show'), '#collapseOne is not shown') + assert.ok($collapseTwo.hasClass('show'), '#collapseTwo is shown') + assert.ok($nestedCollapseOne.hasClass('show'), '#nestedCollapseOne is shown') + done() + }) + $triggerTwo.trigger($.Event('click')) + }) + $nestedTrigger.trigger($.Event('click')) + }) + $trigger.trigger($.Event('click')) + }) + + QUnit.test('should not prevent event for input', function (assert) { + assert.expect(3) + var done = assert.async() + var $target = $('<input type="checkbox" data-toggle="collapse" data-target="#collapsediv1" />').appendTo('#qunit-fixture') + + $('<div id="collapsediv1"/>') + .appendTo('#qunit-fixture') + .on('shown.bs.collapse', function () { + assert.ok($(this).hasClass('show')) + assert.ok($target.attr('aria-expanded') === 'true') + assert.ok($target.prop('checked')) + done() + }) + + $target.trigger($.Event('click')) + }) + + QUnit.test('should add "collapsed" class to triggers only when all the targeted collapse are hidden', function (assert) { + assert.expect(9) + var done = assert.async() + + var $trigger1 = $('<a role="button" data-toggle="collapse" href="#test1"/>').appendTo('#qunit-fixture') + var $trigger2 = $('<a role="button" data-toggle="collapse" href="#test2"/>').appendTo('#qunit-fixture') + var $trigger3 = $('<a role="button" data-toggle="collapse" href=".multi"/>').appendTo('#qunit-fixture') + + var $target1 = $('<div id="test1" class="multi"/>').appendTo('#qunit-fixture') + var $target2 = $('<div id="test2" class="multi"/>').appendTo('#qunit-fixture') + + $target2.one('shown.bs.collapse', function () { + assert.ok(!$trigger1.hasClass('collapsed'), 'trigger1 does not have collapsed class') + assert.ok(!$trigger2.hasClass('collapsed'), 'trigger2 does not have collapsed class') + assert.ok(!$trigger3.hasClass('collapsed'), 'trigger3 does not have collapsed class') + $target2.one('hidden.bs.collapse', function () { + assert.ok(!$trigger1.hasClass('collapsed'), 'trigger1 does not have collapsed class') + assert.ok($trigger2.hasClass('collapsed'), 'trigger2 has collapsed class') + assert.ok(!$trigger3.hasClass('collapsed'), 'trigger3 does not have collapsed class') + $target1.one('hidden.bs.collapse', function () { + assert.ok($trigger1.hasClass('collapsed'), 'trigger1 has collapsed class') + assert.ok($trigger2.hasClass('collapsed'), 'trigger2 has collapsed class') + assert.ok($trigger3.hasClass('collapsed'), 'trigger3 has collapsed class') + done() + }) + $trigger1.trigger('click') + }) + $trigger2.trigger('click') + }) + $trigger3.trigger('click') + }) + + QUnit.test('should set aria-expanded="true" to triggers targeting shown collaspe and aria-expanded="false" only when all the targeted collapses are shown', function (assert) { + assert.expect(9) + var done = assert.async() + + var $trigger1 = $('<a role="button" data-toggle="collapse" href="#test1"/>').appendTo('#qunit-fixture') + var $trigger2 = $('<a role="button" data-toggle="collapse" href="#test2"/>').appendTo('#qunit-fixture') + var $trigger3 = $('<a role="button" data-toggle="collapse" href=".multi"/>').appendTo('#qunit-fixture') + + var $target1 = $('<div id="test1" class="multi collapse"/>').appendTo('#qunit-fixture') + var $target2 = $('<div id="test2" class="multi collapse"/>').appendTo('#qunit-fixture') + + $target2.one('shown.bs.collapse', function () { + assert.strictEqual($trigger1.attr('aria-expanded'), 'true', 'aria-expanded on trigger1 is "true"') + assert.strictEqual($trigger2.attr('aria-expanded'), 'true', 'aria-expanded on trigger2 is "true"') + assert.strictEqual($trigger3.attr('aria-expanded'), 'true', 'aria-expanded on trigger3 is "true"') + $target2.one('hidden.bs.collapse', function () { + assert.strictEqual($trigger1.attr('aria-expanded'), 'true', 'aria-expanded on trigger1 is "true"') + assert.strictEqual($trigger2.attr('aria-expanded'), 'false', 'aria-expanded on trigger2 is "false"') + assert.strictEqual($trigger3.attr('aria-expanded'), 'true', 'aria-expanded on trigger3 is "true"') + $target1.one('hidden.bs.collapse', function () { + assert.strictEqual($trigger1.attr('aria-expanded'), 'false', 'aria-expanded on trigger1 is "fasle"') + assert.strictEqual($trigger2.attr('aria-expanded'), 'false', 'aria-expanded on trigger2 is "false"') + assert.strictEqual($trigger3.attr('aria-expanded'), 'false', 'aria-expanded on trigger3 is "false"') + done() + }) + $trigger1.trigger('click') + }) + $trigger2.trigger('click') + }) + $trigger3.trigger('click') + }) + + QUnit.test('should not prevent interactions inside the collapse element', function (assert) { + assert.expect(2) + var done = assert.async() + + var $target = $('<input type="checkbox" data-toggle="collapse" data-target="#collapsediv1" />').appendTo('#qunit-fixture') + var htmlCollapse = + '<div id="collapsediv1" class="collapse">' + + ' <input type="checkbox" id="testCheckbox" />' + + '</div>' + + $(htmlCollapse) + .appendTo('#qunit-fixture') + .on('shown.bs.collapse', function () { + assert.ok($target.prop('checked'), '$trigger is checked') + var $testCheckbox = $('#testCheckbox') + $testCheckbox.trigger($.Event('click')) + setTimeout(function () { + assert.ok($testCheckbox.prop('checked'), '$testCheckbox is checked too') + done() + }, 5) + }) + + $target.trigger($.Event('click')) + }) + + QUnit.test('should allow jquery object in parent config', function (assert) { + assert.expect(1) + var html = + '<div class="my-collapse">' + + ' <div class="item">' + + ' <a data-toggle="collapse" href="#">Toggle item</a>' + + ' <div class="collapse">Lorem ipsum</div>' + + ' </div>' + + '</div>' + + $(html).appendTo('#qunit-fixture') + try { + $('[data-toggle="collapse"]').bootstrapCollapse({ + parent: $('.my-collapse') + }) + assert.ok(true, 'collapse correctly created') + } catch (err) { + assert.ok(false, 'collapse not created') + } + }) + + QUnit.test('should allow DOM object in parent config', function (assert) { + assert.expect(1) + var html = + '<div class="my-collapse">' + + ' <div class="item">' + + ' <a data-toggle="collapse" href="#">Toggle item</a>' + + ' <div class="collapse">Lorem ipsum</div>' + + ' </div>' + + '</div>' + + $(html).appendTo('#qunit-fixture') + try { + $('[data-toggle="collapse"]').bootstrapCollapse({ + parent: $('.my-collapse')[0] + }) + assert.ok(true, 'collapse correctly created') + } catch (err) { + assert.ok(false, 'collapse not created') + } + }) +}) diff --git a/themes/docsy/assets/vendor/bootstrap/js/tests/unit/dropdown.js b/themes/docsy/assets/vendor/bootstrap/js/tests/unit/dropdown.js new file mode 100644 index 0000000..81d35ff --- /dev/null +++ b/themes/docsy/assets/vendor/bootstrap/js/tests/unit/dropdown.js @@ -0,0 +1,1124 @@ +$(function () { + 'use strict' + + QUnit.module('dropdowns plugin') + + QUnit.test('should be defined on jquery object', function (assert) { + assert.expect(1) + assert.ok($(document.body).dropdown, 'dropdown method is defined') + }) + + QUnit.module('dropdowns', { + beforeEach: 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() + }, + afterEach: function () { + $.fn.dropdown = $.fn.bootstrapDropdown + delete $.fn.bootstrapDropdown + $('#qunit-fixture').html('') + } + }) + + QUnit.test('should provide no conflict', function (assert) { + assert.expect(1) + assert.strictEqual(typeof $.fn.dropdown, 'undefined', 'dropdown was set back to undefined (org value)') + }) + + QUnit.test('should throw explicit error on undefined method', function (assert) { + assert.expect(1) + var $el = $('<div/>') + $el.bootstrapDropdown() + try { + $el.bootstrapDropdown('noMethod') + } catch (err) { + assert.strictEqual(err.message, 'No method named "noMethod"') + } + }) + + QUnit.test('should return jquery collection containing the element', function (assert) { + assert.expect(2) + var $el = $('<div/>') + var $dropdown = $el.bootstrapDropdown() + assert.ok($dropdown instanceof $, 'returns jquery collection') + assert.strictEqual($dropdown[0], $el[0], 'collection contains element') + }) + + QUnit.test('should not open dropdown if target is disabled via attribute', function (assert) { + assert.expect(1) + var done = assert.async() + var dropdownHTML = '<div class="tabs">' + + '<div class="dropdown">' + + '<button disabled href="#" class="btn dropdown-toggle" data-toggle="dropdown">Dropdown</button>' + + '<div class="dropdown-menu">' + + '<a class="dropdown-item" href="#">Secondary link</a>' + + '<a class="dropdown-item" href="#">Something else here</a>' + + '<div class="divider"/>' + + '<a class="dropdown-item" href="#">Another link</a>' + + '</div>' + + '</div>' + + '</div>' + $(dropdownHTML).appendTo('#qunit-fixture') + var $dropdown = $('#qunit-fixture').find('[data-toggle="dropdown"]').bootstrapDropdown() + $dropdown.on('click', function () { + assert.ok(!$dropdown.parent('.dropdown').hasClass('show')) + done() + }) + $dropdown.trigger($.Event('click')) + }) + + QUnit.test('should not add class position-static to dropdown if boundary not set', function (assert) { + assert.expect(1) + var done = assert.async() + 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>' + + '</div>' + + '</div>' + var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown() + $dropdown + .parent('.dropdown') + .on('shown.bs.dropdown', function () { + assert.ok(!$dropdown.parent('.dropdown').hasClass('position-static'), '"position-static" class not added') + done() + }) + $dropdown.trigger('click') + }) + + QUnit.test('should add class position-static to dropdown if boundary not scrollParent', function (assert) { + assert.expect(1) + var done = assert.async() + var dropdownHTML = '<div class="tabs">' + + '<div class="dropdown">' + + '<a href="#" class="dropdown-toggle" data-toggle="dropdown" data-boundary="viewport">Dropdown</a>' + + '<div class="dropdown-menu">' + + '<a class="dropdown-item" href="#">Secondary link</a>' + + '<a class="dropdown-item" href="#">Something else here</a>' + + '</div>' + + '</div>' + + '</div>' + var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown() + $dropdown + .parent('.dropdown') + .on('shown.bs.dropdown', function () { + assert.ok($dropdown.parent('.dropdown').hasClass('position-static'), '"position-static" class added') + done() + }) + $dropdown.trigger('click') + }) + + QUnit.test('should set aria-expanded="true" on target when dropdown menu is shown', function (assert) { + assert.expect(1) + var done = assert.async() + var dropdownHTML = '<div class="tabs">' + + '<div class="dropdown">' + + '<a href="#" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false">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="divider"/>' + + '<a class="dropdown-item" href="#">Another link</a>' + + '</div>' + + '</div>' + + '</div>' + var $dropdown = $(dropdownHTML) + .appendTo('#qunit-fixture') + .find('[data-toggle="dropdown"]') + .bootstrapDropdown() + $dropdown + .parent('.dropdown') + .on('shown.bs.dropdown', function () { + assert.strictEqual($dropdown.attr('aria-expanded'), 'true', 'aria-expanded is set to string "true" on click') + done() + }) + $dropdown.trigger('click') + }) + + QUnit.test('should set aria-expanded="false" on target when dropdown menu is hidden', function (assert) { + assert.expect(1) + var done = assert.async() + var dropdownHTML = '<div class="tabs">' + + '<div class="dropdown">' + + '<a href="#" class="dropdown-toggle" aria-expanded="false" 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="divider"/>' + + '<a class="dropdown-item" href="#">Another link</a>' + + '</div>' + + '</div>' + + '</div>' + var $dropdown = $(dropdownHTML) + .appendTo('#qunit-fixture') + .find('[data-toggle="dropdown"]') + .bootstrapDropdown() + + $dropdown + .parent('.dropdown') + .on('hidden.bs.dropdown', function () { + assert.strictEqual($dropdown.attr('aria-expanded'), 'false', 'aria-expanded is set to string "false" on hide') + done() + }) + + $dropdown.trigger('click') + $(document.body).trigger('click') + }) + + QUnit.test('should not open dropdown if target is disabled via class', function (assert) { + assert.expect(1) + var done = assert.async() + var dropdownHTML = '<div class="tabs">' + + '<div class="dropdown">' + + '<button href="#" class="btn dropdown-toggle disabled" data-toggle="dropdown">Dropdown</button>' + + '<div class="dropdown-menu">' + + '<a class="dropdown-item" href="#">Secondary link</a>' + + '<a class="dropdown-item" href="#">Something else here</a>' + + '<div class="divider"/>' + + '<a class="dropdown-item" href="#">Another link</a>' + + '</div>' + + '</div>' + + '</div>' + + $(dropdownHTML).appendTo('#qunit-fixture') + var $dropdown = $('#qunit-fixture').find('[data-toggle="dropdown"]').bootstrapDropdown() + $dropdown.on('click', function () { + assert.ok(!$dropdown.parent('.dropdown').hasClass('show')) + done() + }) + $dropdown.trigger($.Event('click')) + }) + + QUnit.test('should add class show to menu if clicked', function (assert) { + assert.expect(1) + var done = assert.async() + 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="divider"/>' + + '<a class="dropdown-item" href="#">Another link</a>' + + '</div>' + + '</div>' + + '</div>' + var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown() + $dropdown + .parent('.dropdown') + .on('shown.bs.dropdown', function () { + assert.ok($dropdown.parent('.dropdown').hasClass('show'), '"show" class added on click') + done() + }) + $dropdown.trigger('click') + }) + + QUnit.test('should test if element has a # before assuming it\'s a selector', function (assert) { + assert.expect(1) + var done = assert.async() + var dropdownHTML = '<div class="tabs">' + + '<div class="dropdown">' + + '<a href="/foo/" 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="divider"/>' + + '<a class="dropdown-item" href="#">Another link</a>' + + '</div>' + + '</div>' + + '</div>' + var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown() + $dropdown + .parent('.dropdown') + .on('shown.bs.dropdown', function () { + assert.ok($dropdown.parent('.dropdown').hasClass('show'), '"show" class added on click') + done() + }) + $dropdown.trigger('click') + }) + + QUnit.test('should remove "show" class if body is clicked', function (assert) { + assert.expect(2) + var done = assert.async() + 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="divider"/>' + + '<a class="dropdown-item" href="#">Another link</a>' + + '</div>' + + '</div>' + + '</div>' + var $dropdown = $(dropdownHTML) + .appendTo('#qunit-fixture') + .find('[data-toggle="dropdown"]') + .bootstrapDropdown() + + $dropdown + .parent('.dropdown') + .on('shown.bs.dropdown', function () { + assert.ok($dropdown.parent('.dropdown').hasClass('show'), '"show" class added on click') + $(document.body).trigger('click') + }).on('hidden.bs.dropdown', function () { + assert.ok(!$dropdown.parent('.dropdown').hasClass('show'), '"show" class removed') + done() + }) + $dropdown.trigger('click') + }) + + QUnit.test('should remove "show" class if tabbing outside of menu', function (assert) { + assert.expect(2) + var done = assert.async() + 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() + $dropdown + .parent('.dropdown') + .on('shown.bs.dropdown', function () { + assert.ok($dropdown.parent('.dropdown').hasClass('show'), '"show" class added on click') + var e = $.Event('keyup') + e.which = 9 // Tab + $(document.body).trigger(e) + }).on('hidden.bs.dropdown', function () { + assert.ok(!$dropdown.parent('.dropdown').hasClass('show'), '"show" class removed') + done() + }) + $dropdown.trigger('click') + }) + + QUnit.test('should remove "show" class if body is clicked, with multiple dropdowns', function (assert) { + assert.expect(7) + var done = assert.async() + 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"></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.parent('.dropdown') + .on('shown.bs.dropdown', function () { + assert.strictEqual($first.parents('.show').length, 1, '"show" class added on click') + assert.strictEqual($('#qunit-fixture .dropdown-menu.show').length, 1, 'only one dropdown is shown') + $(document.body).trigger('click') + }).on('hidden.bs.dropdown', function () { + assert.strictEqual($('#qunit-fixture .dropdown-menu.show').length, 0, '"show" class removed') + $last.trigger('click') + }) + + $last.parent('.btn-group') + .on('shown.bs.dropdown', function () { + assert.strictEqual($last.parent('.show').length, 1, '"show" class added on click') + assert.strictEqual($('#qunit-fixture .dropdown-menu.show').length, 1, 'only one dropdown is shown') + $(document.body).trigger('click') + }).on('hidden.bs.dropdown', function () { + assert.strictEqual($('#qunit-fixture .dropdown-menu.show').length, 0, '"show" class removed') + done() + }) + $first.trigger('click') + }) + + QUnit.test('should remove "show" class if body if tabbing outside of menu, with multiple dropdowns', function (assert) { + assert.expect(7) + var done = assert.async() + 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.parent('.dropdown') + .on('shown.bs.dropdown', function () { + assert.strictEqual($first.parents('.show').length, 1, '"show" class added on click') + assert.strictEqual($('#qunit-fixture .dropdown-menu.show').length, 1, 'only one dropdown is shown') + var e = $.Event('keyup') + e.which = 9 // Tab + $(document.body).trigger(e) + }).on('hidden.bs.dropdown', function () { + assert.strictEqual($('#qunit-fixture .dropdown-menu.show').length, 0, '"show" class removed') + $last.trigger('click') + }) + + $last.parent('.btn-group') + .on('shown.bs.dropdown', function () { + assert.strictEqual($last.parent('.show').length, 1, '"show" class added on click') + assert.strictEqual($('#qunit-fixture .dropdown-menu.show').length, 1, 'only one dropdown is shown') + var e = $.Event('keyup') + e.which = 9 // Tab + $(document.body).trigger(e) + }).on('hidden.bs.dropdown', function () { + assert.strictEqual($('#qunit-fixture .dropdown-menu.show').length, 0, '"show" class removed') + done() + }) + $first.trigger('click') + }) + + QUnit.test('should fire show and hide event', 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="divider"/>' + + '<a class="dropdown-item" href="#">Another link</a>' + + '</div>' + + '</div>' + + '</div>' + var $dropdown = $(dropdownHTML) + .appendTo('#qunit-fixture') + .find('[data-toggle="dropdown"]') + .bootstrapDropdown() + + var done = assert.async() + + $dropdown + .parent('.dropdown') + .on('show.bs.dropdown', function () { + assert.ok(true, 'show was fired') + }) + .on('hide.bs.dropdown', function () { + assert.ok(true, 'hide was fired') + done() + }) + + $dropdown.trigger('click') + $(document.body).trigger('click') + }) + + QUnit.test('should fire shown and hidden event', 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="divider"/>' + + '<a class="dropdown-item" href="#">Another link</a>' + + '</div>' + + '</div>' + + '</div>' + var $dropdown = $(dropdownHTML) + .appendTo('#qunit-fixture') + .find('[data-toggle="dropdown"]') + .bootstrapDropdown() + + var done = assert.async() + + $dropdown + .parent('.dropdown') + .on('shown.bs.dropdown', function () { + assert.ok(true, 'shown was fired') + }) + .on('hidden.bs.dropdown', function () { + assert.ok(true, 'hidden was fired') + done() + }) + + $dropdown.trigger('click') + $(document.body).trigger('click') + }) + + QUnit.test('should fire shown and hidden event with a relatedTarget', 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="divider"/>' + + '<a class="dropdown-item" href="#">Another link</a>' + + '</div>' + + '</div>' + + '</div>' + var $dropdown = $(dropdownHTML) + .appendTo('#qunit-fixture') + .find('[data-toggle="dropdown"]') + .bootstrapDropdown() + var done = assert.async() + + $dropdown.parent('.dropdown') + .on('hidden.bs.dropdown', function (e) { + assert.strictEqual(e.relatedTarget, $dropdown[0]) + done() + }) + .on('shown.bs.dropdown', function (e) { + assert.strictEqual(e.relatedTarget, $dropdown[0]) + $(document.body).trigger('click') + }) + + $dropdown.trigger('click') + }) + + QUnit.test('should fire hide and hidden event with a clickEvent', function (assert) { + assert.expect(3) + 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="divider"/>' + + '<a class="dropdown-item" href="#">Another link</a>' + + '</div>' + + '</div>' + + '</div>' + var $dropdown = $(dropdownHTML) + .appendTo('#qunit-fixture') + .find('[data-toggle="dropdown"]') + .bootstrapDropdown() + + $dropdown.parent('.dropdown') + .on('hide.bs.dropdown', function (e) { + assert.ok(e.clickEvent) + }) + .on('hidden.bs.dropdown', function (e) { + assert.ok(e.clickEvent) + }) + .on('shown.bs.dropdown', function () { + assert.ok(true, 'shown was fired') + $(document.body).trigger('click') + }) + + $dropdown.trigger('click') + }) + + QUnit.test('should fire hide and hidden event without a clickEvent if event type is not click', function (assert) { + assert.expect(3) + 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="divider"/>' + + '<a class="dropdown-item" href="#">Another link</a>' + + '</div>' + + '</div>' + + '</div>' + var $dropdown = $(dropdownHTML) + .appendTo('#qunit-fixture') + .find('[data-toggle="dropdown"]') + .bootstrapDropdown() + + $dropdown.parent('.dropdown') + .on('hide.bs.dropdown', function (e) { + assert.notOk(e.clickEvent) + }) + .on('hidden.bs.dropdown', function (e) { + assert.notOk(e.clickEvent) + }) + .on('shown.bs.dropdown', function () { + assert.ok(true, 'shown was fired') + $dropdown.trigger($.Event('keydown', { + which: 27 + })) + }) + + $dropdown.trigger('click') + }) + + QUnit.test('should ignore keyboard events within <input>s and <textarea>s', function (assert) { + assert.expect(3) + var done = assert.async() + + 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="divider"/>' + + '<a class="dropdown-item" href="#">Another link</a>' + + '<input type="text" id="input">' + + '<textarea id="textarea"/>' + + '</div>' + + '</div>' + + '</div>' + var $dropdown = $(dropdownHTML) + .appendTo('#qunit-fixture') + .find('[data-toggle="dropdown"]') + .bootstrapDropdown() + + var $input = $('#input') + var $textarea = $('#textarea') + + $dropdown + .parent('.dropdown') + .on('shown.bs.dropdown', function () { + assert.ok(true, 'shown was fired') + + $input.trigger('focus').trigger($.Event('keydown', { + which: 38 + })) + assert.ok($(document.activeElement).is($input), 'input still focused') + + $textarea.trigger('focus').trigger($.Event('keydown', { + which: 38 + })) + assert.ok($(document.activeElement).is($textarea), 'textarea still focused') + + done() + }) + + $dropdown.trigger('click') + }) + + QUnit.test('should skip disabled element when using keyboard navigation', function (assert) { + assert.expect(3) + var done = assert.async() + 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 disabled" href="#">Disabled link</a>' + + '<button class="dropdown-item" type="button" disabled>Disabled button</button>' + + '<a id="item1" class="dropdown-item" href="#">Another link</a>' + + '</div>' + + '</div>' + + '</div>' + var $dropdown = $(dropdownHTML) + .appendTo('#qunit-fixture') + .find('[data-toggle="dropdown"]') + .bootstrapDropdown() + + $dropdown + .parent('.dropdown') + .on('shown.bs.dropdown', function () { + assert.ok(true, 'shown was fired') + $dropdown.trigger($.Event('keydown', { + which: 40 + })) + $dropdown.trigger($.Event('keydown', { + which: 40 + })) + assert.ok(!$(document.activeElement).is('.disabled'), '.disabled is not focused') + assert.ok(!$(document.activeElement).is(':disabled'), ':disabled is not focused') + done() + }) + $dropdown.trigger('click') + }) + + QUnit.test('should focus next/previous element when using keyboard navigation', function (assert) { + assert.expect(4) + var done = assert.async() + var dropdownHTML = '<div class="tabs">' + + '<div class="dropdown">' + + '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>' + + '<div class="dropdown-menu">' + + '<a id="item1" class="dropdown-item" href="#">A link</a>' + + '<a id="item2" class="dropdown-item" href="#">Another link</a>' + + '</div>' + + '</div>' + + '</div>' + var $dropdown = $(dropdownHTML) + .appendTo('#qunit-fixture') + .find('[data-toggle="dropdown"]') + .bootstrapDropdown() + + $dropdown + .parent('.dropdown') + .on('shown.bs.dropdown', function () { + assert.ok(true, 'shown was fired') + $dropdown.trigger($.Event('keydown', { + which: 40 + })) + assert.ok($(document.activeElement).is($('#item1')), 'item1 is focused') + + $(document.activeElement).trigger($.Event('keydown', { + which: 40 + })) + assert.ok($(document.activeElement).is($('#item2')), 'item2 is focused') + + $(document.activeElement).trigger($.Event('keydown', { + which: 38 + })) + assert.ok($(document.activeElement).is($('#item1')), 'item1 is focused') + done() + }) + $dropdown.trigger('click') + }) + + QUnit.test('should not close the dropdown if the user clicks on a text field', function (assert) { + assert.expect(2) + var done = assert.async() + var dropdownHTML = '<div class="dropdown">' + + '<button type="button" data-toggle="dropdown">Dropdown</button>' + + '<div class="dropdown-menu">' + + '<input id="textField" type="text" />' + + '</div>' + + '</div>' + var $dropdown = $(dropdownHTML) + .appendTo('#qunit-fixture') + .find('[data-toggle="dropdown"]') + .bootstrapDropdown() + + var $textfield = $('#textField') + $textfield.on('click', function () { + assert.ok($dropdown.parent('.dropdown').hasClass('show'), 'dropdown menu is shown') + done() + }) + + $dropdown + .parent('.dropdown') + .on('shown.bs.dropdown', function () { + assert.ok($dropdown.parent('.dropdown').hasClass('show'), 'dropdown menu is shown') + $textfield.trigger($.Event('click')) + }) + $dropdown.trigger('click') + }) + + QUnit.test('should not close the dropdown if the user clicks on a textarea', function (assert) { + assert.expect(2) + var done = assert.async() + var dropdownHTML = '<div class="dropdown">' + + '<button type="button" data-toggle="dropdown">Dropdown</button>' + + '<div class="dropdown-menu">' + + '<textarea id="textArea"></textarea>' + + '</div>' + + '</div>' + var $dropdown = $(dropdownHTML) + .appendTo('#qunit-fixture') + .find('[data-toggle="dropdown"]') + .bootstrapDropdown() + + var $textarea = $('#textArea') + $textarea.on('click', function () { + assert.ok($dropdown.parent('.dropdown').hasClass('show'), 'dropdown menu is shown') + done() + }) + + $dropdown + .parent('.dropdown') + .on('shown.bs.dropdown', function () { + assert.ok($dropdown.parent('.dropdown').hasClass('show'), 'dropdown menu is shown') + $textarea.trigger($.Event('click')) + }) + $dropdown.trigger('click') + }) + + QUnit.test('Dropdown should not use Popper.js in navbar', function (assert) { + assert.expect(1) + var done = assert.async() + var html = '<nav class="navbar navbar-expand-md navbar-light bg-light">' + + '<div class="dropdown">' + + ' <a class="nav-link dropdown-toggle" href="#" id="dropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dropdown</a>' + + ' <div class="dropdown-menu" aria-labelledby="dropdown">' + + ' <a class="dropdown-item" href="#">Action</a>' + + ' <a class="dropdown-item" href="#">Another action</a>' + + ' <a class="dropdown-item" href="#">Something else here</a>' + + ' </div>' + + '</div>' + + '</nav>' + + $(html).appendTo('#qunit-fixture') + var $triggerDropdown = $('#qunit-fixture') + .find('[data-toggle="dropdown"]') + .bootstrapDropdown() + var $dropdownMenu = $triggerDropdown.next() + + $triggerDropdown + .parent('.dropdown') + .on('shown.bs.dropdown', function () { + assert.ok(typeof $dropdownMenu.attr('style') === 'undefined', 'No inline style applied by Popper.js') + done() + }) + $triggerDropdown.trigger($.Event('click')) + }) + + QUnit.test('should ignore keyboard events for <input>s and <textarea>s within dropdown-menu, except for escape key', function (assert) { + assert.expect(7) + var done = assert.async() + + 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="divider"/>' + + '<a class="dropdown-item" href="#">Another link</a>' + + '<input type="text" id="input">' + + '<textarea id="textarea"/>' + + '</div>' + + '</div>' + + '</div>' + var $dropdown = $(dropdownHTML) + .appendTo('#qunit-fixture') + .find('[data-toggle="dropdown"]') + .bootstrapDropdown() + + var $input = $('#input') + var $textarea = $('#textarea') + + $dropdown + .parent('.dropdown') + .on('shown.bs.dropdown', function () { + // Space key + $input.trigger('focus').trigger($.Event('keydown', { + which: 32 + })) + assert.ok($(document.activeElement)[0] === $input[0], 'input still focused') + $textarea.trigger('focus').trigger($.Event('keydown', { + which: 32 + })) + assert.ok($(document.activeElement)[0] === $textarea[0], 'textarea still focused') + + // Key up + $input.trigger('focus').trigger($.Event('keydown', { + which: 38 + })) + assert.ok($(document.activeElement)[0] === $input[0], 'input still focused') + $textarea.trigger('focus').trigger($.Event('keydown', { + which: 38 + })) + assert.ok($(document.activeElement)[0] === $textarea[0], 'textarea still focused') + + // Key down + $input.trigger('focus').trigger($.Event('keydown', { + which: 40 + })) + assert.ok($(document.activeElement)[0] === $input[0], 'input still focused') + $textarea.trigger('focus').trigger($.Event('keydown', { + which: 40 + })) + assert.ok($(document.activeElement)[0] === $textarea[0], 'textarea still focused') + + // Key escape + $input.trigger('focus').trigger($.Event('keydown', { + which: 27 + })) + assert.ok(!$dropdown.parent('.dropdown').hasClass('show'), 'dropdown menu is not shown') + done() + }) + + $dropdown.trigger('click') + }) + + QUnit.test('should ignore space key events for <input>s within dropdown, and accept up, down and escape', function (assert) { + assert.expect(6) + var done = assert.async() + + var dropdownHTML = + '<ul class="nav tabs">' + + ' <li class="dropdown">' + + ' <input type="text" id="input" data-toggle="dropdown">' + + ' <div class="dropdown-menu" role="menu">' + + ' <a id="item1" class="dropdown-item" href="#">Secondary link</a>' + + ' <a id="item2" class="dropdown-item" href="#">Something else here</a>' + + ' <div class="divider"></div>' + + ' <a class="dropdown-item" href="#">Another link</a>' + + ' </div>' + + ' </li>' + + '</ul>' + + var $dropdown = $(dropdownHTML) + .appendTo('#qunit-fixture') + .find('[data-toggle="dropdown"]') + .bootstrapDropdown() + + var $input = $('#input') + + $dropdown + .parent('.dropdown') + .one('shown.bs.dropdown', function () { + assert.ok(true, 'shown was fired') + + // Key space + $input.trigger('focus').trigger($.Event('keydown', { + which: 32 + })) + assert.ok($dropdown.parent('.dropdown').hasClass('show'), 'dropdown menu is shown') + assert.ok($(document.activeElement).is($input), 'input is still focused') + + // Key escape + $input.trigger('focus').trigger($.Event('keydown', { + which: 27 + })) + assert.ok(!$dropdown.parent('.dropdown').hasClass('show'), 'dropdown menu is not shown') + + $dropdown + .parent('.dropdown') + .one('shown.bs.dropdown', function () { + // Key down + $input.trigger('focus').trigger($.Event('keydown', { + which: 40 + })) + assert.ok(document.activeElement === $('#item1')[0], 'item1 is focused') + + $dropdown + .parent('.dropdown') + .one('shown.bs.dropdown', function () { + // Key up + $input.trigger('focus').trigger($.Event('keydown', { + which: 38 + })) + assert.ok(document.activeElement === $('#item1')[0], 'item1 is focused') + done() + }).bootstrapDropdown('toggle') + $input.trigger('click') + }) + $input.trigger('click') + }) + $input.trigger('click') + }) + + QUnit.test('should ignore space key events for <textarea>s within dropdown, and accept up, down and escape', function (assert) { + assert.expect(6) + var done = assert.async() + + var dropdownHTML = + '<ul class="nav tabs">' + + ' <li class="dropdown">' + + ' <textarea id="textarea" data-toggle="dropdown"></textarea>' + + ' <div class="dropdown-menu" role="menu">' + + ' <a id="item1" class="dropdown-item" href="#">Secondary link</a>' + + ' <a id="item2" class="dropdown-item" href="#">Something else here</a>' + + ' <div class="divider"></div>' + + ' <a class="dropdown-item" href="#">Another link</a>' + + ' </div>' + + ' </li>' + + '</ul>' + + var $dropdown = $(dropdownHTML) + .appendTo('#qunit-fixture') + .find('[data-toggle="dropdown"]') + .bootstrapDropdown() + + var $textarea = $('#textarea') + + $dropdown + .parent('.dropdown') + .one('shown.bs.dropdown', function () { + assert.ok(true, 'shown was fired') + + // Key space + $textarea.trigger('focus').trigger($.Event('keydown', { + which: 32 + })) + assert.ok($dropdown.parent('.dropdown').hasClass('show'), 'dropdown menu is shown') + assert.ok($(document.activeElement).is($textarea), 'textarea is still focused') + + // Key escape + $textarea.trigger('focus').trigger($.Event('keydown', { + which: 27 + })) + assert.ok(!$dropdown.parent('.dropdown').hasClass('show'), 'dropdown menu is not shown') + + $dropdown + .parent('.dropdown') + .one('shown.bs.dropdown', function () { + // Key down + $textarea.trigger('focus').trigger($.Event('keydown', { + which: 40 + })) + assert.ok(document.activeElement === $('#item1')[0], 'item1 is focused') + + $dropdown + .parent('.dropdown') + .one('shown.bs.dropdown', function () { + // Key up + $textarea.trigger('focus').trigger($.Event('keydown', { + which: 38 + })) + assert.ok(document.activeElement === $('#item1')[0], 'item1 is focused') + done() + }).bootstrapDropdown('toggle') + $textarea.trigger('click') + }) + $textarea.trigger('click') + }) + $textarea.trigger('click') + }) + + QUnit.test('should not use Popper.js if display set to static', function (assert) { + assert.expect(1) + var dropdownHTML = + '<div class="dropdown">' + + '<a href="#" class="dropdown-toggle" data-toggle="dropdown" data-display="static">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="divider"/>' + + '<a class="dropdown-item" href="#">Another link</a>' + + '</div>' + + '</div>' + + var $dropdown = $(dropdownHTML) + .appendTo('#qunit-fixture') + .find('[data-toggle="dropdown"]') + .bootstrapDropdown() + var done = assert.async() + var dropdownMenu = $dropdown.next()[0] + + $dropdown.parent('.dropdown') + .on('shown.bs.dropdown', function () { + // Popper.js add this attribute when we use it + assert.strictEqual(dropdownMenu.getAttribute('x-placement'), null) + done() + }) + + $dropdown.trigger('click') + }) + + QUnit.test('should call Popper.js and detect navbar on update', function (assert) { + assert.expect(3) + + 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') + dropdown.toggle() + assert.ok(dropdown._popper) + + var spyPopper = sinon.spy(dropdown._popper, 'scheduleUpdate') + var spyDetectNavbar = sinon.spy(dropdown, '_detectNavbar') + dropdown.update() + + assert.ok(spyPopper.called) + assert.ok(spyDetectNavbar.called) + }) + + QUnit.test('should just detect navbar on update', 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 spyDetectNavbar = sinon.spy(dropdown, '_detectNavbar') + + dropdown.update() + + assert.notOk(dropdown._popper) + assert.ok(spyDetectNavbar.called) + }) + + QUnit.test('should dispose dropdown with Popper', function (assert) { + assert.expect(6) + + 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') + dropdown.toggle() + + assert.ok(dropdown._popper) + assert.ok(dropdown._menu !== null) + assert.ok(dropdown._element !== null) + var spyDestroy = sinon.spy(dropdown._popper, 'destroy') + + dropdown.dispose() + + assert.ok(spyDestroy.called) + assert.ok(dropdown._menu === null) + assert.ok(dropdown._element === null) + }) + + QUnit.test('should dispose dropdown', function (assert) { + assert.expect(5) + + 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') + + assert.notOk(dropdown._popper) + assert.ok(dropdown._menu !== null) + assert.ok(dropdown._element !== null) + + dropdown.dispose() + + assert.ok(dropdown._menu === null) + assert.ok(dropdown._element === null) + }) +}) diff --git a/themes/docsy/assets/vendor/bootstrap/js/tests/unit/modal.js b/themes/docsy/assets/vendor/bootstrap/js/tests/unit/modal.js new file mode 100644 index 0000000..53a2e04 --- /dev/null +++ b/themes/docsy/assets/vendor/bootstrap/js/tests/unit/modal.js @@ -0,0 +1,657 @@ +$(function () { + 'use strict' + + QUnit.module('modal plugin') + + QUnit.test('should be defined on jquery object', function (assert) { + assert.expect(1) + assert.ok($(document.body).modal, 'modal method is defined') + }) + + QUnit.module('modal', { + before: function () { + // Enable the scrollbar measurer + $('<style type="text/css"> .modal-scrollbar-measure { position: absolute; top: -9999px; width: 50px; height: 50px; overflow: scroll; } </style>').appendTo('head') + // Function to calculate the scrollbar width which is then compared to the padding or margin changes + $.fn.getScrollbarWidth = function () { + var scrollDiv = document.createElement('div') + scrollDiv.className = 'modal-scrollbar-measure' + document.body.appendChild(scrollDiv) + var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth + document.body.removeChild(scrollDiv) + return scrollbarWidth + } + + // Simulate scrollbars + $('html').css('padding-right', '16px') + }, + beforeEach: 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() + }, + afterEach: function () { + $('.modal-backdrop, #modal-test').remove() + $(document.body).removeClass('modal-open') + $.fn.modal = $.fn.bootstrapModal + delete $.fn.bootstrapModal + $('#qunit-fixture').html('') + } + }) + + QUnit.test('should provide no conflict', function (assert) { + assert.expect(1) + assert.strictEqual(typeof $.fn.modal, 'undefined', 'modal was set back to undefined (orig value)') + }) + + QUnit.test('should throw explicit error on undefined method', function (assert) { + assert.expect(1) + var $el = $('<div id="modal-test"/>') + $el.bootstrapModal() + try { + $el.bootstrapModal('noMethod') + } catch (err) { + assert.strictEqual(err.message, 'No method named "noMethod"') + } + }) + + QUnit.test('should return jquery collection containing the element', function (assert) { + assert.expect(2) + var $el = $('<div id="modal-test"/>') + var $modal = $el.bootstrapModal() + assert.ok($modal instanceof $, 'returns jquery collection') + assert.strictEqual($modal[0], $el[0], 'collection contains element') + }) + + QUnit.test('should expose defaults var for settings', function (assert) { + assert.expect(1) + assert.ok($.fn.bootstrapModal.Constructor.Default, 'default object exposed') + }) + + QUnit.test('should insert into dom when show method is called', function (assert) { + assert.expect(1) + var done = assert.async() + + $('<div id="modal-test"/>') + .on('shown.bs.modal', function () { + assert.notEqual($('#modal-test').length, 0, 'modal inserted into dom') + done() + }) + .bootstrapModal('show') + }) + + QUnit.test('should fire show event', function (assert) { + assert.expect(1) + var done = assert.async() + + $('<div id="modal-test"/>') + .on('show.bs.modal', function () { + assert.ok(true, 'show event fired') + done() + }) + .bootstrapModal('show') + }) + + QUnit.test('should not fire shown when show was prevented', function (assert) { + assert.expect(1) + var done = assert.async() + + $('<div id="modal-test"/>') + .on('show.bs.modal', function (e) { + e.preventDefault() + assert.ok(true, 'show event fired') + done() + }) + .on('shown.bs.modal', function () { + assert.ok(false, 'shown event fired') + }) + .bootstrapModal('show') + }) + + QUnit.test('should hide modal when hide is called', function (assert) { + assert.expect(3) + var done = assert.async() + + $('<div id="modal-test"/>') + .on('shown.bs.modal', function () { + assert.ok($('#modal-test').is(':visible'), 'modal visible') + assert.notEqual($('#modal-test').length, 0, 'modal inserted into dom') + $(this).bootstrapModal('hide') + }) + .on('hidden.bs.modal', function () { + assert.ok(!$('#modal-test').is(':visible'), 'modal hidden') + done() + }) + .bootstrapModal('show') + }) + + QUnit.test('should toggle when toggle is called', function (assert) { + assert.expect(3) + var done = assert.async() + + $('<div id="modal-test"/>') + .on('shown.bs.modal', function () { + assert.ok($('#modal-test').is(':visible'), 'modal visible') + assert.notEqual($('#modal-test').length, 0, 'modal inserted into dom') + $(this).bootstrapModal('toggle') + }) + .on('hidden.bs.modal', function () { + assert.ok(!$('#modal-test').is(':visible'), 'modal hidden') + done() + }) + .bootstrapModal('toggle') + }) + + QUnit.test('should remove from dom when click [data-dismiss="modal"]', function (assert) { + assert.expect(3) + var done = assert.async() + + $('<div id="modal-test"><span class="close" data-dismiss="modal"/></div>') + .on('shown.bs.modal', function () { + assert.ok($('#modal-test').is(':visible'), 'modal visible') + assert.notEqual($('#modal-test').length, 0, 'modal inserted into dom') + $(this).find('.close').trigger('click') + }) + .on('hidden.bs.modal', function () { + assert.ok(!$('#modal-test').is(':visible'), 'modal hidden') + done() + }) + .bootstrapModal('toggle') + }) + + QUnit.test('should allow modal close with "backdrop:false"', function (assert) { + assert.expect(2) + var done = assert.async() + + $('<div id="modal-test" data-backdrop="false"/>') + .on('shown.bs.modal', function () { + assert.ok($('#modal-test').is(':visible'), 'modal visible') + $(this).bootstrapModal('hide') + }) + .on('hidden.bs.modal', function () { + assert.ok(!$('#modal-test').is(':visible'), 'modal hidden') + done() + }) + .bootstrapModal('show') + }) + + QUnit.test('should close modal when clicking outside of modal-content', function (assert) { + assert.expect(3) + var done = assert.async() + + $('<div id="modal-test"><div class="contents"/></div>') + .on('shown.bs.modal', function () { + assert.notEqual($('#modal-test').length, 0, 'modal inserted into dom') + $('.contents').trigger('click') + assert.ok($('#modal-test').is(':visible'), 'modal visible') + $('#modal-test').trigger('click') + }) + .on('hidden.bs.modal', function () { + assert.ok(!$('#modal-test').is(':visible'), 'modal hidden') + done() + }) + .bootstrapModal('show') + }) + + QUnit.test('should not close modal when clicking outside of modal-content if data-backdrop="true"', function (assert) { + assert.expect(1) + var done = assert.async() + + $('<div id="modal-test" data-backdrop="false"><div class="contents"/></div>') + .on('shown.bs.modal', function () { + $('#modal-test').trigger('click') + assert.ok($('#modal-test').is(':visible'), 'modal not hidden') + done() + }) + .bootstrapModal('show') + }) + + QUnit.test('should close modal when escape key is pressed via keydown', function (assert) { + assert.expect(3) + var done = assert.async() + + var $div = $('<div id="modal-test"/>') + $div + .on('shown.bs.modal', function () { + assert.ok($('#modal-test').length, 'modal inserted into dom') + assert.ok($('#modal-test').is(':visible'), 'modal visible') + $div.trigger($.Event('keydown', { + which: 27 + })) + + setTimeout(function () { + assert.ok(!$('#modal-test').is(':visible'), 'modal hidden') + $div.remove() + done() + }, 0) + }) + .bootstrapModal('show') + }) + + QUnit.test('should not close modal when escape key is pressed via keyup', function (assert) { + assert.expect(3) + var done = assert.async() + + var $div = $('<div id="modal-test"/>') + $div + .on('shown.bs.modal', function () { + assert.ok($('#modal-test').length, 'modal inserted into dom') + assert.ok($('#modal-test').is(':visible'), 'modal visible') + $div.trigger($.Event('keyup', { + which: 27 + })) + + setTimeout(function () { + assert.ok($div.is(':visible'), 'modal still visible') + $div.remove() + done() + }, 0) + }) + .bootstrapModal('show') + }) + + QUnit.test('should trigger hide event once when clicking outside of modal-content', function (assert) { + assert.expect(1) + var done = assert.async() + + var triggered + + $('<div id="modal-test"><div class="contents"/></div>') + .on('shown.bs.modal', function () { + triggered = 0 + $('#modal-test').trigger('click') + }) + .on('hide.bs.modal', function () { + triggered += 1 + assert.strictEqual(triggered, 1, 'modal hide triggered once') + done() + }) + .bootstrapModal('show') + }) + + QUnit.test('should remove aria-hidden attribute when shown, add it back when hidden', function (assert) { + assert.expect(3) + var done = assert.async() + + $('<div id="modal-test" aria-hidden="true"/>') + .on('shown.bs.modal', function () { + assert.notOk($('#modal-test').is('[aria-hidden]'), 'aria-hidden attribute removed') + $(this).bootstrapModal('hide') + }) + .on('hidden.bs.modal', function () { + assert.ok($('#modal-test').is('[aria-hidden]'), 'aria-hidden attribute added') + assert.strictEqual($('#modal-test').attr('aria-hidden'), 'true', 'correct aria-hidden="true" added') + done() + }) + .bootstrapModal('show') + }) + + QUnit.test('should close reopened modal with [data-dismiss="modal"] click', function (assert) { + assert.expect(2) + var done = assert.async() + + $('<div id="modal-test"><div class="contents"><div id="close" data-dismiss="modal"/></div></div>') + .one('shown.bs.modal', function () { + $('#close').trigger('click') + }) + .one('hidden.bs.modal', function () { + // After one open-close cycle + assert.ok(!$('#modal-test').is(':visible'), 'modal hidden') + $(this) + .one('shown.bs.modal', function () { + $('#close').trigger('click') + }) + .one('hidden.bs.modal', function () { + assert.ok(!$('#modal-test').is(':visible'), 'modal hidden') + done() + }) + .bootstrapModal('show') + }) + .bootstrapModal('show') + }) + + QUnit.test('should restore focus to toggling element when modal is hidden after having been opened via data-api', function (assert) { + assert.expect(1) + var done = assert.async() + + var $toggleBtn = $('<button data-toggle="modal" data-target="#modal-test"/>').appendTo('#qunit-fixture') + + $('<div id="modal-test"><div class="contents"><div id="close" data-dismiss="modal"/></div></div>') + .on('hidden.bs.modal', function () { + setTimeout(function () { + assert.ok($(document.activeElement).is($toggleBtn), 'toggling element is once again focused') + done() + }, 0) + }) + .on('shown.bs.modal', function () { + $('#close').trigger('click') + }) + .appendTo('#qunit-fixture') + + $toggleBtn.trigger('click') + }) + + QUnit.test('should not restore focus to toggling element if the associated show event gets prevented', function (assert) { + assert.expect(1) + var done = assert.async() + var $toggleBtn = $('<button data-toggle="modal" data-target="#modal-test"/>').appendTo('#qunit-fixture') + var $otherBtn = $('<button id="other-btn"/>').appendTo('#qunit-fixture') + + $('<div id="modal-test"><div class="contents"><div id="close" data-dismiss="modal"/></div>') + .one('show.bs.modal', function (e) { + e.preventDefault() + $otherBtn.trigger('focus') + setTimeout($.proxy(function () { + $(this).bootstrapModal('show') + }, this), 0) + }) + .on('hidden.bs.modal', function () { + setTimeout(function () { + assert.ok($(document.activeElement).is($otherBtn), 'focus returned to toggling element') + done() + }, 0) + }) + .on('shown.bs.modal', function () { + $('#close').trigger('click') + }) + .appendTo('#qunit-fixture') + + $toggleBtn.trigger('click') + }) + + QUnit.test('should adjust the inline padding of the modal when opening', function (assert) { + assert.expect(1) + var done = assert.async() + + $('<div id="modal-test"/>') + .on('shown.bs.modal', function () { + var expectedPadding = $(this).getScrollbarWidth() + 'px' + var currentPadding = $(this).css('padding-right') + assert.strictEqual(currentPadding, expectedPadding, 'modal padding should be adjusted while opening') + done() + }) + .bootstrapModal('show') + }) + + QUnit.test('should adjust the inline body padding when opening and restore when closing', function (assert) { + assert.expect(2) + var done = assert.async() + var $body = $(document.body) + var originalPadding = $body.css('padding-right') + + $('<div id="modal-test"/>') + .on('hidden.bs.modal', function () { + var currentPadding = $body.css('padding-right') + assert.strictEqual(currentPadding, originalPadding, 'body padding should be reset after closing') + $body.removeAttr('style') + done() + }) + .on('shown.bs.modal', function () { + var expectedPadding = parseFloat(originalPadding) + $(this).getScrollbarWidth() + 'px' + var currentPadding = $body.css('padding-right') + assert.strictEqual(currentPadding, expectedPadding, 'body padding should be adjusted while opening') + $(this).bootstrapModal('hide') + }) + .bootstrapModal('show') + }) + + QUnit.test('should store the original body padding in data-padding-right before showing', function (assert) { + assert.expect(2) + var done = assert.async() + var $body = $(document.body) + var originalPadding = '0px' + $body.css('padding-right', originalPadding) + + $('<div id="modal-test"/>') + .on('hidden.bs.modal', function () { + assert.strictEqual(typeof $body.data('padding-right'), 'undefined', 'data-padding-right should be cleared after closing') + $body.removeAttr('style') + done() + }) + .on('shown.bs.modal', function () { + assert.strictEqual($body.data('padding-right'), originalPadding, 'original body padding should be stored in data-padding-right') + $(this).bootstrapModal('hide') + }) + .bootstrapModal('show') + }) + + QUnit.test('should not adjust the inline body padding when it does not overflow', function (assert) { + assert.expect(1) + var done = assert.async() + var $body = $(document.body) + var originalPadding = $body.css('padding-right') + + // Hide scrollbars to prevent the body overflowing + $body.css('overflow', 'hidden') // Real scrollbar (for in-browser testing) + $('html').css('padding-right', '0px') // Simulated scrollbar (for PhantomJS) + + $('<div id="modal-test"/>') + .on('shown.bs.modal', function () { + var currentPadding = $body.css('padding-right') + assert.strictEqual(currentPadding, originalPadding, 'body padding should not be adjusted') + $(this).bootstrapModal('hide') + + // Restore scrollbars + $body.css('overflow', 'auto') + $('html').css('padding-right', '16px') + done() + }) + .bootstrapModal('show') + }) + + QUnit.test('should adjust the inline padding of fixed elements when opening and restore when closing', function (assert) { + assert.expect(2) + var done = assert.async() + var $element = $('<div class="fixed-top"></div>').appendTo('#qunit-fixture') + var originalPadding = $element.css('padding-right') + + $('<div id="modal-test"/>') + .on('hidden.bs.modal', function () { + var currentPadding = $element.css('padding-right') + assert.strictEqual(currentPadding, originalPadding, 'fixed element padding should be reset after closing') + $element.remove() + done() + }) + .on('shown.bs.modal', function () { + var expectedPadding = parseFloat(originalPadding) + $(this).getScrollbarWidth() + 'px' + var currentPadding = $element.css('padding-right') + assert.strictEqual(currentPadding, expectedPadding, 'fixed element padding should be adjusted while opening') + $(this).bootstrapModal('hide') + }) + .bootstrapModal('show') + }) + + QUnit.test('should store the original padding of fixed elements in data-padding-right before showing', function (assert) { + assert.expect(2) + var done = assert.async() + var $element = $('<div class="fixed-top"></div>').appendTo('#qunit-fixture') + var originalPadding = '0px' + $element.css('padding-right', originalPadding) + + $('<div id="modal-test"/>') + .on('hidden.bs.modal', function () { + assert.strictEqual(typeof $element.data('padding-right'), 'undefined', 'data-padding-right should be cleared after closing') + $element.remove() + done() + }) + .on('shown.bs.modal', function () { + assert.strictEqual($element.data('padding-right'), originalPadding, 'original fixed element padding should be stored in data-padding-right') + $(this).bootstrapModal('hide') + }) + .bootstrapModal('show') + }) + + QUnit.test('should adjust the inline margin of sticky elements when opening and restore when closing', function (assert) { + assert.expect(2) + var done = assert.async() + var $element = $('<div class="sticky-top"></div>').appendTo('#qunit-fixture') + var originalPadding = $element.css('margin-right') + + $('<div id="modal-test"/>') + .on('hidden.bs.modal', function () { + var currentPadding = $element.css('margin-right') + assert.strictEqual(currentPadding, originalPadding, 'sticky element margin should be reset after closing') + $element.remove() + done() + }) + .on('shown.bs.modal', function () { + var expectedPadding = parseFloat(originalPadding) - $(this).getScrollbarWidth() + 'px' + var currentPadding = $element.css('margin-right') + assert.strictEqual(currentPadding, expectedPadding, 'sticky element margin should be adjusted while opening') + $(this).bootstrapModal('hide') + }) + .bootstrapModal('show') + }) + + QUnit.test('should store the original margin of sticky elements in data-margin-right before showing', function (assert) { + assert.expect(2) + var done = assert.async() + var $element = $('<div class="sticky-top"></div>').appendTo('#qunit-fixture') + var originalPadding = '0px' + $element.css('margin-right', originalPadding) + + $('<div id="modal-test"/>') + .on('hidden.bs.modal', function () { + assert.strictEqual(typeof $element.data('margin-right'), 'undefined', 'data-margin-right should be cleared after closing') + $element.remove() + done() + }) + .on('shown.bs.modal', function () { + assert.strictEqual($element.data('margin-right'), originalPadding, 'original sticky element margin should be stored in data-margin-right') + $(this).bootstrapModal('hide') + }) + .bootstrapModal('show') + }) + + QUnit.test('should ignore values set via CSS when trying to restore body padding after closing', function (assert) { + assert.expect(1) + var done = assert.async() + var $body = $(document.body) + var $style = $('<style>body { padding-right: 42px; }</style>').appendTo('head') + + $('<div id="modal-test"/>') + .on('hidden.bs.modal', function () { + assert.strictEqual($body.attr('style').indexOf('padding-right'), -1, 'body does not have inline padding set') + $style.remove() + done() + }) + .on('shown.bs.modal', function () { + $(this).bootstrapModal('hide') + }) + .bootstrapModal('show') + }) + + QUnit.test('should ignore other inline styles when trying to restore body padding after closing', function (assert) { + assert.expect(2) + var done = assert.async() + var $body = $(document.body) + var $style = $('<style>body { padding-right: 42px; }</style>').appendTo('head') + + $body.css('color', 'red') + + $('<div id="modal-test"/>') + .on('hidden.bs.modal', function () { + assert.strictEqual($body[0].style.paddingRight, '', 'body does not have inline padding set') + assert.strictEqual($body[0].style.color, 'red', 'body still has other inline styles set') + $body.removeAttr('style') + $style.remove() + done() + }) + .on('shown.bs.modal', function () { + $(this).bootstrapModal('hide') + }) + .bootstrapModal('show') + }) + + QUnit.test('should properly restore non-pixel inline body padding after closing', function (assert) { + assert.expect(1) + var done = assert.async() + var $body = $(document.body) + + $body.css('padding-right', '5%') + + $('<div id="modal-test"/>') + .on('hidden.bs.modal', function () { + assert.strictEqual($body[0].style.paddingRight, '5%', 'body does not have inline padding set') + $body.removeAttr('style') + done() + }) + .on('shown.bs.modal', function () { + $(this).bootstrapModal('hide') + }) + .bootstrapModal('show') + }) + + QUnit.test('should not follow link in area tag', function (assert) { + assert.expect(2) + var done = assert.async() + + $('<map><area id="test" shape="default" data-toggle="modal" data-target="#modal-test" href="demo.html"/></map>') + .appendTo('#qunit-fixture') + + $('<div id="modal-test"><div class="contents"><div id="close" data-dismiss="modal"/></div></div>') + .appendTo('#qunit-fixture') + + $('#test') + .on('click.bs.modal.data-api', function (event) { + assert.notOk(event.isDefaultPrevented(), 'navigating to href will happen') + + setTimeout(function () { + assert.ok(event.isDefaultPrevented(), 'model shown instead of navigating to href') + done() + }, 1) + }) + .trigger('click') + }) + + 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() + }, 1) + }) + + 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() + var count = 0 + + $('<div id="modal-test"/>').on('shown.bs.modal', function () { + count++ + }).on('hidden.bs.modal', function () { + assert.strictEqual(count, 1, 'show() runs only once') + done() + }) + .bootstrapModal('show') + .bootstrapModal('show') + .bootstrapModal('hide') + }) +}) diff --git a/themes/docsy/assets/vendor/bootstrap/js/tests/unit/popover.js b/themes/docsy/assets/vendor/bootstrap/js/tests/unit/popover.js new file mode 100644 index 0000000..f4b04de --- /dev/null +++ b/themes/docsy/assets/vendor/bootstrap/js/tests/unit/popover.js @@ -0,0 +1,471 @@ +$(function () { + 'use strict' + + QUnit.module('popover plugin') + + QUnit.test('should be defined on jquery object', function (assert) { + assert.expect(1) + assert.ok($(document.body).popover, 'popover method is defined') + }) + + QUnit.module('popover', { + beforeEach: 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() + }, + afterEach: function () { + $.fn.popover = $.fn.bootstrapPopover + delete $.fn.bootstrapPopover + $('.popover').remove() + $('#qunit-fixture').html('') + } + }) + + QUnit.test('should provide no conflict', function (assert) { + assert.expect(1) + assert.strictEqual(typeof $.fn.popover, 'undefined', 'popover was set back to undefined (org value)') + }) + + QUnit.test('should throw explicit error on undefined method', function (assert) { + assert.expect(1) + var $el = $('<div/>') + $el.bootstrapPopover() + try { + $el.bootstrapPopover('noMethod') + } catch (err) { + assert.strictEqual(err.message, 'No method named "noMethod"') + } + }) + + QUnit.test('should return jquery collection containing the element', function (assert) { + assert.expect(2) + var $el = $('<div/>') + var $popover = $el.bootstrapPopover() + assert.ok($popover instanceof $, 'returns jquery collection') + assert.strictEqual($popover[0], $el[0], 'collection contains element') + }) + + QUnit.test('should render popover element', function (assert) { + assert.expect(2) + var done = assert.async() + $('<a href="#" title="mdo" data-content="https://twitter.com/mdo">@mdo</a>') + .appendTo('#qunit-fixture') + .on('shown.bs.popover', function () { + assert.notEqual($('.popover').length, 0, 'popover was inserted') + $(this).bootstrapPopover('hide') + }) + .on('hidden.bs.popover', function () { + assert.strictEqual($('.popover').length, 0, 'popover removed') + done() + }) + .bootstrapPopover('show') + }) + + QUnit.test('should store popover instance in popover data object', function (assert) { + assert.expect(1) + var $popover = $('<a href="#" title="mdo" data-content="https://twitter.com/mdo">@mdo</a>').bootstrapPopover() + + assert.ok($popover.data('bs.popover'), 'popover instance exists') + }) + + QUnit.test('should store popover trigger in popover instance data object', function (assert) { + assert.expect(1) + var $popover = $('<a href="#" title="ResentedHook">@ResentedHook</a>') + .appendTo('#qunit-fixture') + .bootstrapPopover() + + $popover.bootstrapPopover('show') + + assert.ok($('.popover').data('bs.popover'), 'popover trigger stored in instance data') + }) + + QUnit.test('should get title and content from options', function (assert) { + assert.expect(4) + var done = assert.async() + var $popover = $('<a href="#">@fat</a>') + .appendTo('#qunit-fixture') + .bootstrapPopover({ + title: function () { + return '@fat' + }, + content: function () { + return 'loves writing tests (╯°□°)╯︵ ┻━┻' + } + }) + + $popover + .one('shown.bs.popover', function () { + assert.notEqual($('.popover').length, 0, 'popover was inserted') + assert.strictEqual($('.popover .popover-header').text(), '@fat', 'title correctly inserted') + assert.strictEqual($('.popover .popover-body').text(), 'loves writing tests (╯°□°)╯︵ ┻━┻', 'content correctly inserted') + $popover.bootstrapPopover('hide') + }) + .one('hidden.bs.popover', function () { + assert.strictEqual($('.popover').length, 0, 'popover was removed') + done() + }) + .bootstrapPopover('show') + }) + + QUnit.test('should allow DOMElement title and content (html: true)', function (assert) { + assert.expect(5) + var title = document.createTextNode('@glebm <3 writing tests') + var content = $('<i>¯\\_(ツ)_/¯</i>').get(0) + var $popover = $('<a href="#" rel="tooltip"/>') + .appendTo('#qunit-fixture') + .bootstrapPopover({ + html: true, + title: title, + content: content + }) + + $popover.bootstrapPopover('show') + + assert.notEqual($('.popover').length, 0, 'popover inserted') + assert.strictEqual($('.popover .popover-header').text(), '@glebm <3 writing tests', 'title inserted') + assert.ok($.contains($('.popover').get(0), title), 'title node moved, not copied') + // toLowerCase because IE8 will return <I>...</I> + assert.strictEqual($('.popover .popover-body').html().toLowerCase(), '<i>¯\\_(ツ)_/¯</i>', 'content inserted') + assert.ok($.contains($('.popover').get(0), content), 'content node moved, not copied') + }) + + QUnit.test('should allow DOMElement title and content (html: false)', function (assert) { + assert.expect(5) + var title = document.createTextNode('@glebm <3 writing tests') + var content = $('<i>¯\\_(ツ)_/¯</i>').get(0) + var $popover = $('<a href="#" rel="tooltip"/>') + .appendTo('#qunit-fixture') + .bootstrapPopover({ + title: title, + content: content + }) + + $popover.bootstrapPopover('show') + + assert.notEqual($('.popover').length, 0, 'popover inserted') + assert.strictEqual($('.popover .popover-header').text(), '@glebm <3 writing tests', 'title inserted') + assert.ok(!$.contains($('.popover').get(0), title), 'title node copied, not moved') + assert.strictEqual($('.popover .popover-body').html(), '¯\\_(ツ)_/¯', 'content inserted') + assert.ok(!$.contains($('.popover').get(0), content), 'content node copied, not moved') + }) + + QUnit.test('should not duplicate HTML object', function (assert) { + assert.expect(6) + var done = assert.async() + var $div = $('<div/>').html('loves writing tests (╯°□°)╯︵ ┻━┻') + + var $popover = $('<a href="#">@fat</a>') + .appendTo('#qunit-fixture') + .bootstrapPopover({ + html: true, + content: function () { + return $div + } + }) + + function popoverInserted() { + assert.notEqual($('.popover').length, 0, 'popover was inserted') + assert.equal($('.popover .popover-body').html(), $div[0].outerHTML, 'content correctly inserted') + } + + $popover + .one('shown.bs.popover', function () { + popoverInserted() + + $popover.one('hidden.bs.popover', function () { + assert.strictEqual($('.popover').length, 0, 'popover was removed') + + $popover.one('shown.bs.popover', function () { + popoverInserted() + + $popover.one('hidden.bs.popover', function () { + assert.strictEqual($('.popover').length, 0, 'popover was removed') + done() + }).bootstrapPopover('hide') + }).bootstrapPopover('show') + }).bootstrapPopover('hide') + }) + .bootstrapPopover('show') + }) + + QUnit.test('should get title and content from attributes', function (assert) { + assert.expect(4) + var done = assert.async() + var $popover = $('<a href="#" title="@mdo" data-content="loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻" >@mdo</a>') + .appendTo('#qunit-fixture') + .bootstrapPopover() + .one('shown.bs.popover', function () { + assert.notEqual($('.popover').length, 0, 'popover was inserted') + assert.strictEqual($('.popover .popover-header').text(), '@mdo', 'title correctly inserted') + assert.strictEqual($('.popover .popover-body').text(), 'loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻', 'content correctly inserted') + $popover.bootstrapPopover('hide') + }) + .one('hidden.bs.popover', function () { + assert.strictEqual($('.popover').length, 0, 'popover was removed') + done() + }) + .bootstrapPopover('show') + }) + + QUnit.test('should get title and content from attributes ignoring options passed via js', function (assert) { + assert.expect(4) + var done = assert.async() + var $popover = $('<a href="#" title="@mdo" data-content="loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻" >@mdo</a>') + .appendTo('#qunit-fixture') + .bootstrapPopover({ + title: 'ignored title option', + content: 'ignored content option' + }) + .one('shown.bs.popover', function () { + assert.notEqual($('.popover').length, 0, 'popover was inserted') + assert.strictEqual($('.popover .popover-header').text(), '@mdo', 'title correctly inserted') + assert.strictEqual($('.popover .popover-body').text(), 'loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻', 'content correctly inserted') + $popover.bootstrapPopover('hide') + }) + .one('hidden.bs.popover', function () { + assert.strictEqual($('.popover').length, 0, 'popover was removed') + done() + }) + .bootstrapPopover('show') + }) + + QUnit.test('should respect custom template', function (assert) { + assert.expect(3) + var done = assert.async() + var $popover = $('<a href="#">@fat</a>') + .appendTo('#qunit-fixture') + .bootstrapPopover({ + title: 'Test', + content: 'Test', + template: '<div class="popover foobar"><div class="arrow"></div><div class="inner"><h3 class="title"/><div class="content"><p/></div></div></div>' + }) + .one('shown.bs.popover', function () { + assert.notEqual($('.popover').length, 0, 'popover was inserted') + assert.ok($('.popover').hasClass('foobar'), 'custom class is present') + $popover.bootstrapPopover('hide') + }) + .one('hidden.bs.popover', function () { + assert.strictEqual($('.popover').length, 0, 'popover was removed') + done() + }) + .bootstrapPopover('show') + }) + + QUnit.test('should destroy popover', function (assert) { + assert.expect(7) + var $popover = $('<div/>') + .bootstrapPopover({ + trigger: 'hover' + }) + .on('click.foo', $.noop) + + assert.ok($popover.data('bs.popover'), 'popover has data') + assert.ok($._data($popover[0], 'events').mouseover && $._data($popover[0], 'events').mouseout, 'popover has hover event') + assert.strictEqual($._data($popover[0], 'events').click[0].namespace, 'foo', 'popover has extra click.foo event') + + $popover.bootstrapPopover('show') + $popover.bootstrapPopover('dispose') + + assert.ok(!$popover.hasClass('show'), 'popover is hidden') + assert.ok(!$popover.data('popover'), 'popover does not have data') + assert.strictEqual($._data($popover[0], 'events').click[0].namespace, 'foo', 'popover still has click.foo') + assert.ok(!$._data($popover[0], 'events').mouseover && !$._data($popover[0], 'events').mouseout, 'popover does not have any events') + }) + + QUnit.test('should render popover element using delegated selector', function (assert) { + assert.expect(2) + var done = assert.async() + var $div = $('<div><a href="#" title="mdo" data-content="https://twitter.com/mdo">@mdo</a></div>') + .appendTo('#qunit-fixture') + .bootstrapPopover({ + selector: 'a', + trigger: 'click' + }) + .one('shown.bs.popover', function () { + assert.notEqual($('.popover').length, 0, 'popover was inserted') + $div.find('a').trigger('click') + }) + .one('hidden.bs.popover', function () { + assert.strictEqual($('.popover').length, 0, 'popover was removed') + done() + }) + + $div.find('a').trigger('click') + }) + + QUnit.test('should detach popover content rather than removing it so that event handlers are left intact', function (assert) { + assert.expect(1) + var $content = $('<div class="content-with-handler"><a class="btn btn-warning">Button with event handler</a></div>').appendTo('#qunit-fixture') + + var handlerCalled = false + $('.content-with-handler .btn').on('click', function () { + handlerCalled = true + }) + + var $div = $('<div><a href="#">Show popover</a></div>') + .appendTo('#qunit-fixture') + .bootstrapPopover({ + html: true, + trigger: 'manual', + container: 'body', + animation: false, + content: function () { + return $content + } + }) + + var done = assert.async() + $div + .one('shown.bs.popover', function () { + $div + .one('hidden.bs.popover', function () { + $div + .one('shown.bs.popover', function () { + $('.content-with-handler .btn').trigger('click') + assert.ok(handlerCalled, 'content\'s event handler still present') + $div.bootstrapPopover('dispose') + done() + }) + .bootstrapPopover('show') + }) + .bootstrapPopover('hide') + }) + .bootstrapPopover('show') + }) + + QUnit.test('should do nothing when an attempt is made to hide an uninitialized popover', function (assert) { + assert.expect(1) + + var $popover = $('<span data-toggle="popover" data-title="some title" data-content="some content">some text</span>') + .appendTo('#qunit-fixture') + .on('hidden.bs.popover shown.bs.popover', function () { + assert.ok(false, 'should not fire any popover events') + }) + .bootstrapPopover('hide') + assert.strictEqual(typeof $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() + + $('<a href="#">@Johann-S</a>') + .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') + }) + + QUnit.test('should throw an error when show is called on hidden elements', function (assert) { + assert.expect(1) + var done = assert.async() + + try { + $('<div data-toggle="popover" data-title="some title" data-content="@Johann-S" style="display: none"/>').bootstrapPopover('show') + } catch (err) { + assert.strictEqual(err.message, 'Please use show on visible elements') + 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') + }) + + QUnit.test('should convert number to string without error for content and title', function (assert) { + assert.expect(2) + var done = assert.async() + var $popover = $('<a href="#">@mdo</a>') + .appendTo('#qunit-fixture') + .bootstrapPopover({ + title: 5, + content: 7 + }) + .on('shown.bs.popover', function () { + assert.strictEqual($('.popover .popover-header').text(), '5') + assert.strictEqual($('.popover .popover-body').text(), '7') + done() + }) + + $popover.bootstrapPopover('show') + }) + + QUnit.test('popover should be shown right away after the call of disable/enable', function (assert) { + assert.expect(2) + var done = assert.async() + var $popover = $('<a href="#">@mdo</a>') + .appendTo('#qunit-fixture') + .bootstrapPopover({ + title: 'Test popover', + content: 'with disable/enable' + }) + .on('shown.bs.popover', function () { + assert.strictEqual($('.popover').hasClass('show'), true) + done() + }) + + $popover.bootstrapPopover('disable') + $popover.trigger($.Event('click')) + setTimeout(function () { + assert.strictEqual($('.popover').length === 0, true) + $popover.bootstrapPopover('enable') + $popover.trigger($.Event('click')) + }, 200) + }) + + QUnit.test('popover should call content function only once', function (assert) { + assert.expect(1) + var done = assert.async() + var nbCall = 0 + $('<div id="popover" style="display:none">content</div>').appendTo('#qunit-fixture') + var $popover = $('<a href="#">@Johann-S</a>') + .appendTo('#qunit-fixture') + .bootstrapPopover({ + content: function () { + nbCall++ + return $('#popover').clone().show().get(0) + } + }) + .on('shown.bs.popover', function () { + assert.strictEqual(nbCall, 1) + done() + }) + + $popover.trigger($.Event('click')) + }) +}) diff --git a/themes/docsy/assets/vendor/bootstrap/js/tests/unit/scrollspy.js b/themes/docsy/assets/vendor/bootstrap/js/tests/unit/scrollspy.js new file mode 100644 index 0000000..1337e58 --- /dev/null +++ b/themes/docsy/assets/vendor/bootstrap/js/tests/unit/scrollspy.js @@ -0,0 +1,728 @@ +$(function () { + 'use strict' + + QUnit.module('scrollspy plugin') + + QUnit.test('should be defined on jquery object', function (assert) { + assert.expect(1) + assert.ok($(document.body).scrollspy, 'scrollspy method is defined') + }) + + QUnit.module('scrollspy', { + beforeEach: 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() + }, + afterEach: function () { + $.fn.scrollspy = $.fn.bootstrapScrollspy + delete $.fn.bootstrapScrollspy + $('#qunit-fixture').html('') + } + }) + + QUnit.test('should provide no conflict', function (assert) { + assert.expect(1) + assert.strictEqual(typeof $.fn.scrollspy, 'undefined', 'scrollspy was set back to undefined (org value)') + }) + + QUnit.test('should throw explicit error on undefined method', function (assert) { + assert.expect(1) + var $el = $('<div/>').appendTo('#qunit-fixture') + $el.bootstrapScrollspy() + try { + $el.bootstrapScrollspy('noMethod') + } catch (err) { + assert.strictEqual(err.message, 'No method named "noMethod"') + } + }) + + QUnit.test('should return jquery collection containing the element', function (assert) { + assert.expect(2) + var $el = $('<div/>').appendTo('#qunit-fixture') + var $scrollspy = $el.bootstrapScrollspy() + assert.ok($scrollspy instanceof $, 'returns jquery collection') + assert.strictEqual($scrollspy[0], $el[0], 'collection contains element') + }) + + QUnit.test('should only switch "active" class on current target', function (assert) { + assert.expect(1) + var done = assert.async() + + var sectionHTML = '<div id="root" class="active">' + + '<div class="topbar">' + + '<div class="topbar-inner">' + + '<div class="container" id="ss-target">' + + '<ul class="nav">' + + '<li class="nav-item"><a href="#masthead">Overview</a></li>' + + '<li class="nav-item"><a href="#detail">Detail</a></li>' + + '</ul>' + + '</div>' + + '</div>' + + '</div>' + + '<div id="scrollspy-example" style="height: 100px; overflow: auto;">' + + '<div style="height: 200px;">' + + '<h4 id="masthead">Overview</h4>' + + '<p style="height: 200px">' + + 'Ad leggings keytar, brunch id art party dolor labore.' + + '</p>' + + '</div>' + + '<div style="height: 200px;">' + + '<h4 id="detail">Detail</h4>' + + '<p style="height: 200px">' + + 'Veniam marfa mustache skateboard, adipisicing fugiat velit pitchfork beard.' + + '</p>' + + '</div>' + + '</div>' + + '</div>' + var $section = $(sectionHTML).appendTo('#qunit-fixture') + + var $scrollspy = $section + .show() + .find('#scrollspy-example') + .bootstrapScrollspy({ + target: '#ss-target' + }) + + $scrollspy.one('scroll', function () { + assert.ok($section.hasClass('active'), '"active" class still on root node') + done() + }) + + $scrollspy.scrollTop(350) + }) + + QUnit.test('should only switch "active" class on current target specified w element', function (assert) { + assert.expect(1) + var done = assert.async() + + var sectionHTML = '<div id="root" class="active">' + + '<div class="topbar">' + + '<div class="topbar-inner">' + + '<div class="container" id="ss-target">' + + '<ul class="nav">' + + '<li class="nav-item"><a href="#masthead">Overview</a></li>' + + '<li class="nav-item"><a href="#detail">Detail</a></li>' + + '</ul>' + + '</div>' + + '</div>' + + '</div>' + + '<div id="scrollspy-example" style="height: 100px; overflow: auto;">' + + '<div style="height: 200px;">' + + '<h4 id="masthead">Overview</h4>' + + '<p style="height: 200px">' + + 'Ad leggings keytar, brunch id art party dolor labore.' + + '</p>' + + '</div>' + + '<div style="height: 200px;">' + + '<h4 id="detail">Detail</h4>' + + '<p style="height: 200px">' + + 'Veniam marfa mustache skateboard, adipisicing fugiat velit pitchfork beard.' + + '</p>' + + '</div>' + + '</div>' + + '</div>' + var $section = $(sectionHTML).appendTo('#qunit-fixture') + + var $scrollspy = $section + .show() + .find('#scrollspy-example') + .bootstrapScrollspy({ + target: document.getElementById('#ss-target') + }) + + $scrollspy.one('scroll', function () { + assert.ok($section.hasClass('active'), '"active" class still on root node') + done() + }) + + $scrollspy.scrollTop(350) + }) + + QUnit.test('should correctly select middle navigation option when large offset is used', function (assert) { + assert.expect(3) + var done = assert.async() + + var sectionHTML = '<div id="header" style="height: 500px;"></div>' + + '<nav id="navigation" class="navbar">' + + '<ul class="navbar-nav">' + + '<li class="nav-item active"><a class="nav-link" id="one-link" href="#one">One</a></li>' + + '<li class="nav-item"><a class="nav-link" id="two-link" href="#two">Two</a></li>' + + '<li class="nav-item"><a class="nav-link" id="three-link" href="#three">Three</a></li>' + + '</ul>' + + '</nav>' + + '<div id="content" style="height: 200px; overflow-y: auto;">' + + '<div id="one" style="height: 500px;"></div>' + + '<div id="two" style="height: 300px;"></div>' + + '<div id="three" style="height: 10px;"></div>' + + '</div>' + var $section = $(sectionHTML).appendTo('#qunit-fixture') + var $scrollspy = $section + .show() + .filter('#content') + + $scrollspy.bootstrapScrollspy({ + target: '#navigation', + offset: $scrollspy.position().top + }) + + $scrollspy.one('scroll', function () { + assert.ok(!$section.find('#one-link').hasClass('active'), '"active" class removed from first section') + assert.ok($section.find('#two-link').hasClass('active'), '"active" class on middle section') + assert.ok(!$section.find('#three-link').hasClass('active'), '"active" class not on last section') + done() + }) + + $scrollspy.scrollTop(550) + }) + + QUnit.test('should add the active class to the correct element', function (assert) { + assert.expect(2) + var navbarHtml = + '<nav class="navbar">' + + '<ul class="nav">' + + '<li class="nav-item"><a class="nav-link" id="a-1" href="#div-1">div 1</a></li>' + + '<li class="nav-item"><a class="nav-link" id="a-2" href="#div-2">div 2</a></li>' + + '</ul>' + + '</nav>' + var contentHtml = + '<div class="content" style="overflow: auto; height: 50px">' + + '<div id="div-1" style="height: 100px; padding: 0; margin: 0">div 1</div>' + + '<div id="div-2" style="height: 200px; padding: 0; margin: 0">div 2</div>' + + '</div>' + + $(navbarHtml).appendTo('#qunit-fixture') + var $content = $(contentHtml) + .appendTo('#qunit-fixture') + .bootstrapScrollspy({ + offset: 0, + target: '.navbar' + }) + + var done = assert.async() + var testElementIsActiveAfterScroll = function (element, target) { + var deferred = $.Deferred() + var scrollHeight = Math.ceil($content.scrollTop() + $(target).position().top) + $content.one('scroll', function () { + assert.ok($(element).hasClass('active'), 'target:' + target + ', element' + element) + deferred.resolve() + }) + $content.scrollTop(scrollHeight) + return deferred.promise() + } + + $.when(testElementIsActiveAfterScroll('#a-1', '#div-1')) + .then(function () { + return testElementIsActiveAfterScroll('#a-2', '#div-2') + }) + .then(function () { + done() + }) + }) + + QUnit.test('should add the active class to the correct element (nav markup)', function (assert) { + assert.expect(2) + var navbarHtml = + '<nav class="navbar">' + + '<nav class="nav">' + + '<a class="nav-link" id="a-1" href="#div-1">div 1</a>' + + '<a class="nav-link" id="a-2" href="#div-2">div 2</a>' + + '</nav>' + + '</nav>' + var contentHtml = + '<div class="content" style="overflow: auto; height: 50px">' + + '<div id="div-1" style="height: 100px; padding: 0; margin: 0">div 1</div>' + + '<div id="div-2" style="height: 200px; padding: 0; margin: 0">div 2</div>' + + '</div>' + + $(navbarHtml).appendTo('#qunit-fixture') + var $content = $(contentHtml) + .appendTo('#qunit-fixture') + .bootstrapScrollspy({ + offset: 0, + target: '.navbar' + }) + + var done = assert.async() + var testElementIsActiveAfterScroll = function (element, target) { + var deferred = $.Deferred() + var scrollHeight = Math.ceil($content.scrollTop() + $(target).position().top) + $content.one('scroll', function () { + assert.ok($(element).hasClass('active'), 'target:' + target + ', element' + element) + deferred.resolve() + }) + $content.scrollTop(scrollHeight) + return deferred.promise() + } + + $.when(testElementIsActiveAfterScroll('#a-1', '#div-1')) + .then(function () { + return testElementIsActiveAfterScroll('#a-2', '#div-2') + }) + .then(function () { + done() + }) + }) + + QUnit.test('should add the active class to the correct element (list-group markup)', function (assert) { + assert.expect(2) + var navbarHtml = + '<nav class="navbar">' + + '<div class="list-group">' + + '<a class="list-group-item" id="a-1" href="#div-1">div 1</a>' + + '<a class="list-group-item" id="a-2" href="#div-2">div 2</a>' + + '</div>' + + '</nav>' + var contentHtml = + '<div class="content" style="overflow: auto; height: 50px">' + + '<div id="div-1" style="height: 100px; padding: 0; margin: 0">div 1</div>' + + '<div id="div-2" style="height: 200px; padding: 0; margin: 0">div 2</div>' + + '</div>' + + $(navbarHtml).appendTo('#qunit-fixture') + var $content = $(contentHtml) + .appendTo('#qunit-fixture') + .bootstrapScrollspy({ + offset: 0, + target: '.navbar' + }) + + var done = assert.async() + var testElementIsActiveAfterScroll = function (element, target) { + var deferred = $.Deferred() + var scrollHeight = Math.ceil($content.scrollTop() + $(target).position().top) + $content.one('scroll', function () { + assert.ok($(element).hasClass('active'), 'target:' + target + ', element' + element) + deferred.resolve() + }) + $content.scrollTop(scrollHeight) + return deferred.promise() + } + + $.when(testElementIsActiveAfterScroll('#a-1', '#div-1')) + .then(function () { + return testElementIsActiveAfterScroll('#a-2', '#div-2') + }) + .then(function () { + done() + }) + }) + + QUnit.test('should add the active class correctly when there are nested elements at 0 scroll offset', function (assert) { + assert.expect(6) + var times = 0 + var done = assert.async() + var navbarHtml = '<nav id="navigation" class="navbar">' + + '<ul class="nav">' + + '<li class="nav-item"><a id="a-1" class="nav-link" href="#div-1">div 1</a>' + + '<ul class="nav">' + + '<li class="nav-item"><a id="a-2" class="nav-link" href="#div-2">div 2</a></li>' + + '</ul>' + + '</li>' + + '</ul>' + + '</nav>' + + var contentHtml = '<div class="content" style="position: absolute; top: 0px; overflow: auto; height: 50px">' + + '<div id="div-1" style="padding: 0; margin: 0">' + + '<div id="div-2" style="height: 200px; padding: 0; margin: 0">div 2</div>' + + '</div>' + + '</div>' + + $(navbarHtml).appendTo('#qunit-fixture') + + var $content = $(contentHtml) + .appendTo('#qunit-fixture') + .bootstrapScrollspy({ + offset: 0, + target: '#navigation' + }) + + function testActiveElements() { + if (++times > 3) { + return done() + } + + $content.one('scroll', function () { + assert.ok($('#a-1').hasClass('active'), 'nav item for outer element has "active" class') + assert.ok($('#a-2').hasClass('active'), 'nav item for inner element has "active" class') + testActiveElements() + }) + + $content.scrollTop($content.scrollTop() + 10) + } + + testActiveElements() + }) + + QUnit.test('should add the active class correctly when there are nested elements (nav markup)', function (assert) { + assert.expect(6) + var times = 0 + var done = assert.async() + var navbarHtml = '<nav id="navigation" class="navbar">' + + '<nav class="nav">' + + '<a id="a-1" class="nav-link" href="#div-1">div 1</a>' + + '<nav class="nav">' + + '<a id="a-2" class="nav-link" href="#div-2">div 2</a>' + + '</nav>' + + '</nav>' + + '</nav>' + + var contentHtml = '<div class="content" style="position: absolute; top: 0px; overflow: auto; height: 50px">' + + '<div id="div-1" style="padding: 0; margin: 0">' + + '<div id="div-2" style="height: 200px; padding: 0; margin: 0">div 2</div>' + + '</div>' + + '</div>' + + $(navbarHtml).appendTo('#qunit-fixture') + + var $content = $(contentHtml) + .appendTo('#qunit-fixture') + .bootstrapScrollspy({ + offset: 0, + target: '#navigation' + }) + + function testActiveElements() { + if (++times > 3) { + return done() + } + + $content.one('scroll', function () { + assert.ok($('#a-1').hasClass('active'), 'nav item for outer element has "active" class') + assert.ok($('#a-2').hasClass('active'), 'nav item for inner element has "active" class') + testActiveElements() + }) + + $content.scrollTop($content.scrollTop() + 10) + } + + testActiveElements() + }) + + QUnit.test('should add the active class correctly when there are nested elements (nav nav-item markup)', function (assert) { + assert.expect(6) + var times = 0 + var done = assert.async() + var navbarHtml = '<nav id="navigation" class="navbar">' + + '<ul class="nav">' + + '<li class="nav-item"><a id="a-1" class="nav-link" href="#div-1">div 1</a></li>' + + '<ul class="nav">' + + '<li class="nav-item"><a id="a-2" class="nav-link" href="#div-2">div 2</a></li>' + + '</ul>' + + '</ul>' + + '</nav>' + + var contentHtml = '<div class="content" style="position: absolute; top: 0px; overflow: auto; height: 50px">' + + '<div id="div-1" style="padding: 0; margin: 0">' + + '<div id="div-2" style="height: 200px; padding: 0; margin: 0">div 2</div>' + + '</div>' + + '</div>' + + $(navbarHtml).appendTo('#qunit-fixture') + + var $content = $(contentHtml) + .appendTo('#qunit-fixture') + .bootstrapScrollspy({ + offset: 0, + target: '#navigation' + }) + + function testActiveElements() { + if (++times > 3) { + return done() + } + + $content.one('scroll', function () { + assert.ok($('#a-1').hasClass('active'), 'nav item for outer element has "active" class') + assert.ok($('#a-2').hasClass('active'), 'nav item for inner element has "active" class') + testActiveElements() + }) + + $content.scrollTop($content.scrollTop() + 10) + } + + testActiveElements() + }) + + QUnit.test('should add the active class correctly when there are nested elements (list-group markup)', function (assert) { + assert.expect(6) + var times = 0 + var done = assert.async() + var navbarHtml = '<nav id="navigation" class="navbar">' + + '<div class="list-group">' + + '<a id="a-1" class="list-group-item" href="#div-1">div 1</a>' + + '<div class="list-group">' + + '<a id="a-2" class="list-group-item" href="#div-2">div 2</a>' + + '</div>' + + '</div>' + + '</nav>' + + var contentHtml = '<div class="content" style="position: absolute; top: 0px; overflow: auto; height: 50px">' + + '<div id="div-1" style="padding: 0; margin: 0">' + + '<div id="div-2" style="height: 200px; padding: 0; margin: 0">div 2</div>' + + '</div>' + + '</div>' + + $(navbarHtml).appendTo('#qunit-fixture') + + var $content = $(contentHtml) + .appendTo('#qunit-fixture') + .bootstrapScrollspy({ + offset: 0, + target: '#navigation' + }) + + function testActiveElements() { + if (++times > 3) { + return done() + } + + $content.one('scroll', function () { + assert.ok($('#a-1').hasClass('active'), 'nav item for outer element has "active" class') + assert.ok($('#a-2').hasClass('active'), 'nav item for inner element has "active" class') + testActiveElements() + }) + + $content.scrollTop($content.scrollTop() + 10) + } + + testActiveElements() + }) + + QUnit.test('should clear selection if above the first section', function (assert) { + assert.expect(3) + var done = assert.async() + + var sectionHTML = '<div id="header" style="height: 500px;"></div>' + + '<nav id="navigation" class="navbar">' + + '<ul class="navbar-nav">' + + '<li class="nav-item"><a id="one-link" class="nav-link active" href="#one">One</a></li>' + + '<li class="nav-item"><a id="two-link" class="nav-link" href="#two">Two</a></li>' + + '<li class="nav-item"><a id="three-link" class="nav-link" href="#three">Three</a></li>' + + '</ul>' + + '</nav>' + $(sectionHTML).appendTo('#qunit-fixture') + + var scrollspyHTML = '<div id="content" style="height: 200px; overflow-y: auto;">' + + '<div id="spacer" style="height: 100px;"/>' + + '<div id="one" style="height: 100px;"/>' + + '<div id="two" style="height: 100px;"/>' + + '<div id="three" style="height: 100px;"/>' + + '<div id="spacer" style="height: 100px;"/>' + + '</div>' + var $scrollspy = $(scrollspyHTML).appendTo('#qunit-fixture') + + $scrollspy + .bootstrapScrollspy({ + target: '#navigation', + offset: $scrollspy.position().top + }) + .one('scroll', function () { + assert.strictEqual($('.active').length, 1, '"active" class on only one element present') + assert.strictEqual($('.active').is('#two-link'), true, '"active" class on second section') + $scrollspy + .one('scroll', function () { + assert.strictEqual($('.active').length, 0, 'selection cleared') + done() + }) + .scrollTop(0) + }) + .scrollTop(201) + }) + + QUnit.test('should NOT clear selection if above the first section and first section is at the top', function (assert) { + assert.expect(4) + var done = assert.async() + + var sectionHTML = '<div id="header" style="height: 500px;"></div>' + + '<nav id="navigation" class="navbar">' + + '<ul class="navbar-nav">' + + '<li class="nav-item"><a id="one-link" class="nav-link active" href="#one">One</a></li>' + + '<li class="nav-item"><a id="two-link" class="nav-link" href="#two">Two</a></li>' + + '<li class="nav-item"><a id="three-link" class="nav-link" href="#three">Three</a></li>' + + '</ul>' + + '</nav>' + $(sectionHTML).appendTo('#qunit-fixture') + + var negativeHeight = -10 + var startOfSectionTwo = 101 + + var scrollspyHTML = '<div id="content" style="height: 200px; overflow-y: auto;">' + + '<div id="one" style="height: 100px;"/>' + + '<div id="two" style="height: 100px;"/>' + + '<div id="three" style="height: 100px;"/>' + + '<div id="spacer" style="height: 100px;"/>' + + '</div>' + var $scrollspy = $(scrollspyHTML).appendTo('#qunit-fixture') + + $scrollspy + .bootstrapScrollspy({ + target: '#navigation', + offset: $scrollspy.position().top + }) + .one('scroll', function () { + assert.strictEqual($('.active').length, 1, '"active" class on only one element present') + assert.strictEqual($('.active').is('#two-link'), true, '"active" class on second section') + $scrollspy + .one('scroll', function () { + assert.strictEqual($('.active').length, 1, '"active" class on only one element present') + assert.strictEqual($('.active').is('#one-link'), true, '"active" class on first section') + done() + }) + .scrollTop(negativeHeight) + }) + .scrollTop(startOfSectionTwo) + }) + + QUnit.test('should correctly select navigation element on backward scrolling when each target section height is 100%', function (assert) { + assert.expect(5) + var navbarHtml = + '<nav class="navbar">' + + '<ul class="nav">' + + '<li class="nav-item"><a id="li-100-1" class="nav-link" href="#div-100-1">div 1</a></li>' + + '<li class="nav-item"><a id="li-100-2" class="nav-link" href="#div-100-2">div 2</a></li>' + + '<li class="nav-item"><a id="li-100-3" class="nav-link" href="#div-100-3">div 3</a></li>' + + '<li class="nav-item"><a id="li-100-4" class="nav-link" href="#div-100-4">div 4</a></li>' + + '<li class="nav-item"><a id="li-100-5" class="nav-link" href="#div-100-5">div 5</a></li>' + + '</ul>' + + '</nav>' + var contentHtml = + '<div class="content" style="position: relative; overflow: auto; height: 100px">' + + '<div id="div-100-1" style="position: relative; height: 100%; padding: 0; margin: 0">div 1</div>' + + '<div id="div-100-2" style="position: relative; height: 100%; padding: 0; margin: 0">div 2</div>' + + '<div id="div-100-3" style="position: relative; height: 100%; padding: 0; margin: 0">div 3</div>' + + '<div id="div-100-4" style="position: relative; height: 100%; padding: 0; margin: 0">div 4</div>' + + '<div id="div-100-5" style="position: relative; height: 100%; padding: 0; margin: 0">div 5</div>' + + '</div>' + + $(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 = Math.ceil($content.scrollTop() + $(target).position().top) + $content.one('scroll', function () { + assert.ok($(element).hasClass('active'), 'target:' + target + ', element: ' + element) + deferred.resolve() + }) + $content.scrollTop(scrollHeight) + return deferred.promise() + } + + var done = assert.async() + $.when(testElementIsActiveAfterScroll('#li-100-5', '#div-100-5')) + .then(function () { + return testElementIsActiveAfterScroll('#li-100-4', '#div-100-4') + }) + .then(function () { + return testElementIsActiveAfterScroll('#li-100-3', '#div-100-3') + }) + .then(function () { + return testElementIsActiveAfterScroll('#li-100-2', '#div-100-2') + }) + .then(function () { + return testElementIsActiveAfterScroll('#li-100-1', '#div-100-1') + }) + .then(function () { + done() + }) + }) + + QUnit.test('should allow passed in option offset method: offset', function (assert) { + assert.expect(4) + + var testOffsetMethod = function (type) { + var $navbar = $( + '<nav class="navbar"' + (type === 'data' ? ' id="navbar-offset-method-menu"' : '') + '>' + + '<ul class="nav">' + + '<li class="nav-item"><a id="li-' + type + 'm-1" class="nav-link" href="#div-' + type + 'm-1">div 1</a></li>' + + '<li class="nav-item"><a id="li-' + type + 'm-2" class="nav-link" href="#div-' + type + 'm-2">div 2</a></li>' + + '<li class="nav-item"><a id="li-' + type + 'm-3" class="nav-link" href="#div-' + type + 'm-3">div 3</a></li>' + + '</ul>' + + '</nav>' + ) + var $content = $( + '<div class="content"' + (type === 'data' ? ' data-spy="scroll" data-target="#navbar-offset-method-menu" data-offset="0" data-method="offset"' : '') + ' style="position: relative; overflow: auto; height: 100px">' + + '<div id="div-' + type + 'm-1" style="position: relative; height: 200px; padding: 0; margin: 0">div 1</div>' + + '<div id="div-' + type + 'm-2" style="position: relative; height: 150px; padding: 0; margin: 0">div 2</div>' + + '<div id="div-' + type + 'm-3" style="position: relative; height: 250px; padding: 0; margin: 0">div 3</div>' + + '</div>' + ) + + $navbar.appendTo('#qunit-fixture') + $content.appendTo('#qunit-fixture') + + if (type === 'js') { + $content.bootstrapScrollspy({ + target: '.navbar', + offset: 0, + method: 'offset' + }) + } else if (type === 'data') { + $(window).trigger('load') + } + + var $target = $('#div-' + type + 'm-2') + var scrollspy = $content.data('bs.scrollspy') + + assert.ok(scrollspy._offsets[1] === $target.offset().top, 'offset method with ' + type + ' option') + assert.ok(scrollspy._offsets[1] !== $target.position().top, 'position method with ' + type + ' option') + $navbar.remove() + $content.remove() + } + + testOffsetMethod('js') + testOffsetMethod('data') + }) + + QUnit.test('should allow passed in option offset method: position', function (assert) { + assert.expect(4) + + var testOffsetMethod = function (type) { + var $navbar = $( + '<nav class="navbar"' + (type === 'data' ? ' id="navbar-offset-method-menu"' : '') + '>' + + '<ul class="nav">' + + '<li class="nav-item"><a class="nav-link" id="li-' + type + 'm-1" href="#div-' + type + 'm-1">div 1</a></li>' + + '<li class="nav-item"><a class="nav-link" id="li-' + type + 'm-2" href="#div-' + type + 'm-2">div 2</a></li>' + + '<li class="nav-item"><a class="nav-link" id="li-' + type + 'm-3" href="#div-' + type + 'm-3">div 3</a></li>' + + '</ul>' + + '</nav>' + ) + var $content = $( + '<div class="content"' + (type === 'data' ? ' data-spy="scroll" data-target="#navbar-offset-method-menu" data-offset="0" data-method="position"' : '') + ' style="position: relative; overflow: auto; height: 100px">' + + '<div id="div-' + type + 'm-1" style="position: relative; height: 200px; padding: 0; margin: 0">div 1</div>' + + '<div id="div-' + type + 'm-2" style="position: relative; height: 150px; padding: 0; margin: 0">div 2</div>' + + '<div id="div-' + type + 'm-3" style="position: relative; height: 250px; padding: 0; margin: 0">div 3</div>' + + '</div>' + ) + + $navbar.appendTo('#qunit-fixture') + $content.appendTo('#qunit-fixture') + + if (type === 'js') { + $content.bootstrapScrollspy({ + target: '.navbar', + offset: 0, + method: 'position' + }) + } else if (type === 'data') { + $(window).trigger('load') + } + + var $target = $('#div-' + type + 'm-2') + var scrollspy = $content.data('bs.scrollspy') + + assert.ok(scrollspy._offsets[1] !== $target.offset().top, 'offset method with ' + type + ' option') + assert.ok(scrollspy._offsets[1] === $target.position().top, 'position method with ' + type + ' option') + $navbar.remove() + $content.remove() + } + + testOffsetMethod('js') + testOffsetMethod('data') + }) +}) diff --git a/themes/docsy/assets/vendor/bootstrap/js/tests/unit/tab.js b/themes/docsy/assets/vendor/bootstrap/js/tests/unit/tab.js new file mode 100644 index 0000000..c70e0d1 --- /dev/null +++ b/themes/docsy/assets/vendor/bootstrap/js/tests/unit/tab.js @@ -0,0 +1,417 @@ +$(function () { + 'use strict' + + QUnit.module('tabs plugin') + + QUnit.test('should be defined on jquery object', function (assert) { + assert.expect(1) + assert.ok($(document.body).tab, 'tabs method is defined') + }) + + QUnit.module('tabs', { + beforeEach: 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() + }, + afterEach: function () { + $.fn.tab = $.fn.bootstrapTab + delete $.fn.bootstrapTab + $('#qunit-fixture').html('') + } + }) + + QUnit.test('should provide no conflict', function (assert) { + assert.expect(1) + assert.strictEqual(typeof $.fn.tab, 'undefined', 'tab was set back to undefined (org value)') + }) + + QUnit.test('should throw explicit error on undefined method', function (assert) { + assert.expect(1) + var $el = $('<div/>') + $el.bootstrapTab() + try { + $el.bootstrapTab('noMethod') + } catch (err) { + assert.strictEqual(err.message, 'No method named "noMethod"') + } + }) + + QUnit.test('should return jquery collection containing the element', function (assert) { + assert.expect(2) + var $el = $('<div/>') + var $tab = $el.bootstrapTab() + assert.ok($tab instanceof $, 'returns jquery collection') + assert.strictEqual($tab[0], $el[0], 'collection contains element') + }) + + QUnit.test('should activate element by tab id', function (assert) { + assert.expect(2) + var tabsHTML = '<ul class="nav">' + + '<li><a href="#home">Home</a></li>' + + '<li><a href="#profile">Profile</a></li>' + + '</ul>' + + $('<ul><li id="home"/><li id="profile"/></ul>').appendTo('#qunit-fixture') + + $(tabsHTML).find('li:last-child a').bootstrapTab('show') + assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'profile') + + $(tabsHTML).find('li:first-child a').bootstrapTab('show') + assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'home') + }) + + QUnit.test('should activate element by tab id', function (assert) { + assert.expect(2) + var pillsHTML = '<ul class="nav nav-pills">' + + '<li><a href="#home">Home</a></li>' + + '<li><a href="#profile">Profile</a></li>' + + '</ul>' + + $('<ul><li id="home"/><li id="profile"/></ul>').appendTo('#qunit-fixture') + + $(pillsHTML).find('li:last-child a').bootstrapTab('show') + assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'profile') + + $(pillsHTML).find('li:first-child a').bootstrapTab('show') + assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'home') + }) + + QUnit.test('should activate element by tab id in ordered list', function (assert) { + assert.expect(2) + var pillsHTML = '<ol class="nav nav-pills">' + + '<li><a href="#home">Home</a></li>' + + '<li><a href="#profile">Profile</a></li>' + + '</ol>' + + $('<ol><li id="home"/><li id="profile"/></ol>').appendTo('#qunit-fixture') + + $(pillsHTML).find('li:last-child a').bootstrapTab('show') + assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'profile') + + $(pillsHTML).find('li:first-child a').bootstrapTab('show') + 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-child').bootstrapTab('show') + assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'profile') + + $(tabsHTML).find('a:first-child').bootstrapTab('show') + assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'home') + }) + + QUnit.test('should activate element by tab id in list group', function (assert) { + assert.expect(2) + var tabsHTML = '<div class="list-group">' + + '<a href="#home">Home</a>' + + '<a href="#profile">Profile</a>' + + '</div>' + + $('<nav><div id="home"></div><div id="profile"></div></nav>').appendTo('#qunit-fixture') + + $(tabsHTML).find('a:last-child').bootstrapTab('show') + assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'profile') + + $(tabsHTML).find('a:first-child').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() + + $('<div class="nav"/>') + .on('show.bs.tab', function (e) { + e.preventDefault() + assert.ok(true, 'show event fired') + done() + }) + .on('shown.bs.tab', function () { + assert.ok(false, 'shown event fired') + }) + .bootstrapTab('show') + }) + + QUnit.test('should not fire shown when tab is already active', function (assert) { + assert.expect(0) + var tabsHTML = '<ul class="nav nav-tabs" role="tablist">' + + '<li class="nav-item"><a href="#home" class="nav-link active" role="tab">Home</a></li>' + + '<li class="nav-item"><a href="#profile" class="nav-link" role="tab">Profile</a></li>' + + '</ul>' + + '<div class="tab-content">' + + '<div class="tab-pane active" id="home" role="tabpanel"></div>' + + '<div class="tab-pane" id="profile" role="tabpanel"></div>' + + '</div>' + + $(tabsHTML) + .find('a.active') + .on('shown.bs.tab', function () { + assert.ok(true, 'shown event fired') + }) + .bootstrapTab('show') + }) + + QUnit.test('should not fire shown when tab is disabled', function (assert) { + assert.expect(0) + var tabsHTML = '<ul class="nav nav-tabs" role="tablist">' + + '<li class="nav-item"><a href="#home" class="nav-link active" role="tab">Home</a></li>' + + '<li class="nav-item"><a href="#profile" class="nav-link disabled" role="tab">Profile</a></li>' + + '</ul>' + + '<div class="tab-content">' + + '<div class="tab-pane active" id="home" role="tabpanel"></div>' + + '<div class="tab-pane" id="profile" role="tabpanel"></div>' + + '</div>' + + $(tabsHTML) + .find('a.disabled') + .on('shown.bs.tab', function () { + assert.ok(true, 'shown event fired') + }) + .bootstrapTab('show') + }) + + QUnit.test('show and shown events should reference correct relatedTarget', function (assert) { + assert.expect(2) + var done = assert.async() + + var dropHTML = + '<ul class="drop nav">' + + ' <li class="dropdown"><a data-toggle="dropdown" href="#">1</a>' + + ' <ul class="dropdown-menu nav">' + + ' <li><a href="#1-1" data-toggle="tab">1-1</a></li>' + + ' <li><a href="#1-2" data-toggle="tab">1-2</a></li>' + + ' </ul>' + + ' </li>' + + '</ul>' + + $(dropHTML) + .find('ul > li:first-child a') + .bootstrapTab('show') + .end() + .find('ul > li:last-child a') + .on('show.bs.tab', function (e) { + assert.strictEqual(e.relatedTarget.hash, '#1-1', 'references correct element as relatedTarget') + }) + .on('shown.bs.tab', function (e) { + assert.strictEqual(e.relatedTarget.hash, '#1-1', 'references correct element as relatedTarget') + done() + }) + .bootstrapTab('show') + }) + + QUnit.test('should fire hide and hidden events', function (assert) { + assert.expect(2) + var done = assert.async() + + var tabsHTML = '<ul class="nav">' + + '<li><a href="#home">Home</a></li>' + + '<li><a href="#profile">Profile</a></li>' + + '</ul>' + + $(tabsHTML) + .find('li:first-child a') + .on('hide.bs.tab', function () { + assert.ok(true, 'hide event fired') + }) + .bootstrapTab('show') + .end() + .find('li:last-child a') + .bootstrapTab('show') + + $(tabsHTML) + .find('li:first-child a') + .on('hidden.bs.tab', function () { + assert.ok(true, 'hidden event fired') + done() + }) + .bootstrapTab('show') + .end() + .find('li:last-child a') + .bootstrapTab('show') + }) + + QUnit.test('should not fire hidden when hide is prevented', function (assert) { + assert.expect(1) + var done = assert.async() + + var tabsHTML = '<ul class="nav">' + + '<li><a href="#home">Home</a></li>' + + '<li><a href="#profile">Profile</a></li>' + + '</ul>' + + $(tabsHTML) + .find('li:first-child a') + .on('hide.bs.tab', function (e) { + e.preventDefault() + assert.ok(true, 'hide event fired') + done() + }) + .on('hidden.bs.tab', function () { + assert.ok(false, 'hidden event fired') + }) + .bootstrapTab('show') + .end() + .find('li:last-child a') + .bootstrapTab('show') + }) + + QUnit.test('hide and hidden events contain correct relatedTarget', function (assert) { + assert.expect(2) + var done = assert.async() + + var tabsHTML = '<ul class="nav">' + + '<li><a href="#home">Home</a></li>' + + '<li><a href="#profile">Profile</a></li>' + + '</ul>' + + $(tabsHTML) + .find('li:first-child a') + .on('hide.bs.tab', function (e) { + assert.strictEqual(e.relatedTarget.hash, '#profile', 'references correct element as relatedTarget') + }) + .on('hidden.bs.tab', function (e) { + assert.strictEqual(e.relatedTarget.hash, '#profile', 'references correct element as relatedTarget') + done() + }) + .bootstrapTab('show') + .end() + .find('li:last-child a') + .bootstrapTab('show') + }) + + QUnit.test('selected tab should have aria-selected', function (assert) { + assert.expect(8) + var tabsHTML = '<ul class="nav nav-tabs">' + + '<li><a class="nav-item active" href="#home" toggle="tab" aria-selected="true">Home</a></li>' + + '<li><a class="nav-item" href="#profile" toggle="tab" aria-selected="false">Profile</a></li>' + + '</ul>' + var $tabs = $(tabsHTML).appendTo('#qunit-fixture') + + $tabs.find('li:first-child a').bootstrapTab('show') + assert.strictEqual($tabs.find('.active').attr('aria-selected'), 'true', 'shown tab has aria-selected = true') + assert.strictEqual($tabs.find('a:not(.active)').attr('aria-selected'), 'false', 'hidden tab has aria-selected = false') + + $tabs.find('li:last-child a').trigger('click') + assert.strictEqual($tabs.find('.active').attr('aria-selected'), 'true', 'after click, shown tab has aria-selected = true') + assert.strictEqual($tabs.find('a:not(.active)').attr('aria-selected'), 'false', 'after click, hidden tab has aria-selected = false') + + $tabs.find('li:first-child a').bootstrapTab('show') + assert.strictEqual($tabs.find('.active').attr('aria-selected'), 'true', 'shown tab has aria-selected = true') + assert.strictEqual($tabs.find('a:not(.active)').attr('aria-selected'), 'false', 'hidden tab has aria-selected = false') + + $tabs.find('li:first-child a').trigger('click') + assert.strictEqual($tabs.find('.active').attr('aria-selected'), 'true', 'after second show event, shown tab still has aria-selected = true') + assert.strictEqual($tabs.find('a:not(.active)').attr('aria-selected'), 'false', 'after second show event, hidden tab has aria-selected = false') + }) + + QUnit.test('selected tab should deactivate previous selected tab', function (assert) { + assert.expect(2) + var tabsHTML = '<ul class="nav nav-tabs">' + + '<li class="nav-item"><a class="nav-link active" href="#home" data-toggle="tab">Home</a></li>' + + '<li class="nav-item"><a class="nav-link" href="#profile" data-toggle="tab">Profile</a></li>' + + '</ul>' + var $tabs = $(tabsHTML).appendTo('#qunit-fixture') + + $tabs.find('li:last-child a').trigger('click') + assert.notOk($tabs.find('li:first-child a').hasClass('active')) + assert.ok($tabs.find('li:last-child a').hasClass('active')) + }) + + QUnit.test('selected tab should deactivate previous selected link in dropdown', function (assert) { + assert.expect(3) + var tabsHTML = '<ul class="nav nav-tabs">' + + '<li class="nav-item"><a class="nav-link" href="#home" data-toggle="tab">Home</a></li>' + + '<li class="nav-item"><a class="nav-link" href="#profile" data-toggle="tab">Profile</a></li>' + + '<li class="nav-item dropdown"><a class="nav-link dropdown-toggle active" data-toggle="dropdown" href="#">Dropdown</a>' + + '<div class="dropdown-menu">' + + '<a class="dropdown-item active" href="#dropdown1" id="dropdown1-tab" data-toggle="tab">@fat</a>' + + '<a class="dropdown-item" href="#dropdown2" id="dropdown2-tab" data-toggle="tab">@mdo</a>' + + '</div>' + + '</li>' + + '</ul>' + var $tabs = $(tabsHTML).appendTo('#qunit-fixture') + + $tabs.find('li:first-child a').trigger('click') + assert.ok($tabs.find('li:first-child a').hasClass('active')) + assert.notOk($tabs.find('li:last-child a').hasClass('active')) + assert.notOk($tabs.find('li:last-child .dropdown-menu a:first-child').hasClass('active')) + }) + + QUnit.test('Nested tabs', function (assert) { + assert.expect(2) + var done = assert.async() + var tabsHTML = + '<nav class="nav nav-tabs" role="tablist">' + + ' <a id="tab1" href="#x-tab1" class="nav-item nav-link" data-toggle="tab" role="tab" aria-controls="x-tab1">Tab 1</a>' + + ' <a href="#x-tab2" class="nav-item nav-link active" data-toggle="tab" role="tab" aria-controls="x-tab2" aria-selected="true">Tab 2</a>' + + ' <a href="#x-tab3" class="nav-item nav-link" data-toggle="tab" role="tab" aria-controls="x-tab3">Tab 3</a>' + + '</nav>' + + '<div class="tab-content">' + + ' <div class="tab-pane" id="x-tab1" role="tabpanel">' + + ' <nav class="nav nav-tabs" role="tablist">' + + ' <a href="#nested-tab1" class="nav-item nav-link active" data-toggle="tab" role="tab" aria-controls="x-tab1" aria-selected="true">Nested Tab 1</a>' + + ' <a id="tabNested2" href="#nested-tab2" class="nav-item nav-link" data-toggle="tab" role="tab" aria-controls="x-profile">Nested Tab2</a>' + + ' </nav>' + + ' <div class="tab-content">' + + ' <div class="tab-pane active" id="nested-tab1" role="tabpanel">Nested Tab1 Content</div>' + + ' <div class="tab-pane" id="nested-tab2" role="tabpanel">Nested Tab2 Content</div>' + + ' </div>' + + ' </div>' + + ' <div class="tab-pane active" id="x-tab2" role="tabpanel">Tab2 Content</div>' + + ' <div class="tab-pane" id="x-tab3" role="tabpanel">Tab3 Content</div>' + + '</div>' + + $(tabsHTML).appendTo('#qunit-fixture') + + $('#tabNested2').on('shown.bs.tab', function () { + assert.ok($('#x-tab1').hasClass('active')) + done() + }) + + $('#tab1').on('shown.bs.tab', function () { + assert.ok($('#x-tab1').hasClass('active')) + $('#tabNested2').trigger($.Event('click')) + }) + .trigger($.Event('click')) + }) + + QUnit.test('should not remove fade class if no active pane is present', function (assert) { + assert.expect(6) + var done = assert.async() + var tabsHTML = '<ul class="nav nav-tabs" role="tablist">' + + '<li class="nav-item"><a id="tab-home" href="#home" class="nav-link" data-toggle="tab" role="tab">Home</a></li>' + + '<li class="nav-item"><a id="tab-profile" href="#profile" class="nav-link" data-toggle="tab" role="tab">Profile</a></li>' + + '</ul>' + + '<div class="tab-content">' + + '<div class="tab-pane fade" id="home" role="tabpanel"></div>' + + '<div class="tab-pane fade" id="profile" role="tabpanel"></div>' + + '</div>' + + $(tabsHTML).appendTo('#qunit-fixture') + $('#tab-profile') + .on('shown.bs.tab', function () { + assert.ok($('#profile').hasClass('fade')) + assert.ok($('#profile').hasClass('show')) + + $('#tab-home') + .on('shown.bs.tab', function () { + assert.ok($('#profile').hasClass('fade')) + assert.notOk($('#profile').hasClass('show')) + assert.ok($('#home').hasClass('fade')) + assert.ok($('#home').hasClass('show')) + + done() + }) + .trigger($.Event('click')) + }) + .trigger($.Event('click')) + }) +}) diff --git a/themes/docsy/assets/vendor/bootstrap/js/tests/unit/tooltip.js b/themes/docsy/assets/vendor/bootstrap/js/tests/unit/tooltip.js new file mode 100644 index 0000000..9cf3068 --- /dev/null +++ b/themes/docsy/assets/vendor/bootstrap/js/tests/unit/tooltip.js @@ -0,0 +1,969 @@ +$(function () { + 'use strict' + + QUnit.module('tooltip plugin') + + QUnit.test('should be defined on jquery object', function (assert) { + assert.expect(1) + assert.ok($(document.body).tooltip, 'tooltip method is defined') + }) + + QUnit.module('tooltip', { + beforeEach: 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() + }, + afterEach: function () { + $.fn.tooltip = $.fn.bootstrapTooltip + delete $.fn.bootstrapTooltip + $('.tooltip').remove() + $('#qunit-fixture').html('') + } + }) + + QUnit.test('should provide no conflict', function (assert) { + assert.expect(1) + assert.strictEqual(typeof $.fn.tooltip, 'undefined', 'tooltip was set back to undefined (org value)') + }) + + QUnit.test('should throw explicit error on undefined method', function (assert) { + assert.expect(1) + var $el = $('<div/>') + $el.bootstrapTooltip() + try { + $el.bootstrapTooltip('noMethod') + } catch (err) { + assert.strictEqual(err.message, 'No method named "noMethod"') + } + }) + + QUnit.test('should return jquery collection containing the element', function (assert) { + assert.expect(2) + var $el = $('<div/>') + var $tooltip = $el.bootstrapTooltip() + assert.ok($tooltip instanceof $, 'returns jquery collection') + assert.strictEqual($tooltip[0], $el[0], 'collection contains element') + }) + + QUnit.test('should expose default settings', function (assert) { + assert.expect(1) + assert.ok($.fn.bootstrapTooltip.Constructor.Default, 'defaults is defined') + }) + + QUnit.test('should empty title attribute', function (assert) { + assert.expect(1) + var $trigger = $('<a href="#" rel="tooltip" title="Another tooltip"/>').bootstrapTooltip() + assert.strictEqual($trigger.attr('title'), '', 'title attribute was emptied') + }) + + QUnit.test('should add data attribute for referencing original title', function (assert) { + assert.expect(1) + var $trigger = $('<a href="#" rel="tooltip" title="Another tooltip"/>').bootstrapTooltip() + assert.strictEqual($trigger.attr('data-original-title'), 'Another tooltip', 'original title preserved in data attribute') + }) + + QUnit.test('should add aria-describedby to the trigger on show', function (assert) { + assert.expect(3) + var $trigger = $('<a href="#" rel="tooltip" title="Another tooltip"/>') + .bootstrapTooltip() + .appendTo('#qunit-fixture') + .bootstrapTooltip('show') + + var id = $('.tooltip').attr('id') + + assert.strictEqual($('#' + id).length, 1, 'has a unique id') + assert.strictEqual($('.tooltip').attr('aria-describedby'), $trigger.attr('id'), 'tooltip id and aria-describedby on trigger match') + assert.ok($trigger[0].hasAttribute('aria-describedby'), 'trigger has aria-describedby') + }) + + QUnit.test('should remove aria-describedby from trigger on hide', function (assert) { + assert.expect(2) + var done = assert.async() + var $trigger = $('<a href="#" rel="tooltip" title="Another tooltip"/>') + .bootstrapTooltip() + .appendTo('#qunit-fixture') + + $trigger + .one('shown.bs.tooltip', function () { + assert.ok($trigger[0].hasAttribute('aria-describedby'), 'trigger has aria-describedby') + $trigger.bootstrapTooltip('hide') + }) + .one('hidden.bs.tooltip', function () { + assert.ok(!$trigger[0].hasAttribute('aria-describedby'), 'trigger does not have aria-describedby') + done() + }) + .bootstrapTooltip('show') + }) + + QUnit.test('should assign a unique id tooltip element', function (assert) { + assert.expect(2) + $('<a href="#" rel="tooltip" title="Another tooltip"/>') + .appendTo('#qunit-fixture') + .bootstrapTooltip('show') + + var id = $('.tooltip').attr('id') + + assert.strictEqual($('#' + id).length, 1, 'tooltip has unique id') + assert.strictEqual(id.indexOf('tooltip'), 0, 'tooltip id has prefix') + }) + + QUnit.test('should place tooltips relative to placement option', function (assert) { + assert.expect(2) + var done = assert.async() + var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>') + .appendTo('#qunit-fixture') + .bootstrapTooltip({ + placement: 'bottom' + }) + + $tooltip + .one('shown.bs.tooltip', function () { + assert.ok($('.tooltip') + .is('.fade.bs-tooltip-bottom.show'), 'has correct classes applied') + + $tooltip.bootstrapTooltip('hide') + }) + .one('hidden.bs.tooltip', function () { + assert.strictEqual($tooltip.data('bs.tooltip').tip.parentNode, null, 'tooltip removed') + done() + }) + .bootstrapTooltip('show') + }) + + QUnit.test('should allow html entities', function (assert) { + assert.expect(2) + var done = assert.async() + var $tooltip = $('<a href="#" rel="tooltip" title="<b>@fat</b>"/>') + .appendTo('#qunit-fixture') + .bootstrapTooltip({ + html: true + }) + + $tooltip + .one('shown.bs.tooltip', function () { + assert.notEqual($('.tooltip b').length, 0, 'b tag was inserted') + $tooltip.bootstrapTooltip('hide') + }) + .one('hidden.bs.tooltip', function () { + assert.strictEqual($tooltip.data('bs.tooltip').tip.parentNode, null, 'tooltip removed') + done() + }) + .bootstrapTooltip('show') + }) + + QUnit.test('should allow DOMElement title (html: false)', function (assert) { + assert.expect(3) + var done = assert.async() + var title = document.createTextNode('<3 writing tests') + var $tooltip = $('<a href="#" rel="tooltip"/>') + .appendTo('#qunit-fixture') + .bootstrapTooltip({ + title: title + }) + + $tooltip + .one('shown.bs.tooltip', function () { + assert.notEqual($('.tooltip').length, 0, 'tooltip inserted') + assert.strictEqual($('.tooltip').text(), '<3 writing tests', 'title inserted') + assert.ok(!$.contains($('.tooltip').get(0), title), 'title node copied, not moved') + done() + }) + .bootstrapTooltip('show') + }) + + QUnit.test('should allow DOMElement title (html: true)', function (assert) { + assert.expect(3) + var done = assert.async() + var title = document.createTextNode('<3 writing tests') + var $tooltip = $('<a href="#" rel="tooltip"/>') + .appendTo('#qunit-fixture') + .bootstrapTooltip({ + html: true, + title: title + }) + + $tooltip + .one('shown.bs.tooltip', function () { + assert.notEqual($('.tooltip').length, 0, 'tooltip inserted') + assert.strictEqual($('.tooltip').text(), '<3 writing tests', 'title inserted') + assert.ok($.contains($('.tooltip').get(0), title), 'title node moved, not copied') + done() + }) + .bootstrapTooltip('show') + }) + + QUnit.test('should respect custom classes', function (assert) { + assert.expect(2) + var done = assert.async() + var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>') + .appendTo('#qunit-fixture') + .bootstrapTooltip({ + template: '<div class="tooltip some-class"><div class="tooltip-arrow"/><div class="tooltip-inner"/></div>' + }) + + $tooltip + .one('shown.bs.tooltip', function () { + assert.ok($('.tooltip').hasClass('some-class'), 'custom class is present') + $tooltip.bootstrapTooltip('hide') + }) + .one('hidden.bs.tooltip', function () { + assert.strictEqual($tooltip.data('bs.tooltip').tip.parentNode, null, 'tooltip removed') + done() + }) + .bootstrapTooltip('show') + }) + + QUnit.test('should fire show event', function (assert) { + assert.expect(1) + var done = assert.async() + + $('<div title="tooltip title"/>') + .on('show.bs.tooltip', function () { + assert.ok(true, 'show event fired') + done() + }) + .bootstrapTooltip('show') + }) + + QUnit.test('should throw an error when show is called on hidden elements', function (assert) { + assert.expect(1) + var done = assert.async() + + try { + $('<div title="tooltip title" style="display: none"/>').bootstrapTooltip('show') + } catch (err) { + assert.strictEqual(err.message, 'Please use show on visible elements') + done() + } + }) + + QUnit.test('should fire inserted event', function (assert) { + assert.expect(2) + var done = assert.async() + + $('<div title="tooltip title"/>') + .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() + + $('<div title="tooltip title"></div>') + .appendTo('#qunit-fixture') + .on('shown.bs.tooltip', function () { + assert.ok(true, 'shown was called') + done() + }) + .bootstrapTooltip('show') + }) + + QUnit.test('should not fire shown event when show was prevented', function (assert) { + assert.expect(1) + var done = assert.async() + + $('<div title="tooltip title"/>') + .on('show.bs.tooltip', function (e) { + e.preventDefault() + assert.ok(true, 'show event fired') + done() + }) + .on('shown.bs.tooltip', function () { + assert.ok(false, 'shown event fired') + }) + .bootstrapTooltip('show') + }) + + QUnit.test('should fire hide event', function (assert) { + assert.expect(1) + var done = assert.async() + + $('<div title="tooltip title"/>') + .appendTo('#qunit-fixture') + .on('shown.bs.tooltip', function () { + $(this).bootstrapTooltip('hide') + }) + .on('hide.bs.tooltip', function () { + assert.ok(true, 'hide event fired') + done() + }) + .bootstrapTooltip('show') + }) + + QUnit.test('should fire hidden event', function (assert) { + assert.expect(1) + var done = assert.async() + + $('<div title="tooltip title"/>') + .appendTo('#qunit-fixture') + .on('shown.bs.tooltip', function () { + $(this).bootstrapTooltip('hide') + }) + .on('hidden.bs.tooltip', function () { + assert.ok(true, 'hidden event fired') + done() + }) + .bootstrapTooltip('show') + }) + + QUnit.test('should not fire hidden event when hide was prevented', function (assert) { + assert.expect(1) + var done = assert.async() + + $('<div title="tooltip title"/>') + .appendTo('#qunit-fixture') + .on('shown.bs.tooltip', function () { + $(this).bootstrapTooltip('hide') + }) + .on('hide.bs.tooltip', function (e) { + e.preventDefault() + assert.ok(true, 'hide event fired') + done() + }) + .on('hidden.bs.tooltip', function () { + assert.ok(false, 'hidden event fired') + }) + .bootstrapTooltip('show') + }) + + QUnit.test('should destroy tooltip', function (assert) { + assert.expect(7) + var $tooltip = $('<div/>') + .bootstrapTooltip() + .on('click.foo', function () {}) // eslint-disable-line no-empty-function + + assert.ok($tooltip.data('bs.tooltip'), 'tooltip has data') + assert.ok($._data($tooltip[0], 'events').mouseover && $._data($tooltip[0], 'events').mouseout, 'tooltip has hover events') + assert.strictEqual($._data($tooltip[0], 'events').click[0].namespace, 'foo', 'tooltip has extra click.foo event') + + $tooltip.bootstrapTooltip('show') + $tooltip.bootstrapTooltip('dispose') + + assert.ok(!$tooltip.hasClass('show'), 'tooltip is hidden') + assert.ok(!$._data($tooltip[0], 'bs.tooltip'), 'tooltip does not have data') + assert.strictEqual($._data($tooltip[0], 'events').click[0].namespace, 'foo', 'tooltip still has click.foo') + assert.ok(!$._data($tooltip[0], 'events').mouseover && !$._data($tooltip[0], 'events').mouseout, 'tooltip does not have hover events') + }) + + // QUnit.test('should show tooltip with delegate selector on click', function (assert) { + // assert.expect(2) + // var $div = $('<div><a href="#" rel="tooltip" title="Another tooltip"/></div>') + // .appendTo('#qunit-fixture') + // .bootstrapTooltip({ + // selector: 'a[rel="tooltip"]', + // trigger: 'click' + // }) + + // $div.find('a').trigger('click') + // assert.ok($('.tooltip').is('.fade.in'), 'tooltip is faded in') + + // $div.find('a').trigger('click') + // assert.strictEqual($div.data('bs.tooltip').tip.parentNode, null, 'tooltip removed') + // }) + + QUnit.test('should show tooltip when toggle is called', function (assert) { + assert.expect(1) + $('<a href="#" rel="tooltip" title="tooltip on toggle"/>') + .appendTo('#qunit-fixture') + .bootstrapTooltip({ + trigger: 'manual' + }) + .bootstrapTooltip('toggle') + + assert.ok($('.tooltip').is('.fade.show'), 'tooltip is faded active') + }) + + QUnit.test('should hide previously shown tooltip when toggle is called on tooltip', function (assert) { + assert.expect(1) + $('<a href="#" rel="tooltip" title="tooltip on toggle">@ResentedHook</a>') + .appendTo('#qunit-fixture') + .bootstrapTooltip({ + trigger: 'manual' + }) + .bootstrapTooltip('show') + + $('.tooltip').bootstrapTooltip('toggle') + assert.ok($('.tooltip').not('.fade.show'), 'tooltip was faded out') + }) + + QUnit.test('should place tooltips inside body when container is body', function (assert) { + assert.expect(3) + var done = assert.async() + var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>') + .appendTo('#qunit-fixture') + .bootstrapTooltip({ + container: 'body' + }) + + $tooltip + .one('shown.bs.tooltip', function () { + assert.notEqual($('body > .tooltip').length, 0, 'tooltip is direct descendant of body') + assert.strictEqual($('#qunit-fixture > .tooltip').length, 0, 'tooltip is not in parent') + $tooltip.bootstrapTooltip('hide') + }) + .one('hidden.bs.tooltip', function () { + assert.strictEqual($('body > .tooltip').length, 0, 'tooltip was removed from dom') + done() + }) + .bootstrapTooltip('show') + }) + + QUnit.test('should add position class before positioning so that position-specific styles are taken into account', function (assert) { + assert.expect(2) + var done = assert.async() + var styles = '<style>' + + '.bs-tooltip-right { white-space: nowrap; }' + + '.bs-tooltip-right .tooltip-inner { max-width: none; }' + + '</style>' + var $styles = $(styles).appendTo('head') + + var $container = $('<div/>').appendTo('#qunit-fixture') + $('<a href="#" rel="tooltip" title="very very very very very very very very long tooltip in one line"/>') + .appendTo($container) + .bootstrapTooltip({ + placement: 'right', + trigger: 'manual' + }) + .on('inserted.bs.tooltip', function () { + var $tooltip = $($(this).data('bs.tooltip').tip) + assert.ok($tooltip.hasClass('bs-tooltip-right')) + assert.ok(typeof $tooltip.attr('style') === 'undefined') + $styles.remove() + done() + }) + .bootstrapTooltip('show') + }) + + QUnit.test('should use title attribute for tooltip text', function (assert) { + assert.expect(2) + var done = assert.async() + var $tooltip = $('<a href="#" rel="tooltip" title="Simple tooltip"/>') + .appendTo('#qunit-fixture') + .bootstrapTooltip() + + $tooltip + .one('shown.bs.tooltip', function () { + assert.strictEqual($('.tooltip').children('.tooltip-inner').text(), 'Simple tooltip', 'title from title attribute is set') + $tooltip.bootstrapTooltip('hide') + }) + .one('hidden.bs.tooltip', function () { + assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom') + done() + }) + .bootstrapTooltip('show') + }) + + QUnit.test('should prefer title attribute over title option', function (assert) { + assert.expect(2) + var done = assert.async() + var $tooltip = $('<a href="#" rel="tooltip" title="Simple tooltip"/>') + .appendTo('#qunit-fixture') + .bootstrapTooltip({ + title: 'This is a tooltip with some content' + }) + + $tooltip + .one('shown.bs.tooltip', function () { + assert.strictEqual($('.tooltip').children('.tooltip-inner').text(), 'Simple tooltip', 'title is set from title attribute while preferred over title option') + $tooltip.bootstrapTooltip('hide') + }) + .one('hidden.bs.tooltip', function () { + assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom') + done() + }) + .bootstrapTooltip('show') + }) + + QUnit.test('should use title option', function (assert) { + assert.expect(2) + var done = assert.async() + var $tooltip = $('<a href="#" rel="tooltip"/>') + .appendTo('#qunit-fixture') + .bootstrapTooltip({ + title: 'This is a tooltip with some content' + }) + + $tooltip + .one('shown.bs.tooltip', function () { + assert.strictEqual($('.tooltip').children('.tooltip-inner').text(), 'This is a tooltip with some content', 'title from title option is set') + $tooltip.bootstrapTooltip('hide') + }) + .one('hidden.bs.tooltip', function () { + assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom') + done() + }) + .bootstrapTooltip('show') + }) + + QUnit.test('should not error when trying to show an top-placed tooltip that has been removed from the dom', function (assert) { + assert.expect(1) + var passed = true + var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>') + .appendTo('#qunit-fixture') + .one('show.bs.tooltip', function () { + $(this).remove() + }) + .bootstrapTooltip({ + placement: 'top' + }) + + try { + $tooltip.bootstrapTooltip('show') + } catch (err) { + passed = false + console.log(err) + } + + assert.ok(passed, '.tooltip(\'show\') should not throw an error if element no longer is in dom') + }) + + QUnit.test('should show tooltip if leave event hasn\'t occurred before delay expires', function (assert) { + assert.expect(2) + var done = assert.async() + + var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>') + .appendTo('#qunit-fixture') + .bootstrapTooltip({ + delay: 150 + }) + + setTimeout(function () { + assert.ok(!$('.tooltip').is('.fade.show'), '100ms: tooltip is not faded active') + }, 100) + + setTimeout(function () { + assert.ok($('.tooltip').is('.fade.show'), '200ms: tooltip is faded active') + done() + }, 200) + + $tooltip.trigger('mouseenter') + }) + + QUnit.test('should not show tooltip if leave event occurs before delay expires', function (assert) { + assert.expect(2) + var done = assert.async() + + var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>') + .appendTo('#qunit-fixture') + .bootstrapTooltip({ + delay: 150 + }) + + setTimeout(function () { + assert.ok(!$('.tooltip').is('.fade.show'), '100ms: tooltip not faded active') + $tooltip.trigger('mouseout') + }, 100) + + setTimeout(function () { + assert.ok(!$('.tooltip').is('.fade.show'), '200ms: tooltip not faded active') + done() + }, 200) + + $tooltip.trigger('mouseenter') + }) + + QUnit.test('should not hide tooltip if leave event occurs and enter event occurs within the hide delay', function (assert) { + assert.expect(3) + var done = assert.async() + + var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>') + .appendTo('#qunit-fixture') + .bootstrapTooltip({ + delay: { + show: 0, + hide: 150 + } + }) + + setTimeout(function () { + assert.ok($('.tooltip').is('.fade.show'), '1ms: tooltip faded active') + $tooltip.trigger('mouseout') + + setTimeout(function () { + assert.ok($('.tooltip').is('.fade.show'), '100ms: tooltip still faded active') + $tooltip.trigger('mouseenter') + }, 100) + + setTimeout(function () { + assert.ok($('.tooltip').is('.fade.show'), '200ms: tooltip still faded active') + done() + }, 200) + }, 0) + + $tooltip.trigger('mouseenter') + }) + + QUnit.test('should not show tooltip if leave event occurs before delay expires', function (assert) { + assert.expect(2) + var done = assert.async() + + var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>') + .appendTo('#qunit-fixture') + .bootstrapTooltip({ + delay: 150 + }) + + setTimeout(function () { + assert.ok(!$('.tooltip').is('.fade.show'), '100ms: tooltip not faded active') + $tooltip.trigger('mouseout') + }, 100) + + setTimeout(function () { + assert.ok(!$('.tooltip').is('.fade.show'), '200ms: tooltip not faded active') + done() + }, 200) + + $tooltip.trigger('mouseenter') + }) + + QUnit.test('should not show tooltip if leave event occurs before delay expires, even if hide delay is 0', function (assert) { + assert.expect(2) + var done = assert.async() + + var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>') + .appendTo('#qunit-fixture') + .bootstrapTooltip({ + delay: { + show: 150, + hide: 0 + } + }) + + setTimeout(function () { + assert.ok(!$('.tooltip').is('.fade.show'), '100ms: tooltip not faded active') + $tooltip.trigger('mouseout') + }, 100) + + setTimeout(function () { + assert.ok(!$('.tooltip').is('.fade.show'), '250ms: tooltip not faded active') + done() + }, 250) + + $tooltip.trigger('mouseenter') + }) + + QUnit.test('should wait 200ms before hiding the tooltip', function (assert) { + assert.expect(3) + var done = assert.async() + + var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>') + .appendTo('#qunit-fixture') + .bootstrapTooltip({ + delay: { + show: 0, + hide: 150 + } + }) + + setTimeout(function () { + assert.ok($($tooltip.data('bs.tooltip').tip).is('.fade.show'), '1ms: tooltip faded active') + + $tooltip.trigger('mouseout') + + setTimeout(function () { + assert.ok($($tooltip.data('bs.tooltip').tip).is('.fade.show'), '100ms: tooltip still faded active') + }, 100) + + setTimeout(function () { + assert.ok(!$($tooltip.data('bs.tooltip').tip).is('.show'), '200ms: tooltip removed') + done() + }, 200) + }, 0) + + $tooltip.trigger('mouseenter') + }) + + QUnit.test('should not reload the tooltip on subsequent mouseenter events', function (assert) { + assert.expect(1) + var titleHtml = function () { + var uid = Util.getUID('tooltip') + return '<p id="tt-content">' + uid + '</p><p>' + uid + '</p><p>' + uid + '</p>' + } + + var $tooltip = $('<span id="tt-outer" rel="tooltip" data-trigger="hover" data-placement="top">some text</span>') + .appendTo('#qunit-fixture') + + $tooltip.bootstrapTooltip({ + html: true, + animation: false, + trigger: 'hover', + delay: { + show: 0, + hide: 500 + }, + container: $tooltip, + title: titleHtml + }) + + $('#tt-outer').trigger('mouseenter') + + var currentUid = $('#tt-content').text() + + $('#tt-content').trigger('mouseenter') + assert.strictEqual(currentUid, $('#tt-content').text()) + }) + + QUnit.test('should not reload the tooltip if the mouse leaves and re-enters before hiding', function (assert) { + assert.expect(4) + + var titleHtml = function () { + var uid = Util.getUID('tooltip') + return '<p id="tt-content">' + uid + '</p><p>' + uid + '</p><p>' + uid + '</p>' + } + + var $tooltip = $('<span id="tt-outer" rel="tooltip" data-trigger="hover" data-placement="top">some text</span>') + .appendTo('#qunit-fixture') + + $tooltip.bootstrapTooltip({ + html: true, + animation: false, + trigger: 'hover', + delay: { + show: 0, + hide: 500 + }, + title: titleHtml + }) + + var obj = $tooltip.data('bs.tooltip') + + $('#tt-outer').trigger('mouseenter') + + var currentUid = $('#tt-content').text() + + $('#tt-outer').trigger('mouseleave') + assert.strictEqual(currentUid, $('#tt-content').text()) + + assert.ok(obj._hoverState === 'out', 'the tooltip hoverState should be set to "out"') + + $('#tt-outer').trigger('mouseenter') + assert.ok(obj._hoverState === 'show', 'the tooltip hoverState should be set to "show"') + + assert.strictEqual(currentUid, $('#tt-content').text()) + }) + + QUnit.test('should do nothing when an attempt is made to hide an uninitialized tooltip', function (assert) { + assert.expect(1) + + var $tooltip = $('<span data-toggle="tooltip" title="some tip">some text</span>') + .appendTo('#qunit-fixture') + .on('hidden.bs.tooltip shown.bs.tooltip', function () { + assert.ok(false, 'should not fire any tooltip events') + }) + .bootstrapTooltip('hide') + assert.strictEqual(typeof $tooltip.data('bs.tooltip'), 'undefined', 'should not initialize the tooltip') + }) + + QUnit.test('should not remove tooltip if multiple triggers are set and one is still active', function (assert) { + assert.expect(41) + var $el = $('<button>Trigger</button>') + .appendTo('#qunit-fixture') + .bootstrapTooltip({ + trigger: 'click hover focus', + animation: false + }) + var tooltip = $el.data('bs.tooltip') + var $tooltip = $(tooltip.getTipElement()) + + function showingTooltip() { + return $tooltip.hasClass('show') || tooltip._hoverState === 'show' + } + + 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()) + } + }) + }) + + QUnit.test('should show on first trigger after hide', function (assert) { + assert.expect(3) + var $el = $('<a href="#" rel="tooltip" title="Test tooltip"/>') + .appendTo('#qunit-fixture') + .bootstrapTooltip({ + trigger: 'click hover focus', + animation: false + }) + + var tooltip = $el.data('bs.tooltip') + var $tooltip = $(tooltip.getTipElement()) + + function showingTooltip() { + return $tooltip.hasClass('show') || tooltip._hoverState === 'show' + } + + $el.trigger('click') + assert.ok(showingTooltip(), 'tooltip is faded in') + + $el.bootstrapTooltip('hide') + assert.ok(!showingTooltip(), 'tooltip was faded out') + + $el.trigger('click') + 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') + }) + + QUnit.test('should reset tip classes when hidden event triggered', function (assert) { + assert.expect(2) + var done = assert.async() + var $el = $('<a href="#" rel="tooltip" title="Test tooltip"/>') + .appendTo('#qunit-fixture') + .bootstrapTooltip('show') + .on('hidden.bs.tooltip', function () { + var tooltip = $el.data('bs.tooltip') + var $tooltip = $(tooltip.getTipElement()) + assert.ok($tooltip.hasClass('tooltip')) + assert.ok($tooltip.hasClass('fade')) + done() + }) + + $el.bootstrapTooltip('hide') + }) + + QUnit.test('should convert number in title to string', function (assert) { + assert.expect(1) + var done = assert.async() + var $el = $('<a href="#" rel="tooltip" title="7"/>') + .appendTo('#qunit-fixture') + .on('shown.bs.tooltip', function () { + var tooltip = $el.data('bs.tooltip') + var $tooltip = $(tooltip.getTipElement()) + assert.strictEqual($tooltip.children().text(), '7') + done() + }) + + $el.bootstrapTooltip('show') + }) + + QUnit.test('tooltip should be shown right away after the call of disable/enable', function (assert) { + assert.expect(2) + var done = assert.async() + + var $trigger = $('<a href="#" rel="tooltip" data-trigger="click" title="Another tooltip"/>') + .appendTo('#qunit-fixture') + .bootstrapTooltip() + .on('shown.bs.tooltip', function () { + assert.strictEqual($('.tooltip').hasClass('show'), true) + done() + }) + + $trigger.bootstrapTooltip('disable') + $trigger.trigger($.Event('click')) + setTimeout(function () { + assert.strictEqual($('.tooltip').length === 0, true) + $trigger.bootstrapTooltip('enable') + $trigger.trigger($.Event('click')) + }, 200) + }) + + QUnit.test('should call Popper.js to update', function (assert) { + assert.expect(2) + + var $tooltip = $('<a href="#" rel="tooltip" data-trigger="click" title="Another tooltip"/>') + .appendTo('#qunit-fixture') + .bootstrapTooltip() + + var tooltip = $tooltip.data('bs.tooltip') + tooltip.show() + assert.ok(tooltip._popper) + + var spyPopper = sinon.spy(tooltip._popper, 'scheduleUpdate') + tooltip.update() + assert.ok(spyPopper.called) + }) + + QUnit.test('should not call Popper.js to update', function (assert) { + assert.expect(1) + + var $tooltip = $('<a href="#" rel="tooltip" data-trigger="click" title="Another tooltip"/>') + .appendTo('#qunit-fixture') + .bootstrapTooltip() + + var tooltip = $tooltip.data('bs.tooltip') + tooltip.update() + + assert.ok(tooltip._popper === null) + }) + + QUnit.test('should use Popper.js to get the tip on placement change', function (assert) { + assert.expect(1) + + var $tooltip = $('<a href="#" rel="tooltip" data-trigger="click" title="Another tooltip"/>') + .appendTo('#qunit-fixture') + .bootstrapTooltip() + + var $tipTest = $('<div class="bs-tooltip" />') + .appendTo('#qunit-fixture') + + var tooltip = $tooltip.data('bs.tooltip') + tooltip.tip = null + + tooltip._handlePopperPlacementChange({ + instance: { + popper: $tipTest[0] + }, + placement: 'auto' + }) + + assert.ok(tooltip.tip === $tipTest[0]) + }) +}) diff --git a/themes/docsy/assets/vendor/bootstrap/js/tests/unit/util.js b/themes/docsy/assets/vendor/bootstrap/js/tests/unit/util.js new file mode 100644 index 0000000..37327b8 --- /dev/null +++ b/themes/docsy/assets/vendor/bootstrap/js/tests/unit/util.js @@ -0,0 +1,104 @@ +$(function () { + 'use strict' + + window.Util = typeof bootstrap !== 'undefined' ? bootstrap.Util : Util + + QUnit.module('util', { + afterEach: function () { + $('#qunit-fixture').html('') + } + }) + + QUnit.test('Util.getSelectorFromElement should return the correct element', function (assert) { + assert.expect(2) + + var $el = $('<div data-target="body"></div>').appendTo($('#qunit-fixture')) + assert.strictEqual(Util.getSelectorFromElement($el[0]), 'body') + + // Not found element + var $el2 = $('<div data-target="#fakeDiv"></div>').appendTo($('#qunit-fixture')) + assert.strictEqual(Util.getSelectorFromElement($el2[0]), null) + }) + + QUnit.test('Util.typeCheckConfig should thrown an error when a bad config is passed', function (assert) { + assert.expect(1) + var namePlugin = 'collapse' + var defaultType = { + toggle: 'boolean', + parent: '(string|element)' + } + var config = { + toggle: true, + parent: 777 + } + + try { + Util.typeCheckConfig(namePlugin, config, defaultType) + } catch (err) { + assert.strictEqual(err.message, 'COLLAPSE: Option "parent" provided type "number" but expected type "(string|element)".') + } + }) + + QUnit.test('Util.isElement should check if we passed an element or not', function (assert) { + assert.expect(3) + var $div = $('<div id="test"></div>').appendTo($('#qunit-fixture')) + + assert.strictEqual(Util.isElement($div), 1) + assert.strictEqual(Util.isElement($div[0]), 1) + assert.strictEqual(typeof Util.isElement({}) === 'undefined', true) + }) + + QUnit.test('Util.getTransitionDurationFromElement should accept transition durations in milliseconds', function (assert) { + assert.expect(1) + var $div = $('<div style="transition: all 300ms ease-out;"></div>').appendTo($('#qunit-fixture')) + + assert.strictEqual(Util.getTransitionDurationFromElement($div[0]), 300) + }) + + QUnit.test('Util.getTransitionDurationFromElement should accept transition durations in seconds', function (assert) { + assert.expect(1) + var $div = $('<div style="transition: all .4s ease-out;"></div>').appendTo($('#qunit-fixture')) + + assert.strictEqual(Util.getTransitionDurationFromElement($div[0]), 400) + }) + + QUnit.test('Util.getTransitionDurationFromElement should get the first transition duration if multiple transition durations are defined', function (assert) { + assert.expect(1) + var $div = $('<div style="transition: transform .3s ease-out, opacity .2s;"></div>').appendTo($('#qunit-fixture')) + + assert.strictEqual(Util.getTransitionDurationFromElement($div[0]), 300) + }) + + QUnit.test('Util.getTransitionDurationFromElement should return 0 if transition duration is not defined', function (assert) { + assert.expect(1) + var $div = $('<div></div>').appendTo($('#qunit-fixture')) + + assert.strictEqual(Util.getTransitionDurationFromElement($div[0]), 0) + }) + + QUnit.test('Util.getTransitionDurationFromElement should return 0 if element is not found in DOM', function (assert) { + assert.expect(1) + var $div = $('#fake-id') + + assert.strictEqual(Util.getTransitionDurationFromElement($div[0]), 0) + }) + + QUnit.test('Util.getUID should generate a new id uniq', function (assert) { + assert.expect(2) + var id = Util.getUID('test') + var id2 = Util.getUID('test') + + assert.ok(id !== id2, id + ' !== ' + id2) + + id = Util.getUID('test') + $('<div id="' + id + '"></div>').appendTo($('#qunit-fixture')) + + id2 = Util.getUID('test') + assert.ok(id !== id2, id + ' !== ' + id2) + }) + + QUnit.test('Util.supportsTransitionEnd should return true', function (assert) { + assert.expect(1) + assert.ok(Util.supportsTransitionEnd()) + }) +}) |