info@54: $(function () { info@54: info@54: module("button") info@54: info@54: test("should provide no conflict", function () { info@54: var button = $.fn.button.noConflict() info@54: ok(!$.fn.button, 'button was set back to undefined (org value)') info@54: $.fn.button = button info@54: }) info@54: info@54: test("should be defined on jquery object", function () { info@54: ok($(document.body).button, 'button method is defined') info@54: }) info@54: info@54: test("should return element", function () { info@54: ok($(document.body).button()[0] == document.body, 'document.body returned') info@54: }) info@54: info@54: test("should return set state to loading", function () { info@54: var btn = $('') info@54: equal(btn.html(), 'mdo', 'btn text equals mdo') info@54: btn.button('loading') info@54: equal(btn.html(), 'fat', 'btn text equals fat') info@54: stop() info@54: setTimeout(function () { info@54: ok(btn.attr('disabled'), 'btn is disabled') info@54: ok(btn.hasClass('disabled'), 'btn has disabled class') info@54: start() info@54: }, 0) info@54: }) info@54: info@54: test("should return reset state", function () { info@54: var btn = $('') info@54: equal(btn.html(), 'mdo', 'btn text equals mdo') info@54: btn.button('loading') info@54: equal(btn.html(), 'fat', 'btn text equals fat') info@54: stop() info@54: setTimeout(function () { info@54: ok(btn.attr('disabled'), 'btn is disabled') info@54: ok(btn.hasClass('disabled'), 'btn has disabled class') info@54: start() info@54: stop() info@54: btn.button('reset') info@54: equal(btn.html(), 'mdo', 'btn text equals mdo') info@54: setTimeout(function () { info@54: ok(!btn.attr('disabled'), 'btn is not disabled') info@54: ok(!btn.hasClass('disabled'), 'btn does not have disabled class') info@54: start() info@54: }, 0) info@54: }, 0) info@54: info@54: }) info@54: info@54: test("should toggle active", function () { info@54: var btn = $('') info@54: ok(!btn.hasClass('active'), 'btn does not have active class') info@54: btn.button('toggle') info@54: ok(btn.hasClass('active'), 'btn has class active') info@54: }) info@54: info@54: test("should toggle active when btn children are clicked", function () { info@54: var btn = $('') info@54: , inner = $('') info@54: btn info@54: .append(inner) info@54: .appendTo($('#qunit-fixture')) info@54: ok(!btn.hasClass('active'), 'btn does not have active class') info@54: inner.click() info@54: ok(btn.hasClass('active'), 'btn has class active') info@54: }) info@54: info@54: test("should toggle active when btn children are clicked within btn-group", function () { info@54: var btngroup = $('
') info@54: , btn = $('') info@54: , inner = $('') info@54: btngroup info@54: .append(btn.append(inner)) info@54: .appendTo($('#qunit-fixture')) info@54: ok(!btn.hasClass('active'), 'btn does not have active class') info@54: inner.click() info@54: ok(btn.hasClass('active'), 'btn has class active') info@54: }) info@54: info@54: test("should check for closest matching toggle", function () { info@54: var group = '
' + info@54: '' + info@54: '' + info@54: '' + info@54: '
' info@54: info@54: group = $(group) info@54: info@54: var btn1 = $(group.children()[0]) info@54: var btn2 = $(group.children()[1]) info@54: var btn3 = $(group.children()[2]) info@54: info@54: group.appendTo($('#qunit-fixture')) info@54: info@54: ok(btn1.hasClass('active'), 'btn1 has active class') info@54: ok(btn1.find('input').prop('checked'), 'btn1 is checked') info@54: ok(!btn2.hasClass('active'), 'btn2 does not have active class') info@54: ok(!btn2.find('input').prop('checked'), 'btn2 is not checked') info@54: btn2.find('input').click() info@54: ok(!btn1.hasClass('active'), 'btn1 does not have active class') info@54: ok(!btn1.find('input').prop('checked'), 'btn1 is checked') info@54: ok(btn2.hasClass('active'), 'btn2 has active class') info@54: ok(btn2.find('input').prop('checked'), 'btn2 is checked') info@54: info@54: btn2.find('input').click() /* clicking an already checked radio should not un-check it */ info@54: ok(!btn1.hasClass('active'), 'btn1 does not have active class') info@54: ok(!btn1.find('input').prop('checked'), 'btn1 is checked') info@54: ok(btn2.hasClass('active'), 'btn2 has active class') info@54: ok(btn2.find('input').prop('checked'), 'btn2 is checked') info@54: }) info@54: info@54: })