| 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <meta http-equiv="Content-type" content="text/html; charset=utf-8"> |
| 5 | |
| 6 | <title>dijit/registry unit test</title> |
| 7 | |
| 8 | <script src="boilerplate.js"></script> |
| 9 | |
| 10 | <script type="text/javascript"> |
| 11 | require([ |
| 12 | "doh/runner", |
| 13 | "dojo/_base/array", "dojo/_base/declare", "dojo/dom", "dojo/parser", "dojo/_base/window", |
| 14 | "dijit/_WidgetBase", "dijit/registry", |
| 15 | "dojo/domReady!" |
| 16 | ], function(doh, array, declare, dom, parser, win, _WidgetBase, registry){ |
| 17 | |
| 18 | declare("foo", _WidgetBase, { |
| 19 | name: "", |
| 20 | attr1: 0, |
| 21 | attr2: 0 |
| 22 | }); |
| 23 | |
| 24 | declare("bar", _WidgetBase, { |
| 25 | name: "", |
| 26 | attr1: 0, |
| 27 | attr2: 0 |
| 28 | }); |
| 29 | |
| 30 | declare("Baz", _WidgetBase, { |
| 31 | name: "", |
| 32 | attr1: 1, |
| 33 | attr2: 1 |
| 34 | }); |
| 35 | |
| 36 | doh.register("parse", function(){ |
| 37 | parser.parse(); |
| 38 | }); |
| 39 | |
| 40 | doh.register("dijit/registry", [ |
| 41 | function byId(){ |
| 42 | doh.is(registry.byId("three").name, "your"); |
| 43 | doh.f(registry.byId("nonexistent")); |
| 44 | }, |
| 45 | function toArray(){ |
| 46 | var wa = registry.toArray(); |
| 47 | |
| 48 | doh.is(4, wa.length, "length"); |
| 49 | |
| 50 | var wda = array.map(wa, function(w){ |
| 51 | return w.domNode; |
| 52 | }); |
| 53 | |
| 54 | var w = registry.byNode(wda[0]); |
| 55 | doh.is(w.declaredClass, "foo"); |
| 56 | }, |
| 57 | function getEnclosingWidget(){ |
| 58 | doh.is(registry.getEnclosingWidget(dom.byId("not-a-widget")), null); |
| 59 | doh.is(registry.getEnclosingWidget(dom.byId("three")).name, "your"); |
| 60 | doh.is(registry.getEnclosingWidget(dom.byId("three.one")).name, "your"); |
| 61 | doh.is(registry.getEnclosingWidget(dom.byId("three.one.one")).name, "your"); |
| 62 | }, |
| 63 | function findWidgets(){ |
| 64 | doh.is(3, registry.findWidgets(win.body()).length); |
| 65 | doh.is(1, registry.findWidgets(dom.byId("threeWrapper")).length); |
| 66 | }, |
| 67 | function destroy(){ |
| 68 | registry.byId("two").destroy(); |
| 69 | registry.byId("four").destroy(); |
| 70 | var names = array.map(registry.toArray(), function(widget){ return widget.name; }); |
| 71 | doh.is(names.join(" "), "bob your"); |
| 72 | } |
| 73 | ]); |
| 74 | |
| 75 | doh.run(); |
| 76 | }); |
| 77 | |
| 78 | </script> |
| 79 | </head> |
| 80 | <body> |
| 81 | <h1>Dijit/registry Unit Test</h1> |
| 82 | <div id="one" data-dojo-type="foo" data-dojo-props='name:"bob", attr1:10, attr2:10'></div> |
| 83 | <div id="two" data-dojo-type="foo" data-dojo-props='name:"is", attr1:5, attr2:10'></div> |
| 84 | <div id="threeWrapper"> |
| 85 | <div id="three" data-dojo-type="bar" data-dojo-props='name:"your", attr1:5, attr2:5'> |
| 86 | <div id="three.one"> |
| 87 | <div id="three.one.one"></div> |
| 88 | <div id="four" data-dojo-type="bar" data-dojo-props='name:"uncle", attr1:10, attr2:5'></div> |
| 89 | </div> |
| 90 | </div> |
| 91 | </div> |
| 92 | <div id="not-a-widget"></div> |
| 93 | </body> |
| 94 | </html> |