annotate static/bootstrap/js/tests/unit/bootstrap-tab.js @ 88:a5a3d454eac9

Updated Bootstrap.
author Ludovic Chabant <ludovic@chabant.com>
date Fri, 05 Apr 2013 08:08:12 -0700
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
88
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1 $(function () {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
2
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
3 module("bootstrap-tabs")
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
4
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
5 test("should provide no conflict", function () {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
6 var tab = $.fn.tab.noConflict()
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
7 ok(!$.fn.tab, 'tab was set back to undefined (org value)')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
8 $.fn.tab = tab
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
9 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
10
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
11 test("should be defined on jquery object", function () {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
12 ok($(document.body).tab, 'tabs method is defined')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
13 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
14
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
15 test("should return element", function () {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
16 ok($(document.body).tab()[0] == document.body, 'document.body returned')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
17 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
18
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
19 test("should activate element by tab id", function () {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
20 var tabsHTML =
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
21 '<ul class="tabs">'
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
22 + '<li><a href="#home">Home</a></li>'
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
23 + '<li><a href="#profile">Profile</a></li>'
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
24 + '</ul>'
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
25
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
26 $('<ul><li id="home"></li><li id="profile"></li></ul>').appendTo("#qunit-fixture")
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
27
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
28 $(tabsHTML).find('li:last a').tab('show')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
29 equals($("#qunit-fixture").find('.active').attr('id'), "profile")
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
30
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
31 $(tabsHTML).find('li:first a').tab('show')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
32 equals($("#qunit-fixture").find('.active').attr('id'), "home")
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
33 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
34
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
35 test("should activate element by tab id", function () {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
36 var pillsHTML =
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
37 '<ul class="pills">'
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
38 + '<li><a href="#home">Home</a></li>'
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
39 + '<li><a href="#profile">Profile</a></li>'
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
40 + '</ul>'
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
41
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
42 $('<ul><li id="home"></li><li id="profile"></li></ul>').appendTo("#qunit-fixture")
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
43
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
44 $(pillsHTML).find('li:last a').tab('show')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
45 equals($("#qunit-fixture").find('.active').attr('id'), "profile")
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
46
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
47 $(pillsHTML).find('li:first a').tab('show')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
48 equals($("#qunit-fixture").find('.active').attr('id'), "home")
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
49 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
50
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
51
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
52 test("should not fire closed when close is prevented", function () {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
53 $.support.transition = false
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
54 stop();
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
55 $('<div class="tab"/>')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
56 .bind('show', function (e) {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
57 e.preventDefault();
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
58 ok(true);
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
59 start();
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
60 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
61 .bind('shown', function () {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
62 ok(false);
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
63 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
64 .tab('show')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
65 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
66
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
67 test("show and shown events should reference correct relatedTarget", function () {
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
68 var dropHTML =
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
69 '<ul class="drop">'
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
70 + '<li class="dropdown"><a data-toggle="dropdown" href="#">1</a>'
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
71 + '<ul class="dropdown-menu">'
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
72 + '<li><a href="#1-1" data-toggle="tab">1-1</a></li>'
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
73 + '<li><a href="#1-2" data-toggle="tab">1-2</a></li>'
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
74 + '</ul>'
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
75 + '</li>'
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
76 + '</ul>'
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
77
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
78 $(dropHTML).find('ul>li:first a').tab('show').end()
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
79 .find('ul>li:last a').on('show', function(event){
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
80 equals(event.relatedTarget.hash, "#1-1")
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
81 }).on('shown', function(event){
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
82 equals(event.relatedTarget.hash, "#1-1")
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
83 }).tab('show')
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
84 })
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
85
a5a3d454eac9 Updated Bootstrap.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
86 })