@@ -9,6 +9,39 @@ module( "widget factory", {
9
9
}
10
10
} ) ;
11
11
12
+ test ( "widget namespaces" , function ( ) {
13
+ var fail = function ( msg ) { ok ( false , msg ) ; } ;
14
+
15
+ var uiPrototype = {
16
+ _create : function ( ) { fail ( "This widget should not have been instantiated" ) ; }
17
+ } ;
18
+
19
+ var customPrototype = {
20
+ _create : function ( ) { ok ( true , "Second defined widget is the one that takes over default scope" ) }
21
+ }
22
+
23
+ $ . widget ( "ui.testWidget" , uiPrototype ) ;
24
+ $ . widget ( "custom.testWidget" , customPrototype ) ;
25
+
26
+ var elem = $ ( "<div></div>" ) . testWidget ( ) ;
27
+
28
+ ok ( $ . isFunction ( $ . ui . testWidget ) , "constructor was created in the ui namespace" ) ;
29
+ ok ( $ . isFunction ( $ . custom . testWidget ) , "constructor was created in the custom namespace" ) ;
30
+ equals ( uiPrototype . _create , $ . ui . testWidget . prototype . _create , "ui widget is in the ui namespace" ) ;
31
+ equals ( customPrototype . _create , $ . custom . testWidget . prototype . _create , "custom namespace is maintained" ) ;
32
+
33
+ // Now make sure we can explicitly pick the one we want
34
+ var which = "neither" ;
35
+ $ . ui . testWidget . prototype . _create = function ( ) { which = "ui" ; } ;
36
+ var elem2 = $ ( "<div></div>" ) . ui_testWidget ( ) ;
37
+ equals ( which , "ui" , "creating a namespaced widget makes the correct one" ) ;
38
+
39
+ which = "neither" ;
40
+ $ . custom . testWidget . prototype . _create = function ( ) { which = "custom" ; } ;
41
+ var elem3 = $ ( "<div></div>" ) . custom_testWidget ( ) ;
42
+ equals ( which , "custom" , "creating a namespaced widget makes the correct one" ) ;
43
+ } ) ;
44
+
12
45
test ( "widget creation" , function ( ) {
13
46
var myPrototype = {
14
47
_create : function ( ) { } ,
@@ -236,7 +269,35 @@ test( ".option() - delegate to ._setOptions()", function() {
236
269
"_setOptions called with multiple options" ) ;
237
270
} ) ;
238
271
239
- test ( ".option() - delegate to ._setOption()" , function ( ) {
272
+ test ( ".option() - getter - custom namespace" , function ( ) {
273
+ $ . widget ( "custom.testWidget" , {
274
+ _create : function ( ) { }
275
+ } ) ;
276
+
277
+ var div = $ ( "<div></div>" ) . custom_testWidget ( {
278
+ foo : "bar" ,
279
+ baz : 5 ,
280
+ qux : [ "quux" , "quuux" ]
281
+ } ) ;
282
+
283
+ same ( div . custom_testWidget ( "option" , "foo" ) , "bar" , "single option - string" ) ;
284
+ same ( div . custom_testWidget ( "option" , "baz" ) , 5 , "single option - number" ) ;
285
+ same ( div . custom_testWidget ( "option" , "qux" ) , [ "quux" , "quuux" ] ,
286
+ "single option - array" ) ;
287
+
288
+ var options = div . custom_testWidget ( "option" ) ;
289
+ same ( options , {
290
+ disabled : false ,
291
+ foo : "bar" ,
292
+ baz : 5 ,
293
+ qux : [ "quux" , "quuux" ]
294
+ } , "full options hash returned" ) ;
295
+ options . foo = "notbar" ;
296
+ same ( div . custom_testWidget ( "option" , "foo" ) , "bar" ,
297
+ "modifying returned options hash does not modify plugin instance" ) ;
298
+ } ) ;
299
+
300
+ test ( ".option() - setter" , function ( ) {
240
301
var calls = [ ] ;
241
302
$ . widget ( "ui.testWidget" , {
242
303
_create : function ( ) { } ,
0 commit comments