source: Dev/branches/rest-dojo-ui/client/dijit/tests/_Widget-lifecycle.html @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 2.8 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2                "http://www.w3.org/TR/html4/strict.dtd">
3<html>
4<head>
5
6        <title>_Widget.destroy() unit test</title>
7
8        <script type="text/javascript" src="../../dojo/dojo.js" djConfig="isDebug: true"></script>
9        <script type="text/javascript">
10                dojo.require("doh.runner");
11                dojo.require("dijit._Widget");
12
13                dojo.ready(function(){
14                        var obj = {
15                                foo: function(){
16                                        // summary: empty function that we connect to
17                                }
18                        };
19       
20                        // Number of times foo was called while TestWidget existed
21                        var calls = 0;
22       
23                        dojo.declare("dijit.TestWidget", dijit._Widget, {
24                                postCreate: function(){
25                                        // Rather odd call to this.connect() For testing the connections are dropped on destroy()
26                                        this.connect(obj, "foo", function(){
27                                                calls++;
28                                        });
29                                }
30                        });
31       
32                        var w;
33
34                        doh.register("dijit._Widget-lifecycle",
35                                [
36                                        {
37                                                name: "create",
38                                                runTest: function(t){
39                                                        w = new dijit.TestWidget({id: "w1"}, "w1");
40
41                                                        doh.t(dijit.byId("w1"), "widget in registry");
42
43                                                        // since there's no template, the widget just points to the srcNodeRef
44                                                        doh.is(w.domNode, dojo.byId("w1"), "srcNodeRef read in");
45
46                                                        // test the connection
47                                                        doh.is(0, calls, "foo() not called yet");
48                                                        obj.foo();
49                                                        doh.is(1, calls, "foo() called");
50                                                }
51                                        },
52                                        {
53                                                name: "destroy",
54                                                runTest: function(t){
55                                                        w.destroy();
56
57                                                        doh.f(dijit.byId("w1"), "widget no longer in registry");
58
59                                                        // test the connection was destroyed
60                                                        calls = 0;
61                                                        obj.foo();
62                                                        doh.is(0, calls, "connection was deleted");
63
64                                                        // test the DOM node was removed
65                                                        doh.f(dojo.byId("w1"), "DOM Node removed");
66                                                }
67                                        },
68                                        {
69                                                name: "destroy(true)  (preserving DOM node)",
70                                                runTest: function(t){
71                                                        w = new dijit.TestWidget({id: "w2"}, "w2");
72
73                                                        doh.t(dijit.byId("w2"), "widget in registry");
74                                                        w.destroy(true);
75
76                                                        doh.f(dijit.byId("w2"), "widget no longer in registry");
77
78                                                        // test the DOM node *wasn't* removed
79                                                        doh.t(dojo.byId("w2"), "DOM Node left");
80                                                }
81                                        }
82
83                                ]
84                        );
85
86                        doh.register("setter calls on creation", function(){
87                                // Make sure setters are called even for anonymous classes (#12122),
88                                // and even when there's no value explicitly specified in the parameters
89                                var fooSetterCalled,
90                                        Widget1 = dojo.declare([dijit._Widget], {}),
91                                    Widget2 = dojo.declare([dijit._Widget], {
92                                                foo: 345,
93                                        _setFooAttr: function(val){
94                                                        fooSetterCalled = val;
95                                            this.foo = val;
96                                        }
97                                    });
98                               
99                                new Widget1();
100                                new Widget2();
101                               
102                                doh.is(345, fooSetterCalled, "fooSetterCalled");
103                        });
104       
105                        doh.run();
106                });
107
108        </script>
109</head>
110<body class="claro">
111
112        <div id="w1"></div>
113        <div id="w2"></div>
114</body>
115</html>
Note: See TracBrowser for help on using the repository browser.