From 45b476bdbff7ac38518deb7898529bb9510f648f Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Sat, 1 Mar 2014 18:19:50 +0200 Subject: JS: remove unused variables. --- js/tests/unit/button.js | 1 - 1 file changed, 1 deletion(-) (limited to 'js/tests/unit/button.js') diff --git a/js/tests/unit/button.js b/js/tests/unit/button.js index 73420863c..ea1236478 100644 --- a/js/tests/unit/button.js +++ b/js/tests/unit/button.js @@ -98,7 +98,6 @@ $(function () { var btn1 = $(group.children()[0]) var btn2 = $(group.children()[1]) - var btn3 = $(group.children()[2]) group.appendTo($('#qunit-fixture')) -- cgit v1.2.3 From a9f2b6ce0fb2ac059e30da259f7ae25282803c09 Mon Sep 17 00:00:00 2001 From: Collin Donahue-Oponski Date: Mon, 21 Apr 2014 23:03:33 -0600 Subject: #11464 - Fix JS noConflict mode - Refactor all plugins to use an internal reference to the jQuery plugin, because in noConflict mode you can never expect to be defined on the jQuery object --- js/tests/unit/button.js | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'js/tests/unit/button.js') diff --git a/js/tests/unit/button.js b/js/tests/unit/button.js index ea1236478..10bff1442 100644 --- a/js/tests/unit/button.js +++ b/js/tests/unit/button.js @@ -1,25 +1,34 @@ $(function () { - module('button') - - test('should provide no conflict', function () { - var button = $.fn.button.noConflict() - ok(!$.fn.button, 'button was set back to undefined (org value)') - $.fn.button = button - }) + module('button plugin') test('should be defined on jquery object', function () { 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 () { + ok(!$.fn.button, 'button was set back to undefined (org value)') + }) + test('should return element', function () { - ok($(document.body).button()[0] == document.body, 'document.body returned') + ok($(document.body).bootstrapButton()[0] == document.body, 'document.body returned') }) test('should return set state to loading', function () { var btn = $('') equal(btn.html(), 'mdo', 'btn text equals mdo') - btn.button('loading') + btn.bootstrapButton('loading') equal(btn.html(), 'fat', 'btn text equals fat') stop() setTimeout(function () { @@ -32,7 +41,7 @@ $(function () { test('should return reset state', function () { var btn = $('') equal(btn.html(), 'mdo', 'btn text equals mdo') - btn.button('loading') + btn.bootstrapButton('loading') equal(btn.html(), 'fat', 'btn text equals fat') stop() setTimeout(function () { @@ -40,7 +49,7 @@ $(function () { ok(btn.hasClass('disabled'), 'btn has disabled class') start() stop() - btn.button('reset') + btn.bootstrapButton('reset') equal(btn.html(), 'mdo', 'btn text equals mdo') setTimeout(function () { ok(!btn.attr('disabled'), 'btn is not disabled') @@ -54,7 +63,7 @@ $(function () { test('should toggle active', function () { var btn = $('') ok(!btn.hasClass('active'), 'btn does not have active class') - btn.button('toggle') + btn.bootstrapButton('toggle') ok(btn.hasClass('active'), 'btn has class active') }) -- cgit v1.2.3 From d8ee1ba9b61ef4ba5b0494433e3a6eac414ef782 Mon Sep 17 00:00:00 2001 From: Heinrich Fenkart Date: Mon, 5 May 2014 12:11:59 +0200 Subject: Allow for resetText of a button to be a falsey value; fixes #13466 --- js/tests/unit/button.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'js/tests/unit/button.js') diff --git a/js/tests/unit/button.js b/js/tests/unit/button.js index 10bff1442..da65ae383 100644 --- a/js/tests/unit/button.js +++ b/js/tests/unit/button.js @@ -57,7 +57,27 @@ $(function () { start() }, 0) }, 0) + }) + test('should work with an empty string as reset state', function () { + var btn = $('') + equal(btn.html(), '', 'btn text equals ""') + btn.bootstrapButton('loading') + equal(btn.html(), 'fat', 'btn text equals fat') + stop() + setTimeout(function () { + ok(btn.attr('disabled'), 'btn is disabled') + ok(btn.hasClass('disabled'), 'btn has disabled class') + start() + stop() + btn.bootstrapButton('reset') + equal(btn.html(), '', 'btn text equals ""') + setTimeout(function () { + ok(!btn.attr('disabled'), 'btn is not disabled') + ok(!btn.hasClass('disabled'), 'btn does not have disabled class') + start() + }, 0) + }, 0) }) test('should toggle active', function () { -- cgit v1.2.3 From 7b0acf14d8a7c7c6089035a848cba540ed963f36 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Mon, 17 Mar 2014 09:12:55 +0200 Subject: Comply to the new style. --- js/tests/unit/button.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'js/tests/unit/button.js') diff --git a/js/tests/unit/button.js b/js/tests/unit/button.js index da65ae383..671a93891 100644 --- a/js/tests/unit/button.js +++ b/js/tests/unit/button.js @@ -1,4 +1,5 @@ $(function () { + 'use strict'; module('button plugin') @@ -7,11 +8,11 @@ $(function () { }) module('button', { - setup: function() { + 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() { + teardown: function () { $.fn.button = $.fn.bootstrapButton delete $.fn.bootstrapButton } @@ -88,8 +89,8 @@ $(function () { }) test('should toggle active when btn children are clicked', function () { - var btn = $(''), - inner = $('') + var btn = $('') + var inner = $('') btn .append(inner) .appendTo($('#qunit-fixture')) @@ -99,9 +100,9 @@ $(function () { }) test('should toggle active when btn children are clicked within btn-group', function () { - var btngroup = $('
'), - btn = $(''), - inner = $('') + var btngroup = $('
') + var btn = $('') + var inner = $('') btngroup .append(btn.append(inner)) .appendTo($('#qunit-fixture')) -- cgit v1.2.3 From f3345f68d777fe2b6fb5fa113ce19d604ab61583 Mon Sep 17 00:00:00 2001 From: Heinrich Fenkart Date: Wed, 18 Jun 2014 21:33:38 +0200 Subject: Clean button unit tests up --- js/tests/unit/button.js | 156 ++++++++++++++++++++++++------------------------ 1 file changed, 78 insertions(+), 78 deletions(-) (limited to 'js/tests/unit/button.js') diff --git a/js/tests/unit/button.js b/js/tests/unit/button.js index 671a93891..04457010e 100644 --- a/js/tests/unit/button.js +++ b/js/tests/unit/button.js @@ -19,133 +19,133 @@ $(function () { }) test('should provide no conflict', function () { - ok(!$.fn.button, 'button was set back to undefined (org value)') + strictEqual($.fn.button, undefined, 'button was set back to undefined (org value)') }) - test('should return element', function () { - ok($(document.body).bootstrapButton()[0] == document.body, 'document.body returned') + test('should return jquery collection containing the element', function () { + var $el = $('
') + var $button = $el.bootstrapButton() + ok($button instanceof $, 'returns jquery collection') + strictEqual($button[0], $el[0], 'collection contains element') }) test('should return set state to loading', function () { - var btn = $('') - equal(btn.html(), 'mdo', 'btn text equals mdo') - btn.bootstrapButton('loading') - equal(btn.html(), 'fat', 'btn text equals fat') + var $btn = $('') + equal($btn.html(), 'mdo', 'btn text equals mdo') + $btn.bootstrapButton('loading') + equal($btn.html(), 'fat', 'btn text equals fat') stop() setTimeout(function () { - ok(btn.attr('disabled'), 'btn is disabled') - ok(btn.hasClass('disabled'), 'btn has disabled class') + ok($btn[0].hasAttribute('disabled'), 'btn is disabled') + ok($btn.hasClass('disabled'), 'btn has disabled class') start() }, 0) }) test('should return reset state', function () { - var btn = $('') - equal(btn.html(), 'mdo', 'btn text equals mdo') - btn.bootstrapButton('loading') - equal(btn.html(), 'fat', 'btn text equals fat') + var $btn = $('') + equal($btn.html(), 'mdo', 'btn text equals mdo') + $btn.bootstrapButton('loading') + equal($btn.html(), 'fat', 'btn text equals fat') stop() setTimeout(function () { - ok(btn.attr('disabled'), 'btn is disabled') - ok(btn.hasClass('disabled'), 'btn has disabled class') + ok($btn[0].hasAttribute('disabled'), 'btn is disabled') + ok($btn.hasClass('disabled'), 'btn has disabled class') start() stop() - btn.bootstrapButton('reset') - equal(btn.html(), 'mdo', 'btn text equals mdo') + $btn.bootstrapButton('reset') + equal($btn.html(), 'mdo', 'btn text equals mdo') setTimeout(function () { - ok(!btn.attr('disabled'), 'btn is not disabled') - ok(!btn.hasClass('disabled'), 'btn does not have disabled class') + ok(!$btn[0].hasAttribute('disabled'), 'btn is not disabled') + ok(!$btn.hasClass('disabled'), 'btn does not have disabled class') start() }, 0) }, 0) }) test('should work with an empty string as reset state', function () { - var btn = $('') - equal(btn.html(), '', 'btn text equals ""') - btn.bootstrapButton('loading') - equal(btn.html(), 'fat', 'btn text equals fat') + var $btn = $('') - ok(!btn.hasClass('active'), 'btn does not have active class') - btn.bootstrapButton('toggle') - ok(btn.hasClass('active'), 'btn has class active') + var $btn = $('') + ok(!$btn.hasClass('active'), 'btn does not have active class') + $btn.bootstrapButton('toggle') + ok($btn.hasClass('active'), 'btn has class active') }) test('should toggle active when btn children are clicked', function () { - var btn = $('') - var inner = $('') - btn - .append(inner) - .appendTo($('#qunit-fixture')) - ok(!btn.hasClass('active'), 'btn does not have active class') - inner.click() - ok(btn.hasClass('active'), 'btn has class active') + var $btn = $('') + var $inner = $('') + $btn + .append($inner) + .appendTo('#qunit-fixture') + ok(!$btn.hasClass('active'), 'btn does not have active class') + $inner.click() + ok($btn.hasClass('active'), 'btn has class active') }) test('should toggle active when btn children are clicked within btn-group', function () { - var btngroup = $('
') - var btn = $('') - var inner = $('') - btngroup - .append(btn.append(inner)) - .appendTo($('#qunit-fixture')) - ok(!btn.hasClass('active'), 'btn does not have active class') - inner.click() - ok(btn.hasClass('active'), 'btn has class active') + var $btngroup = $('
') + var $btn = $('') + var $inner = $('') + $btngroup + .append($btn.append($inner)) + .appendTo('#qunit-fixture') + ok(!$btn.hasClass('active'), 'btn does not have active class') + $inner.click() + ok($btn.hasClass('active'), 'btn has class active') }) test('should check for closest matching toggle', function () { - var group = '
' + + var groupHTML = '
' + '' + '' + '' + - '
' - - group = $(group) - - var btn1 = $(group.children()[0]) - var btn2 = $(group.children()[1]) - - group.appendTo($('#qunit-fixture')) - - ok(btn1.hasClass('active'), 'btn1 has active class') - ok(btn1.find('input').prop('checked'), 'btn1 is checked') - ok(!btn2.hasClass('active'), 'btn2 does not have active class') - ok(!btn2.find('input').prop('checked'), 'btn2 is not checked') - btn2.find('input').click() - ok(!btn1.hasClass('active'), 'btn1 does not have active class') - ok(!btn1.find('input').prop('checked'), 'btn1 is checked') - ok(btn2.hasClass('active'), 'btn2 has active class') - ok(btn2.find('input').prop('checked'), 'btn2 is checked') - - btn2.find('input').click() /* clicking an already checked radio should not un-check it */ - ok(!btn1.hasClass('active'), 'btn1 does not have active class') - ok(!btn1.find('input').prop('checked'), 'btn1 is checked') - ok(btn2.hasClass('active'), 'btn2 has active class') - ok(btn2.find('input').prop('checked'), 'btn2 is checked') + '
' + var $group = $(groupHTML).appendTo('#qunit-fixture') + + var $btn1 = $group.children().eq(0) + var $btn2 = $group.children().eq(1) + + ok($btn1.hasClass('active'), 'btn1 has active class') + ok($btn1.find('input').prop('checked'), 'btn1 is checked') + ok(!$btn2.hasClass('active'), 'btn2 does not have active class') + ok(!$btn2.find('input').prop('checked'), 'btn2 is not checked') + $btn2.find('input').click() + ok(!$btn1.hasClass('active'), 'btn1 does not have active class') + ok(!$btn1.find('input').prop('checked'), 'btn1 is checked') + ok($btn2.hasClass('active'), 'btn2 has active class') + ok($btn2.find('input').prop('checked'), 'btn2 is checked') + + $btn2.find('input').click() // clicking an already checked radio should not un-check it + ok(!$btn1.hasClass('active'), 'btn1 does not have active class') + ok(!$btn1.find('input').prop('checked'), 'btn1 is checked') + ok($btn2.hasClass('active'), 'btn2 has active class') + ok($btn2.find('input').prop('checked'), 'btn2 is checked') }) }) -- cgit v1.2.3 From 58eb8b2ae39baeb37514e5bf5ffcaf2a7c221202 Mon Sep 17 00:00:00 2001 From: Heinrich Fenkart Date: Sun, 6 Jul 2014 11:56:12 +0200 Subject: Move to leading pluses --- js/tests/unit/button.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'js/tests/unit/button.js') diff --git a/js/tests/unit/button.js b/js/tests/unit/button.js index 04457010e..bd431d546 100644 --- a/js/tests/unit/button.js +++ b/js/tests/unit/button.js @@ -115,17 +115,17 @@ $(function () { }) test('should check for closest matching toggle', function () { - var groupHTML = '
' + - '' + - '' + - '' + - '
' + var groupHTML = '
' + + '' + + '' + + '' + + '
' var $group = $(groupHTML).appendTo('#qunit-fixture') var $btn1 = $group.children().eq(0) -- cgit v1.2.3