~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to gis/dhis-gis-geostat/mfbase/openlayers/tests/BaseTypes/Element.html

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<html>
 
2
  <head>
 
3
  
 
4
    <script src="../../lib/OpenLayers.js"></script>
 
5
 
 
6
    <script type="text/javascript">
 
7
 
 
8
    function test_Element_visible(t) {
 
9
        t.plan(3);
 
10
        
 
11
        var elem = {
 
12
            style: {
 
13
                'display': ""
 
14
            }
 
15
        };
 
16
        
 
17
        elem.style.display = "";
 
18
        t.ok(OpenLayers.Element.visible(elem), "element with style.display == '' is visible");
 
19
            
 
20
        elem.style.display = "block";
 
21
        t.ok(OpenLayers.Element.visible(elem), "element with style.display == block is visible");
 
22
            
 
23
        elem.style.display = "none";
 
24
        t.ok(!OpenLayers.Element.visible(elem), "element with style.display == none is not visible");
 
25
    }
 
26
    
 
27
    function test_Element_toggle(t) {
 
28
        t.plan(2);
 
29
 
 
30
        var elem1 = {
 
31
            style: {
 
32
                'display': "none"
 
33
            }
 
34
        };
 
35
        
 
36
        var elem2 = {
 
37
            style: {
 
38
                'display': ""
 
39
            }
 
40
        };
 
41
 
 
42
        OpenLayers.Element.toggle(elem1, elem2);
 
43
        
 
44
        t.eq(elem1.style.display, "", "hidden element toggled to display");
 
45
        t.eq(elem2.style.display, "none", "shown element toggled to hidden");
 
46
    }
 
47
    
 
48
    function test_Element_hide(t) {
 
49
        t.plan(2);
 
50
 
 
51
        var elem1 = {
 
52
            style: {
 
53
                'display': "none"
 
54
            }
 
55
        };
 
56
        
 
57
        var elem2 = {
 
58
            style: {
 
59
                'display': ""
 
60
            }
 
61
        };
 
62
 
 
63
        OpenLayers.Element.hide(elem1, elem2);
 
64
        
 
65
        t.eq(elem1.style.display, "none", "hidden element stays hidden");
 
66
        t.eq(elem2.style.display, "none", "shown element hidden");
 
67
    }
 
68
    
 
69
    function test_Element_show(t) {
 
70
        t.plan(2);
 
71
 
 
72
        var elem1 = {
 
73
            style: {
 
74
                'display': "none"
 
75
            }
 
76
        };
 
77
        
 
78
        var elem2 = {
 
79
            style: {
 
80
                'display': ""
 
81
            }
 
82
        };
 
83
 
 
84
        OpenLayers.Element.show(elem1, elem2);
 
85
        
 
86
        t.eq(elem1.style.display, "", "hidden element shown");
 
87
        t.eq(elem2.style.display, "", "shown element stays shown");
 
88
    }
 
89
    
 
90
    function test_Element_remove(t) {
 
91
        t.plan(1);
 
92
 
 
93
        var elem = {
 
94
            parentNode: {
 
95
                'removeChild': function(elem) {
 
96
                    t.ok(true, "removeChild called");
 
97
                }
 
98
            }        
 
99
        };
 
100
        OpenLayers.Element.remove(elem);
 
101
    }
 
102
    
 
103
    function test_Element_getHeight(t) {
 
104
        t.plan(1);
 
105
 
 
106
        var elem = {
 
107
            'offsetHeight': {}
 
108
        };
 
109
        
 
110
        t.ok(OpenLayers.Element.getHeight(elem) == elem.offsetHeight, "offsetHeight returned");
 
111
    }
 
112
    
 
113
    function test_Element_getDimensions(t) {
 
114
        t.plan(4);
 
115
        
 
116
      //shown
 
117
        t.open_window( "BaseTypes/Element.html", function( wnd ) {
 
118
            t.delay_call( 0.5, function() {
 
119
                var elem = wnd.document.getElementById("elemID");
 
120
 
 
121
                var dims = OpenLayers.Element.getDimensions(elem);
 
122
                t.eq(dims.width, 50, "width correct when displayed");
 
123
                t.eq(dims.height, 100, "height correct when displayed")
 
124
      
 
125
                elem.style.display = "none";
 
126
                dims = OpenLayers.Element.getDimensions(elem);
 
127
                t.eq(dims.width, 50, "width correct when hidden");
 
128
                t.eq(dims.height, 100, "height correct when hidden")
 
129
      
 
130
 
 
131
            });
 
132
        });      
 
133
      
 
134
      //hidden
 
135
        
 
136
 
 
137
    }    
 
