From 3efa533d1c19f318dad8e1631e74d6020e2bf2f9 Mon Sep 17 00:00:00 2001 From: sclarson Date: Sun, 1 Dec 2013 10:10:21 -0600 Subject: [PATCH 1/7] Adds affix events test --- js/tests/unit/affix.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/js/tests/unit/affix.js b/js/tests/unit/affix.js index b74bc51e48bd..2a95365a12be 100644 --- a/js/tests/unit/affix.js +++ b/js/tests/unit/affix.js @@ -22,4 +22,34 @@ $(function () { ok(!$affix.hasClass('affix'), 'affix class was not added') }) + asyncTest("should trigger affixed event after affix", function(){ + + var template = $('
') + template.appendTo("body") + var affixer = $('#affixTarget').affix({ + offset: $('#affixTarget ul').position() + }) + + $('#affixTarget').on('affixed.bs.affix', function(e){ + ok(true, 'affixed event triggered') + }) + + $('#affixTarget').on('unaffixed.bs.affix', function(e){ + ok(true, 'unaffixed event triggered') + }) + + $('html,body').animate({ + scrollTop: $(window).scrollTop() + 5000 + },10) + + $('html,body').animate({ + scrollTop: $(window).scrollTop() - 5000 + },10) + expect(2) + setTimeout(function(){ + $('#affixTarget').remove() + $('#affixAfter').remove() + start() + },70) + }) }) From 7ed3d372278963f58081174d85be2f2757a4f11e Mon Sep 17 00:00:00 2001 From: sclarson Date: Sun, 1 Dec 2013 10:11:08 -0600 Subject: [PATCH 2/7] adds affix and unaffix events --- js/affix.js | 1 + 1 file changed, 1 insertion(+) diff --git a/js/affix.js b/js/affix.js index 7d111ecc4d08..d3f91f8717a4 100644 --- a/js/affix.js +++ b/js/affix.js @@ -71,6 +71,7 @@ this.unpin = affix == 'bottom' ? position.top - scrollTop : null this.$element.removeClass(Affix.RESET).addClass('affix' + (affix ? '-' + affix : '')) + this.$element.trigger($.Event((affix ? 'affixed' : 'unaffixed') + '.bs.affix')) if (affix == 'bottom') { this.$element.offset({ top: document.body.offsetHeight - offsetBottom - this.$element.height() }) From 4fa52a830cebddffdac19b5783a950ab64c51529 Mon Sep 17 00:00:00 2001 From: sclarson Date: Sun, 1 Dec 2013 11:43:38 -0600 Subject: [PATCH 3/7] Moves expect to before window animations which trigger the ok calls. Passed locally before but not on travis. --- js/tests/unit/affix.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/js/tests/unit/affix.js b/js/tests/unit/affix.js index 2a95365a12be..6d7da12d3b6a 100644 --- a/js/tests/unit/affix.js +++ b/js/tests/unit/affix.js @@ -37,6 +37,7 @@ $(function () { $('#affixTarget').on('unaffixed.bs.affix', function(e){ ok(true, 'unaffixed event triggered') }) + expect(2) $('html,body').animate({ scrollTop: $(window).scrollTop() + 5000 @@ -45,11 +46,13 @@ $(function () { $('html,body').animate({ scrollTop: $(window).scrollTop() - 5000 },10) - expect(2) - setTimeout(function(){ + + + setTimeout(function(){ + start() $('#affixTarget').remove() $('#affixAfter').remove() - start() },70) + }) }) From 0f395eb1b764ea99724c38d76be84ea9fa0777ba Mon Sep 17 00:00:00 2001 From: sclarson Date: Mon, 16 Dec 2013 23:39:08 -0600 Subject: [PATCH 4/7] Fix broken tests in affix events --- js/tests/unit/affix.js | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/js/tests/unit/affix.js b/js/tests/unit/affix.js index 6d7da12d3b6a..a4d20d5ff628 100644 --- a/js/tests/unit/affix.js +++ b/js/tests/unit/affix.js @@ -22,8 +22,7 @@ $(function () { ok(!$affix.hasClass('affix'), 'affix class was not added') }) - asyncTest("should trigger affixed event after affix", function(){ - + test("should trigger affixed event after affix", function(){ var template = $('
  • Please affix
  • And unaffix
') template.appendTo("body") var affixer = $('#affixTarget').affix({ @@ -31,28 +30,18 @@ $(function () { }) $('#affixTarget').on('affixed.bs.affix', function(e){ - ok(true, 'affixed event triggered') - }) - - $('#affixTarget').on('unaffixed.bs.affix', function(e){ - ok(true, 'unaffixed event triggered') + ok(true, 'affixed event triggered') + start() + }).on('unaffixed.bs.affix', function(e){ + ok(true,'unaffixed event triggered') }) - expect(2) - $('html,body').animate({ - scrollTop: $(window).scrollTop() + 5000 - },10) - - $('html,body').animate({ - scrollTop: $(window).scrollTop() - 5000 - },10) - - + stop() setTimeout(function(){ - start() - $('#affixTarget').remove() - $('#affixAfter').remove() - },70) - + window.scrollTo(0,document.body.scrollHeight) + setTimeout(function(){ + window.scroll(0,0) + },0) + },0) }) -}) +}) \ No newline at end of file From 55ae60a60eb5e95dfc8b1d784a7619ce3ee3c9ff Mon Sep 17 00:00:00 2001 From: sclarson Date: Tue, 17 Dec 2013 00:26:26 -0600 Subject: [PATCH 5/7] Change double quote to single to get rid of lint error --- js/tests/unit/affix.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/tests/unit/affix.js b/js/tests/unit/affix.js index a4d20d5ff628..069ece08459a 100644 --- a/js/tests/unit/affix.js +++ b/js/tests/unit/affix.js @@ -24,7 +24,7 @@ $(function () { test("should trigger affixed event after affix", function(){ var template = $('
  • Please affix
  • And unaffix
') - template.appendTo("body") + template.appendTo('body') var affixer = $('#affixTarget').affix({ offset: $('#affixTarget ul').position() }) @@ -44,4 +44,4 @@ $(function () { },0) },0) }) -}) \ No newline at end of file +}) From f773cf9d25634f125f1b9f19552d68c8ae0de9be Mon Sep 17 00:00:00 2001 From: sclarson Date: Tue, 17 Dec 2013 00:34:52 -0600 Subject: [PATCH 6/7] Change double quote to single to get rid of lint error --- js/tests/unit/affix.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/tests/unit/affix.js b/js/tests/unit/affix.js index 069ece08459a..d4453d00a163 100644 --- a/js/tests/unit/affix.js +++ b/js/tests/unit/affix.js @@ -22,7 +22,7 @@ $(function () { ok(!$affix.hasClass('affix'), 'affix class was not added') }) - test("should trigger affixed event after affix", function(){ + test('should trigger affixed event after affix', function(){ var template = $('
  • Please affix
  • And unaffix
') template.appendTo('body') var affixer = $('#affixTarget').affix({ From 97cef5327e7b44644469215ce843a1c29c37438e Mon Sep 17 00:00:00 2001 From: sclarson Date: Tue, 17 Dec 2013 22:38:52 -0600 Subject: [PATCH 7/7] Fixes some whitespace issues aroung opening curly braces --- js/tests/unit/affix.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/js/tests/unit/affix.js b/js/tests/unit/affix.js index d4453d00a163..a1050993a115 100644 --- a/js/tests/unit/affix.js +++ b/js/tests/unit/affix.js @@ -22,24 +22,24 @@ $(function () { ok(!$affix.hasClass('affix'), 'affix class was not added') }) - test('should trigger affixed event after affix', function(){ + test('should trigger affixed event after affix', function () { var template = $('
  • Please affix
  • And unaffix
') template.appendTo('body') - var affixer = $('#affixTarget').affix({ + var affixer = $('#affixTarget').affix( { offset: $('#affixTarget ul').position() }) - $('#affixTarget').on('affixed.bs.affix', function(e){ + $('#affixTarget').on('affixed.bs.affix', function (e) { ok(true, 'affixed event triggered') start() - }).on('unaffixed.bs.affix', function(e){ + }).on('unaffixed.bs.affix', function (e) { ok(true,'unaffixed event triggered') }) stop() - setTimeout(function(){ + setTimeout(function () { window.scrollTo(0,document.body.scrollHeight) - setTimeout(function(){ + setTimeout(function () { window.scroll(0,0) },0) },0)