2
0
mirror of https://github.com/tenrok/bootstrap.git synced 2026-06-17 19:21:23 +03:00

JS unit tests: use QUnit.module() & QUnit.test() everywhere

[skip validator]
This commit is contained in:
Chris Rebert
2015-02-23 22:04:48 -08:00
parent 7c19fee3f1
commit 118b8c2695
11 changed files with 204 additions and 204 deletions
+57 -57
View File
@@ -1,13 +1,13 @@
$(function () {
'use strict';
module('tooltip plugin')
QUnit.module('tooltip plugin')
test('should be defined on jquery object', function (assert) {
QUnit.test('should be defined on jquery object', function (assert) {
assert.ok($(document.body).tooltip, 'tooltip method is defined')
})
module('tooltip', {
QUnit.module('tooltip', {
setup: 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()
@@ -18,32 +18,32 @@ $(function () {
}
})
test('should provide no conflict', function (assert) {
QUnit.test('should provide no conflict', function (assert) {
assert.strictEqual($.fn.tooltip, undefined, 'tooltip was set back to undefined (org value)')
})
test('should return jquery collection containing the element', function (assert) {
QUnit.test('should return jquery collection containing the element', function (assert) {
var $el = $('<div/>')
var $tooltip = $el.bootstrapTooltip()
assert.ok($tooltip instanceof $, 'returns jquery collection')
assert.strictEqual($tooltip[0], $el[0], 'collection contains element')
})
test('should expose default settings', function (assert) {
QUnit.test('should expose default settings', function (assert) {
assert.ok($.fn.bootstrapTooltip.Constructor.DEFAULTS, 'defaults is defined')
})
test('should empty title attribute', function (assert) {
QUnit.test('should empty title attribute', function (assert) {
var $trigger = $('<a href="#" rel="tooltip" title="Another tooltip"/>').bootstrapTooltip()
assert.strictEqual($trigger.attr('title'), '', 'title attribute was emptied')
})
test('should add data attribute for referencing original title', function (assert) {
QUnit.test('should add data attribute for referencing original title', function (assert) {
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')
})
test('should add aria-describedby to the trigger on show', function (assert) {
QUnit.test('should add aria-describedby to the trigger on show', function (assert) {
var $trigger = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
.bootstrapTooltip()
.appendTo('#qunit-fixture')
@@ -56,7 +56,7 @@ $(function () {
assert.ok($trigger[0].hasAttribute('aria-describedby'), 'trigger has aria-describedby')
})
test('should remove aria-describedby from trigger on hide', function (assert) {
QUnit.test('should remove aria-describedby from trigger on hide', function (assert) {
var $trigger = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
.bootstrapTooltip()
.appendTo('#qunit-fixture')
@@ -68,7 +68,7 @@ $(function () {
assert.ok(!$trigger[0].hasAttribute('aria-describedby'), 'trigger does not have aria-describedby')
})
test('should assign a unique id tooltip element', function (assert) {
QUnit.test('should assign a unique id tooltip element', function (assert) {
$('<a href="#" rel="tooltip" title="Another tooltip"/>')
.appendTo('#qunit-fixture')
.bootstrapTooltip('show')
@@ -79,7 +79,7 @@ $(function () {
assert.strictEqual(id.indexOf('tooltip'), 0, 'tooltip id has prefix')
})
test('should place tooltips relative to placement option', function (assert) {
QUnit.test('should place tooltips relative to placement option', function (assert) {
var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
.appendTo('#qunit-fixture')
.bootstrapTooltip({ placement: 'bottom' })
@@ -91,7 +91,7 @@ $(function () {
assert.equal($('.tooltip').length, 0, 'tooltip removed')
})
test('should allow html entities', function (assert) {
QUnit.test('should allow html entities', function (assert) {
var $tooltip = $('<a href="#" rel="tooltip" title="&lt;b&gt;@fat&lt;/b&gt;"/>')
.appendTo('#qunit-fixture')
.bootstrapTooltip({ html: true })
@@ -103,7 +103,7 @@ $(function () {
assert.equal($('.tooltip').length, 0, 'tooltip removed')
})
test('should respect custom classes', function (assert) {
QUnit.test('should respect custom classes', function (assert) {
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>' })
@@ -115,7 +115,7 @@ $(function () {
assert.equal($('.tooltip').length, 0, 'tooltip removed')
})
test('should fire show event', function (assert) {
QUnit.test('should fire show event', function (assert) {
var done = assert.async()
$('<div title="tooltip title"/>')
@@ -126,7 +126,7 @@ $(function () {
.bootstrapTooltip('show')
})
test('should fire shown event', function (assert) {
QUnit.test('should fire shown event', function (assert) {
var done = assert.async()
$('<div title="tooltip title"></div>')
@@ -138,7 +138,7 @@ $(function () {
.bootstrapTooltip('show')
})
test('should not fire shown event when show was prevented', function (assert) {
QUnit.test('should not fire shown event when show was prevented', function (assert) {
var done = assert.async()
$('<div title="tooltip title"/>')
@@ -153,7 +153,7 @@ $(function () {
.bootstrapTooltip('show')
})
test('should fire hide event', function (assert) {
QUnit.test('should fire hide event', function (assert) {
var done = assert.async()
$('<div title="tooltip title"/>')
@@ -168,7 +168,7 @@ $(function () {
.bootstrapTooltip('show')
})
test('should fire hidden event', function (assert) {
QUnit.test('should fire hidden event', function (assert) {
var done = assert.async()
$('<div title="tooltip title"/>')
@@ -183,7 +183,7 @@ $(function () {
.bootstrapTooltip('show')
})
test('should not fire hidden event when hide was prevented', function (assert) {
QUnit.test('should not fire hidden event when hide was prevented', function (assert) {
var done = assert.async()
$('<div title="tooltip title"/>')
@@ -202,7 +202,7 @@ $(function () {
.bootstrapTooltip('show')
})
test('should destroy tooltip', function (assert) {
QUnit.test('should destroy tooltip', function (assert) {
var $tooltip = $('<div/>')
.bootstrapTooltip()
.on('click.foo', function () {})
@@ -220,7 +220,7 @@ $(function () {
assert.ok(!$._data($tooltip[0], 'events').mouseover && !$._data($tooltip[0], 'events').mouseout, 'tooltip does not have hover events')
})
test('should show tooltip with delegate selector on click', function (assert) {
QUnit.test('should show tooltip with delegate selector on click', function (assert) {
var $div = $('<div><a href="#" rel="tooltip" title="Another tooltip"/></div>')
.appendTo('#qunit-fixture')
.bootstrapTooltip({
@@ -235,7 +235,7 @@ $(function () {
assert.equal($('.tooltip').length, 0, 'tooltip was removed from dom')
})
test('should show tooltip when toggle is called', function (assert) {
QUnit.test('should show tooltip when toggle is called', function (assert) {
$('<a href="#" rel="tooltip" title="tooltip on toggle"/>')
.appendTo('#qunit-fixture')
.bootstrapTooltip({ trigger: 'manual' })
@@ -244,7 +244,7 @@ $(function () {
assert.ok($('.tooltip').is('.fade.in'), 'tooltip is faded in')
})
test('should hide previously shown tooltip when toggle is called on tooltip', function (assert) {
QUnit.test('should hide previously shown tooltip when toggle is called on tooltip', function (assert) {
$('<a href="#" rel="tooltip" title="tooltip on toggle">@ResentedHook</a>')
.appendTo('#qunit-fixture')
.bootstrapTooltip({ trigger: 'manual' })
@@ -254,7 +254,7 @@ $(function () {
assert.ok($('.tooltip').not('.fade.in'), 'tooltip was faded out')
})
test('should place tooltips inside body when container is body', function (assert) {
QUnit.test('should place tooltips inside body when container is body', function (assert) {
var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
.appendTo('#qunit-fixture')
.bootstrapTooltip({ container: 'body' })
@@ -267,7 +267,7 @@ $(function () {
assert.equal($('body > .tooltip').length, 0, 'tooltip was removed from dom')
})
test('should add position class before positioning so that position-specific styles are taken into account', function (assert) {
QUnit.test('should add position class before positioning so that position-specific styles are taken into account', function (assert) {
var styles = '<style>'
+ '.tooltip.right { white-space: nowrap; }'
+ '.tooltip.right .tooltip-inner { max-width: none; }'
@@ -295,7 +295,7 @@ $(function () {
$styles.remove()
})
test('should use title attribute for tooltip text', function (assert) {
QUnit.test('should use title attribute for tooltip text', function (assert) {
var $tooltip = $('<a href="#" rel="tooltip" title="Simple tooltip"/>')
.appendTo('#qunit-fixture')
.bootstrapTooltip()
@@ -307,7 +307,7 @@ $(function () {
assert.equal($('.tooltip').length, 0, 'tooltip removed from dom')
})
test('should prefer title attribute over title option', function (assert) {
QUnit.test('should prefer title attribute over title option', function (assert) {
var $tooltip = $('<a href="#" rel="tooltip" title="Simple tooltip"/>')
.appendTo('#qunit-fixture')
.bootstrapTooltip({
@@ -321,7 +321,7 @@ $(function () {
assert.equal($('.tooltip').length, 0, 'tooltip removed from dom')
})
test('should use title option', function (assert) {
QUnit.test('should use title option', function (assert) {
var $tooltip = $('<a href="#" rel="tooltip"/>')
.appendTo('#qunit-fixture')
.bootstrapTooltip({
@@ -335,7 +335,7 @@ $(function () {
assert.equal($('.tooltip').length, 0, 'tooltip removed from dom')
})
test('should be placed dynamically with the dynamic placement option', function (assert) {
QUnit.test('should be placed dynamically with the dynamic placement option', function (assert) {
var $style = $('<style> a[rel="tooltip"] { display: inline-block; position: absolute; } </style>')
var $container = $('<div/>')
.css({
@@ -382,7 +382,7 @@ $(function () {
$style.remove()
})
test('should position tip on top if viewport has enough space and placement is "auto top"', function (assert) {
QUnit.test('should position tip on top if viewport has enough space and placement is "auto top"', function (assert) {
var styles = '<style>'
+ 'body { padding-top: 100px; }'
+ '#section { height: 300px; border: 1px solid red; padding-top: 50px }'
@@ -407,7 +407,7 @@ $(function () {
$styles.remove()
})
test('should position tip on bottom if the tip\'s dimension exceeds the viewport area and placement is "auto top"', function (assert) {
QUnit.test('should position tip on bottom if the tip\'s dimension exceeds the viewport area and placement is "auto top"', function (assert) {
var styles = '<style>'
+ 'body { padding-top: 100px; }'
+ '#section { height: 300px; border: 1px solid red; }'
@@ -432,7 +432,7 @@ $(function () {
$styles.remove()
})
test('should display the tip on top whenever scrollable viewport has enough room if the given placement is "auto top"', function (assert) {
QUnit.test('should display the tip on top whenever scrollable viewport has enough room if the given placement is "auto top"', function (assert) {
var styles = '<style>'
+ '#scrollable-div { height: 200px; overflow: auto; }'
+ '.tooltip-item { margin: 200px 0 400px; width: 150px; }'
@@ -458,7 +458,7 @@ $(function () {
$styles.remove()
})
test('should display the tip on bottom whenever scrollable viewport doesn\'t have enough room if the given placement is "auto top"', function (assert) {
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) {
var styles = '<style>'
+ '#scrollable-div { height: 200px; overflow: auto; }'
+ '.tooltip-item { padding: 200px 0 400px; width: 150px; }'
@@ -484,7 +484,7 @@ $(function () {
$styles.remove()
})
test('should display the tip on bottom whenever scrollable viewport has enough room if the given placement is "auto bottom"', function (assert) {
QUnit.test('should display the tip on bottom whenever scrollable viewport has enough room if the given placement is "auto bottom"', function (assert) {
var styles = '<style>'
+ '#scrollable-div { height: 200px; overflow: auto; }'
+ '.spacer { height: 400px; }'
@@ -514,7 +514,7 @@ $(function () {
$styles.remove()
})
test('should display the tip on top whenever scrollable viewport doesn\'t have enough room if the given placement is "auto bottom"', function (assert) {
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) {
var styles = '<style>'
+ '#scrollable-div { height: 200px; overflow: auto; }'
+ '.tooltip-item { margin-top: 400px; width: 150px; }'
@@ -540,7 +540,7 @@ $(function () {
$styles.remove()
})
test('should adjust the tip\'s top position when up against the top of the viewport', function (assert) {
QUnit.test('should adjust the tip\'s top position when up against the top of the viewport', function (assert) {
var styles = '<style>'
+ '.tooltip .tooltip-inner { width: 200px; height: 200px; max-width: none; }'
+ 'a[rel="tooltip"] { position: fixed; }'
@@ -567,7 +567,7 @@ $(function () {
$styles.remove()
})
test('should adjust the tip\'s top position when up against the bottom of the viewport', function (assert) {
QUnit.test('should adjust the tip\'s top position when up against the bottom of the viewport', function (assert) {
var styles = '<style>'
+ '.tooltip .tooltip-inner { width: 200px; height: 200px; max-width: none; }'
+ 'a[rel="tooltip"] { position: fixed; }'
@@ -596,7 +596,7 @@ $(function () {
$styles.remove()
})
test('should adjust the tip\'s left position when up against the left of the viewport', function (assert) {
QUnit.test('should adjust the tip\'s left position when up against the left of the viewport', function (assert) {
var styles = '<style>'
+ '.tooltip .tooltip-inner { width: 200px; height: 200px; max-width: none; }'
+ 'a[rel="tooltip"] { position: fixed; }'
@@ -624,7 +624,7 @@ $(function () {
$styles.remove()
})
test('should adjust the tip\'s left position when up against the right of the viewport', function (assert) {
QUnit.test('should adjust the tip\'s left position when up against the right of the viewport', function (assert) {
var styles = '<style>'
+ '.tooltip .tooltip-inner { width: 200px; height: 200px; max-width: none; }'
+ 'a[rel="tooltip"] { position: fixed; }'
@@ -653,7 +653,7 @@ $(function () {
$styles.remove()
})
test('should adjust the tip when up against the right of an arbitrary viewport', function (assert) {
QUnit.test('should adjust the tip when up against the right of an arbitrary viewport', function (assert) {
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; }'
@@ -680,7 +680,7 @@ $(function () {
$styles.remove()
})
test('should not error when trying to show an auto-placed tooltip that has been removed from the dom', function (assert) {
QUnit.test('should not error when trying to show an auto-placed tooltip that has been removed from the dom', function (assert) {
var passed = true
var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
.appendTo('#qunit-fixture')
@@ -699,7 +699,7 @@ $(function () {
assert.ok(passed, '.tooltip(\'show\') should not throw an error if element no longer is in dom')
})
test('should place tooltip on top of element', function (assert) {
QUnit.test('should place tooltip on top of element', function (assert) {
var done = assert.async()
var containerHTML = '<div>'
@@ -736,7 +736,7 @@ $(function () {
}, 0)
})
test('should place tooltip inside viewport', function (assert) {
QUnit.test('should place tooltip inside viewport', function (assert) {
var done = assert.async()
var $container = $('<div/>')
@@ -767,7 +767,7 @@ $(function () {
}, 0)
})
test('should show tooltip if leave event hasn\'t occurred before delay expires', function (assert) {
QUnit.test('should show tooltip if leave event hasn\'t occurred before delay expires', function (assert) {
var done = assert.async()
var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
@@ -786,7 +786,7 @@ $(function () {
$tooltip.trigger('mouseenter')
})
test('should not show tooltip if leave event occurs before delay expires', function (assert) {
QUnit.test('should not show tooltip if leave event occurs before delay expires', function (assert) {
var done = assert.async()
var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
@@ -806,7 +806,7 @@ $(function () {
$tooltip.trigger('mouseenter')
})
test('should not hide tooltip if leave event occurs and enter event occurs within the hide delay', function (assert) {
QUnit.test('should not hide tooltip if leave event occurs and enter event occurs within the hide delay', function (assert) {
var done = assert.async()
var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
@@ -831,7 +831,7 @@ $(function () {
$tooltip.trigger('mouseenter')
})
test('should not show tooltip if leave event occurs before delay expires', function (assert) {
QUnit.test('should not show tooltip if leave event occurs before delay expires', function (assert) {
var done = assert.async()
var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
@@ -851,7 +851,7 @@ $(function () {
$tooltip.trigger('mouseenter')
})
test('should not show tooltip if leave event occurs before delay expires, even if hide delay is 0', function (assert) {
QUnit.test('should not show tooltip if leave event occurs before delay expires, even if hide delay is 0', function (assert) {
var done = assert.async()
var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
@@ -871,7 +871,7 @@ $(function () {
$tooltip.trigger('mouseenter')
})
test('should wait 200ms before hiding the tooltip', function (assert) {
QUnit.test('should wait 200ms before hiding the tooltip', function (assert) {
var done = assert.async()
var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
@@ -897,7 +897,7 @@ $(function () {
$tooltip.trigger('mouseenter')
})
test('should correctly position tooltips on SVG elements', function (assert) {
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)
@@ -935,7 +935,7 @@ $(function () {
$circle.bootstrapTooltip('show')
})
test('should correctly determine auto placement based on container rather than parent', function (assert) {
QUnit.test('should correctly determine auto placement based on container rather than parent', function (assert) {
var done = assert.async()
var styles = '<style>'
@@ -976,7 +976,7 @@ $(function () {
$trigger.bootstrapTooltip('show')
})
test('should not reload the tooltip on subsequent mouseenter events', function (assert) {
QUnit.test('should not reload the tooltip on subsequent mouseenter events', function (assert) {
var titleHtml = function () {
var uid = $.fn.bootstrapTooltip.Constructor.prototype.getUID('tooltip')
return '<p id="tt-content">' + uid + '</p><p>' + uid + '</p><p>' + uid + '</p>'
@@ -1002,7 +1002,7 @@ $(function () {
assert.equal(currentUid, $('#tt-content').text())
})
test('should not reload the tooltip if the mouse leaves and re-enters before hiding', function (assert) {
QUnit.test('should not reload the tooltip if the mouse leaves and re-enters before hiding', function (assert) {
var titleHtml = function () {
var uid = $.fn.bootstrapTooltip.Constructor.prototype.getUID('tooltip')
return '<p id="tt-content">' + uid + '</p><p>' + uid + '</p><p>' + uid + '</p>'
@@ -1037,7 +1037,7 @@ $(function () {
assert.equal(currentUid, $('#tt-content').text())
})
test('should position arrow correctly when tooltip is moved to not appear offscreen', function (assert) {
QUnit.test('should position arrow correctly when tooltip is moved to not appear offscreen', function (assert) {
var done = assert.async()
var styles = '<style>'
@@ -1069,7 +1069,7 @@ $(function () {
.bootstrapTooltip('show')
})
test('should correctly position tooltips on transformed elements', function (assert) {
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)
@@ -1107,7 +1107,7 @@ $(function () {
$element.bootstrapTooltip('show')
})
test('should throw an error when initializing tooltip on the document object without specifying a delegation selector', function (assert) {
QUnit.test('should throw an error when initializing tooltip on the document object without specifying a delegation selector', function (assert) {
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!'))