2011-09-10 21:49:21 +02:00
|
|
|
$(function () {
|
|
|
|
|
|
|
|
module("bootstrap-tabs")
|
|
|
|
|
|
|
|
test("should be defined on jquery object", function () {
|
|
|
|
ok($(document.body).tabs, 'tabs method is defined')
|
|
|
|
})
|
|
|
|
|
|
|
|
test("should return element", function () {
|
|
|
|
ok($(document.body).tabs()[0] == document.body, 'document.body returned')
|
|
|
|
})
|
|
|
|
|
|
|
|
test("should activate element by tab id", function () {
|
2011-09-18 10:15:24 +02:00
|
|
|
var $tabsHTML = $('<ul class="tabs">'
|
2011-09-10 21:49:21 +02:00
|
|
|
+ '<li class="active"><a href="#home">Home</a></li>'
|
|
|
|
+ '<li><a href="#profile">Profile</a></li>'
|
2011-09-18 10:15:24 +02:00
|
|
|
+ '</ul>')
|
2011-09-10 21:49:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
$('<ul><li id="home"></li><li id="profile"></li></ul>').appendTo("#qunit-runoff")
|
|
|
|
|
2011-09-18 10:15:24 +02:00
|
|
|
$tabsHTML.tabs().find('a').last().click()
|
2011-09-10 21:49:21 +02:00
|
|
|
equals($("#qunit-runoff").find('.active').attr('id'), "profile")
|
|
|
|
|
2011-09-18 10:15:24 +02:00
|
|
|
$tabsHTML.tabs().find('a').first().click()
|
2011-09-10 21:49:21 +02:00
|
|
|
equals($("#qunit-runoff").find('.active').attr('id'), "home")
|
|
|
|
|
|
|
|
$("#qunit-runoff").empty()
|
|
|
|
})
|
|
|
|
|
|
|
|
test("should activate element by pill id", function () {
|
2011-09-18 10:15:24 +02:00
|
|
|
var $pillsHTML = $('<ul class="pills">'
|
2011-09-10 21:49:21 +02:00
|
|
|
+ '<li class="active"><a href="#home">Home</a></li>'
|
|
|
|
+ '<li><a href="#profile">Profile</a></li>'
|
2011-09-18 10:15:24 +02:00
|
|
|
+ '</ul>')
|
2011-09-10 21:49:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
$('<ul><li id="home"></li><li id="profile"></li></ul>').appendTo("#qunit-runoff")
|
|
|
|
|
2011-09-18 10:15:24 +02:00
|
|
|
$pillsHTML.pills().find('a').last().click()
|
2011-09-10 21:49:21 +02:00
|
|
|
equals($("#qunit-runoff").find('.active').attr('id'), "profile")
|
|
|
|
|
2011-09-18 10:15:24 +02:00
|
|
|
$pillsHTML.pills().find('a').first().click()
|
2011-09-10 21:49:21 +02:00
|
|
|
equals($("#qunit-runoff").find('.active').attr('id'), "home")
|
|
|
|
|
|
|
|
$("#qunit-runoff").empty()
|
|
|
|
})
|
2011-09-18 10:15:24 +02:00
|
|
|
|
|
|
|
test( "should trigger changed event on activate", function () {
|
|
|
|
var $tabsHTML = $('<ul class="tabs">'
|
|
|
|
+ '<li class="active"><a href="#home">Home</a></li>'
|
|
|
|
+ '<li><a href="#profile">Profile</a></li>'
|
|
|
|
+ '</ul>')
|
|
|
|
, changeCount = 0
|
|
|
|
, from
|
|
|
|
, to;
|
|
|
|
|
|
|
|
$tabsHTML.tabs().bind( "changed", function (e, c){
|
|
|
|
from = c.from;
|
|
|
|
to = c.to;
|
|
|
|
changeCount++
|
|
|
|
})
|
|
|
|
|
|
|
|
$tabsHTML.tabs().find('a').last().click()
|
|
|
|
|
|
|
|
equals(from, "#home")
|
|
|
|
equals(to, "#profile")
|
|
|
|
equals(changeCount, 1)
|
|
|
|
})
|
2011-09-10 21:49:21 +02:00
|
|
|
|
|
|
|
})
|