0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-12-14 02:24:00 +01:00
Bootstrap/js/tests/unit/bootstrap-tabs.js

71 lines
2.2 KiB
JavaScript
Raw Normal View History

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 () {
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>'
+ '</ul>')
2011-09-10 21:49:21 +02:00
$('<ul><li id="home"></li><li id="profile"></li></ul>').appendTo("#qunit-runoff")
$tabsHTML.tabs().find('a').last().click()
2011-09-10 21:49:21 +02:00
equals($("#qunit-runoff").find('.active').attr('id'), "profile")
$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 () {
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>'
+ '</ul>')
2011-09-10 21:49:21 +02:00
$('<ul><li id="home"></li><li id="profile"></li></ul>').appendTo("#qunit-runoff")
$pillsHTML.pills().find('a').last().click()
2011-09-10 21:49:21 +02:00
equals($("#qunit-runoff").find('.active').attr('id'), "profile")
$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()
})
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
})