2011-12-21 03:02:47 +01:00
|
|
|
$(function () {
|
2016-11-21 15:36:00 +01:00
|
|
|
'use strict'
|
2011-12-21 03:02:47 +01:00
|
|
|
|
2015-02-24 07:04:48 +01:00
|
|
|
QUnit.module('tabs plugin')
|
2012-12-07 23:06:01 +01:00
|
|
|
|
2015-02-24 07:04:48 +01:00
|
|
|
QUnit.test('should be defined on jquery object', function (assert) {
|
2015-03-01 15:33:48 +01:00
|
|
|
assert.expect(1)
|
2015-02-24 06:55:07 +01:00
|
|
|
assert.ok($(document.body).tab, 'tabs method is defined')
|
2014-02-13 08:55:12 +01:00
|
|
|
})
|
2011-12-21 03:02:47 +01:00
|
|
|
|
2015-02-24 07:04:48 +01:00
|
|
|
QUnit.module('tabs', {
|
2015-02-26 08:20:42 +01:00
|
|
|
beforeEach: function () {
|
2014-04-22 07:03:33 +02:00
|
|
|
// 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()
|
|
|
|
},
|
2015-02-26 08:20:42 +01:00
|
|
|
afterEach: function () {
|
2014-04-22 07:03:33 +02:00
|
|
|
$.fn.tab = $.fn.bootstrapTab
|
|
|
|
delete $.fn.bootstrapTab
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2015-02-24 07:04:48 +01:00
|
|
|
QUnit.test('should provide no conflict', function (assert) {
|
2015-03-01 15:33:48 +01:00
|
|
|
assert.expect(1)
|
2017-07-27 12:39:55 +02:00
|
|
|
assert.strictEqual(typeof $.fn.tab, 'undefined', 'tab was set back to undefined (org value)')
|
2014-04-22 07:03:33 +02:00
|
|
|
})
|
|
|
|
|
2015-09-16 10:35:29 +02:00
|
|
|
QUnit.test('should throw explicit error on undefined method', function (assert) {
|
|
|
|
assert.expect(1)
|
|
|
|
var $el = $('<div/>')
|
|
|
|
$el.bootstrapTab()
|
|
|
|
try {
|
|
|
|
$el.bootstrapTab('noMethod')
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
assert.strictEqual(err.message, 'No method named "noMethod"')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2015-02-24 07:04:48 +01:00
|
|
|
QUnit.test('should return jquery collection containing the element', function (assert) {
|
2015-03-01 15:33:48 +01:00
|
|
|
assert.expect(2)
|
2014-06-18 21:34:53 +02:00
|
|
|
var $el = $('<div/>')
|
|
|
|
var $tab = $el.bootstrapTab()
|
2015-02-24 06:55:07 +01:00
|
|
|
assert.ok($tab instanceof $, 'returns jquery collection')
|
|
|
|
assert.strictEqual($tab[0], $el[0], 'collection contains element')
|
2014-02-13 08:55:12 +01:00
|
|
|
})
|
2011-12-21 03:02:47 +01:00
|
|
|
|
2015-02-24 07:04:48 +01:00
|
|
|
QUnit.test('should activate element by tab id', function (assert) {
|
2015-03-01 15:33:48 +01:00
|
|
|
assert.expect(2)
|
2017-04-02 11:21:04 +02:00
|
|
|
var tabsHTML = '<ul class="nav">'
|
2014-07-06 11:56:12 +02:00
|
|
|
+ '<li><a href="#home">Home</a></li>'
|
|
|
|
+ '<li><a href="#profile">Profile</a></li>'
|
|
|
|
+ '</ul>'
|
2011-12-21 03:02:47 +01:00
|
|
|
|
2014-06-18 21:34:53 +02:00
|
|
|
$('<ul><li id="home"/><li id="profile"/></ul>').appendTo('#qunit-fixture')
|
2011-12-21 03:02:47 +01:00
|
|
|
|
2014-04-22 07:03:33 +02:00
|
|
|
$(tabsHTML).find('li:last a').bootstrapTab('show')
|
2015-02-24 07:41:08 +01:00
|
|
|
assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'profile')
|
2011-12-21 03:02:47 +01:00
|
|
|
|
2014-04-22 07:03:33 +02:00
|
|
|
$(tabsHTML).find('li:first a').bootstrapTab('show')
|
2015-02-24 07:41:08 +01:00
|
|
|
assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'home')
|
2014-02-13 08:55:12 +01:00
|
|
|
})
|
2011-12-21 03:02:47 +01:00
|
|
|
|
2015-02-24 07:04:48 +01:00
|
|
|
QUnit.test('should activate element by tab id', function (assert) {
|
2015-03-01 15:33:48 +01:00
|
|
|
assert.expect(2)
|
2017-04-02 11:21:04 +02:00
|
|
|
var pillsHTML = '<ul class="nav nav-pills">'
|
2014-07-06 11:56:12 +02:00
|
|
|
+ '<li><a href="#home">Home</a></li>'
|
|
|
|
+ '<li><a href="#profile">Profile</a></li>'
|
|
|
|
+ '</ul>'
|
2011-12-21 03:02:47 +01:00
|
|
|
|
2014-06-18 21:34:53 +02:00
|
|
|
$('<ul><li id="home"/><li id="profile"/></ul>').appendTo('#qunit-fixture')
|
2011-12-21 03:02:47 +01:00
|
|
|
|
2014-04-22 07:03:33 +02:00
|
|
|
$(pillsHTML).find('li:last a').bootstrapTab('show')
|
2015-02-24 07:41:08 +01:00
|
|
|
assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'profile')
|
2011-12-21 03:02:47 +01:00
|
|
|
|
2014-04-22 07:03:33 +02:00
|
|
|
$(pillsHTML).find('li:first a').bootstrapTab('show')
|
2015-02-24 07:41:08 +01:00
|
|
|
assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'home')
|
2014-02-13 08:55:12 +01:00
|
|
|
})
|
2011-12-21 03:02:47 +01:00
|
|
|
|
2016-08-05 01:57:08 +02:00
|
|
|
QUnit.test('should activate element by tab id in ordered list', function (assert) {
|
|
|
|
assert.expect(2)
|
2017-04-02 11:21:04 +02:00
|
|
|
var pillsHTML = '<ol class="nav nav-pills">'
|
2016-08-05 01:57:08 +02:00
|
|
|
+ '<li><a href="#home">Home</a></li>'
|
|
|
|
+ '<li><a href="#profile">Profile</a></li>'
|
|
|
|
+ '</ol>'
|
|
|
|
|
|
|
|
$('<ol><li id="home"/><li id="profile"/></ol>').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')
|
|
|
|
})
|
|
|
|
|
2016-12-28 11:58:50 +01:00
|
|
|
QUnit.test('should activate element by tab id in nav list', function (assert) {
|
|
|
|
assert.expect(2)
|
|
|
|
var tabsHTML = '<nav class="nav">' +
|
|
|
|
'<a href="#home">Home</a>' +
|
|
|
|
'<a href="#profile">Profile</a>' +
|
|
|
|
'</nav>'
|
|
|
|
|
|
|
|
$('<nav><div id="home"></div><div id="profile"></div></nav>').appendTo('#qunit-fixture')
|
|
|
|
|
|
|
|
$(tabsHTML).find('a:last').bootstrapTab('show')
|
|
|
|
assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'profile')
|
|
|
|
|
|
|
|
$(tabsHTML).find('a:first').bootstrapTab('show')
|
|
|
|
assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'home')
|
|
|
|
})
|
|
|
|
|
2017-04-02 11:21:04 +02:00
|
|
|
QUnit.test('should activate element by tab id in list group', function (assert) {
|
2017-03-19 00:36:33 +01:00
|
|
|
assert.expect(2)
|
2017-04-02 11:21:04 +02:00
|
|
|
var tabsHTML = '<div class="list-group">' +
|
|
|
|
'<a href="#home">Home</a>' +
|
|
|
|
'<a href="#profile">Profile</a>' +
|
|
|
|
'</div>'
|
2017-03-19 00:36:33 +01:00
|
|
|
|
2017-04-02 11:21:04 +02:00
|
|
|
$('<nav><div id="home"></div><div id="profile"></div></nav>').appendTo('#qunit-fixture')
|
2017-03-19 00:36:33 +01:00
|
|
|
|
2017-04-02 11:21:04 +02:00
|
|
|
$(tabsHTML).find('a:last').bootstrapTab('show')
|
2017-03-19 00:36:33 +01:00
|
|
|
assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'profile')
|
|
|
|
|
2017-04-02 11:21:04 +02:00
|
|
|
$(tabsHTML).find('a:first').bootstrapTab('show')
|
2017-03-19 00:36:33 +01:00
|
|
|
assert.strictEqual($('#qunit-fixture').find('.active').attr('id'), 'home')
|
|
|
|
})
|
|
|
|
|
2015-02-24 07:04:48 +01:00
|
|
|
QUnit.test('should not fire shown when show is prevented', function (assert) {
|
2015-03-01 15:33:48 +01:00
|
|
|
assert.expect(1)
|
2015-01-21 04:40:50 +01:00
|
|
|
var done = assert.async()
|
2014-06-18 21:34:53 +02:00
|
|
|
|
2017-04-02 11:21:04 +02:00
|
|
|
$('<div class="nav"/>')
|
2014-02-13 08:55:12 +01:00
|
|
|
.on('show.bs.tab', function (e) {
|
2014-02-17 20:56:46 +01:00
|
|
|
e.preventDefault()
|
2015-02-24 06:55:07 +01:00
|
|
|
assert.ok(true, 'show event fired')
|
2015-01-21 04:40:50 +01:00
|
|
|
done()
|
2012-03-25 03:20:09 +02:00
|
|
|
})
|
2014-02-13 08:55:12 +01:00
|
|
|
.on('shown.bs.tab', function () {
|
2015-02-24 06:55:07 +01:00
|
|
|
assert.ok(false, 'shown event fired')
|
2014-02-13 08:55:12 +01:00
|
|
|
})
|
2014-04-22 07:03:33 +02:00
|
|
|
.bootstrapTab('show')
|
2014-02-13 08:55:12 +01:00
|
|
|
})
|
|
|
|
|
2016-12-25 08:31:34 +01:00
|
|
|
QUnit.test('should not fire shown when tab is already active', function (assert) {
|
|
|
|
assert.expect(0)
|
|
|
|
var tabsHTML = '<ul class="nav nav-tabs" role="tablist">'
|
|
|
|
+ '<li class="nav-item"><a href="#home" class="nav-link active" role="tab">Home</a></li>'
|
|
|
|
+ '<li class="nav-item"><a href="#profile" class="nav-link" role="tab">Profile</a></li>'
|
|
|
|
+ '</ul>'
|
|
|
|
+ '<div class="tab-content">'
|
|
|
|
+ '<div class="tab-pane active" id="home" role="tabpanel"></div>'
|
|
|
|
+ '<div class="tab-pane" id="profile" role="tabpanel"></div>'
|
|
|
|
+ '</div>'
|
|
|
|
|
|
|
|
$(tabsHTML)
|
|
|
|
.find('a.active')
|
|
|
|
.on('shown.bs.tab', function () {
|
|
|
|
assert.ok(true, 'shown event fired')
|
|
|
|
})
|
|
|
|
.bootstrapTab('show')
|
|
|
|
})
|
|
|
|
|
|
|
|
QUnit.test('should not fire shown when tab is disabled', function (assert) {
|
|
|
|
assert.expect(0)
|
|
|
|
var tabsHTML = '<ul class="nav nav-tabs" role="tablist">'
|
|
|
|
+ '<li class="nav-item"><a href="#home" class="nav-link active" role="tab">Home</a></li>'
|
|
|
|
+ '<li class="nav-item"><a href="#profile" class="nav-link disabled" role="tab">Profile</a></li>'
|
|
|
|
+ '</ul>'
|
|
|
|
+ '<div class="tab-content">'
|
|
|
|
+ '<div class="tab-pane active" id="home" role="tabpanel"></div>'
|
|
|
|
+ '<div class="tab-pane" id="profile" role="tabpanel"></div>'
|
|
|
|
+ '</div>'
|
|
|
|
|
|
|
|
$(tabsHTML)
|
|
|
|
.find('a.disabled')
|
|
|
|
.on('shown.bs.tab', function () {
|
|
|
|
assert.ok(true, 'shown event fired')
|
|
|
|
})
|
|
|
|
.bootstrapTab('show')
|
|
|
|
})
|
|
|
|
|
2015-02-24 07:04:48 +01:00
|
|
|
QUnit.test('show and shown events should reference correct relatedTarget', function (assert) {
|
2015-03-01 15:33:48 +01:00
|
|
|
assert.expect(2)
|
2015-01-21 04:40:50 +01:00
|
|
|
var done = assert.async()
|
2014-06-18 21:34:53 +02:00
|
|
|
|
2017-07-18 14:22:39 +02:00
|
|
|
var dropHTML =
|
|
|
|
'<ul class="drop nav">'
|
|
|
|
+ ' <li class="dropdown"><a data-toggle="dropdown" href="#">1</a>'
|
|
|
|
+ ' <ul class="dropdown-menu nav">'
|
|
|
|
+ ' <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>'
|
2014-07-06 11:56:12 +02:00
|
|
|
+ '</ul>'
|
2014-02-13 08:55:12 +01:00
|
|
|
|
2014-06-18 21:34:53 +02:00
|
|
|
$(dropHTML)
|
|
|
|
.find('ul > li:first a')
|
|
|
|
.bootstrapTab('show')
|
|
|
|
.end()
|
|
|
|
.find('ul > li:last a')
|
|
|
|
.on('show.bs.tab', function (e) {
|
2015-02-24 07:41:08 +01:00
|
|
|
assert.strictEqual(e.relatedTarget.hash, '#1-1', 'references correct element as relatedTarget')
|
2014-06-18 21:34:53 +02:00
|
|
|
})
|
|
|
|
.on('shown.bs.tab', function (e) {
|
2015-02-24 07:41:08 +01:00
|
|
|
assert.strictEqual(e.relatedTarget.hash, '#1-1', 'references correct element as relatedTarget')
|
2015-01-21 05:16:42 +01:00
|
|
|
done()
|
2014-06-18 21:34:53 +02:00
|
|
|
})
|
|
|
|
.bootstrapTab('show')
|
2014-02-13 08:55:12 +01:00
|
|
|
})
|
2012-10-09 07:29:44 +02:00
|
|
|
|
2015-02-24 07:04:48 +01:00
|
|
|
QUnit.test('should fire hide and hidden events', function (assert) {
|
2015-03-01 15:33:48 +01:00
|
|
|
assert.expect(2)
|
2015-01-21 04:40:50 +01:00
|
|
|
var done = assert.async()
|
2014-10-10 16:50:00 +02:00
|
|
|
|
2017-04-02 11:21:04 +02:00
|
|
|
var tabsHTML = '<ul class="nav">'
|
2014-10-10 16:50:00 +02:00
|
|
|
+ '<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 () {
|
2015-02-24 06:55:07 +01:00
|
|
|
assert.ok(true, 'hide event fired')
|
2014-10-10 16:50:00 +02:00
|
|
|
})
|
|
|
|
.bootstrapTab('show')
|
|
|
|
.end()
|
|
|
|
.find('li:last a')
|
|
|
|
.bootstrapTab('show')
|
|
|
|
|
|
|
|
$(tabsHTML)
|
|
|
|
.find('li:first a')
|
|
|
|
.on('hidden.bs.tab', function () {
|
2015-02-24 06:55:07 +01:00
|
|
|
assert.ok(true, 'hidden event fired')
|
2015-01-21 04:40:50 +01:00
|
|
|
done()
|
2014-10-10 16:50:00 +02:00
|
|
|
})
|
|
|
|
.bootstrapTab('show')
|
|
|
|
.end()
|
|
|
|
.find('li:last a')
|
|
|
|
.bootstrapTab('show')
|
|
|
|
})
|
|
|
|
|
2015-02-24 07:04:48 +01:00
|
|
|
QUnit.test('should not fire hidden when hide is prevented', function (assert) {
|
2015-03-01 15:33:48 +01:00
|
|
|
assert.expect(1)
|
2015-01-21 04:40:50 +01:00
|
|
|
var done = assert.async()
|
2014-10-10 16:50:00 +02:00
|
|
|
|
2017-04-02 11:21:04 +02:00
|
|
|
var tabsHTML = '<ul class="nav">'
|
2014-10-10 16:50:00 +02:00
|
|
|
+ '<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()
|
2015-02-24 06:55:07 +01:00
|
|
|
assert.ok(true, 'hide event fired')
|
2015-01-21 04:40:50 +01:00
|
|
|
done()
|
2014-10-10 16:50:00 +02:00
|
|
|
})
|
|
|
|
.on('hidden.bs.tab', function () {
|
2015-02-24 06:55:07 +01:00
|
|
|
assert.ok(false, 'hidden event fired')
|
2014-10-10 16:50:00 +02:00
|
|
|
})
|
|
|
|
.bootstrapTab('show')
|
|
|
|
.end()
|
|
|
|
.find('li:last a')
|
|
|
|
.bootstrapTab('show')
|
|
|
|
})
|
|
|
|
|
2015-02-24 07:04:48 +01:00
|
|
|
QUnit.test('hide and hidden events contain correct relatedTarget', function (assert) {
|
2015-03-01 15:33:48 +01:00
|
|
|
assert.expect(2)
|
2015-01-21 04:40:50 +01:00
|
|
|
var done = assert.async()
|
2014-10-10 16:50:00 +02:00
|
|
|
|
2017-04-02 11:21:04 +02:00
|
|
|
var tabsHTML = '<ul class="nav">'
|
2014-10-10 16:50:00 +02:00
|
|
|
+ '<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) {
|
2015-02-24 07:41:08 +01:00
|
|
|
assert.strictEqual(e.relatedTarget.hash, '#profile', 'references correct element as relatedTarget')
|
2014-10-10 16:50:00 +02:00
|
|
|
})
|
|
|
|
.on('hidden.bs.tab', function (e) {
|
2015-02-24 07:41:08 +01:00
|
|
|
assert.strictEqual(e.relatedTarget.hash, '#profile', 'references correct element as relatedTarget')
|
2015-01-21 04:40:50 +01:00
|
|
|
done()
|
2014-10-10 16:50:00 +02:00
|
|
|
})
|
|
|
|
.bootstrapTab('show')
|
|
|
|
.end()
|
|
|
|
.find('li:last a')
|
|
|
|
.bootstrapTab('show')
|
|
|
|
})
|
|
|
|
|
2017-09-24 12:00:54 +02:00
|
|
|
QUnit.test('selected tab should have aria-selected', function (assert) {
|
2015-03-01 15:33:48 +01:00
|
|
|
assert.expect(8)
|
2014-09-09 18:17:56 +02:00
|
|
|
var tabsHTML = '<ul class="nav nav-tabs">'
|
2017-09-24 12:00:54 +02:00
|
|
|
+ '<li><a class="nav-item active" href="#home" toggle="tab" aria-selected="true">Home</a></li>'
|
|
|
|
+ '<li><a class="nav-item" href="#profile" toggle="tab" aria-selected="false">Profile</a></li>'
|
2014-09-09 18:17:56 +02:00
|
|
|
+ '</ul>'
|
|
|
|
var $tabs = $(tabsHTML).appendTo('#qunit-fixture')
|
|
|
|
|
|
|
|
$tabs.find('li:first a').bootstrapTab('show')
|
2017-09-24 12:00:54 +02:00
|
|
|
assert.strictEqual($tabs.find('.active').attr('aria-selected'), 'true', 'shown tab has aria-selected = true')
|
|
|
|
assert.strictEqual($tabs.find('a:not(.active)').attr('aria-selected'), 'false', 'hidden tab has aria-selected = false')
|
2014-09-09 18:17:56 +02:00
|
|
|
|
2015-03-06 13:34:28 +01:00
|
|
|
$tabs.find('li:last a').trigger('click')
|
2017-09-24 12:00:54 +02:00
|
|
|
assert.strictEqual($tabs.find('.active').attr('aria-selected'), 'true', 'after click, shown tab has aria-selected = true')
|
|
|
|
assert.strictEqual($tabs.find('a:not(.active)').attr('aria-selected'), 'false', 'after click, hidden tab has aria-selected = false')
|
2014-09-09 18:17:56 +02:00
|
|
|
|
|
|
|
$tabs.find('li:first a').bootstrapTab('show')
|
2017-09-24 12:00:54 +02:00
|
|
|
assert.strictEqual($tabs.find('.active').attr('aria-selected'), 'true', 'shown tab has aria-selected = true')
|
|
|
|
assert.strictEqual($tabs.find('a:not(.active)').attr('aria-selected'), 'false', 'hidden tab has aria-selected = false')
|
2014-09-09 18:17:56 +02:00
|
|
|
|
2015-03-06 13:34:28 +01:00
|
|
|
$tabs.find('li:first a').trigger('click')
|
2017-09-24 12:00:54 +02:00
|
|
|
assert.strictEqual($tabs.find('.active').attr('aria-selected'), 'true', 'after second show event, shown tab still has aria-selected = true')
|
|
|
|
assert.strictEqual($tabs.find('a:not(.active)').attr('aria-selected'), 'false', 'after second show event, hidden tab has aria-selected = false')
|
2014-09-09 18:17:56 +02:00
|
|
|
})
|
|
|
|
|
2016-11-25 23:56:41 +01:00
|
|
|
QUnit.test('selected tab should deactivate previous selected tab', function (assert) {
|
|
|
|
assert.expect(2)
|
|
|
|
var tabsHTML = '<ul class="nav nav-tabs">'
|
|
|
|
+ '<li class="nav-item"><a class="nav-link active" href="#home" data-toggle="tab">Home</a></li>'
|
|
|
|
+ '<li class="nav-item"><a class="nav-link" href="#profile" data-toggle="tab">Profile</a></li>'
|
|
|
|
+ '</ul>'
|
|
|
|
var $tabs = $(tabsHTML).appendTo('#qunit-fixture')
|
|
|
|
|
|
|
|
$tabs.find('li:last a').trigger('click')
|
|
|
|
assert.notOk($tabs.find('li:first a').hasClass('active'))
|
|
|
|
assert.ok($tabs.find('li:last a').hasClass('active'))
|
|
|
|
})
|
|
|
|
|
|
|
|
QUnit.test('selected tab should deactivate previous selected link in dropdown', function (assert) {
|
|
|
|
assert.expect(3)
|
|
|
|
var tabsHTML = '<ul class="nav nav-tabs">'
|
|
|
|
+ '<li class="nav-item"><a class="nav-link" href="#home" data-toggle="tab">Home</a></li>'
|
|
|
|
+ '<li class="nav-item"><a class="nav-link" href="#profile" data-toggle="tab">Profile</a></li>'
|
|
|
|
+ '<li class="nav-item dropdown"><a class="nav-link dropdown-toggle active" data-toggle="dropdown" href="#">Dropdown</a>'
|
|
|
|
+ '<div class="dropdown-menu">'
|
|
|
|
+ '<a class="dropdown-item active" href="#dropdown1" id="dropdown1-tab" data-toggle="tab">@fat</a>'
|
|
|
|
+ '<a class="dropdown-item" href="#dropdown2" id="dropdown2-tab" data-toggle="tab">@mdo</a>'
|
|
|
|
+ '</div>'
|
|
|
|
+ '</li>'
|
|
|
|
+ '</ul>'
|
|
|
|
var $tabs = $(tabsHTML).appendTo('#qunit-fixture')
|
|
|
|
|
|
|
|
$tabs.find('li:first > a').trigger('click')
|
|
|
|
assert.ok($tabs.find('li:first a').hasClass('active'))
|
|
|
|
assert.notOk($tabs.find('li:last > a').hasClass('active'))
|
|
|
|
assert.notOk($tabs.find('li:last > .dropdown-menu > a:first').hasClass('active'))
|
|
|
|
})
|
2017-07-17 10:05:45 +02:00
|
|
|
|
|
|
|
QUnit.test('Nested tabs', function (assert) {
|
|
|
|
assert.expect(2)
|
|
|
|
var done = assert.async()
|
|
|
|
var tabsHTML =
|
|
|
|
'<nav class="nav nav-tabs" role="tablist">'
|
|
|
|
+ ' <a id="tab1" href="#x-tab1" class="nav-item nav-link" data-toggle="tab" role="tab" aria-controls="x-tab1">Tab 1</a>'
|
2017-09-24 12:00:54 +02:00
|
|
|
+ ' <a href="#x-tab2" class="nav-item nav-link active" data-toggle="tab" role="tab" aria-controls="x-tab2" aria-selected="true">Tab 2</a>'
|
2017-07-17 10:05:45 +02:00
|
|
|
+ ' <a href="#x-tab3" class="nav-item nav-link" data-toggle="tab" role="tab" aria-controls="x-tab3">Tab 3</a>'
|
|
|
|
+ '</nav>'
|
|
|
|
+ '<div class="tab-content">'
|
|
|
|
+ ' <div class="tab-pane" id="x-tab1" role="tabpanel">'
|
|
|
|
+ ' <nav class="nav nav-tabs" role="tablist">'
|
2017-09-24 12:00:54 +02:00
|
|
|
+ ' <a href="#nested-tab1" class="nav-item nav-link active" data-toggle="tab" role="tab" aria-controls="x-tab1" aria-selected="true">Nested Tab 1</a>'
|
2017-07-17 10:05:45 +02:00
|
|
|
+ ' <a id="tabNested2" href="#nested-tab2" class="nav-item nav-link" data-toggle="tab" role="tab" aria-controls="x-profile">Nested Tab2</a>'
|
|
|
|
+ ' </nav>'
|
|
|
|
+ ' <div class="tab-content">'
|
|
|
|
+ ' <div class="tab-pane active" id="nested-tab1" role="tabpanel">Nested Tab1 Content</div>'
|
|
|
|
+ ' <div class="tab-pane" id="nested-tab2" role="tabpanel">Nested Tab2 Content</div>'
|
|
|
|
+ ' </div>'
|
|
|
|
+ ' </div>'
|
|
|
|
+ ' <div class="tab-pane active" id="x-tab2" role="tabpanel">Tab2 Content</div>'
|
|
|
|
+ ' <div class="tab-pane" id="x-tab3" role="tabpanel">Tab3 Content</div>'
|
|
|
|
+ '</div>'
|
|
|
|
|
|
|
|
$(tabsHTML).appendTo('#qunit-fixture')
|
|
|
|
|
|
|
|
$('#tabNested2').on('shown.bs.tab', function () {
|
|
|
|
assert.ok($('#x-tab1').hasClass('active'))
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
|
|
|
|
$('#tab1').on('shown.bs.tab', function () {
|
|
|
|
assert.ok($('#x-tab1').hasClass('active'))
|
|
|
|
$('#tabNested2').trigger($.Event('click'))
|
|
|
|
})
|
|
|
|
.trigger($.Event('click'))
|
|
|
|
})
|
2013-04-23 09:34:27 +02:00
|
|
|
})
|