diff options
author | Dimitri Staessens <dimitri@ouroboros.rocks> | 2019-10-06 21:10:46 +0200 |
---|---|---|
committer | Dimitri Staessens <dimitri@ouroboros.rocks> | 2019-10-06 21:10:46 +0200 |
commit | 568553394d0a8b34668a75c9839a0f1f426469b2 (patch) | |
tree | 175c08844f05611b059ba6900fb6519dbbc735d2 /themes/docsy/assets/vendor/bootstrap/js/tests/unit/util.js | |
parent | d5d6f70371958eec0679831abd283498ff2731e5 (diff) | |
download | website-568553394d0a8b34668a75c9839a0f1f426469b2.tar.gz website-568553394d0a8b34668a75c9839a0f1f426469b2.zip |
theme: Switch to docsy theme
Diffstat (limited to 'themes/docsy/assets/vendor/bootstrap/js/tests/unit/util.js')
-rw-r--r-- | themes/docsy/assets/vendor/bootstrap/js/tests/unit/util.js | 104 |
1 files changed, 104 insertions, 0 deletions
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()) + }) +}) |