corrade-http-templates – Blame information for rev 57

Subversion Repositories:
Rev:
Rev Author Line No. Line
57 office 1 define( [
2 "qunit",
3 "jquery" ],
4 function( QUnit, $ ) {
5  
6 var exports = {};
7  
8 function testWidgetDefaults( widget, defaults ) {
9 var pluginDefaults = $.ui[ widget ].prototype.options;
10  
11 // Ensure that all defaults have the correct value
12 QUnit.test( "defined defaults", function( assert ) {
13 var count = 0;
14 $.each( defaults, function( key, val ) {
15 assert.expect( ++count );
16 if ( $.isFunction( val ) ) {
17 assert.ok( $.isFunction( pluginDefaults[ key ] ), key );
18 return;
19 }
20 assert.deepEqual( pluginDefaults[ key ], val, key );
21 } );
22 } );
23  
24 // Ensure that all defaults were tested
25 QUnit.test( "tested defaults", function( assert ) {
26 var count = 0;
27 $.each( pluginDefaults, function( key ) {
28 assert.expect( ++count );
29 assert.ok( key in defaults, key );
30 } );
31 } );
32 }
33  
34 function testWidgetOverrides( widget ) {
35 if ( $.uiBackCompat === false ) {
36 QUnit.test( "$.widget overrides", function( assert ) {
37 assert.expect( 4 );
38 $.each( [
39 "_createWidget",
40 "destroy",
41 "option",
42 "_trigger"
43 ], function( i, method ) {
44 assert.strictEqual( $.ui[ widget ].prototype[ method ],
45 $.Widget.prototype[ method ], "should not override " + method );
46 } );
47 } );
48 }
49 }
50  
51 function testBasicUsage( widget ) {
52 QUnit.test( "basic usage", function( assert ) {
53 assert.expect( 3 );
54  
55 var defaultElement = $.ui[ widget ].prototype.defaultElement;
56 $( defaultElement ).appendTo( "body" )[ widget ]().remove();
57 assert.ok( true, "initialized on element" );
58  
59 $( defaultElement )[ widget ]().remove();
60 assert.ok( true, "initialized on disconnected DOMElement - never connected" );
61  
62 // Ensure manipulating removed elements works (#3664)
63 $( defaultElement ).appendTo( "body" ).remove()[ widget ]().remove();
64 assert.ok( true, "initialized on disconnected DOMElement - removed" );
65 } );
66 }
67  
68 exports.testWidget = function( widget, settings ) {
69 QUnit.module( widget + ": common widget" );
70  
71 exports.testJshint( "/widgets/" + widget );
72 testWidgetDefaults( widget, settings.defaults );
73 testWidgetOverrides( widget );
74 if ( !settings.noDefaultElement ) {
75 testBasicUsage( widget );
76 }
77 QUnit.test( "version", function( assert ) {
78 assert.expect( 1 );
79 assert.ok( "version" in $.ui[ widget ].prototype, "version property exists" );
80 } );
81 };
82  
83 exports.testJshint = function( module ) {
84  
85 // Function.prototype.bind check is needed because JSHint doesn't work in ES3 browsers anymore
86 // https://github.com/jshint/jshint/issues/1384
87 if ( QUnit.urlParams.nojshint || !Function.prototype.bind ) {
88 return;
89 }
90  
91 QUnit.test( "JSHint", function( assert ) {
92 var ready = assert.async();
93 require( [ "jshint" ], function() {
94 assert.expect( 1 );
95  
96 $.when(
97 $.ajax( {
98 url: "../../../ui/.jshintrc",
99 dataType: "json"
100 } ),
101 $.ajax( {
102 url: "../../../ui/" + module + ".js",
103 dataType: "text"
104 } )
105 )
106 .done( function( hintArgs, srcArgs ) {
107 var globals, passed, errors,
108 jshintrc = hintArgs[ 0 ],
109 source = srcArgs[ 0 ];
110  
111 globals = jshintrc.globals || {};
112 delete jshintrc.globals;
113 passed = JSHINT( source, jshintrc, globals );
114 errors = $.map( JSHINT.errors, function( error ) {
115  
116 // JSHINT may report null if there are too many errors
117 if ( !error ) {
118 return;
119 }
120  
121 return "[L" + error.line + ":C" + error.character + "] " +
122 error.reason + "\n" + error.evidence + "\n";
123 } ).join( "\n" );
124 assert.ok( passed, errors );
125 ready();
126 } )
127 .fail( function( hintError, srcError ) {
128 assert.ok( false, "error loading source: " + ( hintError || srcError ).statusText );
129 ready();
130 } );
131 } );
132 } );
133 };
134  
135 return exports;
136  
137 } );