|
2 | 2 | * mobile core unit tests |
3 | 3 | */ |
4 | 4 |
|
5 | | -(function( $ ) { |
6 | | - var libName = "jquery.mobile.core.js", |
7 | | - setGradeA = function(value) { $.support.mediaquery = value; }, |
8 | | - extendFn = $.extend; |
9 | | - |
10 | | - module(libName, { |
11 | | - setup: function(){ |
12 | | - // NOTE reset for gradeA tests |
13 | | - $('html').removeClass('ui-mobile'); |
14 | | - |
15 | | - // NOTE reset for pageLoading tests |
16 | | - $('.ui-loader').remove(); |
17 | | - }, |
18 | | - teardown: function(){ |
19 | | - $.extend = extendFn; |
20 | | - } |
| 5 | +var libName = "jquery.mobile.core.js", |
| 6 | + setGradeA = function(value) { $.support.mediaquery = value; }, |
| 7 | + extendFn = $.extend; |
| 8 | + |
| 9 | +module(libName, { |
| 10 | + setup: function(){ |
| 11 | + // NOTE reset for gradeA tests |
| 12 | + $('html').removeClass('ui-mobile'); |
| 13 | + |
| 14 | + // NOTE reset for pageLoading tests |
| 15 | + $('.ui-loader').remove(); |
| 16 | + }, |
| 17 | + teardown: function(){ |
| 18 | + $.extend = extendFn; |
| 19 | + } |
| 20 | +}); |
| 21 | + |
| 22 | +$.testHelper.excludeFileProtocol(function(){ |
| 23 | + test( "grade A browser support media queries", function(){ |
| 24 | + setGradeA(false); |
| 25 | + $.testHelper.reloadLib(libName); |
| 26 | + ok(!$.mobile.gradeA()); |
| 27 | + |
| 28 | + setGradeA(true); |
| 29 | + $.testHelper.reloadLib(libName); |
| 30 | + ok($.mobile.gradeA()); |
21 | 31 | }); |
22 | 32 |
|
23 | | - $.testHelper.excludeFileProtocol(function(){ |
24 | | - test( "grade A browser support media queries", function(){ |
25 | | - setGradeA(false); |
26 | | - $.testHelper.reloadLib(libName); |
27 | | - ok(!$.mobile.gradeA()); |
| 33 | + test( "loading the core library triggers mobilinit on the document", function(){ |
| 34 | + expect( 1 ); |
28 | 35 |
|
29 | | - setGradeA(true); |
30 | | - $.testHelper.reloadLib(libName); |
31 | | - ok($.mobile.gradeA()); |
| 36 | + $(window.document).bind('mobileinit', function(event){ |
| 37 | + ok(true); |
32 | 38 | }); |
33 | 39 |
|
34 | | - test( "loading the core library triggers mobilinit on the document", function(){ |
35 | | - expect( 1 ); |
36 | | - |
37 | | - $(window.document).bind('mobileinit', function(event){ |
38 | | - ok(true); |
39 | | - }); |
40 | | - |
41 | | - $.testHelper.reloadLib(libName); |
42 | | - }); |
43 | | - |
44 | | - test( "enhancments are skipped when the browser is not grade A", function(){ |
45 | | - setGradeA(false); |
46 | | - $.testHelper.reloadLib(libName); |
| 40 | + $.testHelper.reloadLib(libName); |
| 41 | + }); |
47 | 42 |
|
48 | | - //NOTE easiest way to check for enhancements, not the most obvious |
49 | | - ok(!$("html").hasClass("ui-mobile")); |
50 | | - }); |
| 43 | + test( "enhancments are skipped when the browser is not grade A", function(){ |
| 44 | + setGradeA(false); |
| 45 | + $.testHelper.reloadLib(libName); |
51 | 46 |
|
52 | | - test( "enhancments are added when the browser is grade A", function(){ |
53 | | - setGradeA(true); |
54 | | - $.testHelper.reloadLib(libName); |
| 47 | + //NOTE easiest way to check for enhancements, not the most obvious |
| 48 | + ok(!$("html").hasClass("ui-mobile")); |
| 49 | + }); |
55 | 50 |
|
56 | | - ok($("html").hasClass("ui-mobile")); |
57 | | - }); |
| 51 | + test( "enhancments are added when the browser is grade A", function(){ |
| 52 | + setGradeA(true); |
| 53 | + $.testHelper.reloadLib(libName); |
58 | 54 |
|
| 55 | + ok($("html").hasClass("ui-mobile")); |
| 56 | + }); |
59 | 57 |
|
60 | | - //TODO lots of duplication |
61 | | - test( "pageLoading doesn't add the dialog to the page when loading message is false", function(){ |
62 | | - $.testHelper.alterExtend({loadingMessage: false}); |
63 | | - $.testHelper.reloadLib(libName); |
64 | | - $.mobile.pageLoading(false); |
65 | | - ok(!$(".ui-loader").length); |
66 | | - }); |
67 | 58 |
|
68 | | - test( "pageLoading doesn't add the dialog to the page when done is passed as true", function(){ |
69 | | - $.testHelper.alterExtend({loadingMessage: true}); |
70 | | - $.testHelper.reloadLib(libName); |
| 59 | + //TODO lots of duplication |
| 60 | + test( "pageLoading doesn't add the dialog to the page when loading message is false", function(){ |
| 61 | + $.testHelper.alterExtend({loadingMessage: false}); |
| 62 | + $.testHelper.reloadLib(libName); |
| 63 | + $.mobile.pageLoading(false); |
| 64 | + ok(!$(".ui-loader").length); |
| 65 | + }); |
71 | 66 |
|
72 | | - // TODO add post reload callback |
73 | | - $('.ui-loader').remove(); |
| 67 | + test( "pageLoading doesn't add the dialog to the page when done is passed as true", function(){ |
| 68 | + $.testHelper.alterExtend({loadingMessage: true}); |
| 69 | + $.testHelper.reloadLib(libName); |
74 | 70 |
|
75 | | - $.mobile.pageLoading(true); |
76 | | - ok(!$(".ui-loader").length); |
77 | | - }); |
| 71 | + // TODO add post reload callback |
| 72 | + $('.ui-loader').remove(); |
78 | 73 |
|
79 | | - test( "pageLoading adds the dialog to the page when done is true", function(){ |
80 | | - $.testHelper.alterExtend({loadingMessage: true}); |
81 | | - $.testHelper.reloadLib(libName); |
82 | | - $.mobile.pageLoading(false); |
83 | | - ok($(".ui-loader").length); |
84 | | - }); |
| 74 | + $.mobile.pageLoading(true); |
| 75 | + ok(!$(".ui-loader").length); |
| 76 | + }); |
85 | 77 |
|
86 | | - var metaViewportSelector = "head meta[name=viewport]", |
87 | | - setViewPortContent = function(value){ |
88 | | - $(metaViewportSelector).remove(); |
89 | | - $.testHelper.alterExtend({metaViewportContent: value}); |
90 | | - $.testHelper.reloadLib(libName); |
91 | | - }; |
| 78 | + test( "pageLoading adds the dialog to the page when done is true", function(){ |
| 79 | + $.testHelper.alterExtend({loadingMessage: true}); |
| 80 | + $.testHelper.reloadLib(libName); |
| 81 | + $.mobile.pageLoading(false); |
| 82 | + ok($(".ui-loader").length); |
| 83 | + }); |
92 | 84 |
|
93 | | - test( "meta view port element is added to head when defined on mobile", function(){ |
94 | | - setViewPortContent("width=device-width"); |
95 | | - same($(metaViewportSelector).length, 1); |
96 | | - }); |
| 85 | + var metaViewportSelector = "head meta[name=viewport]", |
| 86 | + setViewPortContent = function(value){ |
| 87 | + $(metaViewportSelector).remove(); |
| 88 | + $.testHelper.alterExtend({metaViewportContent: value}); |
| 89 | + $.testHelper.reloadLib(libName); |
| 90 | + }; |
97 | 91 |
|
98 | | - test( "meta view port element not added to head when not defined on mobile", function(){ |
99 | | - setViewPortContent(false); |
100 | | - same($(metaViewportSelector).length, 0); |
101 | | - }); |
| 92 | + test( "meta view port element is added to head when defined on mobile", function(){ |
| 93 | + setViewPortContent("width=device-width"); |
| 94 | + same($(metaViewportSelector).length, 1); |
| 95 | + }); |
102 | 96 |
|
103 | | - var findFirstPage = function() { |
104 | | - return $("[data-role='page']").first(); |
105 | | - }; |
| 97 | + test( "meta view port element not added to head when not defined on mobile", function(){ |
| 98 | + setViewPortContent(false); |
| 99 | + same($(metaViewportSelector).length, 0); |
| 100 | + }); |
106 | 101 |
|
107 | | - test( "active page and start page should be set to the fist page in the selected set", function(){ |
108 | | - var firstPage = findFirstPage(); |
109 | | - $.testHelper.reloadLib(libName); |
| 102 | + var findFirstPage = function() { |
| 103 | + return $("[data-role='page']").first(); |
| 104 | + }; |
110 | 105 |
|
111 | | - same($.mobile.startPage, firstPage); |
112 | | - same($.mobile.activePage, firstPage); |
113 | | - }); |
| 106 | + test( "active page and start page should be set to the fist page in the selected set", function(){ |
| 107 | + var firstPage = findFirstPage(); |
| 108 | + $.testHelper.reloadLib(libName); |
114 | 109 |
|
115 | | - test( "mobile viewport class is defined on the first page's parent", function(){ |
116 | | - var firstPage = findFirstPage(); |
117 | | - $.testHelper.reloadLib(libName); |
| 110 | + same($.mobile.startPage, firstPage); |
| 111 | + same($.mobile.activePage, firstPage); |
| 112 | + }); |
118 | 113 |
|
119 | | - ok(firstPage.parent().hasClass('ui-mobile-viewport')); |
120 | | - }); |
| 114 | + test( "mobile viewport class is defined on the first page's parent", function(){ |
| 115 | + var firstPage = findFirstPage(); |
| 116 | + $.testHelper.reloadLib(libName); |
121 | 117 |
|
122 | | - test( "mobile page container is the first page's parent", function(){ |
123 | | - var firstPage = findFirstPage(); |
124 | | - $.testHelper.reloadLib(libName); |
| 118 | + ok(firstPage.parent().hasClass('ui-mobile-viewport')); |
| 119 | + }); |
125 | 120 |
|
126 | | - same($.mobile.pageContainer, firstPage.parent()); |
127 | | - }); |
| 121 | + test( "mobile page container is the first page's parent", function(){ |
| 122 | + var firstPage = findFirstPage(); |
| 123 | + $.testHelper.reloadLib(libName); |
128 | 124 |
|
129 | | - test( "page loading is called on document ready", function(){ |
130 | | - expect( 2 ); |
| 125 | + same($.mobile.pageContainer, firstPage.parent()); |
| 126 | + }); |
131 | 127 |
|
132 | | - $.testHelper.alterExtend({ pageLoading: function(){ |
133 | | - ok("called"); |
134 | | - }}); |
| 128 | + test( "page loading is called on document ready", function(){ |
| 129 | + expect( 2 ); |
135 | 130 |
|
136 | | - $.testHelper.reloadLib(libName); |
137 | | - }); |
| 131 | + $.testHelper.alterExtend({ pageLoading: function(){ |
| 132 | + ok("called"); |
| 133 | + }}); |
138 | 134 |
|
139 | | - test( "hashchange triggered on document ready with single argument: true", function(){ |
140 | | - expect( 2 ); |
| 135 | + $.testHelper.reloadLib(libName); |
| 136 | + }); |
141 | 137 |
|
142 | | - $(window).bind("hashchange", function(ev, arg){ |
143 | | - same(arg, true); |
144 | | - }); |
| 138 | + test( "hashchange triggered on document ready with single argument: true", function(){ |
| 139 | + expect( 2 ); |
145 | 140 |
|
146 | | - $.testHelper.reloadLib(libName); |
| 141 | + $(window).bind("hashchange", function(ev, arg){ |
| 142 | + same(arg, true); |
147 | 143 | }); |
148 | 144 |
|
149 | | - //TODO test that silentScroll is called on window load |
| 145 | + $.testHelper.reloadLib(libName); |
150 | 146 | }); |
151 | | -})(jQuery); |
| 147 | + |
| 148 | + //TODO test that silentScroll is called on window load |
| 149 | +}); |
0 commit comments