Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/bootstrap.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'js/tests/unit/popover.js')
-rw-r--r--js/tests/unit/popover.js35
1 files changed, 31 insertions, 4 deletions
diff --git a/js/tests/unit/popover.js b/js/tests/unit/popover.js
index d2cdadd752..2cbc701387 100644
--- a/js/tests/unit/popover.js
+++ b/js/tests/unit/popover.js
@@ -4,6 +4,7 @@ $(function () {
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')
})
@@ -19,10 +20,12 @@ $(function () {
})
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')
@@ -30,6 +33,7 @@ $(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')
@@ -40,12 +44,14 @@ $(function () {
})
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()
@@ -56,6 +62,7 @@ $(function () {
})
QUnit.test('should get title and content from options', function (assert) {
+ assert.expect(4)
var $popover = $('<a href="#">@fat</a>')
.appendTo('#qunit-fixture')
.bootstrapPopover({
@@ -78,6 +85,7 @@ $(function () {
})
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>')
@@ -104,6 +112,7 @@ $(function () {
})
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()
@@ -119,6 +128,7 @@ $(function () {
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({
@@ -136,6 +146,7 @@ $(function () {
})
QUnit.test('should respect custom template', function (assert) {
+ assert.expect(3)
var $popover = $('<a href="#">@fat</a>')
.appendTo('#qunit-fixture')
.bootstrapPopover({
@@ -154,6 +165,7 @@ $(function () {
})
QUnit.test('should destroy popover', function (assert) {
+ assert.expect(7)
var $popover = $('<div/>')
.bootstrapPopover({
trigger: 'hover'
@@ -174,6 +186,7 @@ $(function () {
})
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({
@@ -181,18 +194,19 @@ $(function () {
trigger: 'click'
})
- $div.find('a').click()
+ $div.find('a').trigger('click')
assert.notEqual($('.popover').length, 0, 'popover was inserted')
- $div.find('a').click()
+ $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').click(function () {
+ $('.content-with-handler .btn').on('click', function () {
handlerCalled = true
})
@@ -214,7 +228,7 @@ $(function () {
.one('hidden.bs.popover', function () {
$div
.one('shown.bs.popover', function () {
- $('.content-with-handler .btn').click()
+ $('.content-with-handler .btn').trigger('click')
$div.bootstrapPopover('destroy')
assert.ok(handlerCalled, 'content\'s event handler still present')
done()
@@ -227,9 +241,22 @@ $(function () {
})
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')
+ })
+
})