Use BrowserStack for our unit tests.

This commit is contained in:
Johann-S 2018-09-07 22:32:52 +03:00 committed by XhmikosR
parent cee8e8653d
commit 4ebe2b8753
20 changed files with 10263 additions and 6686 deletions

View File

@ -36,7 +36,7 @@ env:
matrix:
- TWBS_TEST=core
- TWBS_TEST=validate-html
- TWBS_TEST=sauce-js-unit
- TWBS_TEST=browserstack
matrix:
fast_finish: true
notifications:

View File

@ -145,13 +145,6 @@ module.exports = function (grunt) {
}
},
qunit: {
options: {
inject: 'js/tests/unit/phantom.js'
},
files: 'js/tests/index.html'
},
less: {
compileCore: {
options: {
@ -366,11 +359,11 @@ module.exports = function (grunt) {
watch: {
src: {
files: '<%= jshint.core.src %>',
tasks: ['jshint:core', 'qunit', 'concat']
tasks: ['jshint:core', 'exec:qunit', 'concat']
},
test: {
files: '<%= jshint.test.src %>',
tasks: ['jshint:test', 'qunit']
tasks: ['jshint:test', 'exec:qunit']
},
less: {
files: 'less/**/*.less',
@ -382,22 +375,15 @@ module.exports = function (grunt) {
}
},
'saucelabs-qunit': {
all: {
options: {
build: process.env.TRAVIS_JOB_ID,
throttled: 10,
maxRetries: 3,
maxPollRetries: 4,
urls: ['http://127.0.0.1:3000/js/tests/index.html?hidepassed'],
browsers: grunt.file.readYAML('grunt/sauce_browsers.yml')
}
}
},
exec: {
npmUpdate: {
command: 'npm update'
},
browserstack: {
command: 'cross-env BROWSER=true karma start grunt/karma.conf.js'
},
qunit: {
command: 'karma start grunt/karma.conf.js'
}
},
@ -451,17 +437,15 @@ module.exports = function (grunt) {
isUndefOrNonZero(process.env.TWBS_DO_VALIDATOR)) {
testSubtasks.push('validate-html');
}
// Only run Sauce Labs tests if there's a Sauce access key
if (typeof process.env.SAUCE_ACCESS_KEY !== 'undefined' &&
// Skip Sauce if running a different subset of the test suite
runSubset('sauce-js-unit') &&
// Skip Sauce on Travis when [skip sauce] is in the commit message
isUndefOrNonZero(process.env.TWBS_DO_SAUCE)) {
testSubtasks.push('connect');
testSubtasks.push('saucelabs-qunit');
// Only run BrowserStack tests if there's a BrowserStack access key
if (typeof process.env.BROWSER_STACK_USERNAME !== 'undefined' &&
// Skip BrowserStack if running a different subset of the test suite
runSubset('browserstack')) {
testSubtasks.push('exec:browserstack');
}
grunt.registerTask('test', testSubtasks);
grunt.registerTask('test-js', ['jshint:core', 'jshint:test', 'jshint:grunt', 'jscs:core', 'jscs:test', 'jscs:grunt', 'qunit']);
grunt.registerTask('test-js', ['jshint:core', 'jshint:test', 'jshint:grunt', 'jscs:core', 'jscs:test', 'jscs:grunt', 'exec:qunit']);
// JS distribution task.
grunt.registerTask('dist-js', ['concat', 'uglify:core', 'commonjs']);

View File

@ -22,6 +22,7 @@ To get started, check out <http://getbootstrap.com>!
* [Community](#community)
* [Versioning](#versioning)
* [Creators](#creators)
- [Thanks](#thanks)
* [Copyright and license](#copyright-and-license)
@ -124,6 +125,13 @@ For transparency into our release cycle and in striving to maintain backward com
See [the Releases section of our GitHub project](https://github.com/twbs/bootstrap/releases) for changelogs for each release version of Bootstrap. Release announcement posts on [the official Bootstrap blog](http://blog.getbootstrap.com) contain summaries of the most noteworthy changes made in each release.
## Thanks
<img src="https://live.browserstack.com/images/opensource/browserstack-logo.svg" alt="BrowserStack Logo" width="490" height="106">
Thanks to [BrowserStack](https://www.browserstack.com/) for providing the infrastructure that allows us to test in real browsers!
## Creators
**Mark Otto**

View File

@ -22,7 +22,7 @@
<p>Watches the Less source files and automatically recompiles them to CSS whenever you save a change.</p>
<h3><code>grunt test</code> (Run tests)</h3>
<p>Runs <a href="http://jshint.com">JSHint</a> and runs the <a href="http://qunitjs.com">QUnit</a> tests headlessly in <a href="http://phantomjs.org">PhantomJS</a>.</p>
<p>Runs <a href="http://jshint.com">JSHint</a> and runs the <a href="http://qunitjs.com">QUnit</a> tests in real browsers thanks to <a href="https://karma-runner.github.io/2.0/index.html">Karma</a>.</p>
<h3><code>grunt docs</code> (Build &amp; test the docs assets)</h3>
<p>Builds and tests CSS, JavaScript, and other assets which are used when running the documentation locally via <code>bundle exec jekyll serve</code>.</p>

86
grunt/browsers.js Normal file
View File

@ -0,0 +1,86 @@
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
var browsers = {
safariMac: {
base: 'BrowserStack',
os: 'OS X',
os_version: 'Yosemite',
browser: 'Safari',
browser_version: '8.0'
},
chromeMac: {
base: 'BrowserStack',
os: 'OS X',
os_version: 'Yosemite',
browser : 'Chrome',
browser_version : 'latest'
},
firefoxMac: {
base: 'BrowserStack',
os: 'OS X',
os_version: 'Yosemite',
browser: 'Firefox',
browser_version: 'latest'
},
'ie11Win8.1': {
base: 'BrowserStack',
os: 'Windows',
os_version: '8.1',
browser: 'IE',
browser_version: '11.0'
},
ie10Win8: {
base: 'BrowserStack',
os: 'Windows',
os_version: '8',
browser: 'IE',
browser_version: '10.0'
},
ie9Win7: {
base: 'BrowserStack',
os: 'Windows',
os_version: '7',
browser: 'IE',
browser_version: '9.0'
},
ie8Win7: {
base: 'BrowserStack',
os: 'Windows',
os_version: '7',
browser: 'IE',
browser_version: '8.0'
},
'chromeWin8.1': {
base: 'BrowserStack',
os: 'Windows',
os_version: '8.1',
browser: 'Chrome',
browser_version: 'latest'
},
'firefoxWin8.1': {
base: 'BrowserStack',
os: 'Windows',
os_version: '8.1',
browser: 'Firefox',
browser_version: 'latest'
},
iphone6: {
base: 'BrowserStack',
os: 'ios',
os_version: '11.2',
device: 'iPhone 6',
real_mobile: true
},
nexus5: {
base: 'BrowserStack',
os: 'android',
os_version: '4.4',
device: 'Google Nexus 5',
real_mobile: true
}
};
module.exports = {
list: browsers,
keys: Object.keys(browsers)
};

79
grunt/karma.conf.js Normal file
View File

@ -0,0 +1,79 @@
'use strict';
var ip = require('ip');
var browserConfig = require('./browsers');
var browserStack = process.env.BROWSER === 'true';
module.exports = function (config) {
var conf = {
basePath: '../',
frameworks: ['qunit'],
plugins: ['karma-qunit'],
// list of files / patterns to load in the browser
files: [
'js/tests/vendor/jquery.min.js',
'js/tooltip.js',
'js/!(tooltip).js',
'js/tests/unit/*.js'
],
reporters: ['dots'],
port: 9876,
colors: true,
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_ERROR || config.LOG_WARN,
autoWatch: false,
singleRun: true,
concurrency: Infinity,
client: {
qunit: {
showUI: true
}
}
};
if (browserStack) {
conf.hostname = ip.address();
conf.browserStack = {
username: process.env.BROWSER_STACK_USERNAME,
accessKey: process.env.BROWSER_STACK_ACCESS_KEY,
build: 'bootstrap-v3-' + new Date().toISOString(),
project: 'Bootstrap v3',
retryLimit: 1
};
conf.plugins.push('karma-browserstack-launcher');
conf.customLaunchers = browserConfig.list;
conf.browsers = browserConfig.keys;
conf.reporters.push('BrowserStack');
} else {
conf.frameworks.push('detectBrowsers');
conf.plugins.push(
'karma-chrome-launcher',
'karma-firefox-launcher',
'karma-detect-browsers'
);
conf.detectBrowsers = {
usePhantomJS: false,
postDetection: function (availableBrowser) {
if (typeof process.env.TRAVIS_JOB_ID !== 'undefined' || availableBrowser.includes('Chrome')) {
return ['ChromeHeadless'];
}
if (availableBrowser.includes('Firefox')) {
return ['FirefoxHeadless'];
}
throw new Error('Please install Firefox or Chrome');
}
};
conf.customLaunchers = {
FirefoxHeadless: {
base: 'Firefox',
flags: ['-headless']
}
};
}
config.set(conf);
};

11234
grunt/npm-shrinkwrap.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,82 +0,0 @@
[
# Docs: https://saucelabs.com/docs/platforms/webdriver
{
browserName: "safari",
platform: "OS X 10.10"
},
{
browserName: "chrome",
platform: "OS X 10.10"
},
{
browserName: "firefox",
platform: "OS X 10.10"
},
# Mac Opera not currently supported by Sauce Labs
{
browserName: "internet explorer",
version: "11",
platform: "Windows 8.1"
},
{
browserName: "internet explorer",
version: "10",
platform: "Windows 8"
},
{
browserName: "internet explorer",
version: "9",
platform: "Windows 7"
},
{
browserName: "internet explorer",
version: "8",
platform: "Windows 7"
},
# { # Unofficial
# browserName: "internet explorer",
# version: "7",
# platform: "Windows XP"
# },
{
browserName: "chrome",
platform: "Windows 8.1"
},
{
browserName: "firefox",
platform: "Windows 8.1"
},
# Win Opera 15+ not currently supported by Sauce Labs
{
browserName: "iphone",
platform: "OS X 10.10",
version: "9.2"
},
# iOS Chrome not currently supported by Sauce Labs
# Linux (unofficial)
{
browserName: "chrome",
platform: "Linux"
},
{
browserName: "firefox",
platform: "Linux"
}
# Android Chrome not currently supported by Sauce Labs
# { # Android Browser (super-unofficial)
# browserName: "android",
# version: "4.0",
# platform: "Linux"
# }
]

View File

@ -3,12 +3,11 @@
Bootstrap uses [QUnit](http://api.qunitjs.com/), a powerful, easy-to-use JavaScript unit test framework. Each plugin has a file dedicated to its tests in `unit/<plugin-name>.js`.
* `unit/` contains the unit test files for each Bootstrap plugin.
* `vendor/` contains third-party testing-related code (QUnit and jQuery).
* `vendor/` contains jQuery.
* `visual/` contains "visual" tests which are run interactively in real browsers and require manual verification by humans.
To run the unit test suite via [PhantomJS](http://phantomjs.org/), run `grunt test-js`.
To run the unit test suite via a real web browser, open `index.html` in the browser.
To run our unit tests on a real web browser [Karma](https://karma-runner.github.io/2.0/index.html), run `grunt test-js` or you can
open `index.html`.
## How do I add a new unit test?

View File

@ -52,8 +52,8 @@
</script>
<!-- QUnit -->
<link rel="stylesheet" href="vendor/qunit.css" media="screen">
<script src="vendor/qunit.js"></script>
<link rel="stylesheet" href="../../node_modules/qunitjs/qunit/qunit.css" media="screen">
<script src="../../node_modules/qunitjs/qunit/qunit.js"></script>
<script>
// See https://github.com/axemclion/grunt-saucelabs#test-result-details-with-qunit
var log = []
@ -133,7 +133,6 @@
</script>
<!-- Plugin sources -->
<script>$.support.transition = false</script>
<script src="../../js/alert.js"></script>
<script src="../../js/button.js"></script>
<script src="../../js/carousel.js"></script>

View File

@ -34,12 +34,21 @@ $(function () {
QUnit.test('should exit early if element is not visible', function (assert) {
assert.expect(1)
var $affix = $('<div style="display: none"/>').bootstrapAffix()
var $affix = $('<div style="display: none"/>')
.appendTo('#qunit-fixture')
.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) {
// Disable for iOS because of: https://bugs.webkit.org/show_bug.cgi?id=172854
if (window.navigator.userAgent.match(/iPhone/i)) {
assert.expect(0)
return
}
assert.expect(2)
var done = assert.async()
@ -66,15 +75,22 @@ $(function () {
})
setTimeout(function () {
window.scrollTo(0, document.body.scrollHeight)
window.scrollTo(0, document.body.scrollHeight - 5)
// for testing in a browser
setTimeout(function () {
window.scroll(0, 0)
}, 16) // for testing in a browser
}, 150)
}, 0)
})
QUnit.test('should affix-top when scrolling up to offset when parent has padding', function (assert) {
// Disable for iOS because of: https://bugs.webkit.org/show_bug.cgi?id=172854
if (window.navigator.userAgent.match(/iPhone/i)) {
assert.expect(0)
return
}
assert.expect(1)
var done = assert.async()
@ -97,11 +113,11 @@ $(function () {
})
setTimeout(function () {
window.scrollTo(0, document.body.scrollHeight)
window.scrollTo(0, document.body.scrollHeight - 5)
setTimeout(function () {
window.scroll(0, 119)
}, 250)
}, 250)
}, 0)
})
})

View File

@ -47,6 +47,8 @@ $(function () {
QUnit.test('should remove element when clicking .close', function (assert) {
assert.expect(2)
var done = assert.async()
var alertHTML = '<div class="alert alert-danger fade 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>'
@ -55,9 +57,12 @@ $(function () {
assert.notEqual($('#qunit-fixture').find('.alert').length, 0, 'element added to dom')
$alert.find('.close').trigger('click')
$alert.on('closed.bs.alert', function () {
assert.strictEqual($('#qunit-fixture').find('.alert').length, 0, 'element removed from dom')
done()
})
assert.strictEqual($('#qunit-fixture').find('.alert').length, 0, 'element removed from dom')
$alert.find('.close').trigger('click')
})
QUnit.test('should not fire closed when close is prevented', function (assert) {

View File

@ -34,10 +34,15 @@ $(function () {
QUnit.test('should show a collapsed element', function (assert) {
assert.expect(2)
var $el = $('<div class="collapse"/>').bootstrapCollapse('show')
var done = assert.async()
assert.ok($el.hasClass('in'), 'has class "in"')
assert.ok(!/height/i.test($el.attr('style')), 'has height reset')
$('<div class="collapse"/>')
.on('shown.bs.collapse', function () {
assert.ok($(this).hasClass('in'), 'has class "in"')
assert.ok(!/height/i.test($(this).attr('style')), 'has height reset')
done()
})
.bootstrapCollapse('show')
})
QUnit.test('should hide a collapsed element', function (assert) {

View File

@ -16,6 +16,7 @@ $(function () {
afterEach: function () {
$.fn.modal = $.fn.bootstrapModal
delete $.fn.bootstrapModal
$('#qunit-fixture').html('')
}
})
@ -26,7 +27,7 @@ $(function () {
QUnit.test('should return jquery collection containing the element', function (assert) {
assert.expect(2)
var $el = $('<div id="modal-test"/>')
var $el = $('<div id="modal-test"/>').appendTo('#qunit-fixture')
var $modal = $el.bootstrapModal()
assert.ok($modal instanceof $, 'returns jquery collection')
assert.strictEqual($modal[0], $el[0], 'collection contains element')
@ -42,6 +43,7 @@ $(function () {
var done = assert.async()
$('<div id="modal-test"/>')
.appendTo('#qunit-fixture')
.on('shown.bs.modal', function () {
assert.notEqual($('#modal-test').length, 0, 'modal inserted into dom')
done()
@ -54,6 +56,7 @@ $(function () {
var done = assert.async()
$('<div id="modal-test"/>')
.appendTo('#qunit-fixture')
.on('show.bs.modal', function () {
assert.ok(true, 'show event fired')
done()
@ -66,6 +69,7 @@ $(function () {
var done = assert.async()
$('<div id="modal-test"/>')
.appendTo('#qunit-fixture')
.on('show.bs.modal', function (e) {
e.preventDefault()
assert.ok(true, 'show event fired')
@ -82,6 +86,7 @@ $(function () {
var done = assert.async()
$('<div id="modal-test"/>')
.appendTo('#qunit-fixture')
.on('shown.bs.modal', function () {
assert.ok($('#modal-test').is(':visible'), 'modal visible')
assert.notEqual($('#modal-test').length, 0, 'modal inserted into dom')
@ -99,6 +104,7 @@ $(function () {
var done = assert.async()
$('<div id="modal-test"/>')
.appendTo('#qunit-fixture')
.on('shown.bs.modal', function () {
assert.ok($('#modal-test').is(':visible'), 'modal visible')
assert.notEqual($('#modal-test').length, 0, 'modal inserted into dom')
@ -116,6 +122,7 @@ $(function () {
var done = assert.async()
$('<div id="modal-test"><span class="close" data-dismiss="modal"/></div>')
.appendTo('#qunit-fixture')
.on('shown.bs.modal', function () {
assert.ok($('#modal-test').is(':visible'), 'modal visible')
assert.notEqual($('#modal-test').length, 0, 'modal inserted into dom')
@ -133,6 +140,7 @@ $(function () {
var done = assert.async()
$('<div id="modal-test" data-backdrop="false"/>')
.appendTo('#qunit-fixture')
.on('shown.bs.modal', function () {
assert.ok($('#modal-test').is(':visible'), 'modal visible')
$(this).bootstrapModal('hide')
@ -149,6 +157,7 @@ $(function () {
var done = assert.async()
$('<div id="modal-test"><div class="contents"/></div>')
.appendTo('#qunit-fixture')
.on('shown.bs.modal', function () {
assert.notEqual($('#modal-test').length, 0, 'modal inserted into dom')
$('.contents').trigger('click')
@ -166,7 +175,7 @@ $(function () {
assert.expect(3)
var done = assert.async()
var $div = $('<div id="modal-test"/>')
var $div = $('<div id="modal-test"/>').appendTo('#qunit-fixture')
$div
.on('shown.bs.modal', function () {
assert.ok($('#modal-test').length, 'modal inserted into dom')
@ -186,7 +195,7 @@ $(function () {
assert.expect(3)
var done = assert.async()
var $div = $('<div id="modal-test"/>')
var $div = $('<div id="modal-test"/>').appendTo('#qunit-fixture')
$div
.on('shown.bs.modal', function () {
assert.ok($('#modal-test').length, 'modal inserted into dom')
@ -209,6 +218,7 @@ $(function () {
var triggered
$('<div id="modal-test"><div class="contents"/></div>')
.appendTo('#qunit-fixture')
.on('shown.bs.modal', function () {
triggered = 0
$('#modal-test').trigger('click')
@ -226,6 +236,7 @@ $(function () {
var done = assert.async()
$('<div id="modal-test"><div class="contents"><div id="close" data-dismiss="modal"/></div></div>')
.appendTo('#qunit-fixture')
.one('shown.bs.modal', function () {
$('#close').trigger('click')
})
@ -252,6 +263,7 @@ $(function () {
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>')
.appendTo('#qunit-fixture')
.on('hidden.bs.modal', function () {
setTimeout(function () {
assert.ok($(document.activeElement).is($toggleBtn), 'toggling element is once again focused')
@ -273,6 +285,7 @@ $(function () {
var $otherBtn = $('<button id="other-btn"/>').appendTo('#qunit-fixture')
$('<div id="modal-test"><div class="contents"><div id="close" data-dismiss="modal"/></div>')
.appendTo('#qunit-fixture')
.one('show.bs.modal', function (e) {
e.preventDefault()
$otherBtn.trigger('focus')

View File

@ -1,72 +0,0 @@
/*
* 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 dont 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\u221A All tests passed in "' + obj.name + '" module')
} else {
console.log('\u00D7 ' + 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)
})
}())

View File

@ -34,13 +34,19 @@ $(function () {
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')
var done = assert.async()
assert.notEqual($('.popover').length, 0, 'popover was inserted')
$popover.bootstrapPopover('hide')
assert.strictEqual($('.popover').length, 0, 'popover removed')
$('<a href="#" title="mdo" data-content="https://twitter.com/mdo">@mdo</a>')
.appendTo('#qunit-fixture')
.on('shown.bs.popover', function () {
assert.notEqual($('.popover').length, 0, 'popover was inserted')
$(this).bootstrapPopover('hide')
})
.on('hidden.bs.popover', function () {
assert.strictEqual($('.popover').length, 0, 'popover removed')
done()
})
.bootstrapPopover('show')
})
QUnit.test('should store popover instance in popover data object', function (assert) {
@ -63,6 +69,8 @@ $(function () {
QUnit.test('should get title and content from options', function (assert) {
assert.expect(4)
var done = assert.async()
var $popover = $('<a href="#">@fat</a>')
.appendTo('#qunit-fixture')
.bootstrapPopover({
@ -73,19 +81,24 @@ $(function () {
return 'loves writing tests (╯°□°)╯︵ ┻━┻'
}
})
.on('shown.bs.popover', function () {
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')
})
.on('hidden.bs.popover', function () {
assert.strictEqual($('.popover').length, 0, 'popover was removed')
done()
})
$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 done = assert.async()
var $div = $('<div/>').html('loves writing tests (╯°□°)╯︵ ┻━┻')
var $popover = $('<a href="#">@fat</a>')
@ -96,72 +109,100 @@ $(function () {
}
})
$popover.bootstrapPopover('show')
assert.notEqual($('.popover').length, 0, 'popover was inserted')
assert.equal($('.popover .popover-content').html(), $div, 'content correctly inserted')
$popover.one('shown.bs.popover', function () {
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.one('hidden.bs.popover', function () {
assert.strictEqual($('.popover').length, 0, 'popover was removed')
$popover.one('shown.bs.popover', function () {
assert.notEqual($('.popover').length, 0, 'popover was inserted')
assert.equal($('.popover .popover-content').html(), $div, 'content correctly inserted')
$popover.one('hidden.bs.popover', function () {
assert.strictEqual($('.popover').length, 0, 'popover was removed')
done()
})
$popover.bootstrapPopover('hide')
})
$popover.bootstrapPopover('show')
})
$popover.bootstrapPopover('hide')
})
$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>')
var done = assert.async()
$('<a href="#" title="@mdo" data-content="loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻" >@mdo</a>')
.appendTo('#qunit-fixture')
.bootstrapPopover()
.one('shown.bs.popover', function () {
assert.notEqual($('.popover').length, 0, 'popover was inserted')
assert.strictEqual($('.popover .popover-title').text(), '@mdo', 'title correctly inserted')
assert.strictEqual($('.popover .popover-content').text(), 'loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻', 'content correctly inserted')
$(this).bootstrapPopover('hide')
})
.one('hidden.bs.popover', function () {
assert.strictEqual($('.popover').length, 0, 'popover was removed')
done()
})
.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>')
var done = assert.async()
$('<a href="#" title="@mdo" data-content="loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻" >@mdo</a>')
.appendTo('#qunit-fixture')
.bootstrapPopover({
title: 'ignored title option',
content: 'ignored content option'
})
.one('shown.bs.popover', function () {
assert.notEqual($('.popover').length, 0, 'popover was inserted')
assert.strictEqual($('.popover .popover-title').text(), '@mdo', 'title correctly inserted')
assert.strictEqual($('.popover .popover-content').text(), 'loves data attributes (づ。◕‿‿◕。)づ ︵ ┻━┻', 'content correctly inserted')
$(this).bootstrapPopover('hide')
})
.one('hidden.bs.popover', function () {
assert.strictEqual($('.popover').length, 0, 'popover was removed')
done()
})
.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>')
var done = assert.async()
$('<a href="#">@fat</a>')
.appendTo('#qunit-fixture')
.bootstrapPopover({
title: 'Test',
content: 'Test',
template: '<div class="popover foobar"><div class="arrow"></div><div class="inner"><h3 class="title"/><div class="content"><p/></div></div></div>'
})
.one('shown.bs.popover', function () {
assert.notEqual($('.popover').length, 0, 'popover was inserted')
assert.ok($('.popover').hasClass('foobar'), 'custom class is present')
$popover.bootstrapPopover('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')
$(this).bootstrapPopover('hide')
})
.one('hidden.bs.popover', function () {
assert.strictEqual($('.popover').length, 0, 'popover was removed')
done()
})
.bootstrapPopover('show')
})
QUnit.test('should destroy popover', function (assert) {
@ -187,6 +228,8 @@ $(function () {
QUnit.test('should render popover element using delegated selector', function (assert) {
assert.expect(2)
var done = assert.async()
var $div = $('<div><a href="#" title="mdo" data-content="https://twitter.com/mdo">@mdo</a></div>')
.appendTo('#qunit-fixture')
.bootstrapPopover({
@ -194,11 +237,16 @@ $(function () {
trigger: 'click'
})
$div.find('a').trigger('click')
assert.notEqual($('.popover').length, 0, 'popover was inserted')
$div.one('shown.bs.popover', function () {
assert.notEqual($('.popover').length, 0, 'popover was inserted')
$div.find('a').trigger('click')
})
.one('hidden.bs.popover', function () {
assert.strictEqual($('.popover').length, 0, 'popover was removed')
done()
})
$div.find('a').trigger('click')
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) {

View File

@ -16,6 +16,7 @@ $(function () {
afterEach: function () {
$.fn.tooltip = $.fn.bootstrapTooltip
delete $.fn.bootstrapTooltip
$('#qunit-fixture').html('')
}
})
@ -26,7 +27,7 @@ $(function () {
QUnit.test('should return jquery collection containing the element', function (assert) {
assert.expect(2)
var $el = $('<div/>')
var $el = $('<div/>').appendTo('#qunit-fixture')
var $tooltip = $el.bootstrapTooltip()
assert.ok($tooltip instanceof $, 'returns jquery collection')
assert.strictEqual($tooltip[0], $el[0], 'collection contains element')
@ -39,92 +40,132 @@ $(function () {
QUnit.test('should empty title attribute', function (assert) {
assert.expect(1)
var $trigger = $('<a href="#" rel="tooltip" title="Another tooltip"/>').bootstrapTooltip()
var $trigger = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
.appendTo('#qunit-fixture')
.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()
var $trigger = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
.appendTo('#qunit-fixture')
.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 done = assert.async()
var $trigger = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
.bootstrapTooltip()
.appendTo('#qunit-fixture')
$trigger
.bootstrapTooltip()
.on('shown.bs.tooltip', function () {
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')
done()
})
.bootstrapTooltip('show')
var id = $('.tooltip').attr('id')
assert.strictEqual($('#' + id).length, 1, 'has a unique id')
assert.strictEqual($('.tooltip').attr('aria-describedby'), $trigger.attr('id'), 'tooltip id and aria-describedby on trigger match')
assert.ok($trigger[0].hasAttribute('aria-describedby'), 'trigger has aria-describedby')
})
QUnit.test('should remove aria-describedby from trigger on hide', function (assert) {
assert.expect(2)
var done = assert.async()
var $trigger = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
.bootstrapTooltip()
.appendTo('#qunit-fixture')
$trigger.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')
$trigger.one('shown.bs.tooltip', function () {
assert.ok($trigger[0].hasAttribute('aria-describedby'), 'trigger has aria-describedby')
$trigger.bootstrapTooltip('hide')
})
.one('hidden.bs.tooltip', function () {
assert.ok(!$trigger[0].hasAttribute('aria-describedby'), 'trigger does not have aria-describedby')
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should assign a unique id tooltip element', function (assert) {
assert.expect(2)
var done = assert.async()
$('<a href="#" rel="tooltip" title="Another tooltip"/>')
.appendTo('#qunit-fixture')
.on('shown.bs.tooltip', function () {
var id = $('.tooltip').attr('id')
assert.strictEqual($('#' + id).length, 1, 'tooltip has unique id')
assert.strictEqual(id.indexOf('tooltip'), 0, 'tooltip id has prefix')
done()
})
.bootstrapTooltip('show')
var id = $('.tooltip').attr('id')
assert.strictEqual($('#' + id).length, 1, 'tooltip has unique id')
assert.strictEqual(id.indexOf('tooltip'), 0, 'tooltip id has prefix')
})
QUnit.test('should place tooltips relative to placement option', function (assert) {
assert.expect(2)
var done = assert.async()
var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
.appendTo('#qunit-fixture')
.on('shown.bs.tooltip', function () {
assert.ok($('.tooltip').is('.fade.bottom.in'), 'has correct classes applied')
$tooltip.bootstrapTooltip('hide')
})
.on('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed')
done()
})
.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 done = assert.async()
var $tooltip = $('<a href="#" rel="tooltip" title="&lt;b&gt;@fat&lt;/b&gt;"/>')
.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')
$tooltip.one('shown.bs.tooltip', function () {
assert.notEqual($('.tooltip b').length, 0, 'b tag was inserted')
$tooltip.bootstrapTooltip('hide')
})
.one('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed')
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should respect custom classes', function (assert) {
assert.expect(2)
var done = assert.async()
var $tooltip = $('<a href="#" rel="tooltip" title="Another tooltip"/>')
.appendTo('#qunit-fixture')
.bootstrapTooltip({ template: '<div class="tooltip some-class"><div class="tooltip-arrow"/><div class="tooltip-inner"/></div>' })
$tooltip.bootstrapTooltip('show')
assert.ok($('.tooltip').hasClass('some-class'), 'custom class is present')
$tooltip.bootstrapTooltip('hide')
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed')
$tooltip.one('shown.bs.tooltip', function () {
assert.ok($('.tooltip').hasClass('some-class'), 'custom class is present')
$tooltip.bootstrapTooltip('hide')
})
.one('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed')
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should fire show event', function (assert) {
@ -255,6 +296,8 @@ $(function () {
QUnit.test('should show tooltip with delegate selector on click', function (assert) {
assert.expect(2)
var done = assert.async()
var $div = $('<div><a href="#" rel="tooltip" title="Another tooltip"/></div>')
.appendTo('#qunit-fixture')
.bootstrapTooltip({
@ -262,11 +305,16 @@ $(function () {
trigger: 'click'
})
$div.find('a').trigger('click')
assert.ok($('.tooltip').is('.fade.in'), 'tooltip is faded in')
$div.one('shown.bs.tooltip', function () {
assert.ok($('.tooltip').is('.fade.in'), 'tooltip is faded in')
$div.find('a').trigger('click')
})
.one('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip was removed from dom')
done()
})
$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) {
@ -292,16 +340,22 @@ $(function () {
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"/>')
var done = assert.async()
$('<a href="#" rel="tooltip" title="Another tooltip"/>')
.appendTo('#qunit-fixture')
.bootstrapTooltip({ container: 'body' })
.one('shown.bs.tooltip', function () {
assert.notEqual($('body > .tooltip').length, 0, 'tooltip is direct descendant of body')
assert.strictEqual($('#qunit-fixture > .tooltip').length, 0, 'tooltip is not in parent')
$(this).bootstrapTooltip('hide')
})
.one('hidden.bs.tooltip', function () {
assert.strictEqual($('body > .tooltip').length, 0, 'tooltip was removed from dom')
done()
})
.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) {
@ -335,49 +389,68 @@ $(function () {
QUnit.test('should use title attribute for tooltip text', function (assert) {
assert.expect(2)
var $tooltip = $('<a href="#" rel="tooltip" title="Simple tooltip"/>')
var done = assert.async()
$('<a href="#" rel="tooltip" title="Simple tooltip"/>')
.appendTo('#qunit-fixture')
.bootstrapTooltip()
.one('shown.bs.tooltip', function () {
assert.strictEqual($('.tooltip').children('.tooltip-inner').text(), 'Simple tooltip', 'title from title attribute is set')
$tooltip.bootstrapTooltip('show')
assert.strictEqual($('.tooltip').children('.tooltip-inner').text(), 'Simple tooltip', 'title from title attribute is set')
$(this).bootstrapTooltip('hide')
})
.one('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
done()
})
.bootstrapTooltip('show')
$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"/>')
var done = assert.async()
$('<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')
.one('shown.bs.tooltip', function () {
assert.strictEqual($('.tooltip').children('.tooltip-inner').text(), 'Simple tooltip', 'title is set from title attribute while preferred over title option')
$(this).bootstrapTooltip('hide')
})
.one('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should use title option', function (assert) {
assert.expect(2)
var $tooltip = $('<a href="#" rel="tooltip"/>')
var done = assert.async()
$('<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')
.one('shown.bs.tooltip', function () {
assert.strictEqual($('.tooltip').children('.tooltip-inner').text(), 'This is a tooltip with some content', 'title from title option is set')
$(this).bootstrapTooltip('hide')
})
.one('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should be placed dynamically to viewport with the dynamic placement option', function (assert) {
assert.expect(6)
var done = assert.async()
var $style = $('<style> div[rel="tooltip"] { position: absolute; } #qunit-fixture { top: inherit; left: inherit } </style>').appendTo('head')
var $container = $('<div/>')
.css({
@ -390,38 +463,71 @@ $(function () {
.appendTo($container)
.bootstrapTooltip({ placement: 'auto', viewport: '#qunit-fixture' })
$topTooltip.bootstrapTooltip('show')
assert.ok($('.tooltip').is('.bottom'), 'top positioned tooltip is dynamically positioned to bottom')
var topDone = false
var rightDone = false
var leftDone = false
$topTooltip.bootstrapTooltip('hide')
assert.strictEqual($('.tooltip').length, 0, 'top positioned tooltip removed from dom')
function isDone() {
if (topDone && rightDone && leftDone) {
$container.remove()
$style.remove()
done()
}
}
var $rightTooltip = $('<div style="right: 0;" rel="tooltip" title="Right tooltip">Right Dynamic Tooltip</div>')
function leftTooltip() {
var $leftTooltip = $('<div style="left: 0;" rel="tooltip" title="Left tooltip">Left Dynamic Tooltip</div>')
.appendTo($container)
.bootstrapTooltip({ placement: 'auto left', viewport: '#qunit-fixture' })
$leftTooltip
.one('shown.bs.tooltip', function () {
assert.ok($('.tooltip').is('.right'), 'left positioned tooltip is dynamically positioned right')
$leftTooltip.bootstrapTooltip('hide')
})
.one('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'left positioned tooltip removed from dom')
leftDone = true
isDone()
})
.bootstrapTooltip('show')
}
function rightTooltip() {
var $rightTooltip = $('<div style="right: 0;" rel="tooltip" title="Right tooltip">Right Dynamic Tooltip</div>')
.appendTo($container)
.bootstrapTooltip({ placement: 'right auto', viewport: '#qunit-fixture' })
$rightTooltip.bootstrapTooltip('show')
assert.ok($('.tooltip').is('.left'), 'right positioned tooltip is dynamically positioned left')
$rightTooltip
.one('shown.bs.tooltip', function () {
assert.ok($('.tooltip').is('.in'), 'right positioned tooltip is dynamically positioned left')
$rightTooltip.bootstrapTooltip('hide')
})
.one('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'right positioned tooltip removed from dom')
rightDone = true
leftTooltip()
})
.bootstrapTooltip('show')
}
$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', viewport: '#qunit-fixture' })
$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()
$topTooltip
.one('shown.bs.tooltip', function () {
assert.ok($('.tooltip').is('.bottom'), 'top positioned tooltip is dynamically positioned to bottom')
$topTooltip.bootstrapTooltip('hide')
})
.one('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'top positioned tooltip removed from dom')
topDone = true
rightTooltip()
})
.bootstrapTooltip('show')
})
QUnit.test('should position tip on top if viewport has enough space and placement is "auto top"', function (assert) {
assert.expect(2)
var done = assert.async()
var styles = '<style>'
+ 'body { padding-top: 100px; }'
+ '#section { height: 300px; border: 1px solid red; padding-top: 50px }'
@ -437,17 +543,23 @@ $(function () {
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()
$target
.on('shown.bs.tooltip', function () {
assert.ok($('.tooltip').is('.top'), 'top positioned tooltip is dynamically positioned to top')
$target.bootstrapTooltip('hide')
})
.on('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$styles.remove()
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should position tip on top if viewport has enough space and is not parent', function (assert) {
assert.expect(2)
var done = assert.async()
var styles = '<style>'
+ '#section { height: 300px; border: 1px solid red; margin-top: 100px; }'
+ 'div[rel="tooltip"] { width: 150px; border: 1px solid blue; }'
@ -462,17 +574,23 @@ $(function () {
viewport: '#qunit-fixture'
})
$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()
$target
.on('shown.bs.tooltip', function () {
assert.ok($('.tooltip').is('.top'), 'top positioned tooltip is dynamically positioned to top')
$target.bootstrapTooltip('hide')
})
.on('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$styles.remove()
done()
})
.bootstrapTooltip('show')
})
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 done = assert.async()
var styles = '<style>'
+ 'body { padding-top: 100px; }'
+ '#section { height: 300px; border: 1px solid red; }'
@ -488,17 +606,23 @@ $(function () {
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()
$target
.on('shown.bs.tooltip', function () {
assert.ok($('.tooltip').is('.bottom'), 'top positioned tooltip is dynamically positioned to bottom')
$target.bootstrapTooltip('hide')
})
.on('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$styles.remove()
done()
})
.bootstrapTooltip('show')
})
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 done = assert.async()
var styles = '<style>'
+ '#scrollable-div { height: 200px; overflow: auto; }'
+ '.tooltip-item { margin: 200px 0 400px; width: 150px; }'
@ -515,17 +639,23 @@ $(function () {
$('#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()
$target
.on('shown.bs.tooltip', function () {
assert.ok($('.tooltip').is('.fade.top.in'), 'has correct classes applied')
$target.bootstrapTooltip('hide')
})
.on('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$styles.remove()
done()
})
.bootstrapTooltip('show')
})
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 done = assert.async()
var styles = '<style>'
+ '#scrollable-div { height: 200px; overflow: auto; }'
+ '.tooltip-item { padding: 200px 0 400px; width: 150px; }'
@ -542,17 +672,23 @@ $(function () {
$('#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()
$target
.on('shown.bs.tooltip', function () {
assert.ok($('.tooltip').is('.fade.bottom.in'), 'has correct classes applied')
$target.bootstrapTooltip('hide')
})
.on('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$styles.remove()
done()
})
.bootstrapTooltip('show')
})
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 done = assert.async()
var styles = '<style>'
+ '#scrollable-div { height: 200px; overflow: auto; }'
+ '.spacer { height: 400px; }'
@ -573,17 +709,23 @@ $(function () {
$('#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()
$target
.on('shown.bs.tooltip', function () {
assert.ok($('.tooltip').is('.fade.bottom.in'), 'has correct classes applied')
$target.bootstrapTooltip('hide')
})
.on('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$styles.remove()
done()
})
.bootstrapTooltip('show')
})
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 done = assert.async()
var styles = '<style>'
+ '#scrollable-div { height: 200px; overflow: auto; }'
+ '.tooltip-item { margin-top: 400px; width: 150px; }'
@ -600,17 +742,23 @@ $(function () {
$('#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()
$target
.on('shown.bs.tooltip', function () {
assert.ok($('.tooltip').is('.fade.top.in'), 'has correct classes applied')
$target.bootstrapTooltip('hide')
})
.on('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$styles.remove()
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should adjust the tip\'s top position when up against the top of the viewport', function (assert) {
assert.expect(2)
var done = assert.async()
var styles = '<style>'
+ '.tooltip .tooltip-inner { width: 200px; height: 200px; max-width: none; }'
+ 'a[rel="tooltip"] { position: fixed; }'
@ -628,17 +776,23 @@ $(function () {
}
})
$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()
$target
.on('shown.bs.tooltip', function () {
assert.strictEqual(Math.round($container.find('.tooltip').offset().top), 12)
$target.bootstrapTooltip('hide')
})
.on('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$styles.remove()
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should adjust the tip\'s top position when up against the bottom of the viewport', function (assert) {
assert.expect(2)
var done = assert.async()
var styles = '<style>'
+ '.tooltip .tooltip-inner { width: 200px; height: 200px; max-width: none; }'
+ 'a[rel="tooltip"] { position: fixed; }'
@ -656,19 +810,31 @@ $(function () {
}
})
$target.bootstrapTooltip('show')
var $tooltip = $container.find('.tooltip')
assert.strictEqual(Math.round($tooltip.offset().top), Math.round($(window).height() - 12 - $tooltip[0].offsetHeight))
$target
.on('shown.bs.tooltip', function () {
var $tooltip = $container.find('.tooltip')
var padding = 50
var result = Math.round($tooltip.offset().top)
var resultMax = result + padding
var resultMin = result - padding
var expected = Math.round($(window).height() - 12 - $tooltip[0].offsetHeight)
$target.bootstrapTooltip('hide')
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$container.remove()
$styles.remove()
assert.ok(expected < resultMax && expected > resultMin)
$target.bootstrapTooltip('hide')
})
.on('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$container.remove()
$styles.remove()
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should adjust the tip\'s left position when up against the left of the viewport', function (assert) {
assert.expect(2)
var done = assert.async()
var styles = '<style>'
+ '.tooltip .tooltip-inner { width: 200px; height: 200px; max-width: none; }'
+ 'a[rel="tooltip"] { position: fixed; }'
@ -686,18 +852,24 @@ $(function () {
}
})
$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()
$target
.on('shown.bs.tooltip', function () {
assert.strictEqual(Math.round($container.find('.tooltip').offset().left), 12)
$target.bootstrapTooltip('hide')
})
.on('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$container.remove()
$styles.remove()
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should adjust the tip\'s left position when up against the right of the viewport', function (assert) {
assert.expect(2)
var done = assert.async()
var styles = '<style>'
+ '.tooltip .tooltip-inner { width: 200px; height: 200px; max-width: none; }'
+ 'a[rel="tooltip"] { position: fixed; }'
@ -715,19 +887,25 @@ $(function () {
}
})
$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()
$target
.on('shown.bs.tooltip', function () {
var $tooltip = $container.find('.tooltip')
assert.strictEqual(Math.round($tooltip.offset().left), Math.round($(window).width() - 12 - $tooltip[0].offsetWidth))
$target.bootstrapTooltip('hide')
})
.on('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$container.remove()
$styles.remove()
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should adjust the tip when up against the right of an arbitrary viewport', function (assert) {
assert.expect(2)
var done = assert.async()
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; }'
@ -743,19 +921,25 @@ $(function () {
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()
$target
.on('shown.bs.tooltip', function () {
var $tooltip = $container.find('.tooltip')
assert.strictEqual(Math.round($tooltip.offset().left), Math.round(60 + $container.width() - $tooltip[0].offsetWidth))
$target.bootstrapTooltip('hide')
})
.on('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$container.remove()
$styles.remove()
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should get viewport element from function', function (assert) {
assert.expect(3)
var done = assert.async()
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; }'
@ -774,19 +958,25 @@ $(function () {
}
})
$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()
$target
.on('shown.bs.tooltip', function () {
var $tooltip = $container.find('.tooltip')
assert.strictEqual(Math.round($tooltip.offset().left), Math.round(60 + $container.width() - $tooltip[0].offsetWidth))
$target.bootstrapTooltip('hide')
})
.on('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$container.remove()
$styles.remove()
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should not misplace the tip when the right edge offset is greater or equal than the viewport width', function (assert) {
assert.expect(2)
var done = assert.async()
var styles = '<style>'
+ '.tooltip, .tooltip *, .tooltip *:before, .tooltip *:after { box-sizing: border-box; }'
+ '.container-viewport, .container-viewport *, .container-viewport *:before, .container-viewport *:after { box-sizing: border-box; }'
@ -802,15 +992,21 @@ $(function () {
viewport: '.container-viewport'
})
$target.bootstrapTooltip('show')
var $tooltip = $container.find('.tooltip')
assert.strictEqual(Math.round($tooltip.offset().left), Math.round($target.position().left + $target.width() / 2 - $tooltip[0].offsetWidth / 2))
$target.bootstrapTooltip('hide')
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$container.remove()
$styles.remove()
$target
.on('shown.bs.tooltip', function () {
var $tooltip = $container.find('.tooltip')
var expected = Math.round($target.position().left + $target.width() / 2 - $tooltip[0].offsetWidth / 2)
var result = Math.round($tooltip.offset().left)
assert.ok(result === (expected - 1) || result === expected)
$target.bootstrapTooltip('hide')
})
.on('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
$container.remove()
$styles.remove()
done()
})
.bootstrapTooltip('show')
})
QUnit.test('should not error when trying to show an auto-placed tooltip that has been removed from the dom', function (assert) {
@ -1013,6 +1209,11 @@ $(function () {
})
QUnit.test('should wait 200ms before hiding the tooltip', function (assert) {
if (window.__karma__) {
assert.expect(0)
return
}
assert.expect(3)
var done = assert.async()
@ -1070,6 +1271,9 @@ $(function () {
$styles.remove()
assert.ok(Math.abs(offset.left - 88) <= 1, 'tooltip has correct horizontal location')
$circle.bootstrapTooltip('hide')
})
.on('hidden.bs.tooltip', function () {
assert.strictEqual($('.tooltip').length, 0, 'tooltip removed from dom')
done()
})
@ -1218,10 +1422,11 @@ $(function () {
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)) {
if ((!('transform' in styleProps) && !('webkitTransform' in styleProps) && !('msTransform' in styleProps)) || window.__karma__) {
assert.expect(0)
return
}
assert.expect(2)
var done = assert.async()

View File

@ -1,305 +0,0 @@
/*!
* QUnit 1.22.0
* https://qunitjs.com/
*
* Copyright jQuery Foundation and other contributors
* Released under the MIT license
* https://jquery.org/license
*
* Date: 2016-02-23T15:57Z
*/
/** Font Family and Sizes */
#qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-filteredTest, #qunit-userAgent, #qunit-testresult {
font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial, sans-serif;
}
#qunit-testrunner-toolbar, #qunit-filteredTest, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; }
#qunit-tests { font-size: smaller; }
/** Resets */
#qunit-tests, #qunit-header, #qunit-banner, #qunit-filteredTest, #qunit-userAgent, #qunit-testresult, #qunit-modulefilter {
margin: 0;
padding: 0;
}
/** Header */
#qunit-header {
padding: 0.5em 0 0.5em 1em;
color: #8699A4;
background-color: #0D3349;
font-size: 1.5em;
line-height: 1em;
font-weight: 400;
border-radius: 5px 5px 0 0;
}
#qunit-header a {
text-decoration: none;
color: #C2CCD1;
}
#qunit-header a:hover,
#qunit-header a:focus {
color: #FFF;
}
#qunit-testrunner-toolbar label {
display: inline-block;
padding: 0 0.5em 0 0.1em;
}
#qunit-banner {
height: 5px;
}
#qunit-testrunner-toolbar {
padding: 0.5em 1em 0.5em 1em;
color: #5E740B;
background-color: #EEE;
overflow: hidden;
}
#qunit-filteredTest {
padding: 0.5em 1em 0.5em 1em;
background-color: #F4FF77;
color: #366097;
}
#qunit-userAgent {
padding: 0.5em 1em 0.5em 1em;
background-color: #2B81AF;
color: #FFF;
text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px;
}
#qunit-modulefilter-container {
float: right;
padding: 0.2em;
}
.qunit-url-config {
display: inline-block;
padding: 0.1em;
}
.qunit-filter {
display: block;
float: right;
margin-left: 1em;
}
/** Tests: Pass/Fail */
#qunit-tests {
list-style-position: inside;
}
#qunit-tests li {
padding: 0.4em 1em 0.4em 1em;
border-bottom: 1px solid #FFF;
list-style-position: inside;
}
#qunit-tests > li {
display: none;
}
#qunit-tests li.running,
#qunit-tests li.pass,
#qunit-tests li.fail,
#qunit-tests li.skipped {
display: list-item;
}
#qunit-tests.hidepass {
position: relative;
}
#qunit-tests.hidepass li.running,
#qunit-tests.hidepass li.pass {
visibility: hidden;
position: absolute;
width: 0;
height: 0;
padding: 0;
border: 0;
margin: 0;
}
#qunit-tests li strong {
cursor: pointer;
}
#qunit-tests li.skipped strong {
cursor: default;
}
#qunit-tests li a {
padding: 0.5em;
color: #C2CCD1;
text-decoration: none;
}
#qunit-tests li p a {
padding: 0.25em;
color: #6B6464;
}
#qunit-tests li a:hover,
#qunit-tests li a:focus {
color: #000;
}
#qunit-tests li .runtime {
float: right;
font-size: smaller;
}
.qunit-assert-list {
margin-top: 0.5em;
padding: 0.5em;
background-color: #FFF;
border-radius: 5px;
}
.qunit-source {
margin: 0.6em 0 0.3em;
}
.qunit-collapsed {
display: none;
}
#qunit-tests table {
border-collapse: collapse;
margin-top: 0.2em;
}
#qunit-tests th {
text-align: right;
vertical-align: top;
padding: 0 0.5em 0 0;
}
#qunit-tests td {
vertical-align: top;
}
#qunit-tests pre {
margin: 0;
white-space: pre-wrap;
word-wrap: break-word;
}
#qunit-tests del {
background-color: #E0F2BE;
color: #374E0C;
text-decoration: none;
}
#qunit-tests ins {
background-color: #FFCACA;
color: #500;
text-decoration: none;
}
/*** Test Counts */
#qunit-tests b.counts { color: #000; }
#qunit-tests b.passed { color: #5E740B; }
#qunit-tests b.failed { color: #710909; }
#qunit-tests li li {
padding: 5px;
background-color: #FFF;
border-bottom: none;
list-style-position: inside;
}
/*** Passing Styles */
#qunit-tests li li.pass {
color: #3C510C;
background-color: #FFF;
border-left: 10px solid #C6E746;
}
#qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; }
#qunit-tests .pass .test-name { color: #366097; }
#qunit-tests .pass .test-actual,
#qunit-tests .pass .test-expected { color: #999; }
#qunit-banner.qunit-pass { background-color: #C6E746; }
/*** Failing Styles */
#qunit-tests li li.fail {
color: #710909;
background-color: #FFF;
border-left: 10px solid #EE5757;
white-space: pre;
}
#qunit-tests > li:last-child {
border-radius: 0 0 5px 5px;
}
#qunit-tests .fail { color: #000; background-color: #EE5757; }
#qunit-tests .fail .test-name,
#qunit-tests .fail .module-name { color: #000; }
#qunit-tests .fail .test-actual { color: #EE5757; }
#qunit-tests .fail .test-expected { color: #008000; }
#qunit-banner.qunit-fail { background-color: #EE5757; }
/*** Skipped tests */
#qunit-tests .skipped {
background-color: #EBECE9;
}
#qunit-tests .qunit-skipped-label {
background-color: #F4FF77;
display: inline-block;
font-style: normal;
color: #366097;
line-height: 1.8em;
padding: 0 0.5em;
margin: -0.4em 0.4em -0.4em 0;
}
/** Result */
#qunit-testresult {
padding: 0.5em 1em 0.5em 1em;
color: #2B81AF;
background-color: #D2E0E6;
border-bottom: 1px solid #FFF;
}
#qunit-testresult .module-name {
font-weight: 700;
}
/** Fixture */
#qunit-fixture {
position: absolute;
top: -10000px;
left: -10000px;
width: 1000px;
height: 1000px;
}

4204
js/tests/vendor/qunit.js vendored

File diff suppressed because it is too large Load Diff

View File

@ -31,6 +31,7 @@
"license": "MIT",
"devDependencies": {
"btoa": "~1.2.1",
"cross-env": "^5.2.0",
"glob": "~7.1.2",
"grunt": "~1.0.1",
"grunt-autoprefixer": "~3.0.4",
@ -44,17 +45,23 @@
"grunt-contrib-jshint": "~1.1.0",
"grunt-contrib-less": "~1.4.1",
"grunt-contrib-pug": "~1.0.0",
"grunt-contrib-qunit": "~2.0.0",
"grunt-contrib-uglify": "~3.3.0",
"grunt-contrib-watch": "~1.0.0",
"grunt-exec": "~3.0.0",
"grunt-html": "~9.0.0",
"grunt-jekyll": "~0.4.4",
"grunt-jscs": "~3.0.1",
"grunt-saucelabs": "~9.0.0",
"grunt-stylelint": "^0.10.0",
"ip": "^1.1.5",
"karma": "^3.0.0",
"karma-browserstack-launcher": "^1.3.0",
"karma-chrome-launcher": "^2.2.0",
"karma-detect-browsers": "^2.3.3",
"karma-firefox-launcher": "^1.1.0",
"karma-qunit": "^1.2.1",
"load-grunt-tasks": "~3.5.0",
"markdown-it": "^8.4.0",
"qunitjs": "^1.23.1",
"shelljs": "^0.8.1",
"shx": "^0.2.2",
"stylelint": "^9.2.0",