From 089f2b9753b43027383fe9e8c99140140b5c1f6e Mon Sep 17 00:00:00 2001 From: John Bender Date: Sun, 6 Feb 2011 23:25:03 -0800 Subject: [PATCH] rewrapped the media core tests in an immediate function --- tests/unit/media/media_core.js | 170 +++++++++++++++++---------------- 1 file changed, 86 insertions(+), 84 deletions(-) diff --git a/tests/unit/media/media_core.js b/tests/unit/media/media_core.js index 6e004817..8394625c 100644 --- a/tests/unit/media/media_core.js +++ b/tests/unit/media/media_core.js @@ -2,93 +2,95 @@ * mobile media unit tests */ -var cssFn = $.fn.css, - widthFn = $.fn.width; +(function($){ + var cssFn = $.fn.css, + widthFn = $.fn.width; -// make sure original definitions are reset -module('jquery.mobile.media.js', { - setup: function(){ - $(document).trigger('mobileinit.htmlclass'); - }, - teardown: function(){ - $.fn.css = cssFn; - $.fn.width = widthFn; - } -}); - -test( "media query check returns true when the position is absolute", function(){ - $.fn.css = function(){ return "absolute"; }; - same($.mobile.media("screen 1"), true); -}); - -test( "media query check returns false when the position is not absolute", function(){ - $.fn.css = function(){ return "not absolute"; }; - same($.mobile.media("screen 2"), false); -}); - -test( "media query check is cached", function(){ - $.fn.css = function(){ return "absolute"; }; - same($.mobile.media("screen 3"), true); - - $.fn.css = function(){ return "not absolute"; }; - same($.mobile.media("screen 3"), true); -}); - -test( "window widths smaller than the break points set max-width classes", function(){ - $.fn.width = function(){ return 120; }; - - $.mobile.addResolutionBreakpoints([125]); - ok($("html").hasClass("max-width-125px")); -}); - -test( "window widths larger than the break points set min-width classes", function(){ - $.fn.width = function(){ return 1900; }; - - $.mobile.addResolutionBreakpoints([125]); - ok($("html").hasClass("min-width-125px")); -}); - -test( "many break points result in many class additions", function(){ - $.fn.width = function(){ return 1900; }; - $.mobile.addResolutionBreakpoints([1, 2]); - - ok($("html").hasClass("min-width-1px")); - ok($("html").hasClass("min-width-2px")); -}); - -test( "adds all classes for default res breakpoints", function(){ - expect( 4 ); - $.fn.width = function(){ return 1900; }; - $.mobile.addResolutionBreakpoints([]); - - // TODO should expose the defaults to prevent brittle tests - $.each([320, 480, 768, 1024], function(i, element){ - ok($("html").hasClass("min-width-" + element + "px")); - }); -}); - -test( "binds remove of portrait and landscape classes resize/orientation fired", function(){ - expect( 2 ); - - $.Event.prototype.orientation = "foo"; - - $(window).bind("orientationchange.htmlclass resize.htmlclass", function(event){ - ok(!$("html").hasClass("portrait landscape")); - start(); + // make sure original definitions are reset + module('jquery.mobile.media.js', { + setup: function(){ + $(document).trigger('mobileinit.htmlclass'); + }, + teardown: function(){ + $.fn.css = cssFn; + $.fn.width = widthFn; + } }); - $("html").addClass("portrait landscape"); - $(window).trigger("resize.htmlclass"); + test( "media query check returns true when the position is absolute", function(){ + $.fn.css = function(){ return "absolute"; }; + same($.mobile.media("screen 1"), true); + }); - $("html").addClass("portrait landscape"); - $(window).trigger("orientationchange.htmlclass"); - stop(); -}); + test( "media query check returns false when the position is not absolute", function(){ + $.fn.css = function(){ return "not absolute"; }; + same($.mobile.media("screen 2"), false); + }); -test( "sets break point class additions on resize/orientation change", function(){ - $.fn.width = function(){ return 1900; }; + test( "media query check is cached", function(){ + $.fn.css = function(){ return "absolute"; }; + same($.mobile.media("screen 3"), true); - $("html").removeClass("min-width-320px"); - $(window).trigger("resize.htmlclass"); - ok($("html").hasClass("min-width-320px")); -}); + $.fn.css = function(){ return "not absolute"; }; + same($.mobile.media("screen 3"), true); + }); + + test( "window widths smaller than the break points set max-width classes", function(){ + $.fn.width = function(){ return 120; }; + + $.mobile.addResolutionBreakpoints([125]); + ok($("html").hasClass("max-width-125px")); + }); + + test( "window widths larger than the break points set min-width classes", function(){ + $.fn.width = function(){ return 1900; }; + + $.mobile.addResolutionBreakpoints([125]); + ok($("html").hasClass("min-width-125px")); + }); + + test( "many break points result in many class additions", function(){ + $.fn.width = function(){ return 1900; }; + $.mobile.addResolutionBreakpoints([1, 2]); + + ok($("html").hasClass("min-width-1px")); + ok($("html").hasClass("min-width-2px")); + }); + + test( "adds all classes for default res breakpoints", function(){ + expect( 4 ); + $.fn.width = function(){ return 1900; }; + $.mobile.addResolutionBreakpoints([]); + + // TODO should expose the defaults to prevent brittle tests + $.each([320, 480, 768, 1024], function(i, element){ + ok($("html").hasClass("min-width-" + element + "px")); + }); + }); + + test( "binds remove of portrait and landscape classes resize/orientation fired", function(){ + expect( 2 ); + + $.Event.prototype.orientation = "foo"; + + $(window).bind("orientationchange.htmlclass resize.htmlclass", function(event){ + ok(!$("html").hasClass("portrait landscape")); + start(); + }); + + $("html").addClass("portrait landscape"); + $(window).trigger("resize.htmlclass"); + + $("html").addClass("portrait landscape"); + $(window).trigger("orientationchange.htmlclass"); + stop(); + }); + + test( "sets break point class additions on resize/orientation change", function(){ + $.fn.width = function(){ return 1900; }; + + $("html").removeClass("min-width-320px"); + $(window).trigger("resize.htmlclass"); + ok($("html").hasClass("min-width-320px")); + }); +})(jQuery); \ No newline at end of file