138
 
 
139
    function test_hasClass(t) {        
 
140
        t.plan(14);
 
141
        var has = OpenLayers.Element.hasClass;
 
142
 
 
143
        var element = document.createElement("div");
 
144
        element.className = "fe fi fo fum one.part two-part three:part four";
 
145
        
 
146
        t.ok(has(element, "fe"), "has fe");
 
147
        t.ok(has(element, "fi"), "has fi");
 
148
        t.ok(has(element, "fo"), "has fo");
 
149
        t.ok(!has(element, "f"), "hasn't f");
 
150
        t.ok(!has(element, "o"), "hasn't o");
 
151
        t.ok(!has(element, "fumb"), "hasn't fumb");
 
152
        t.ok(!has(element, "one"), "hasn't one");
 
153
        t.ok(has(element, "one.part"), "has one.part");
 
154
        t.ok(!has(element, "two"), "hasn't two");
 
155
        t.ok(has(element, "two-part"), "has two-part");
 
156
        t.ok(!has(element, "three"), "hasn't three");
 
157
        t.ok(has(element, "three:part"), "has three:part");
 
158
        t.ok(has(element, "four"), "has four");
 
159
        
 
160
        element.className = "";
 
161
        t.ok(!has(element, "nada"), "hasn't nada");
 
162
    }
 
163
 
 
164
    function test_addClass(t) {        
 
165
        t.plan(6);
 
166
        var add = OpenLayers.Element.addClass;
 
167
        
 
168
        var element = document.createElement("div");
 
169
        element.id = "foo";
 
170
        t.eq(element.className, "", "starts with no class name");
 
171
        
 
172
        var mod = add(element, "first");
 
173
        t.eq(mod.id, element.id, "returns the same element");
 
174
        t.eq(element.className, "first", "properly adds first class name");        
 
175
        t.eq(add(element, "second").className, "first second",
 
176
             "properly adds second class name");
 
177
        t.eq(add(element, "second").className, "first second",
 
178
             "doesn't do anything for duplicated names");
 
179
        t.eq(add(element, "third").className, "first second third",
 
180
             "properly adds third class name");
 
181
    }
 
182
    
 
183
    function test_removeClass(t) {
 
184
        t.plan(5);
 
185
        var remove = OpenLayers.Element.removeClass;
 
186
        
 
187
        var element = document.createElement("div");
 
188
        element.id = "foo";
 
189
        element.className = "first second middle fourth last";
 
190
        
 
191
        var mod = remove(element, "last");
 
192
        t.eq(mod.id, element.id, "returns the same element");
 
193
        t.eq(element.className, "first second middle fourth",
 
194
             "properly removes last class name");
 
195
        t.eq(remove(element, "first").className, "second middle fourth",
 
196
             "properly removes first class name");
 
197
        t.eq(remove(element, "middle").className, "second fourth",
 
198
             "properly removes middle class name");
 
199
        t.eq(remove(element, "nada").className, "second fourth",
 
200
             "doesn't do anything for bogus class name");
 
201
    }
 
202
 
 
203
    function test_toggleClass(t) {
 
204
        t.plan(5);
 
205
        var toggle = OpenLayers.Element.toggleClass;
 
206
        
 
207
        var element = document.createElement("div");
 
208
        element.id = "foo";
 
209
        
 
210
        var mod = toggle(element, "first");
 
211
        t.eq(mod.id, element.id, "returns the same element");
 
212
        t.eq(element.className, "first", "adds first new class name");
 
213
        t.eq(toggle(element, "second").className, "first second",
 
214
             "adds second new class name");
 
215
        t.eq(toggle(element, "first").className, "second",
 
216
             "removes first existing class name");
 
217
        t.eq(toggle(element, "second").className, "",
 
218
             "removes second existing class name");
 
219
    }
 
220
 
 
221
    function test_Element_getStyle(t) {
 
222
        t.plan(5);
 
223
 
 
224
    //tests for this function are not 100% complete... there is some funky
 
225
    // business going on in there with 
 
226
    //  * document.defaultView (moz/ff I believe)
 
227
    // but I cant seem to find a good way to test them.
 
228
    // 
 
229
                t.ok(OpenLayers.Element.getStyle(null, null) == null, "passing null values in to getStyle() doesnt bomb, returns null");
 
230
 
 
231
        var elem = document.getElementById("elemID");
 
232
        elem.style.chickenHead = {}
 
233
 
 
234
        var style = "chickenHead";
 
235
        t.ok(OpenLayers.Element.getStyle(elem, style) == elem.style.chickenHead, "get style on basic stylename returns correctly");
 
236
 
 
237
        elem.style.chickenHead = "auto";
 
238
        style = "chickenHead";
 
239
        t.ok(OpenLayers.Element.getStyle(elem, style) == null, "get style on 'auto' style returns null");
 
240
 
 
241
        if (OpenLayers.Util.getBrowserName() == "opera") {
 
242
            elem.style.top = "15px";
 
243
            style = "top";
 
244
 
 
245
            elem.style.position = "static";
 
246
            t.ok(OpenLayers.Element.getStyle(elem, style) == null, "in opera: get (top/left/right/bottom) style when position == 'static' returns null");
 
247
            
 
248
            elem.style.position = "";
 
249
            t.ok(OpenLayers.Element.getStyle(elem, style) == null, "in opera: get (top/left/right/bottom) style when position != 'static', gets computedStyle as static and returns null");
 
250
 
 
251
        } else {
 
252
            t.ok(true, "browser is not opera.");
 
253
            t.ok(true, "trust me. browser is not opera.");
 
254
        }
 
255
 
 
256
    }    
 
257
 
 
258
    </script>
 
259
  </head>
 
260
  <body>
 
261
    <div id="elemID" style="width:50px; height:100px; background-color:red">test</div>
 
262
  </body>
 
263
</html>