You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
2.5 KiB
94 lines
2.5 KiB
<!DOCTYPE html> |
|
<html> |
|
<head> |
|
<meta http-equiv="Content-type" content="text/html; charset=utf-8"> |
|
|
|
<title>dijit/registry unit test</title> |
|
|
|
<script src="boilerplate.js"></script> |
|
|
|
<script type="text/javascript"> |
|
require([ |
|
"doh/runner", |
|
"dojo/_base/array", "dojo/_base/declare", "dojo/dom", "dojo/parser", "dojo/_base/window", |
|
"dijit/_WidgetBase", "dijit/registry", |
|
"dojo/domReady!" |
|
], function(doh, array, declare, dom, parser, win, _WidgetBase, registry){ |
|
|
|
declare("foo", _WidgetBase, { |
|
name: "", |
|
attr1: 0, |
|
attr2: 0 |
|
}); |
|
|
|
declare("bar", _WidgetBase, { |
|
name: "", |
|
attr1: 0, |
|
attr2: 0 |
|
}); |
|
|
|
declare("Baz", _WidgetBase, { |
|
name: "", |
|
attr1: 1, |
|
attr2: 1 |
|
}); |
|
|
|
doh.register("parse", function(){ |
|
parser.parse(); |
|
}); |
|
|
|
doh.register("dijit/registry", [ |
|
function byId(){ |
|
doh.is(registry.byId("three").name, "your"); |
|
doh.f(registry.byId("nonexistent")); |
|
}, |
|
function toArray(){ |
|
var wa = registry.toArray(); |
|
|
|
doh.is(4, wa.length, "length"); |
|
|
|
var wda = array.map(wa, function(w){ |
|
return w.domNode; |
|
}); |
|
|
|
var w = registry.byNode(wda[0]); |
|
doh.is(w.declaredClass, "foo"); |
|
}, |
|
function getEnclosingWidget(){ |
|
doh.is(registry.getEnclosingWidget(dom.byId("not-a-widget")), null); |
|
doh.is(registry.getEnclosingWidget(dom.byId("three")).name, "your"); |
|
doh.is(registry.getEnclosingWidget(dom.byId("three.one")).name, "your"); |
|
doh.is(registry.getEnclosingWidget(dom.byId("three.one.one")).name, "your"); |
|
}, |
|
function findWidgets(){ |
|
doh.is(3, registry.findWidgets(win.body()).length); |
|
doh.is(1, registry.findWidgets(dom.byId("threeWrapper")).length); |
|
}, |
|
function destroy(){ |
|
registry.byId("two").destroy(); |
|
registry.byId("four").destroy(); |
|
var names = array.map(registry.toArray(), function(widget){ return widget.name; }); |
|
doh.is(names.join(" "), "bob your"); |
|
} |
|
]); |
|
|
|
doh.run(); |
|
}); |
|
|
|
</script> |
|
</head> |
|
<body> |
|
<h1>Dijit/registry Unit Test</h1> |
|
<div id="one" data-dojo-type="foo" data-dojo-props='name:"bob", attr1:10, attr2:10'></div> |
|
<div id="two" data-dojo-type="foo" data-dojo-props='name:"is", attr1:5, attr2:10'></div> |
|
<div id="threeWrapper"> |
|
<div id="three" data-dojo-type="bar" data-dojo-props='name:"your", attr1:5, attr2:5'> |
|
<div id="three.one"> |
|
<div id="three.one.one"></div> |
|
<div id="four" data-dojo-type="bar" data-dojo-props='name:"uncle", attr1:10, attr2:5'></div> |
|
</div> |
|
</div> |
|
</div> |
|
<div id="not-a-widget"></div> |
|
</body> |
|
</html>
|
|
|