$(function () { 'use strict'; module('button plugin') test('should be defined on jquery object', function (assert) { assert.ok($(document.body).button, 'button method is defined') }) module('button', { setup: function () { // Run all tests in noConflict mode -- it's the only way to ensure that the plugin works in noConflict mode $.fn.bootstrapButton = $.fn.button.noConflict() }, teardown: function () { $.fn.button = $.fn.bootstrapButton delete $.fn.bootstrapButton } }) test('should provide no conflict', function (assert) { assert.strictEqual($.fn.button, undefined, 'button was set back to undefined (org value)') }) test('should return jquery collection containing the element', function (assert) { var $el = $('
') var $button = $el.bootstrapButton() assert.ok($button instanceof $, 'returns jquery collection') assert.strictEqual($button[0], $el[0], 'collection contains element') }) test('should return set state to loading', function (assert) { var $btn = $('') assert.equal($btn.html(), 'mdo', 'btn text equals mdo') $btn.bootstrapButton('loading') var done = assert.async() setTimeout(function () { assert.equal($btn.html(), 'fat', 'btn text equals fat') assert.ok($btn[0].hasAttribute('disabled'), 'btn is disabled') assert.ok($btn.hasClass('disabled'), 'btn has disabled class') done() }, 0) }) test('should return reset state', function (assert) { var $btn = $('') assert.equal($btn.html(), 'mdo', 'btn text equals mdo') $btn.bootstrapButton('loading') var doneOne = assert.async() setTimeout(function () { assert.equal($btn.html(), 'fat', 'btn text equals fat') assert.ok($btn[0].hasAttribute('disabled'), 'btn is disabled') assert.ok($btn.hasClass('disabled'), 'btn has disabled class') doneOne() var doneTwo = assert.async() $btn.bootstrapButton('reset') setTimeout(function () { assert.equal($btn.html(), 'mdo', 'btn text equals mdo') assert.ok(!$btn[0].hasAttribute('disabled'), 'btn is not disabled') assert.ok(!$btn.hasClass('disabled'), 'btn does not have disabled class') doneTwo() }, 0) }, 0) }) test('should work with an empty string as reset state', function (assert) { var $btn = $('') assert.equal($btn.html(), '', 'btn text equals ""') $btn.bootstrapButton('loading') var doneOne = assert.async() setTimeout(function () { assert.equal($btn.html(), 'fat', 'btn text equals fat') assert.ok($btn[0].hasAttribute('disabled'), 'btn is disabled') assert.ok($btn.hasClass('disabled'), 'btn has disabled class') doneOne() var doneTwo = assert.async() $btn.bootstrapButton('reset') setTimeout(function () { assert.equal($btn.html(), '', 'btn text equals ""') assert.ok(!$btn[0].hasAttribute('disabled'), 'btn is not disabled') assert.ok(!$btn.hasClass('disabled'), 'btn does not have disabled class') doneTwo() }, 0) }, 0) }) test('should toggle active', function (assert) { var $btn = $('') assert.ok(!$btn.hasClass('active'), 'btn does not have active class') $btn.bootstrapButton('toggle') assert.ok($btn.hasClass('active'), 'btn has class active') }) test('should toggle active when btn children are clicked', function (assert) { var $btn = $('') var $inner = $('') $btn .append($inner) .appendTo('#qunit-fixture') assert.ok(!$btn.hasClass('active'), 'btn does not have active class') $inner.click() assert.ok($btn.hasClass('active'), 'btn has class active') }) test('should toggle aria-pressed', function (assert) { var $btn = $('') assert.equal($btn.attr('aria-pressed'), 'false', 'btn aria-pressed state is false') $btn.bootstrapButton('toggle') assert.equal($btn.attr('aria-pressed'), 'true', 'btn aria-pressed state is true') }) test('should toggle aria-pressed when btn children are clicked', function (assert) { var $btn = $('') var $inner = $('') $btn .append($inner) .appendTo('#qunit-fixture') assert.equal($btn.attr('aria-pressed'), 'false', 'btn aria-pressed state is false') $inner.click() assert.equal($btn.attr('aria-pressed'), 'true', 'btn aria-pressed state is true') }) test('should toggle active when btn children are clicked within btn-group', function (assert) { var $btngroup = $('') var $btn = $('') var $inner = $('') $btngroup .append($btn.append($inner)) .appendTo('#qunit-fixture') assert.ok(!$btn.hasClass('active'), 'btn does not have active class') $inner.click() assert.ok($btn.hasClass('active'), 'btn has class active') }) test('should check for closest matching toggle', function (assert) { var groupHTML = '