From 1e64c4c0ba6167b95a7861974554204e869f3a57 Mon Sep 17 00:00:00 2001 From: Heinrich Fenkart Date: Wed, 18 Jun 2014 21:32:03 +0200 Subject: [PATCH 01/16] Update QUnit settings/QUnit phantomjs bridge to new versions --- js/tests/index.html | 21 +++++++------ js/tests/unit/phantom.js | 64 +++++++++++++++++++++------------------- 2 files changed, 44 insertions(+), 41 deletions(-) diff --git a/js/tests/index.html b/js/tests/index.html index 363ebe599adc..3acd3662883a 100644 --- a/js/tests/index.html +++ b/js/tests/index.html @@ -13,23 +13,22 @@ @@ -69,7 +75,7 @@ -
+
From 95d7c9c3fb00aae2e77806c19361b72579ad351d Mon Sep 17 00:00:00 2001 From: Heinrich Fenkart Date: Wed, 18 Jun 2014 21:33:22 +0200 Subject: [PATCH 03/16] Clean affix unit tests up --- js/tests/unit/affix.js | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/js/tests/unit/affix.js b/js/tests/unit/affix.js index 1cdfc7f90711..f93dd62d2b91 100644 --- a/js/tests/unit/affix.js +++ b/js/tests/unit/affix.js @@ -19,15 +19,18 @@ $(function () { }) test('should provide no conflict', function () { - ok(!$.fn.affix, 'affix was set back to undefined (org value)') + strictEqual($.fn.affix, undefined, 'affix was set back to undefined (org value)') }) - test('should return element', function () { - ok($(document.body).bootstrapAffix()[0] == document.body, 'document.body returned') + test('should return jquery collection containing the element', function () { + var $el = $('
') + var $affix = $el.bootstrapAffix() + ok($affix instanceof $, 'returns jquery collection') + strictEqual($affix[0], $el[0], 'collection contains element') }) test('should exit early if element is not visible', function () { - var $affix = $('
').bootstrapAffix() + var $affix = $('
').bootstrapAffix() $affix.data('bs.affix').checkPosition() ok(!$affix.hasClass('affix'), 'affix class was not added') }) @@ -35,8 +38,14 @@ $(function () { test('should trigger affixed event after affix', function () { stop() - var template = $('
  • Please affix
  • And unaffix
') - template.appendTo('body') + var templateHTML = '
' + + '
    ' + + '
  • Please affix
  • ' + + '
  • And unaffix
  • ' + + '
' + + '
' + + '
' + $(templateHTML).appendTo(document.body) $('#affixTarget').bootstrapAffix({ offset: $('#affixTarget ul').position() @@ -44,19 +53,19 @@ $(function () { $('#affixTarget') .on('affix.bs.affix', function () { - ok(true, 'affix event triggered') + ok(true, 'affix event fired') }).on('affixed.bs.affix', function () { - ok(true, 'affixed event triggered') - $('#affixTarget').remove() - $('#affixAfter').remove() + ok(true, 'affixed event fired') + $('#affixTarget, #affixAfter').remove() start() }) setTimeout(function () { window.scrollTo(0, document.body.scrollHeight) + setTimeout(function () { window.scroll(0, 0) - }, 0) + }, 18) // for testing in a browser }, 0) }) }) From b063de54a50ddbc13994f5c24ee0332b84038d99 Mon Sep 17 00:00:00 2001 From: Heinrich Fenkart Date: Wed, 18 Jun 2014 21:33:30 +0200 Subject: [PATCH 04/16] Clean alert unit tests up --- js/tests/unit/alert.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/js/tests/unit/alert.js b/js/tests/unit/alert.js index 31116cce25b0..9e5f9a12e490 100644 --- a/js/tests/unit/alert.js +++ b/js/tests/unit/alert.js @@ -19,11 +19,14 @@ $(function () { }) test('should provide no conflict', function () { - ok(!$.fn.alert, 'alert was set back to undefined (org value)') + strictEqual($.fn.alert, undefined, 'alert was set back to undefined (org value)') }) - test('should return element', function () { - ok($(document.body).bootstrapAlert()[0] == document.body, 'document.body returned') + test('should return jquery collection containing the element', function () { + var $el = $('
') + var $alert = $el.bootstrapAlert() + ok($alert instanceof $, 'returns jquery collection') + strictEqual($alert[0], $el[0], 'collection contains element') }) test('should fade element out on clicking .close', function () { @@ -31,40 +34,37 @@ $(function () { '×' + '

Holy guacamole! Best check yo self, you\'re not looking too good.

' + '
' - var alert = $(alertHTML).bootstrapAlert() + var $alert = $(alertHTML).bootstrapAlert() - alert.find('.close').click() + $alert.find('.close').click() - ok(!alert.hasClass('in'), 'remove .in class on .close click') + equal($alert.hasClass('in'), false, 'remove .in class on .close click') }) test('should remove element when clicking .close', function () { - $.support.transition = false - var alertHTML = '
' + '×' + '

Holy guacamole! Best check yo self, you\'re not looking too good.

' + '
' - var alert = $(alertHTML).appendTo('#qunit-fixture').bootstrapAlert() + var $alert = $(alertHTML).appendTo('#qunit-fixture').bootstrapAlert() - ok($('#qunit-fixture').find('.alert-message').length, 'element added to dom') + notEqual($('#qunit-fixture').find('.alert-message').length, 0, 'element added to dom') - alert.find('.close').click() + $alert.find('.close').click() - ok(!$('#qunit-fixture').find('.alert-message').length, 'element removed from dom') + equal($('#qunit-fixture').find('.alert-message').length, 0, 'element removed from dom') }) test('should not fire closed when close is prevented', function () { - $.support.transition = false stop() $('
') .on('close.bs.alert', function (e) { e.preventDefault() - ok(true) + ok(true, 'close event fired') start() }) .on('closed.bs.alert', function () { - ok(false) + ok(false, 'closed event fired') }) .bootstrapAlert('close') }) From f3345f68d777fe2b6fb5fa113ce19d604ab61583 Mon Sep 17 00:00:00 2001 From: Heinrich Fenkart Date: Wed, 18 Jun 2014 21:33:38 +0200 Subject: [PATCH 05/16] Clean button unit tests up --- js/tests/unit/button.js | 156 ++++++++++++++++++++-------------------- 1 file changed, 78 insertions(+), 78 deletions(-) diff --git a/js/tests/unit/button.js b/js/tests/unit/button.js index 671a93891d4e..04457010e55d 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') }) }) From 6a523bf99d561c99e51bd2f85f3ee6bdbdbc8ffd Mon Sep 17 00:00:00 2001 From: Heinrich Fenkart Date: Wed, 18 Jun 2014 21:33:49 +0200 Subject: [PATCH 06/16] Clean carousel unit tests up --- js/tests/unit/carousel.js | 382 +++++++++++++++++++++++++++++--------- 1 file changed, 292 insertions(+), 90 deletions(-) diff --git a/js/tests/unit/carousel.js b/js/tests/unit/carousel.js index 474cfb40c721..1f2fce30b3af 100644 --- a/js/tests/unit/carousel.js +++ b/js/tests/unit/carousel.js @@ -19,156 +19,358 @@ $(function () { }) test('should provide no conflict', function () { - ok(!$.fn.carousel, 'carousel was set back to undefined (orig value)') + strictEqual($.fn.carousel, undefined, 'carousel was set back to undefined (orig value)') }) - test('should return element', function () { - ok($(document.body).bootstrapCarousel()[0] == document.body, 'document.body returned') + test('should return jquery collection containing the element', function () { + var $el = $('
') + var $carousel = $el.bootstrapCarousel() + ok($carousel instanceof $, 'returns jquery collection') + strictEqual($carousel[0], $el[0], 'collection contains element') }) - test('should not fire slide when slide is prevented', function () { - $.support.transition = false + test('should not fire slid when slide is prevented', function () { stop() $('