manager.html 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  2. "http://www.w3.org/TR/html4/strict.dtd">
  3. <html>
  4. <head>
  5. <title>Dijit manager unit test</title>
  6. <style type="text/css">
  7. @import "../../../dojo/resources/dojo.css";
  8. @import "../css/dijitTests.css";
  9. </style>
  10. <script type="text/javascript" src="../../../dojo/dojo.js"
  11. djConfig="isDebug: true, parseOnLoad: true"></script>
  12. <script type="text/javascript" src="../_testCommon.js"></script>
  13. <script type="text/javascript">
  14. dojo.require("doh.runner");
  15. dojo.require("dijit.dijit");
  16. dojo.declare("foo", dijit._Widget, {
  17. name: "",
  18. attr1: 0,
  19. attr2: 0
  20. });
  21. dojo.declare("bar", dijit._Widget, {
  22. name: "",
  23. attr1: 0,
  24. attr2: 0
  25. });
  26. dojo.addOnLoad(function(){
  27. doh.register("dijit._base.manager",
  28. [
  29. function forEachTest(t){
  30. var names=[];
  31. dijit.registry.forEach(function(widget){ names.push(widget.name); });
  32. t.is(names.join(" "), "bob is your uncle");
  33. },
  34. function filterTest(t){
  35. var names=[];
  36. dijit.registry.
  37. filter(function(widget){ return widget.attr1==10; }).
  38. forEach(function(widget){ names.push(widget.name); });
  39. t.is(names.join(" "), "bob uncle");
  40. },
  41. function byId(t){
  42. t.is(dijit.byId("three").name, "your");
  43. },
  44. function byClass(t){
  45. var names=[];
  46. dijit.registry.
  47. byClass("bar").
  48. forEach(function(widget){ names.push(widget.name); });
  49. t.is(names.join(" "), "your uncle");
  50. },
  51. function deleteTest(t){
  52. var names=[];
  53. dijit.byId("two").destroy();
  54. dijit.byId("four").destroy();
  55. var names=[];
  56. dijit.registry.forEach(function(widget){ names.push(widget.name); });
  57. t.is(names.join(" "), "bob your");
  58. },
  59. function getEnclosingWidgetTest(t){
  60. t.is(dijit.getEnclosingWidget(dojo.byId("not-a-widget")), null);
  61. t.is(dijit.getEnclosingWidget(dojo.byId("three")).name, "your");
  62. t.is(dijit.getEnclosingWidget(dojo.byId("three.one")).name, "your");
  63. t.is(dijit.getEnclosingWidget(dojo.byId("three.one.one")).name, "your");
  64. }
  65. ]
  66. );
  67. doh.run();
  68. });
  69. </script>
  70. </head>
  71. <body>
  72. <h1>Dijit Manager Unit Test</h1>
  73. <div dojoType="foo" id="one" name="bob" attr1="10" attr2="10"></div>
  74. <div dojoType="foo" id="two" name="is" attr1="5" attr2="10"></div>
  75. <div dojoType="bar" id="three" name="your" attr1="5" attr2="5">
  76. <div id="three.one">
  77. <div id="three.one.one"></div>
  78. </div>
  79. </div>
  80. <div dojoType="bar" id="four" name="uncle" attr1="10" attr2="5"></div>
  81. <div id="not-a-widget"></div>
  82. </body>
  83. </html>