diff options
author | 2017-05-03 21:31:58 +0000 | |
---|---|---|
committer | 2017-05-03 21:31:58 +0000 | |
commit | a330af579866dacbe595e2e4ad1dd29cd3c96945 (patch) | |
tree | b9455591600034dfd4f33a9c1f733336280f2208 /POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit | |
parent | 5444e748b8651d8346dcb78c5ab8b0637dea197b (diff) | |
parent | e0addf5b588a1244f9679becd90999dfcb4c3a94 (diff) |
Merge "Policy 1707 commit to LF"
Diffstat (limited to 'POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit')
13 files changed, 4302 insertions, 0 deletions
diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit/.jshintrc b/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit/.jshintrc new file mode 100644 index 000000000..22e878512 --- /dev/null +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit/.jshintrc @@ -0,0 +1,6 @@ +{ + "extends" : "../../.jshintrc", + "devel" : true, + "es3" : false, + "qunit" : true +} diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit/affix.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit/affix.js new file mode 100644 index 000000000..3a6918f86 --- /dev/null +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit/affix.js @@ -0,0 +1,107 @@ +$(function () { + 'use strict'; + + QUnit.module('affix plugin') + + QUnit.test('should be defined on jquery object', function (assert) { + assert.expect(1) + assert.ok($(document.body).affix, 'affix method is defined') + }) + + QUnit.module('affix', { + beforeEach: function () { + // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode + $.fn.bootstrapAffix = $.fn.affix.noConflict() + }, + afterEach: function () { + $.fn.affix = $.fn.bootstrapAffix + delete $.fn.bootstrapAffix + } + }) + + QUnit.test('should provide no conflict', function (assert) { + assert.expect(1) + assert.strictEqual($.fn.affix, undefined, 'affix 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 $affix = $el.bootstrapAffix() + assert.ok($affix instanceof $, 'returns jquery collection') + assert.strictEqual($affix[0], $el[0], 'collection contains element') + }) + + QUnit.test('should exit early if element is not visible', function (assert) { + assert.expect(1) + var $affix = $('<div style="display: none"/>').bootstrapAffix() + $affix.data('bs.affix').checkPosition() + assert.ok(!$affix.hasClass('affix'), 'affix class was not added') + }) + + QUnit.test('should trigger affixed event after affix', function (assert) { + assert.expect(2) + var done = assert.async() + + var templateHTML = '<div id="affixTarget">' + + '<ul>' + + '<li>Please affix</li>' + + '<li>And unaffix</li>' + + '</ul>' + + '</div>' + + '<div id="affixAfter" style="height: 20000px; display: block;"/>' + $(templateHTML).appendTo(document.body) + + $('#affixTarget').bootstrapAffix({ + offset: $('#affixTarget ul').position() + }) + + $('#affixTarget') + .on('affix.bs.affix', function () { + assert.ok(true, 'affix event fired') + }).on('affixed.bs.affix', function () { + assert.ok(true, 'affixed event fired') + $('#affixTarget, #affixAfter').remove() + done() + }) + + setTimeout(function () { + window.scrollTo(0, document.body.scrollHeight) + + setTimeout(function () { + window.scroll(0, 0) + }, 16) // for testing in a browser + }, 0) + }) + + QUnit.test('should affix-top when scrolling up to offset when parent has padding', function (assert) { + assert.expect(1) + var done = assert.async() + + var templateHTML = '<div id="padding-offset" style="padding-top: 20px;">' + + '<div id="affixTopTarget">' + + '<p>Testing affix-top class is added</p>' + + '</div>' + + '<div style="height: 1000px; display: block;"/>' + + '</div>' + $(templateHTML).appendTo(document.body) + + $('#affixTopTarget') + .bootstrapAffix({ + offset: { top: 120, bottom: 0 } + }) + .on('affixed-top.bs.affix', function () { + assert.ok($('#affixTopTarget').hasClass('affix-top'), 'affix-top class applied') + $('#padding-offset').remove() + done() + }) + + setTimeout(function () { + window.scrollTo(0, document.body.scrollHeight) + + setTimeout(function () { + window.scroll(0, 119) + }, 250) + }, 250) + }) +}) diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit/alert.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit/alert.js new file mode 100644 index 000000000..6be990a51 --- /dev/null +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit/alert.js @@ -0,0 +1,78 @@ +$(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.test('should provide no conflict', function (assert) { + assert.expect(1) + assert.strictEqual($.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 in">' + + '<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() + + $alert.find('.close').trigger('click') + + assert.strictEqual($alert.hasClass('in'), false, 'remove .in class on .close click') + }) + + QUnit.test('should remove element when clicking .close', function (assert) { + assert.expect(2) + var alertHTML = '<div class="alert alert-danger fade in">' + + '<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.find('.close').trigger('click') + + assert.strictEqual($('#qunit-fixture').find('.alert').length, 0, 'element removed from dom') + }) + + 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') + }) + +}) diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit/button.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit/button.js new file mode 100644 index 000000000..02312ebaf --- /dev/null +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit/button.js @@ -0,0 +1,181 @@ +$(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.test('should provide no conflict', function (assert) { + assert.expect(1) + assert.strictEqual($.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 return set state to loading', function (assert) { + assert.expect(4) + var $btn = $('<button class="btn" data-loading-text="fat">mdo</button>') + assert.strictEqual($btn.html(), 'mdo', 'btn text equals mdo') + $btn.bootstrapButton('loading') + var done = assert.async() + setTimeout(function () { + assert.strictEqual($btn.html(), 'fat', 'btn text equals fat') + assert.ok($btn[0].hasAttribute('disabled'), 'btn is disabled') + assert.ok($btn.hasClass('disabled'), 'btn has disabled class') + done() + }, 0) + }) + + QUnit.test('should return reset state', function (assert) { + assert.expect(7) + var $btn = $('<button class="btn" data-loading-text="fat">mdo</button>') + assert.strictEqual($btn.html(), 'mdo', 'btn text equals mdo') + $btn.bootstrapButton('loading') + var doneOne = assert.async() + setTimeout(function () { + assert.strictEqual($btn.html(), 'fat', 'btn text equals fat') + assert.ok($btn[0].hasAttribute('disabled'), 'btn is disabled') + assert.ok($btn.hasClass('disabled'), 'btn has disabled class') + doneOne() + var doneTwo = assert.async() + $btn.bootstrapButton('reset') + setTimeout(function () { + assert.strictEqual($btn.html(), 'mdo', 'btn text equals mdo') + assert.ok(!$btn[0].hasAttribute('disabled'), 'btn is not disabled') + assert.ok(!$btn.hasClass('disabled'), 'btn does not have disabled class') + doneTwo() + }, 0) + }, 0) + }) + + QUnit.test('should work with an empty string as reset state', function (assert) { + assert.expect(7) + var $btn = $('<button class="btn" data-loading-text="fat"/>') + assert.strictEqual($btn.html(), '', 'btn text equals ""') + $btn.bootstrapButton('loading') + var doneOne = assert.async() + setTimeout(function () { + assert.strictEqual($btn.html(), 'fat', 'btn text equals fat') + assert.ok($btn[0].hasAttribute('disabled'), 'btn is disabled') + assert.ok($btn.hasClass('disabled'), 'btn has disabled class') + doneOne() + var doneTwo = assert.async() + $btn.bootstrapButton('reset') + setTimeout(function () { + assert.strictEqual($btn.html(), '', 'btn text equals ""') + assert.ok(!$btn[0].hasAttribute('disabled'), 'btn is not disabled') + assert.ok(!$btn.hasClass('disabled'), 'btn does not have disabled class') + doneTwo() + }, 0) + }, 0) + }) + + 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 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 toggle active when btn children are clicked within btn-group', function (assert) { + assert.expect(2) + var $btngroup = $('<div class="btn-group" data-toggle="buttons"/>') + var $btn = $('<button class="btn">fat</button>') + var $inner = $('<i/>') + $btngroup + .append($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 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 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 checked') + assert.ok($btn2.hasClass('active'), 'btn2 has active class') + assert.ok($btn2.find('input').prop('checked'), 'btn2 is checked') + }) + +}) diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit/carousel.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit/carousel.js new file mode 100644 index 000000000..39d250598 --- /dev/null +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit/carousel.js @@ -0,0 +1,718 @@ +$(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.test('should provide no conflict', function (assert) { + assert.expect(1) + assert.strictEqual($.fn.carousel, undefined, 'carousel was set back to undefined (orig value)') + }) + + 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 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="item active">' + + '<div class="carousel-caption"/>' + + '</div>' + + '<div class="item">' + + '<div class="carousel-caption"/>' + + '</div>' + + '<div class="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('.item:eq(0)').is('.active'), 'first item still active') + assert.ok($carousel.find('.carousel-indicators li:eq(0)').is('.active'), 'first indicator still active') + $carousel.bootstrapCarousel('next') + }, 0) + }) + .one('slid.bs.carousel', function () { + setTimeout(function () { + assert.ok(!$carousel.find('.item:eq(0)').is('.active'), 'first item still active') + assert.ok(!$carousel.find('.carousel-indicators li:eq(0)').is('.active'), 'first indicator still active') + assert.ok($carousel.find('.item:eq(1)').is('.active'), 'second item active') + assert.ok($carousel.find('.carousel-indicators li:eq(1)').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="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="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="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="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="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="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="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="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="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('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="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="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="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('item'), 'relatedTarget has class "item"') + done() + }) + .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="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="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="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').options.interval, 1814) + $carousel.remove() + + $carousel.appendTo('body').attr('data-modal', 'foobar') + $('[data-slide]').first().trigger('click') + assert.strictEqual($carousel.data('bs.carousel').options.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').options.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').options.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="item active">' + + '<img alt="">' + + '</div>' + + '<script type="text/x-metamorph" id="thingy"/>' + + '<div class="item">' + + '<img alt="">' + + '</div>' + + '<div class="item">' + + '</div>' + + '</div>' + + '</div>' + var $template = $(templateHTML) + + $template.bootstrapCarousel() + + assert.strictEqual($template.find('.item')[0], $template.find('.active')[0], 'first item active') + + $template.bootstrapCarousel(1) + + assert.strictEqual($template.find('.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="item active">' + + '<img alt="">' + + '</div>' + + '<script type="text/x-metamorph" id="thingy"/>' + + '<div class="item">' + + '<img alt="">' + + '</div>' + + '<div class="item">' + + '</div>' + + '</div>' + + '</div>' + var $template = $(templateHTML) + + $template.bootstrapCarousel() + + assert.strictEqual($template.find('.item')[0], $template.find('.active')[0], 'first item active') + + $template.bootstrapCarousel('next') + + assert.strictEqual($template.find('.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="item">' + + '<img alt="">' + + '</div>' + + '<div id="second" class="item active">' + + '<img alt="">' + + '</div>' + + '<div id="third" class="item">' + + '<img alt="">' + + '</div>' + + '</div>' + + '</div>' + var $template = $(templateHTML) + + $template.bootstrapCarousel() + + assert.strictEqual($template.find('.item')[1], $template.find('.active')[0], 'second item active') + + $template.trigger($.Event('keydown', { which: 37 })) + + assert.strictEqual($template.find('.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="item active">' + + '<img alt="">' + + '</div>' + + '<div id="second" class="item">' + + '<img alt="">' + + '</div>' + + '<div id="third" class="item">' + + '<img alt="">' + + '</div>' + + '</div>' + + '</div>' + var $template = $(templateHTML) + + $template.bootstrapCarousel() + + assert.strictEqual($template.find('.item')[0], $template.find('.active')[0], 'first item active') + + $template.trigger($.Event('keydown', { which: 39 })) + + assert.strictEqual($template.find('.item')[1], $template.find('.active')[0], 'second item active') + }) + + 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="item active">' + + '<img alt="">' + + '</div>' + + '<div id="second" class="item">' + + '<img alt="">' + + '</div>' + + '<div id="third" class="item">' + + '<img alt="">' + + '</div>' + + '</div>' + + '</div>' + var $template = $(templateHTML) + + $template.bootstrapCarousel() + + assert.strictEqual($template.find('.item')[0], $template.find('.active')[0], 'first item active') + + $template.trigger($.Event('keydown', { which: 39 })) + + assert.strictEqual($template.find('.item')[0], $template.find('.active')[0], 'first item still active after right arrow press') + + $template.trigger($.Event('keydown', { which: 37 })) + + assert.strictEqual($template.find('.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="item active">' + + '<img alt="">' + + '<input type="text" id="in-put">' + + '<textarea id="text-area"></textarea>' + + '</div>' + + '<div id="second" class="item">' + + '<img alt="">' + + '</div>' + + '<div id="third" class="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('.item')[0], $template.find('.active')[0], 'first item active') + + + $input.trigger($.Event('keydown', { which: 39 })) + assert.strictEqual($template.find('.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('.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('.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('.item')[0], $template.find('.active')[0], 'first item still active after left arrow press in <textarea>') + }) + + QUnit.test('should only add mouseenter and mouseleave listeners when not on mobile', function (assert) { + assert.expect(2) + var isMobile = 'ontouchstart' in document.documentElement + var templateHTML = '<div id="myCarousel" class="carousel" data-interval="false" data-pause="hover">' + + '<div class="carousel-inner">' + + '<div id="first" class="item active">' + + '<img alt="">' + + '</div>' + + '<div id="second" class="item">' + + '<img alt="">' + + '</div>' + + '<div id="third" class="item">' + + '<img alt="">' + + '</div>' + + '</div>' + + '</div>' + var $template = $(templateHTML).bootstrapCarousel() + + $.each(['mouseover', 'mouseout'], function (i, type) { + assert.strictEqual(type in $._data($template[0], 'events'), !isMobile, 'does' + (isMobile ? ' not' : '') + ' listen for ' + type + ' events') + }) + }) + + 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="item active" id="one">' + + '<div class="carousel-caption"/>' + + '</div>' + + '<div class="item" id="two">' + + '<div class="carousel-caption"/>' + + '</div>' + + '<div class="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('.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="item active" id="one">' + + '<div class="carousel-caption"/>' + + '</div>' + + '<div class="item" id="two">' + + '<div class="carousel-caption"/>' + + '</div>' + + '<div class="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('.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="item active" id="one">' + + '<div class="carousel-caption"/>' + + '</div>' + + '<div class="item" id="two">' + + '<div class="carousel-caption"/>' + + '</div>' + + '<div class="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('.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="item active" id="one">' + + '<div class="carousel-caption"/>' + + '</div>' + + '<div class="item" id="two">' + + '<div class="carousel-caption"/>' + + '</div>' + + '<div class="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('.item.active').attr('id'), 'one', 'carousel did not wrap around and stayed on 1st slide') + }) +}) diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit/collapse.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit/collapse.js new file mode 100644 index 000000000..5073bf109 --- /dev/null +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit/collapse.js @@ -0,0 +1,443 @@ +$(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.test('should provide no conflict', function (assert) { + assert.expect(1) + assert.strictEqual($.fn.collapse, undefined, 'collapse 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 $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 $el = $('<div class="collapse"/>').bootstrapCollapse('show') + + assert.ok($el.hasClass('in'), 'has class "in"') + assert.ok(!/height/i.test($el.attr('style')), 'has height reset') + }) + + QUnit.test('should hide a collapsed element', function (assert) { + assert.expect(1) + var $el = $('<div class="collapse"/>').bootstrapCollapse('hide') + + assert.ok(!$el.hasClass('in'), 'does not have class "in"') + }) + + 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 remove "collapsed" class from target when collapse is shown', function (assert) { + assert.expect(1) + var done = assert.async() + + var $target = $('<a 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 data-toggle="collapse" href="#test1"/>').appendTo('#qunit-fixture') + + $('<div id="test1" class="in"/>') + .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 data-toggle="collapse" class="collapsed" href="#test1"/>').appendTo('#qunit-fixture') + var $alt = $('<a 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 data-toggle="collapse" href="#test1"/>').appendTo('#qunit-fixture') + var $alt = $('<a data-toggle="collapse" href="#test1"/>').appendTo('#qunit-fixture') + + $('<div id="test1" class="in"/>') + .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="in"/>') + .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 in"></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 class="panel-group" id="accordion">' + + '<div class="panel"/>' + + '<div class="panel"/>' + + '<div class="panel"/>' + + '</div>' + var $groups = $(accordionHTML).appendTo('#qunit-fixture').find('.panel') + + var $target1 = $('<a data-toggle="collapse" href="#body1" data-parent="#accordion"/>').appendTo($groups.eq(0)) + + $('<div id="body1" class="in"/>').appendTo($groups.eq(0)) + + var $target2 = $('<a class="collapsed" data-toggle="collapse" href="#body2" data-parent="#accordion"/>').appendTo($groups.eq(1)) + + $('<div id="body2"/>').appendTo($groups.eq(1)) + + var $target3 = $('<a class="collapsed" data-toggle="collapse" href="#body3" data-parent="#accordion"/>').appendTo($groups.eq(2)) + + $('<div id="body3"/>') + .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="panel-group accordion">' + + '<div class="panel"/>' + + '<div class="panel"/>' + + '<div class="panel"/>' + + '</div>' + var $groups = $(accordionHTML).appendTo('#qunit-fixture').find('.panel') + + var $target1 = $('<a data-toggle="collapse" href="#body1" data-parent=".accordion"/>').appendTo($groups.eq(0)) + + $('<div id="body1" class="in"/>').appendTo($groups.eq(0)) + + var $target2 = $('<a class="collapsed" data-toggle="collapse" href="#body2" data-parent=".accordion"/>').appendTo($groups.eq(1)) + + $('<div id="body2"/>').appendTo($groups.eq(1)) + + var $target3 = $('<a class="collapsed" data-toggle="collapse" href="#body3" data-parent=".accordion"/>').appendTo($groups.eq(2)) + + $('<div id="body3"/>') + .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 target when collapse is shown', function (assert) { + assert.expect(1) + var done = assert.async() + + var $target = $('<a 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 target when collapse is hidden', function (assert) { + assert.expect(1) + var done = assert.async() + + var $target = $('<a data-toggle="collapse" href="#test1" aria-expanded="true"/>').appendTo('#qunit-fixture') + + $('<div id="test1" class="in"/>') + .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 data-toggle="collapse" class="collapsed" href="#test1" aria-expanded="false"/>').appendTo('#qunit-fixture') + var $alt = $('<a 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"') + assert.strictEqual($alt.attr('aria-expanded'), 'true', 'aria-expanded on alt 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 data-toggle="collapse" href="#test1" aria-expanded="true"/>').appendTo('#qunit-fixture') + var $alt = $('<a data-toggle="collapse" href="#test1" aria-expanded="true"/>').appendTo('#qunit-fixture') + + $('<div id="test1" class="in"/>') + .appendTo('#qunit-fixture') + .on('hidden.bs.collapse', function () { + assert.strictEqual($target.attr('aria-expanded'), 'false', 'aria-expanded on target is "false"') + assert.strictEqual($alt.attr('aria-expanded'), 'false', 'aria-expanded on alt is "false"') + done() + }) + + $target.trigger('click') + }) + + QUnit.test('should change aria-expanded from active accordion target to "false" and set the newly active one to "true"', function (assert) { + assert.expect(3) + var done = assert.async() + + var accordionHTML = '<div class="panel-group" id="accordion">' + + '<div class="panel"/>' + + '<div class="panel"/>' + + '<div class="panel"/>' + + '</div>' + var $groups = $(accordionHTML).appendTo('#qunit-fixture').find('.panel') + + var $target1 = $('<a data-toggle="collapse" href="#body1" data-parent="#accordion"/>').appendTo($groups.eq(0)) + + $('<div id="body1" aria-expanded="true" class="in"/>').appendTo($groups.eq(0)) + + var $target2 = $('<a class="collapsed" data-toggle="collapse" href="#body2" data-parent="#accordion"/>').appendTo($groups.eq(1)) + + $('<div id="body2" aria-expanded="false"/>').appendTo($groups.eq(1)) + + var $target3 = $('<a class="collapsed" data-toggle="collapse" href="#body3" data-parent="#accordion"/>').appendTo($groups.eq(2)) + + $('<div id="body3" aria-expanded="false"/>') + .appendTo($groups.eq(2)) + .on('shown.bs.collapse', function () { + assert.strictEqual($target1.attr('aria-expanded'), 'false', 'inactive target 1 has aria-expanded="false"') + assert.strictEqual($target2.attr('aria-expanded'), 'false', 'inactive target 2 has aria-expanded="false"') + assert.strictEqual($target3.attr('aria-expanded'), 'true', 'active target 3 has aria-expanded="false"') + + 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="panel"/>' + + '<div class="panel"/>' + + '</div>' + var showFired = false + var $groups = $(accordionHTML).appendTo('#qunit-fixture').find('.panel') + + var $target1 = $('<a data-toggle="collapse" href="#body1" data-parent="#accordion"/>').appendTo($groups.eq(0)) + + $('<div id="body1" class="collapse"/>') + .appendTo($groups.eq(0)) + .on('show.bs.collapse', function () { + showFired = true + }) + + var $target2 = $('<a data-toggle="collapse" href="#body2" data-parent="#accordion"/>').appendTo($groups.eq(1)) + var $body2 = $('<div id="body2" class="collapse"/>').appendTo($groups.eq(1)) + + $target2.trigger('click') + + $body2 + .toggleClass('in collapsing') + .data('bs.collapse').transitioning = 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 data-toggle="collapse" href="#test1"/>').appendTo('#qunit-fixture') + + $('<div id="test1" class="in"/>') + .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 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') + }) + +}) diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit/dropdown.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit/dropdown.js new file mode 100644 index 000000000..40c428682 --- /dev/null +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit/dropdown.js @@ -0,0 +1,353 @@ +$(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.test('should provide no conflict', function (assert) { + assert.expect(1) + assert.strictEqual($.fn.dropdown, undefined, 'dropdown 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 $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 dropdownHTML = '<ul class="tabs">' + + '<li class="dropdown">' + + '<button disabled href="#" class="btn dropdown-toggle" data-toggle="dropdown">Dropdown</button>' + + '<ul class="dropdown-menu">' + + '<li><a href="#">Secondary link</a></li>' + + '<li><a href="#">Something else here</a></li>' + + '<li class="divider"/>' + + '<li><a href="#">Another link</a></li>' + + '</ul>' + + '</li>' + + '</ul>' + var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().trigger('click') + + assert.ok(!$dropdown.parent('.dropdown').hasClass('open'), '"open" class added on click') + }) + + QUnit.test('should set aria-expanded="true" on target when dropdown menu is shown', function (assert) { + assert.expect(1) + var dropdownHTML = '<ul class="tabs">' + + '<li class="dropdown">' + + '<a href="#" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false">Dropdown</a>' + + '<ul class="dropdown-menu">' + + '<li><a href="#">Secondary link</a></li>' + + '<li><a href="#">Something else here</a></li>' + + '<li class="divider"/>' + + '<li><a href="#">Another link</a></li>' + + '</ul>' + + '</li>' + + '</ul>' + var $dropdown = $(dropdownHTML) + .find('[data-toggle="dropdown"]') + .bootstrapDropdown() + .trigger('click') + + assert.strictEqual($dropdown.attr('aria-expanded'), 'true', 'aria-expanded is set to string "true" on 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 = '<ul class="tabs">' + + '<li class="dropdown">' + + '<a href="#" class="dropdown-toggle" aria-expanded="false" data-toggle="dropdown">Dropdown</a>' + + '<ul class="dropdown-menu">' + + '<li><a href="#">Secondary link</a></li>' + + '<li><a href="#">Something else here</a></li>' + + '<li class="divider"/>' + + '<li><a href="#">Another link</a></li>' + + '</ul>' + + '</li>' + + '</ul>' + 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 dropdownHTML = '<ul class="tabs">' + + '<li class="dropdown">' + + '<button href="#" class="btn dropdown-toggle disabled" data-toggle="dropdown">Dropdown</button>' + + '<ul class="dropdown-menu">' + + '<li><a href="#">Secondary link</a></li>' + + '<li><a href="#">Something else here</a></li>' + + '<li class="divider"/>' + + '<li><a href="#">Another link</a></li>' + + '</ul>' + + '</li>' + + '</ul>' + var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().trigger('click') + + assert.ok(!$dropdown.parent('.dropdown').hasClass('open'), '"open" class added on click') + }) + + QUnit.test('should add class open to menu if clicked', function (assert) { + assert.expect(1) + var dropdownHTML = '<ul class="tabs">' + + '<li class="dropdown">' + + '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>' + + '<ul class="dropdown-menu">' + + '<li><a href="#">Secondary link</a></li>' + + '<li><a href="#">Something else here</a></li>' + + '<li class="divider"/>' + + '<li><a href="#">Another link</a></li>' + + '</ul>' + + '</li>' + + '</ul>' + var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().trigger('click') + + assert.ok($dropdown.parent('.dropdown').hasClass('open'), '"open" class added on click') + }) + + QUnit.test('should test if element has a # before assuming it\'s a selector', function (assert) { + assert.expect(1) + var dropdownHTML = '<ul class="tabs">' + + '<li class="dropdown">' + + '<a href="/foo/" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>' + + '<ul class="dropdown-menu">' + + '<li><a href="#">Secondary link</a></li>' + + '<li><a href="#">Something else here</a></li>' + + '<li class="divider"/>' + + '<li><a href="#">Another link</a></li>' + + '</ul>' + + '</li>' + + '</ul>' + var $dropdown = $(dropdownHTML).find('[data-toggle="dropdown"]').bootstrapDropdown().trigger('click') + + assert.ok($dropdown.parent('.dropdown').hasClass('open'), '"open" class added on click') + }) + + + QUnit.test('should remove "open" class if body is clicked', function (assert) { + assert.expect(2) + var dropdownHTML = '<ul class="tabs">' + + '<li class="dropdown">' + + '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>' + + '<ul class="dropdown-menu">' + + '<li><a href="#">Secondary link</a></li>' + + '<li><a href="#">Something else here</a></li>' + + '<li class="divider"/>' + + '<li><a href="#">Another link</a></li>' + + '</ul>' + + '</li>' + + '</ul>' + var $dropdown = $(dropdownHTML) + .appendTo('#qunit-fixture') + .find('[data-toggle="dropdown"]') + .bootstrapDropdown() + .trigger('click') + + assert.ok($dropdown.parent('.dropdown').hasClass('open'), '"open" class added on click') + $(document.body).trigger('click') + assert.ok(!$dropdown.parent('.dropdown').hasClass('open'), '"open" class removed') + }) + + QUnit.test('should remove "open" class if body is clicked, with multiple dropdowns', function (assert) { + assert.expect(7) + var dropdownHTML = '<ul class="nav">' + + '<li><a href="#menu1">Menu 1</a></li>' + + '<li class="dropdown" id="testmenu">' + + '<a class="dropdown-toggle" data-toggle="dropdown" href="#testmenu">Test menu <span class="caret"/></a>' + + '<ul class="dropdown-menu" role="menu">' + + '<li><a href="#sub1">Submenu 1</a></li>' + + '</ul>' + + '</li>' + + '</ul>' + + '<div class="btn-group">' + + '<button class="btn">Actions</button>' + + '<button class="btn dropdown-toggle" data-toggle="dropdown"><span class="caret"/></button>' + + '<ul class="dropdown-menu">' + + '<li><a href="#">Action 1</a></li>' + + '</ul>' + + '</div>' + var $dropdowns = $(dropdownHTML).appendTo('#qunit-fixture').find('[data-toggle="dropdown"]') + var $first = $dropdowns.first() + var $last = $dropdowns.last() + + assert.strictEqual($dropdowns.length, 2, 'two dropdowns') + + $first.trigger('click') + assert.strictEqual($first.parents('.open').length, 1, '"open" class added on click') + assert.strictEqual($('#qunit-fixture .open').length, 1, 'only one dropdown is open') + $(document.body).trigger('click') + assert.strictEqual($('#qunit-fixture .open').length, 0, '"open" class removed') + + $last.trigger('click') + assert.strictEqual($last.parent('.open').length, 1, '"open" class added on click') + assert.strictEqual($('#qunit-fixture .open').length, 1, 'only one dropdown is open') + $(document.body).trigger('click') + assert.strictEqual($('#qunit-fixture .open').length, 0, '"open" class removed') + }) + + QUnit.test('should fire show and hide event', function (assert) { + assert.expect(2) + var dropdownHTML = '<ul class="tabs">' + + '<li class="dropdown">' + + '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>' + + '<ul class="dropdown-menu">' + + '<li><a href="#">Secondary link</a></li>' + + '<li><a href="#">Something else here</a></li>' + + '<li class="divider"/>' + + '<li><a href="#">Another link</a></li>' + + '</ul>' + + '</li>' + + '</ul>' + 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 = '<ul class="tabs">' + + '<li class="dropdown">' + + '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>' + + '<ul class="dropdown-menu">' + + '<li><a href="#">Secondary link</a></li>' + + '<li><a href="#">Something else here</a></li>' + + '<li class="divider"/>' + + '<li><a href="#">Another link</a></li>' + + '</ul>' + + '</li>' + + '</ul>' + 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 ignore keyboard events within <input>s and <textarea>s', function (assert) { + assert.expect(3) + var done = assert.async() + + var dropdownHTML = '<ul class="tabs">' + + '<li class="dropdown">' + + '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>' + + '<ul class="dropdown-menu" role="menu">' + + '<li><a href="#">Secondary link</a></li>' + + '<li><a href="#">Something else here</a></li>' + + '<li class="divider"/>' + + '<li><a href="#">Another link</a></li>' + + '<li><input type="text" id="input"></li>' + + '<li><textarea id="textarea"/></li>' + + '</ul>' + + '</li>' + + '</ul>' + 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(1) + var dropdownHTML = '<ul class="tabs">' + + '<li class="dropdown">' + + '<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown</a>' + + '<ul class="dropdown-menu" role="menu">' + + '<li class="disabled"><a href="#">Disabled link</a></li>' + + '<li><a href="#">Another link</a></li>' + + '</ul>' + + '</li>' + + '</ul>' + var $dropdown = $(dropdownHTML) + .appendTo('#qunit-fixture') + .find('[data-toggle="dropdown"]') + .bootstrapDropdown() + .trigger('click') + + $dropdown.trigger($.Event('keydown', { which: 40 })) + $dropdown.trigger($.Event('keydown', { which: 40 })) + + assert.ok(!$(document.activeElement).parent().is('.disabled'), '.disabled is not focused') + }) +}) diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit/modal.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit/modal.js new file mode 100644 index 000000000..c6e747a3c --- /dev/null +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit/modal.js @@ -0,0 +1,405 @@ +$(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', { + 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 () { + $.fn.modal = $.fn.bootstrapModal + delete $.fn.bootstrapModal + } + }) + + QUnit.test('should provide no conflict', function (assert) { + assert.expect(1) + assert.strictEqual($.fn.modal, undefined, 'modal was set back to undefined (orig value)') + }) + + 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.DEFAULTS, '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 set aria-hidden to false when show method is called', function (assert) { + assert.expect(1) + var done = assert.async() + + $('<div id="modal-test"/>') + .on('shown.bs.modal', function () { + assert.strictEqual($('#modal-test').attr('aria-hidden'), 'false', 'aria-hidden is set to string "false" when modal shown') + 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 set aria-hidden to true when hide is called', function (assert) { + assert.expect(2) + var done = assert.async() + + $('<div id="modal-test"/>') + .on('shown.bs.modal', function () { + assert.strictEqual($('#modal-test').length, 1, 'modal has been inserted into the dom') + $(this).bootstrapModal('hide') + }) + .on('hidden.bs.modal', function () { + assert.strictEqual($('#modal-test').attr('aria-hidden'), 'true', 'aria-hidden is set to string "true" when modal shown') + 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 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 insterted 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($('#modal-test').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 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 restore inline body padding after closing', function (assert) { + assert.expect(2) + var done = assert.async() + var originalBodyPad = 0 + var $body = $(document.body) + + $body.css('padding-right', originalBodyPad) + + $('<div id="modal-test"/>') + .on('hidden.bs.modal', function () { + var currentBodyPad = parseInt($body.css('padding-right'), 10) + assert.notStrictEqual($body.attr('style'), '', 'body has non-empty style attribute') + assert.strictEqual(currentBodyPad, originalBodyPad, 'original body padding was not changed') + $body.removeAttr('style') + done() + }) + .on('shown.bs.modal', function () { + $(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.ok(!$body.attr('style'), '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') + }) +}) diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit/phantom.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit/phantom.js new file mode 100644 index 000000000..f6f0ac00f --- /dev/null +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit/phantom.js @@ -0,0 +1,72 @@ +/* + * grunt-contrib-qunit + * http://gruntjs.com/ + * + * Copyright (c) 2014 "Cowboy" Ben Alman, contributors + * Licensed under the MIT license. + */ + +(function () { + 'use strict'; + + // Don't re-order tests. + QUnit.config.reorder = false + // Run tests serially, not in parallel. + QUnit.config.autorun = false + + // Send messages to the parent PhantomJS process via alert! Good times!! + function sendMessage() { + var args = [].slice.call(arguments) + alert(JSON.stringify(args)) + } + + // These methods connect QUnit to PhantomJS. + QUnit.log(function (obj) { + // What is this I don’t even + if (obj.message === '[object Object], undefined:undefined') { return } + + // Parse some stuff before sending it. + var actual + var expected + if (!obj.result) { + // Dumping large objects can be very slow, and the dump isn't used for + // passing tests, so only dump if the test failed. + actual = QUnit.dump.parse(obj.actual) + expected = QUnit.dump.parse(obj.expected) + } + // Send it. + sendMessage('qunit.log', obj.result, actual, expected, obj.message, obj.source) + }) + + QUnit.testStart(function (obj) { + sendMessage('qunit.testStart', obj.name) + }) + + QUnit.testDone(function (obj) { + sendMessage('qunit.testDone', obj.name, obj.failed, obj.passed, obj.total, obj.duration) + }) + + QUnit.moduleStart(function (obj) { + sendMessage('qunit.moduleStart', obj.name) + }) + + QUnit.moduleDone(function (obj) { + if (obj.failed === 0) { + console.log('\r\u2714 All tests passed in "' + obj.name + '" module') + } else { + console.log('\u2716 ' + obj.failed + ' tests failed in "' + obj.name + '" module') + } + sendMessage('qunit.moduleDone', obj.name, obj.failed, obj.passed, obj.total) + }) + + QUnit.begin(function () { + sendMessage('qunit.begin') + console.log('\n\nStarting test suite') + console.log('================================================\n') + }) + + QUnit.done(function (obj) { + sendMessage('qunit.done', obj.failed, obj.passed, obj.total, obj.runtime) + }) + +}()) diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit/popover.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit/popover.js new file mode 100644 index 000000000..fbabab9e3 --- /dev/null +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit/popover.js @@ -0,0 +1,262 @@ +$(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 + } + }) + + QUnit.test('should provide no conflict', function (assert) { + assert.expect(1) + assert.strictEqual($.fn.popover, undefined, 'popover 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 $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 $popover = $('<a href="#" title="mdo" data-content="https://twitter.com/mdo">@mdo</a>') + .appendTo('#qunit-fixture') + .bootstrapPopover('show') + + assert.notEqual($('.popover').length, 0, 'popover was inserted') + $popover.bootstrapPopover('hide') + assert.strictEqual($('.popover').length, 0, 'popover removed') + }) + + 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 $popover = $('<a href="#">@fat</a>') + .appendTo('#qunit-fixture') + .bootstrapPopover({ + title: function () { + return '@fat' + }, + content: function () { + return 'loves writing tests (╯°□°)╯︵ ┻━┻' + } + }) + + $popover.bootstrapPopover('show') + + assert.notEqual($('.popover').length, 0, 'popover was inserted') + assert.strictEqual($('.popover .popover-title').text(), '@fat', 'title correctly inserted') + assert.strictEqual($('.popover .popover-content').text(), 'loves writing tests (╯°□°)╯︵ ┻━┻', 'content correctly inserted') + + $popover.bootstrapPopover('hide') + assert.strictEqual($('.popover').length, 0, 'popover was removed') + }) + + QUnit.test('should not duplicate HTML object', function (assert) { + assert.expect(6) + var $div = $('<div/>').html('loves writing tests (╯°□°)╯︵ ┻━┻') + + var $popover = $('<a href="#">@fat</a>') + .appendTo('#qunit-fixture') + .bootstrapPopover({ + content: function () { + return $div + } + }) + + $popover.bootstrapPopover('show') + assert.notEqual($('.popover').length, 0, 'popover was inserted') + assert.equal($('.popover .popover-content').html(), $div, 'content correctly inserted') + + $popover.bootstrapPopover('hide') + assert.strictEqual($('.popover').length, 0, 'popover was removed') + + $popover.bootstrapPopover('show') + assert.notEqual($('.popover').length, 0, 'popover was inserted') + assert.equal($('.popover .popover-content').html(), $div, 'content correctly inserted') + + $popover.bootstrapPopover('hide') + assert.strictEqual($('.popover').length, 0, 'popover was removed') + }) + + QUnit.test('should get title and content from attributes', function (assert) { + assert.expect(4) + var $popover = $('<a href="#" title="@mdo" data-content="loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻" >@mdo</a>') + .appendTo('#qunit-fixture') + .bootstrapPopover() + .bootstrapPopover('show') + + assert.notEqual($('.popover').length, 0, 'popover was inserted') + assert.strictEqual($('.popover .popover-title').text(), '@mdo', 'title correctly inserted') + assert.strictEqual($('.popover .popover-content').text(), 'loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻', 'content correctly inserted') + + $popover.bootstrapPopover('hide') + assert.strictEqual($('.popover').length, 0, 'popover was removed') + }) + + + QUnit.test('should get title and content from attributes ignoring options passed via js', function (assert) { + assert.expect(4) + 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' + }) + .bootstrapPopover('show') + + assert.notEqual($('.popover').length, 0, 'popover was inserted') + assert.strictEqual($('.popover .popover-title').text(), '@mdo', 'title correctly inserted') + assert.strictEqual($('.popover .popover-content').text(), 'loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻', 'content correctly inserted') + + $popover.bootstrapPopover('hide') + assert.strictEqual($('.popover').length, 0, 'popover was removed') + }) + + QUnit.test('should respect custom template', function (assert) { + assert.expect(3) + 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>' + }) + + $popover.bootstrapPopover('show') + + assert.notEqual($('.popover').length, 0, 'popover was inserted') + assert.ok($('.popover').hasClass('foobar'), 'custom class is present') + + $popover.bootstrapPopover('hide') + assert.strictEqual($('.popover').length, 0, 'popover was removed') + }) + + 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('destroy') + + assert.ok(!$popover.hasClass('in'), '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 $div = $('<div><a href="#" title="mdo" data-content="http://twitter.com/mdo">@mdo</a></div>') + .appendTo('#qunit-fixture') + .bootstrapPopover({ + selector: 'a', + trigger: 'click' + }) + + $div.find('a').trigger('click') + assert.notEqual($('.popover').length, 0, 'popover was inserted') + + $div.find('a').trigger('click') + assert.strictEqual($('.popover').length, 0, 'popover was removed') + }) + + 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', + 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') + $div.bootstrapPopover('destroy') + assert.ok(handlerCalled, 'content\'s event handler still present') + done() + }) + .bootstrapPopover('show') + }) + .bootstrapPopover('hide') + }) + .bootstrapPopover('show') + }) + + QUnit.test('should throw an error when initializing popover on the document object without specifying a delegation selector', function (assert) { + assert.expect(1) + assert.throws(function () { + $(document).bootstrapPopover({ title: 'What am I on?', content: 'My selector is missing' }) + }, new Error('`selector` option must be specified when initializing popover on the window.document object!')) + }) + + 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($popover.data('bs.popover'), undefined, 'should not initialize the popover') + }) + +}) diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit/scrollspy.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit/scrollspy.js new file mode 100644 index 000000000..bf5fa0bff --- /dev/null +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit/scrollspy.js @@ -0,0 +1,278 @@ +$(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.test('should provide no conflict', function (assert) { + assert.expect(1) + assert.strictEqual($.fn.scrollspy, undefined, 'scrollspy 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 $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><a href="#masthead">Overview</a></li>' + + '<li><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.on('scroll.bs.scrollspy', 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="nav navbar-nav">' + + '<li class="active"><a id="one-link" href="#one">One</a></li>' + + '<li><a id="two-link" href="#two">Two</a></li>' + + '<li><a 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.on('scroll.bs.scrollspy', function () { + assert.ok(!$section.find('#one-link').parent().hasClass('active'), '"active" class removed from first section') + assert.ok($section.find('#two-link').parent().hasClass('active'), '"active" class on middle section') + assert.ok(!$section.find('#three-link').parent().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 id="li-1"><a href="#div-1">div 1</a></li>' + + '<li id="li-2"><a 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 testElementIsActiveAfterScroll = function (element, target) { + var deferred = $.Deferred() + var scrollHeight = Math.ceil($content.scrollTop() + $(target).position().top) + var done = assert.async() + $content.one('scroll', function () { + assert.ok($(element).hasClass('active'), 'target:' + target + ', element' + element) + done() + deferred.resolve() + }) + $content.scrollTop(scrollHeight) + return deferred.promise() + } + + $.when(testElementIsActiveAfterScroll('#li-1', '#div-1')) + .then(function () { return testElementIsActiveAfterScroll('#li-2', '#div-2') }) + }) + + 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 id="li-1"><a href="#div-1">div 1</a>' + + '<ul>' + + '<li id="li-2"><a 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($('#li-1').hasClass('active'), 'nav item for outer element has "active" class') + assert.ok($('#li-2').hasClass('active'), 'nav item for inner element has "active" class') + testActiveElements() + }) + + $content.scrollTop($content.scrollTop() + 10) + }() + }) + + 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="nav navbar-nav">' + + '<li class="active"><a id="one-link" href="#one">One</a></li>' + + '<li><a id="two-link" href="#two">Two</a></li>' + + '<li><a id="three-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.bs.scrollspy', function () { + assert.strictEqual($('.active').length, 1, '"active" class on only one element present') + assert.strictEqual($('.active').has('#two-link').length, 1, '"active" class on second section') + + $scrollspy + .one('scroll.bs.scrollspy', function () { + assert.strictEqual($('.active').length, 0, 'selection cleared') + done() + }) + .scrollTop(0) + }) + .scrollTop(201) + }) + + 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 id="li-100-1"><a href="#div-100-1">div 1</a></li>' + + '<li id="li-100-2"><a href="#div-100-2">div 2</a></li>' + + '<li id="li-100-3"><a href="#div-100-3">div 3</a></li>' + + '<li id="li-100-4"><a href="#div-100-4">div 4</a></li>' + + '<li id="li-100-5"><a 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) + var done = assert.async() + $content.one('scroll', function () { + assert.ok($(element).hasClass('active'), 'target:' + target + ', element: ' + element) + done() + deferred.resolve() + }) + $content.scrollTop(scrollHeight) + return deferred.promise() + } + + $.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') }) + }) + +}) diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit/tab.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit/tab.js new file mode 100644 index 000000000..85d9f67a2 --- /dev/null +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit/tab.js @@ -0,0 +1,216 @@ +$(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.test('should provide no conflict', function (assert) { + assert.expect(1) + assert.strictEqual($.fn.tab, undefined, 'tab 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 $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="tabs">' + + '<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 a').bootstrapTab('show') + assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'profile') + + $(tabsHTML).find('li:first 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="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 a').bootstrapTab('show') + assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'profile') + + $(pillsHTML).find('li:first a').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="tab"/>') + .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('show and shown events should reference correct relatedTarget', function (assert) { + assert.expect(2) + var done = assert.async() + + var dropHTML = '<ul class="drop">' + + '<li class="dropdown"><a data-toggle="dropdown" href="#">1</a>' + + '<ul class="dropdown-menu">' + + '<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 a') + .bootstrapTab('show') + .end() + .find('ul > li:last 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="tabs">' + + '<li><a href="#home">Home</a></li>' + + '<li><a href="#profile">Profile</a></li>' + + '</ul>' + + $(tabsHTML) + .find('li:first a') + .on('hide.bs.tab', function () { + assert.ok(true, 'hide event fired') + }) + .bootstrapTab('show') + .end() + .find('li:last a') + .bootstrapTab('show') + + $(tabsHTML) + .find('li:first a') + .on('hidden.bs.tab', function () { + assert.ok(true, 'hidden event fired') + done() + }) + .bootstrapTab('show') + .end() + .find('li:last 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="tabs">' + + '<li><a href="#home">Home</a></li>' + + '<li><a href="#profile">Profile</a></li>' + + '</ul>' + + $(tabsHTML) + .find('li:first 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 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="tabs">' + + '<li><a href="#home">Home</a></li>' + + '<li><a href="#profile">Profile</a></li>' + + '</ul>' + + $(tabsHTML) + .find('li:first 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 a') + .bootstrapTab('show') + }) + + QUnit.test('selected tab should have aria-expanded', function (assert) { + assert.expect(8) + var tabsHTML = '<ul class="nav nav-tabs">' + + '<li class="active"><a href="#home" toggle="tab" aria-expanded="true">Home</a></li>' + + '<li><a href="#profile" toggle="tab" aria-expanded="false">Profile</a></li>' + + '</ul>' + var $tabs = $(tabsHTML).appendTo('#qunit-fixture') + + $tabs.find('li:first a').bootstrapTab('show') + assert.strictEqual($tabs.find('.active a').attr('aria-expanded'), 'true', 'shown tab has aria-expanded = true') + assert.strictEqual($tabs.find('li:not(.active) a').attr('aria-expanded'), 'false', 'hidden tab has aria-expanded = false') + + $tabs.find('li:last a').trigger('click') + assert.strictEqual($tabs.find('.active a').attr('aria-expanded'), 'true', 'after click, shown tab has aria-expanded = true') + assert.strictEqual($tabs.find('li:not(.active) a').attr('aria-expanded'), 'false', 'after click, hidden tab has aria-expanded = false') + + $tabs.find('li:first a').bootstrapTab('show') + assert.strictEqual($tabs.find('.active a').attr('aria-expanded'), 'true', 'shown tab has aria-expanded = true') + assert.strictEqual($tabs.find('li:not(.active) a').attr('aria-expanded'), 'false', 'hidden tab has aria-expanded = false') + + $tabs.find('li:first a').trigger('click') + assert.strictEqual($tabs.find('.active a').attr('aria-expanded'), 'true', 'after second show event, shown tab still has aria-expanded = true') + assert.strictEqual($tabs.find('li:not(.active) a').attr('aria-expanded'), 'false', 'after second show event, hidden tab has aria-expanded = false') + }) + +}) diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit/tooltip.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit/tooltip.js new file mode 100644 index 000000000..57a59db18 --- /dev/null +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/CSS/bootstrap/js/tests/unit/tooltip.js @@ -0,0 +1,1183 @@ +$(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 + } + }) + + QUnit.test('should provide no conflict', function (assert) { + assert.expect(1) + assert.strictEqual($.fn.tooltip, undefined, 'tooltip 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 $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.DEFAULTS, '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 $trigger = $('<a href="#" rel="tooltip" title="Another tooltip"/>') + .bootstrapTooltip() + .appendTo('#qunit-fixture') + + $trigger.bootstrapTooltip('show') + assert.ok($trigger[0].hasAttribute('aria-describedby'), 'trigger has aria-describedby') + + $trigger.bootstrapTooltip('hide') + assert.ok(!$trigger[0].hasAttribute('aria-describedby'), 'trigger does not have aria-describedby') + }) + + 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 $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>') + .appendTo('#qunit-fixture') + .bootstrapTooltip({ placement: 'bottom' }) + + $tooltip.bootstrapTooltip('show') + assert.ok($('.tooltip').is('.fade.bottom.in'), 'has correct classes applied') + + $tooltip.bootstrapTooltip('hide') + assert.strictEqual($('.tooltip').length, 0, 'tooltip removed') + }) + + QUnit.test('should allow html entities', function (assert) { + assert.expect(2) + var $tooltip = $('<a href="#" rel="tooltip" title="<b>@fat</b>"/>') + .appendTo('#qunit-fixture') + .bootstrapTooltip({ html: true }) + + $tooltip.bootstrapTooltip('show') + assert.notEqual($('.tooltip b').length, 0, 'b tag was inserted') + + $tooltip.bootstrapTooltip('hide') + assert.strictEqual($('.tooltip').length, 0, 'tooltip removed') + }) + + QUnit.test('should respect custom classes', function (assert) { + assert.expect(2) + 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.bootstrapTooltip('show') + assert.ok($('.tooltip').hasClass('some-class'), 'custom class is present') + + $tooltip.bootstrapTooltip('hide') + assert.strictEqual($('.tooltip').length, 0, 'tooltip removed') + }) + + 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 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 () {}) + + 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('destroy') + + assert.ok(!$tooltip.hasClass('in'), '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($('.tooltip').length, 0, 'tooltip was removed from dom') + }) + + 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.in'), 'tooltip is faded in') + }) + + 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.in'), 'tooltip was faded out') + }) + + QUnit.test('should place tooltips inside body when container is body', function (assert) { + assert.expect(3) + var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>') + .appendTo('#qunit-fixture') + .bootstrapTooltip({ container: 'body' }) + .bootstrapTooltip('show') + + 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') + assert.strictEqual($('body > .tooltip').length, 0, 'tooltip was removed from dom') + }) + + QUnit.test('should add position class before positioning so that position-specific styles are taken into account', function (assert) { + assert.expect(1) + var styles = '<style>' + + '.tooltip.right { white-space: nowrap; }' + + '.tooltip.right .tooltip-inner { max-width: none; }' + + '</style>' + var $styles = $(styles).appendTo('head') + + var $container = $('<div/>').appendTo('#qunit-fixture') + var $target = $('<a href="#" rel="tooltip" title="very very very very very very very very long tooltip in one line"/>') + .appendTo($container) + .bootstrapTooltip({ + placement: 'right', + viewport: null + }) + .bootstrapTooltip('show') + var $tooltip = $container.find('.tooltip') + + // this is some dumb hack shit because sub pixels in firefox + var top = Math.round($target.offset().top + ($target[0].offsetHeight / 2) - ($tooltip[0].offsetHeight / 2)) + var top2 = Math.round($tooltip.offset().top) + var topDiff = top - top2 + assert.ok(topDiff <= 1 && topDiff >= -1) + $target.bootstrapTooltip('hide') + + $container.remove() + $styles.remove() + }) + + QUnit.test('should use title attribute for tooltip text', function (assert) { + assert.expect(2) + var $tooltip = $('<a href="#" rel="tooltip" title="Simple tooltip"/>') + .appendTo('#qunit-fixture') + .bootstrapTooltip() + + $tooltip.bootstrapTooltip('show') + assert.strictEqual($('.tooltip').children('.tooltip-inner').text(), 'Simple tooltip', 'title from title attribute is set') + + $tooltip.bootstrapTooltip('hide') + assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom') + }) + + QUnit.test('should prefer title attribute over title option', function (assert) { + assert.expect(2) + var $tooltip = $('<a href="#" rel="tooltip" title="Simple tooltip"/>') + .appendTo('#qunit-fixture') + .bootstrapTooltip({ + title: 'This is a tooltip with some content' + }) + + $tooltip.bootstrapTooltip('show') + assert.strictEqual($('.tooltip').children('.tooltip-inner').text(), 'Simple tooltip', 'title is set from title attribute while preferred over title option') + + $tooltip.bootstrapTooltip('hide') + assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom') + }) + + QUnit.test('should use title option', function (assert) { + assert.expect(2) + var $tooltip = $('<a href="#" rel="tooltip"/>') + .appendTo('#qunit-fixture') + .bootstrapTooltip({ + title: 'This is a tooltip with some content' + }) + + $tooltip.bootstrapTooltip('show') + assert.strictEqual($('.tooltip').children('.tooltip-inner').text(), 'This is a tooltip with some content', 'title from title option is set') + + $tooltip.bootstrapTooltip('hide') + assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom') + }) + + QUnit.test('should be placed dynamically with the dynamic placement option', function (assert) { + assert.expect(6) + var $style = $('<style> a[rel="tooltip"] { display: inline-block; position: absolute; } </style>') + var $container = $('<div/>') + .css({ + position: 'absolute', + overflow: 'hidden', + width: 600, + height: 400, + top: 0, + left: 0 + }) + .appendTo(document.body) + + var $topTooltip = $('<div style="left: 0; top: 0;" rel="tooltip" title="Top tooltip">Top Dynamic Tooltip</div>') + .appendTo($container) + .bootstrapTooltip({ placement: 'auto' }) + + $topTooltip.bootstrapTooltip('show') + assert.ok($('.tooltip').is('.bottom'), 'top positioned tooltip is dynamically positioned to bottom') + + $topTooltip.bootstrapTooltip('hide') + assert.strictEqual($('.tooltip').length, 0, 'top positioned tooltip removed from dom') + + var $rightTooltip = $('<div style="right: 0;" rel="tooltip" title="Right tooltip">Right Dynamic Tooltip</div>') + .appendTo($container) + .bootstrapTooltip({ placement: 'right auto' }) + + $rightTooltip.bootstrapTooltip('show') + assert.ok($('.tooltip').is('.left'), 'right positioned tooltip is dynamically positioned left') + + $rightTooltip.bootstrapTooltip('hide') + assert.strictEqual($('.tooltip').length, 0, 'right positioned tooltip removed from dom') + + var $leftTooltip = $('<div style="left: 0;" rel="tooltip" title="Left tooltip">Left Dynamic Tooltip</div>') + .appendTo($container) + .bootstrapTooltip({ placement: 'auto left' }) + + $leftTooltip.bootstrapTooltip('show') + assert.ok($('.tooltip').is('.right'), 'left positioned tooltip is dynamically positioned right') + + $leftTooltip.bootstrapTooltip('hide') + assert.strictEqual($('.tooltip').length, 0, 'left positioned tooltip removed from dom') + + $container.remove() + $style.remove() + }) + + QUnit.test('should position tip on top if viewport has enough space and placement is "auto top"', function (assert) { + assert.expect(2) + var styles = '<style>' + + 'body { padding-top: 100px; }' + + '#section { height: 300px; border: 1px solid red; padding-top: 50px }' + + 'div[rel="tooltip"] { width: 150px; border: 1px solid blue; }' + + '</style>' + var $styles = $(styles).appendTo('head') + + var $container = $('<div id="section"/>').appendTo('#qunit-fixture') + var $target = $('<div rel="tooltip" title="tip"/>') + .appendTo($container) + .bootstrapTooltip({ + placement: 'auto top', + viewport: '#section' + }) + + $target.bootstrapTooltip('show') + assert.ok($('.tooltip').is('.top'), 'top positioned tooltip is dynamically positioned to top') + + $target.bootstrapTooltip('hide') + assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom') + + $styles.remove() + }) + + QUnit.test('should position tip on bottom if the tip\'s dimension exceeds the viewport area and placement is "auto top"', function (assert) { + assert.expect(2) + var styles = '<style>' + + 'body { padding-top: 100px; }' + + '#section { height: 300px; border: 1px solid red; }' + + 'div[rel="tooltip"] { width: 150px; border: 1px solid blue; }' + + '</style>' + var $styles = $(styles).appendTo('head') + + var $container = $('<div id="section"/>').appendTo('#qunit-fixture') + var $target = $('<div rel="tooltip" title="tip"/>') + .appendTo($container) + .bootstrapTooltip({ + placement: 'auto top', + viewport: '#section' + }) + + $target.bootstrapTooltip('show') + assert.ok($('.tooltip').is('.bottom'), 'top positioned tooltip is dynamically positioned to bottom') + + $target.bootstrapTooltip('hide') + assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom') + + $styles.remove() + }) + + QUnit.test('should display the tip on top whenever scrollable viewport has enough room if the given placement is "auto top"', function (assert) { + assert.expect(2) + var styles = '<style>' + + '#scrollable-div { height: 200px; overflow: auto; }' + + '.tooltip-item { margin: 200px 0 400px; width: 150px; }' + + '</style>' + var $styles = $(styles).appendTo('head') + + var $container = $('<div id="scrollable-div"/>').appendTo('#qunit-fixture') + var $target = $('<div rel="tooltip" title="tip" class="tooltip-item">Tooltip Item</div>') + .appendTo($container) + .bootstrapTooltip({ + placement: 'top auto', + viewport: '#scrollable-div' + }) + + $('#scrollable-div').scrollTop(100) + + $target.bootstrapTooltip('show') + assert.ok($('.tooltip').is('.fade.top.in'), 'has correct classes applied') + + $target.bootstrapTooltip('hide') + assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom') + + $styles.remove() + }) + + QUnit.test('should display the tip on bottom whenever scrollable viewport doesn\'t have enough room if the given placement is "auto top"', function (assert) { + assert.expect(2) + var styles = '<style>' + + '#scrollable-div { height: 200px; overflow: auto; }' + + '.tooltip-item { padding: 200px 0 400px; width: 150px; }' + + '</style>' + var $styles = $(styles).appendTo('head') + + var $container = $('<div id="scrollable-div"/>').appendTo('#qunit-fixture') + var $target = $('<div rel="tooltip" title="tip" class="tooltip-item">Tooltip Item</div>') + .appendTo($container) + .bootstrapTooltip({ + placement: 'top auto', + viewport: '#scrollable-div' + }) + + $('#scrollable-div').scrollTop(200) + + $target.bootstrapTooltip('show') + assert.ok($('.tooltip').is('.fade.bottom.in'), 'has correct classes applied') + + $target.bootstrapTooltip('hide') + assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom') + + $styles.remove() + }) + + QUnit.test('should display the tip on bottom whenever scrollable viewport has enough room if the given placement is "auto bottom"', function (assert) { + assert.expect(2) + var styles = '<style>' + + '#scrollable-div { height: 200px; overflow: auto; }' + + '.spacer { height: 400px; }' + + '.spacer:first-child { height: 200px; }' + + '.tooltip-item { width: 150px; }' + + '</style>' + var $styles = $(styles).appendTo('head') + + var $container = $('<div id="scrollable-div"/>').appendTo('#qunit-fixture') + var $target = $('<div rel="tooltip" title="tip" class="tooltip-item">Tooltip Item</div>') + .appendTo($container) + .before('<div class="spacer"/>') + .after('<div class="spacer"/>') + .bootstrapTooltip({ + placement: 'bottom auto', + viewport: '#scrollable-div' + }) + + $('#scrollable-div').scrollTop(200) + + $target.bootstrapTooltip('show') + assert.ok($('.tooltip').is('.fade.bottom.in'), 'has correct classes applied') + + $target.bootstrapTooltip('hide') + assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom') + + $styles.remove() + }) + + QUnit.test('should display the tip on top whenever scrollable viewport doesn\'t have enough room if the given placement is "auto bottom"', function (assert) { + assert.expect(2) + var styles = '<style>' + + '#scrollable-div { height: 200px; overflow: auto; }' + + '.tooltip-item { margin-top: 400px; width: 150px; }' + + '</style>' + var $styles = $(styles).appendTo('head') + + var $container = $('<div id="scrollable-div"/>').appendTo('#qunit-fixture') + var $target = $('<div rel="tooltip" title="tip" class="tooltip-item">Tooltip Item</div>') + .appendTo($container) + .bootstrapTooltip({ + placement: 'bottom auto', + viewport: '#scrollable-div' + }) + + $('#scrollable-div').scrollTop(400) + + $target.bootstrapTooltip('show') + assert.ok($('.tooltip').is('.fade.top.in'), 'has correct classes applied') + + $target.bootstrapTooltip('hide') + assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom') + + $styles.remove() + }) + + QUnit.test('should adjust the tip\'s top position when up against the top of the viewport', function (assert) { + assert.expect(2) + var styles = '<style>' + + '.tooltip .tooltip-inner { width: 200px; height: 200px; max-width: none; }' + + 'a[rel="tooltip"] { position: fixed; }' + + '</style>' + var $styles = $(styles).appendTo('head') + + var $container = $('<div/>').appendTo('#qunit-fixture') + var $target = $('<a href="#" rel="tooltip" title="tip" style="top: 0px; left: 0px;"/>') + .appendTo($container) + .bootstrapTooltip({ + placement: 'right', + viewport: { + selector: 'body', + padding: 12 + } + }) + + $target.bootstrapTooltip('show') + assert.strictEqual(Math.round($container.find('.tooltip').offset().top), 12) + + $target.bootstrapTooltip('hide') + assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom') + + $styles.remove() + }) + + QUnit.test('should adjust the tip\'s top position when up against the bottom of the viewport', function (assert) { + assert.expect(2) + var styles = '<style>' + + '.tooltip .tooltip-inner { width: 200px; height: 200px; max-width: none; }' + + 'a[rel="tooltip"] { position: fixed; }' + + '</style>' + var $styles = $(styles).appendTo('head') + + var $container = $('<div/>').appendTo('#qunit-fixture') + var $target = $('<a href="#" rel="tooltip" title="tip" style="bottom: 0px; left: 0px;"/>') + .appendTo($container) + .bootstrapTooltip({ + placement: 'right', + viewport: { + selector: 'body', + padding: 12 + } + }) + + $target.bootstrapTooltip('show') + var $tooltip = $container.find('.tooltip') + assert.strictEqual(Math.round($tooltip.offset().top), Math.round($(window).height() - 12 - $tooltip[0].offsetHeight)) + + $target.bootstrapTooltip('hide') + assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom') + + $container.remove() + $styles.remove() + }) + + QUnit.test('should adjust the tip\'s left position when up against the left of the viewport', function (assert) { + assert.expect(2) + var styles = '<style>' + + '.tooltip .tooltip-inner { width: 200px; height: 200px; max-width: none; }' + + 'a[rel="tooltip"] { position: fixed; }' + + '</style>' + var $styles = $(styles).appendTo('head') + + var $container = $('<div/>').appendTo('#qunit-fixture') + var $target = $('<a href="#" rel="tooltip" title="tip" style="top: 0px; left: 0px;"/>') + .appendTo($container) + .bootstrapTooltip({ + placement: 'bottom', + viewport: { + selector: 'body', + padding: 12 + } + }) + + $target.bootstrapTooltip('show') + assert.strictEqual(Math.round($container.find('.tooltip').offset().left), 12) + + $target.bootstrapTooltip('hide') + assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom') + + $container.remove() + $styles.remove() + }) + + QUnit.test('should adjust the tip\'s left position when up against the right of the viewport', function (assert) { + assert.expect(2) + var styles = '<style>' + + '.tooltip .tooltip-inner { width: 200px; height: 200px; max-width: none; }' + + 'a[rel="tooltip"] { position: fixed; }' + + '</style>' + var $styles = $(styles).appendTo('head') + + var $container = $('<div/>').appendTo('body') + var $target = $('<a href="#" rel="tooltip" title="tip" style="top: 0px; right: 0px;"/>') + .appendTo($container) + .bootstrapTooltip({ + placement: 'bottom', + viewport: { + selector: 'body', + padding: 12 + } + }) + + $target.bootstrapTooltip('show') + var $tooltip = $container.find('.tooltip') + assert.strictEqual(Math.round($tooltip.offset().left), Math.round($(window).width() - 12 - $tooltip[0].offsetWidth)) + + $target.bootstrapTooltip('hide') + assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom') + + $container.remove() + $styles.remove() + }) + + QUnit.test('should adjust the tip when up against the right of an arbitrary viewport', function (assert) { + assert.expect(2) + var styles = '<style>' + + '.tooltip, .tooltip .tooltip-inner { width: 200px; height: 200px; max-width: none; }' + + '.container-viewport { position: absolute; top: 50px; left: 60px; width: 300px; height: 300px; }' + + 'a[rel="tooltip"] { position: fixed; }' + + '</style>' + var $styles = $(styles).appendTo('head') + + var $container = $('<div class="container-viewport"/>').appendTo(document.body) + var $target = $('<a href="#" rel="tooltip" title="tip" style="top: 50px; left: 350px;"/>') + .appendTo($container) + .bootstrapTooltip({ + placement: 'bottom', + viewport: '.container-viewport' + }) + + $target.bootstrapTooltip('show') + var $tooltip = $container.find('.tooltip') + assert.strictEqual(Math.round($tooltip.offset().left), Math.round(60 + $container.width() - $tooltip[0].offsetWidth)) + + $target.bootstrapTooltip('hide') + assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom') + + $container.remove() + $styles.remove() + }) + + QUnit.test('should not error when trying to show an auto-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: 'auto' }) + + 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 place tooltip on top of element', function (assert) { + assert.expect(1) + var done = assert.async() + + var containerHTML = '<div>' + + '<p style="margin-top: 200px">' + + '<a href="#" title="very very very very very very very long tooltip">Hover me</a>' + + '</p>' + + '</div>' + + var $container = $(containerHTML) + .css({ + position: 'absolute', + bottom: 0, + left: 0, + textAlign: 'right', + width: 300, + height: 300 + }) + .appendTo('#qunit-fixture') + + var $trigger = $container + .find('a') + .css('margin-top', 200) + .bootstrapTooltip({ + placement: 'top', + animate: false + }) + .bootstrapTooltip('show') + + var $tooltip = $container.find('.tooltip') + + setTimeout(function () { + assert.ok(Math.round($tooltip.offset().top + $tooltip.outerHeight()) <= Math.round($trigger.offset().top)) + done() + }, 0) + }) + + QUnit.test('should place tooltip inside viewport', function (assert) { + assert.expect(1) + var done = assert.async() + + var $container = $('<div/>') + .css({ + position: 'absolute', + width: 200, + height: 200, + bottom: 0, + left: 0 + }) + .appendTo('#qunit-fixture') + + $('<a href="#" title="Very very very very very very very very long tooltip">Hover me</a>') + .css({ + position: 'absolute', + top: 0, + left: 0 + }) + .appendTo($container) + .bootstrapTooltip({ + placement: 'top' + }) + .bootstrapTooltip('show') + + setTimeout(function () { + assert.ok($('.tooltip').offset().left >= 0) + done() + }, 0) + }) + + 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.in'), '100ms: tooltip is not faded in') + }, 100) + + setTimeout(function () { + assert.ok($('.tooltip').is('.fade.in'), '200ms: tooltip is faded in') + 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.in'), '100ms: tooltip not faded in') + $tooltip.trigger('mouseout') + }, 100) + + setTimeout(function () { + assert.ok(!$('.tooltip').is('.fade.in'), '200ms: tooltip not faded in') + 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.in'), '1ms: tooltip faded in') + $tooltip.trigger('mouseout') + + setTimeout(function () { + assert.ok($('.tooltip').is('.fade.in'), '100ms: tooltip still faded in') + $tooltip.trigger('mouseenter') + }, 100) + + setTimeout(function () { + assert.ok($('.tooltip').is('.fade.in'), '200ms: tooltip still faded in') + 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.in'), '100ms: tooltip not faded in') + $tooltip.trigger('mouseout') + }, 100) + + setTimeout(function () { + assert.ok(!$('.tooltip').is('.fade.in'), '200ms: tooltip not faded in') + 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.in'), '100ms: tooltip not faded in') + $tooltip.trigger('mouseout') + }, 100) + + setTimeout(function () { + assert.ok(!$('.tooltip').is('.fade.in'), '250ms: tooltip not faded in') + 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.in'), '1ms: tooltip faded in') + + $tooltip.trigger('mouseout') + + setTimeout(function () { + assert.ok($tooltip.data('bs.tooltip').$tip.is('.fade.in'), '100ms: tooltip still faded in') + }, 100) + + setTimeout(function () { + assert.ok(!$tooltip.data('bs.tooltip').$tip.is('.in'), '200ms: tooltip removed') + done() + }, 200) + + }, 0) + + $tooltip.trigger('mouseenter') + }) + + QUnit.test('should correctly position tooltips on SVG elements', function (assert) { + if (!window.SVGElement) { + // Skip IE8 since it doesn't support SVG + assert.expect(0) + return + } + assert.expect(2) + + var done = assert.async() + + var styles = '<style>' + + '.tooltip, .tooltip *, .tooltip *:before, .tooltip *:after { box-sizing: border-box; }' + + '.tooltip { position: absolute; }' + + '.tooltip .tooltip-inner { width: 24px; height: 24px; font-family: Helvetica; }' + + '</style>' + var $styles = $(styles).appendTo('head') + + $('#qunit-fixture').append( + '<div style="position: fixed; top: 0; left: 0;">' + + ' <svg width="200" height="200">' + + ' <circle cx="100" cy="100" r="10" title="m" id="theCircle" />' + + ' </svg>' + + '</div>') + var $circle = $('#theCircle') + + $circle + .on('shown.bs.tooltip', function () { + var offset = $('.tooltip').offset() + $styles.remove() + assert.ok(Math.abs(offset.left - 88) <= 1, 'tooltip has correct horizontal location') + $circle.bootstrapTooltip('hide') + assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom') + done() + }) + .bootstrapTooltip({ container: 'body', placement: 'top', trigger: 'manual' }) + + $circle.bootstrapTooltip('show') + }) + + QUnit.test('should correctly determine auto placement based on container rather than parent', function (assert) { + assert.expect(2) + var done = assert.async() + + var styles = '<style>' + + '.tooltip, .tooltip *, .tooltip *:before, .tooltip *:after { box-sizing: border-box; }' + + '.tooltip { position: absolute; display: block; font-size: 12px; line-height: 1.4; }' + + '.tooltip .tooltip-inner { max-width: 200px; padding: 3px 8px; font-family: Helvetica; text-align: center; }' + + '#trigger-parent {' + + ' position: fixed;' + + ' top: 100px;' + + ' right: 17px;' + + '}' + + '</style>' + var $styles = $(styles).appendTo('head') + + $('#qunit-fixture').append('<span id="trigger-parent"><a id="tt-trigger" title="If a_larger_text is written here, it won\'t fit using older broken version of BS">HOVER OVER ME</a></span>') + var $trigger = $('#tt-trigger') + + $trigger + .on('shown.bs.tooltip', function () { + var $tip = $('.tooltip-inner') + var tipXrightEdge = $tip.offset().left + $tip.width() + var triggerXleftEdge = $trigger.offset().left + assert.ok(tipXrightEdge < triggerXleftEdge, 'tooltip with auto left placement, when near the right edge of the viewport, gets left placement') + $trigger.bootstrapTooltip('hide') + }) + .on('hidden.bs.tooltip', function () { + $styles.remove() + $(this).remove() + assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom') + done() + }) + .bootstrapTooltip({ + container: 'body', + placement: 'auto left', + trigger: 'manual' + }) + + $trigger.bootstrapTooltip('show') + }) + + QUnit.test('should not reload the tooltip on subsequent mouseenter events', function (assert) { + assert.expect(1) + var titleHtml = function () { + var uid = $.fn.bootstrapTooltip.Constructor.prototype.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 = $.fn.bootstrapTooltip.Constructor.prototype.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 + }) + + 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-content').trigger('mouseenter') + assert.ok(obj.hoverState == 'in', 'the tooltip hoverState should be set to "in"') + + assert.strictEqual(currentUid, $('#tt-content').text()) + }) + + QUnit.test('should position arrow correctly when tooltip is moved to not appear offscreen', function (assert) { + assert.expect(2) + var done = assert.async() + + var styles = '<style>' + + '.tooltip, .tooltip *, .tooltip *:before, .tooltip *:after { box-sizing: border-box; }' + + '.tooltip { position: absolute; }' + + '.tooltip-arrow { position: absolute; width: 0; height: 0; }' + + '.tooltip .tooltip-inner { max-width: 200px; padding: 3px 8px; }' + + '</style>' + var $styles = $(styles).appendTo('head') + + $('<a href="#" title="tooltip title" style="position: absolute; bottom: 0; right: 0;">Foobar</a>') + .appendTo('body') + .on('shown.bs.tooltip', function () { + var arrowStyles = $(this).data('bs.tooltip').$tip.find('.tooltip-arrow').attr('style') + assert.ok(/left/i.test(arrowStyles) && !/top/i.test(arrowStyles), 'arrow positioned correctly') + $(this).bootstrapTooltip('hide') + }) + .on('hidden.bs.tooltip', function () { + $styles.remove() + $(this).remove() + assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom') + done() + }) + .bootstrapTooltip({ + container: 'body', + placement: 'top', + trigger: 'manual' + }) + .bootstrapTooltip('show') + }) + + QUnit.test('should correctly position tooltips on transformed elements', function (assert) { + var styleProps = document.documentElement.style + if (!('transform' in styleProps) && !('webkitTransform' in styleProps) && !('msTransform' in styleProps)) { + assert.expect(0) + return + } + assert.expect(2) + + var done = assert.async() + + var styles = '<style>' + + '#qunit-fixture { top: 0; left: 0; }' + + '.tooltip, .tooltip *, .tooltip *:before, .tooltip *:after { box-sizing: border-box; }' + + '.tooltip { position: absolute; }' + + '.tooltip .tooltip-inner { width: 24px; height: 24px; font-family: Helvetica; }' + + '#target { position: absolute; top: 100px; left: 50px; width: 100px; height: 200px; -webkit-transform: rotate(270deg); -ms-transform: rotate(270deg); transform: rotate(270deg); }' + + '</style>' + var $styles = $(styles).appendTo('head') + + var $element = $('<div id="target" title="1"/>').appendTo('#qunit-fixture') + + $element + .on('shown.bs.tooltip', function () { + var offset = $('.tooltip').offset() + $styles.remove() + assert.ok(Math.abs(offset.left - 88) <= 1, 'tooltip has correct horizontal location') + assert.ok(Math.abs(offset.top - 126) <= 1, 'tooltip has correct vertical location') + $element.bootstrapTooltip('hide') + done() + }) + .bootstrapTooltip({ + container: 'body', + placement: 'top', + trigger: 'manual' + }) + + $element.bootstrapTooltip('show') + }) + + QUnit.test('should throw an error when initializing tooltip on the document object without specifying a delegation selector', function (assert) { + assert.expect(1) + assert.throws(function () { + $(document).bootstrapTooltip({ title: 'What am I on?' }) + }, new Error('`selector` option must be specified when initializing tooltip on the window.document object!')) + }) + + 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($tooltip.data('bs.tooltip'), undefined, 'should not initialize the tooltip') + }) + +}) |