2 * mobile core unit tests
6 var libName = "jquery.mobile.core.js",
7 setGradeA = function(value, version) {
8 $.support.mediaquery = value;
9 $.mobile.browser.ie = version;
15 // NOTE reset for gradeA tests
16 $('html').removeClass('ui-mobile');
18 // NOTE reset for pageLoading tests
19 $('.ui-loader').remove();
26 $.testHelper.excludeFileProtocol(function(){
27 test( "grade A browser either supports media queries or is IE 7+", function(){
29 $.testHelper.reloadLib(libName);
30 ok(!$.mobile.gradeA());
33 $.testHelper.reloadLib(libName);
34 ok($.mobile.gradeA());
38 function clearNSNormalizeDictionary()
40 var dict = $.mobile.nsNormalizeDict;
41 for ( var prop in dict ) {
46 test( "$.mobile.nsNormalize works properly with namespace defined (test default)", function(){
47 // Start with a fresh namespace property cache, just in case
48 // the previous test mucked with namespaces.
49 clearNSNormalizeDictionary();
51 equal($.mobile.nsNormalize("foo"), "nstestFoo", "appends ns and initcaps");
52 equal($.mobile.nsNormalize("fooBar"), "nstestFooBar", "leaves capped strings intact");
53 equal($.mobile.nsNormalize("foo-bar"), "nstestFooBar", "changes dashed strings");
54 equal($.mobile.nsNormalize("foo-bar-bak"), "nstestFooBarBak", "changes multiple dashed strings");
56 // Reset the namespace property cache for the next test.
57 clearNSNormalizeDictionary();
60 test( "$.mobile.nsNormalize works properly with an empty namespace", function(){
61 var realNs = $.mobile.ns;
65 // Start with a fresh namespace property cache, just in case
66 // the previous test mucked with namespaces.
67 clearNSNormalizeDictionary();
69 equal($.mobile.nsNormalize("foo"), "foo", "leaves uncapped and undashed");
70 equal($.mobile.nsNormalize("fooBar"), "fooBar", "leaves capped strings intact");
71 equal($.mobile.nsNormalize("foo-bar"), "fooBar", "changes dashed strings");
72 equal($.mobile.nsNormalize("foo-bar-bak"), "fooBarBak", "changes multiple dashed strings");
76 // Reset the namespace property cache for the next test.
77 clearNSNormalizeDictionary();
81 test( "$.fn.jqmData and $.fn.jqmRemoveData methods are working properly", function(){
84 same( $("body").jqmData("foo", true), $("body"), "setting data returns the element" );
86 same( $("body").jqmData("foo"), true, "getting data returns the right value" );
88 same( $("body").data($.mobile.nsNormalize("foo")), true, "data was set using namespace" );
90 same( $("body").jqmData("foo", undefined), true, "getting data still returns the value if there's an undefined second arg" );
92 data = $.extend( {}, $("body").data() );
93 delete data[ $.expando ]; //discard the expando for that test
94 same( data , { "nstestFoo": true }, "passing .data() no arguments returns a hash with all set properties" );
96 same( $("body").jqmData(), undefined, "passing no arguments returns undefined" );
98 same( $("body").jqmData(undefined), undefined, "passing a single undefined argument returns undefined" );
100 same( $("body").jqmData(undefined, undefined), undefined, "passing 2 undefined arguments returns undefined" );
102 same( $("body").jqmRemoveData("foo"), $("body"), "jqmRemoveData returns the element" );
104 same( $("body").jqmData("foo"), undefined, "jqmRemoveData properly removes namespaced data" );
109 test( "$.jqmData and $.jqmRemoveData methods are working properly", function(){
110 same( $.jqmData(document.body, "foo", true), true, "setting data returns the value" );
112 same( $.jqmData(document.body, "foo"), true, "getting data returns the right value" );
114 same( $.data(document.body, $.mobile.nsNormalize("foo")), true, "data was set using namespace" );
116 same( $.jqmData(document.body, "foo", undefined), true, "getting data still returns the value if there's an undefined second arg" );
118 same( $.jqmData(document.body), undefined, "passing no arguments returns undefined" );
120 same( $.jqmData(document.body, undefined), undefined, "passing a single undefined argument returns undefined" );
122 same( $.jqmData(document.body, undefined, undefined), undefined, "passing 2 undefined arguments returns undefined" );
124 same( $.jqmRemoveData(document.body, "foo"), undefined, "jqmRemoveData returns the undefined value" );
126 same( $("body").jqmData("foo"), undefined, "jqmRemoveData properly removes namespaced data" );
130 test( "addDependents works properly", function() {
131 same( $("#parent").jqmData('dependents'), undefined );
132 $( "#parent" ).addDependents( $("#dependent") );
133 same( $("#parent").jqmData('dependents').length, 1 );
136 test( "removeWithDependents removes the parent element and ", function(){
137 $( "#parent" ).addDependents( $("#dependent") );
138 same($( "#parent, #dependent" ).length, 2);
139 $( "#parent" ).removeWithDependents();
140 same($( "#parent, #dependent" ).length, 0);
143 test( "$.fn.getEncodedText should return the encoded value where $.fn.text doesn't", function() {
144 same( $("#encoded").text(), "foo>");
145 same( $("#encoded").getEncodedText(), "foo>");
146 same( $("#unencoded").getEncodedText(), "foo");