comparison static/bootstrap/js/tests/unit/bootstrap-button.js @ 88:a5a3d454eac9

Updated Bootstrap.
author Ludovic Chabant <ludovic@chabant.com>
date Fri, 05 Apr 2013 08:08:12 -0700
parents
children
comparison
equal deleted inserted replaced
87:c0cf67362fb1 88:a5a3d454eac9
1 $(function () {
2
3 module("bootstrap-buttons")
4
5 test("should provide no conflict", function () {
6 var button = $.fn.button.noConflict()
7 ok(!$.fn.button, 'button was set back to undefined (org value)')
8 $.fn.button = button
9 })
10
11 test("should be defined on jquery object", function () {
12 ok($(document.body).button, 'button method is defined')
13 })
14
15 test("should return element", function () {
16 ok($(document.body).button()[0] == document.body, 'document.body returned')
17 })
18
19 test("should return set state to loading", function () {
20 var btn = $('<button class="btn" data-loading-text="fat">mdo</button>')
21 equals(btn.html(), 'mdo', 'btn text equals mdo')
22 btn.button('loading')
23 equals(btn.html(), 'fat', 'btn text equals fat')
24 stop()
25 setTimeout(function () {
26 ok(btn.attr('disabled'), 'btn is disabled')
27 ok(btn.hasClass('disabled'), 'btn has disabled class')
28 start()
29 }, 0)
30 })
31
32 test("should return reset state", function () {
33 var btn = $('<button class="btn" data-loading-text="fat">mdo</button>')
34 equals(btn.html(), 'mdo', 'btn text equals mdo')
35 btn.button('loading')
36 equals(btn.html(), 'fat', 'btn text equals fat')
37 stop()
38 setTimeout(function () {
39 ok(btn.attr('disabled'), 'btn is disabled')
40 ok(btn.hasClass('disabled'), 'btn has disabled class')
41 start()
42 stop()
43 }, 0)
44 btn.button('reset')
45 equals(btn.html(), 'mdo', 'btn text equals mdo')
46 setTimeout(function () {
47 ok(!btn.attr('disabled'), 'btn is not disabled')
48 ok(!btn.hasClass('disabled'), 'btn does not have disabled class')
49 start()
50 }, 0)
51 })
52
53 test("should toggle active", function () {
54 var btn = $('<button class="btn">mdo</button>')
55 ok(!btn.hasClass('active'), 'btn does not have active class')
56 btn.button('toggle')
57 ok(btn.hasClass('active'), 'btn has class active')
58 })
59
60 test("should toggle active when btn children are clicked", function () {
61 var btn = $('<button class="btn" data-toggle="button">mdo</button>')
62 , inner = $('<i></i>')
63 btn
64 .append(inner)
65 .appendTo($('#qunit-fixture'))
66 ok(!btn.hasClass('active'), 'btn does not have active class')
67 inner.click()
68 ok(btn.hasClass('active'), 'btn has class active')
69 })
70
71 test("should toggle active when btn children are clicked within btn-group", function () {
72 var btngroup = $('<div class="btn-group" data-toggle="buttons-checkbox"></div>')
73 , btn = $('<button class="btn">fat</button>')
74 , inner = $('<i></i>')
75 btngroup
76 .append(btn.append(inner))
77 .appendTo($('#qunit-fixture'))
78 ok(!btn.hasClass('active'), 'btn does not have active class')
79 inner.click()
80 ok(btn.hasClass('active'), 'btn has class active')
81 })
82
83 test("should check for closest matching toggle", function () {
84 var group = $("<div data-toggle='buttons-radio'></div>")
85 , btn1 = $("<button class='btn active'></button>")
86 , btn2 = $("<button class='btn'></button>")
87 , wrap = $("<div></div>")
88
89 wrap.append(btn1, btn2)
90
91 group
92 .append(wrap)
93 .appendTo($('#qunit-fixture'))
94
95 ok(btn1.hasClass('active'), 'btn1 has active class')
96 ok(!btn2.hasClass('active'), 'btn2 does not have active class')
97 btn2.click()
98 ok(!btn1.hasClass('active'), 'btn1 does not have active class')
99 ok(btn2.hasClass('active'), 'btn2 has active class')
100 })
101
102 })