corrade-http-templates – Blame information for rev 62

Subversion Repositories:
Rev:
Rev Author Line No. Line
62 office 1 define( [
2 "qunit",
3 "jquery",
4 "./helper",
5 "ui/widgets/resizable"
6 ], function( QUnit, $, testHelper ) {
7  
8 QUnit.module( "resizable: core" );
9  
10 /*
11 Test("element types", function() {
12 var typeNames = ("p,h1,h2,h3,h4,h5,h6,blockquote,ol,ul,dl,div,form"
13 + ",table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr"
14 + ",acronym,code,samp,kbd,var,img,object,hr"
15 + ",input,button,label,select,iframe").split(",");
16  
17 $.each(typeNames, function(i) {
18 var typeName = typeNames[i];
19 el = $(document.createElement(typeName)).appendTo("body");
20 (typeName == "table" && el.append("<tr><td>content</td></tr>"));
21 el.resizable();
22 ok(true, "$('&lt;" + typeName + "/&gt').resizable()");
23 el.resizable("destroy");
24 el.remove();
25 });
26 });
27 */
28  
29 QUnit.test( "n", function( assert ) {
30 assert.expect( 4 );
31  
32 var handle = ".ui-resizable-n", target = $( "#resizable1" ).resizable( { handles: "all" } );
33  
34 testHelper.drag( handle, 0, -50 );
35 assert.equal( target.height(), 150, "compare height" );
36  
37 testHelper.drag( handle, 0, 50 );
38 assert.equal( target.height(), 100, "compare height" );
39  
40 assert.equal( target[ 0 ].style.left, "", "left should not be modified" );
41 assert.equal( target[ 0 ].style.width, "", "width should not be modified" );
42 } );
43  
44 QUnit.test( "s", function( assert ) {
45 assert.expect( 5 );
46  
47 var handle = ".ui-resizable-s", target = $( "#resizable1" ).resizable( { handles: "all" } );
48  
49 testHelper.drag( handle, 0, 50 );
50 assert.equal( target.height(), 150, "compare height" );
51  
52 testHelper.drag( handle, 0, -50 );
53 assert.equal( target.height(), 100, "compare height" );
54  
55 assert.equal( target[ 0 ].style.top, "", "top should not be modified" );
56 assert.equal( target[ 0 ].style.left, "", "left should not be modified" );
57 assert.equal( target[ 0 ].style.width, "", "width should not be modified" );
58 } );
59  
60 QUnit.test( "e", function( assert ) {
61 assert.expect( 5 );
62  
63 var handle = ".ui-resizable-e", target = $( "#resizable1" ).resizable( { handles: "all" } );
64  
65 testHelper.drag( handle, 50 );
66 assert.equal( target.width(), 150, "compare width" );
67  
68 testHelper.drag( handle, -50 );
69 assert.equal( target.width(), 100, "compare width" );
70  
71 assert.equal( target[ 0 ].style.height, "", "height should not be modified" );
72 assert.equal( target[ 0 ].style.top, "", "top should not be modified" );
73 assert.equal( target[ 0 ].style.left, "", "left should not be modified" );
74 } );
75  
76 QUnit.test( "w", function( assert ) {
77 assert.expect( 4 );
78  
79 var handle = ".ui-resizable-w", target = $( "#resizable1" ).resizable( { handles: "all" } );
80  
81 testHelper.drag( handle, -50 );
82 assert.equal( target.width(), 150, "compare width" );
83  
84 testHelper.drag( handle, 50 );
85 assert.equal( target.width(), 100, "compare width" );
86  
87 assert.equal( target[ 0 ].style.height, "", "height should not be modified" );
88 assert.equal( target[ 0 ].style.top, "", "top should not be modified" );
89 } );
90  
91 QUnit.test( "ne", function( assert ) {
92 assert.expect( 5 );
93  
94 var handle = ".ui-resizable-ne", target = $( "#resizable1" ).css( { overflow: "hidden" } ).resizable( { handles: "all" } );
95  
96 testHelper.drag( handle, -50, -50 );
97 assert.equal( target.width(), 50, "compare width" );
98 assert.equal( target.height(), 150, "compare height" );
99  
100 testHelper.drag( handle, 50, 50 );
101 assert.equal( target.width(), 100, "compare width" );
102 assert.equal( target.height(), 100, "compare height" );
103  
104 assert.equal( target[ 0 ].style.left, "", "left should not be modified" );
105 } );
106  
107 QUnit.test( "se", function( assert ) {
108 assert.expect( 6 );
109  
110 var handle = ".ui-resizable-se", target = $( "#resizable1" ).resizable( { handles: "all" } );
111  
112 testHelper.drag( handle, 50, 50 );
113 assert.equal( target.width(), 150, "compare width" );
114 assert.equal( target.height(), 150, "compare height" );
115  
116 testHelper.drag( handle, -50, -50 );
117 assert.equal( target.width(), 100, "compare width" );
118 assert.equal( target.height(), 100, "compare height" );
119  
120 assert.equal( target[ 0 ].style.top, "", "top should not be modified" );
121 assert.equal( target[ 0 ].style.left, "", "left should not be modified" );
122 } );
123  
124 QUnit.test( "sw", function( assert ) {
125 assert.expect( 5 );
126  
127 var handle = ".ui-resizable-sw", target = $( "#resizable1" ).resizable( { handles: "all" } );
128  
129 testHelper.drag( handle, -50, -50 );
130 assert.equal( target.width(), 150, "compare width" );
131 assert.equal( target.height(), 50, "compare height" );
132  
133 testHelper.drag( handle, 50, 50 );
134 assert.equal( target.width(), 100, "compare width" );
135 assert.equal( target.height(), 100, "compare height" );
136  
137 assert.equal( target[ 0 ].style.top, "", "top should not be modified" );
138 } );
139  
140 QUnit.test( "nw", function( assert ) {
141 assert.expect( 4 );
142  
143 var handle = ".ui-resizable-nw", target = $( "#resizable1" ).resizable( { handles: "all" } );
144  
145 testHelper.drag( handle, -50, -50 );
146 assert.equal( target.width(), 150, "compare width" );
147 assert.equal( target.height(), 150, "compare height" );
148  
149 testHelper.drag( handle, 50, 50 );
150 assert.equal( target.width(), 100, "compare width" );
151 assert.equal( target.height(), 100, "compare height" );
152 } );
153  
154 QUnit.test( "handle with complex markup (#8756)", function( assert ) {
155 assert.expect( 2 );
156  
157 $( "#resizable1" )
158 .append(
159 $( "<div>" )
160 .addClass( "ui-resizable-handle" )
161 .addClass( "ui-resizable-w" )
162 .append( $( "<div>" ) )
163 );
164  
165 var handle = ".ui-resizable-w div", target = $( "#resizable1" ).resizable( { handles: "all" } );
166  
167 testHelper.drag( handle, -50 );
168 assert.equal( target.width(), 150, "compare width" );
169  
170 testHelper.drag( handle, 50 );
171 assert.equal( target.width(), 100, "compare width" );
172 } );
173  
174 QUnit.test( "resizable accounts for scroll position correctly (#3815)", function( assert ) {
175 assert.expect( 4 );
176  
177 var position, top, left,
178 container = $( "<div style='overflow:scroll;height:300px;width:300px;position:relative;'></div>" ).appendTo( "#qunit-fixture" ),
179 overflowed = $( "<div style='width: 1000px; height: 1000px;'></div>" ).appendTo( container ),
180 el = $( "<div style='height:100px;width:100px;position:absolute;top:10px;left:10px;'></div>" ).appendTo( overflowed ).resizable( { handles: "all" } ),
181 handle = ".ui-resizable-e",
182 handlePosition = $( handle ).position().left;
183  
184 container.scrollLeft( 100 ).scrollTop( 100 );
185  
186 position = el.position();
187 left = el.css( "left" );
188 top = el.css( "top" );
189  
190 testHelper.drag( handle, 50, 50 );
191 assert.deepEqual( el.position(), position, "position stays the same when resized" );
192 assert.equal( el.css( "left" ), left, "css('left') stays the same when resized" );
193 assert.equal( el.css( "top" ), top, "css('top') stays the same when resized" );
194 assert.equal( $( handle ).position().left, handlePosition + 50, "handle also moved" );
195 } );
196  
197 QUnit.test( "resizable stores correct size when using helper and grid (#9547)", function( assert ) {
198 assert.expect( 2 );
199  
200 var handle = ".ui-resizable-se",
201 target = $( "#resizable1" ).resizable( {
202 handles: "all",
203 helper: "ui-resizable-helper",
204 grid: [ 10, 10 ]
205 } );
206  
207 testHelper.drag( handle, 1, 1 );
208 assert.equal( target.width(), 100, "compare width" );
209 assert.equal( target.height(), 100, "compare height" );
210 } );
211  
212 QUnit.test( "nested resizable", function( assert ) {
213 assert.expect( 4 );
214  
215 var outer = $( "<div id='outer' style='width:50px'></div>" ),
216 inner = $( "<div id='inner' style='width:30px'></div>" ),
217 target = $( "#resizable1" ),
218 innerHandle,
219 outerHandle;
220  
221 outer.appendTo( target );
222 inner.appendTo( outer );
223  
224 inner.resizable( { handles: "e" } );
225 outer.resizable( { handles: "e" } );
226 target.resizable( { handles: "e" } );
227  
228 innerHandle = $( "#inner > .ui-resizable-e" );
229 outerHandle = $( "#outer > .ui-resizable-e" );
230  
231 testHelper.drag( innerHandle, 10 );
232 assert.equal( inner.width(), 40, "compare width of inner element" );
233 testHelper.drag( innerHandle, -10 );
234 assert.equal( inner.width(), 30, "compare width of inner element" );
235  
236 testHelper.drag( outerHandle, 10 );
237 assert.equal( outer.width(), 60, "compare width of outer element" );
238 testHelper.drag( outerHandle, -10 );
239 assert.equal( outer.width(), 50, "compare width of outer element" );
240  
241 inner.remove();
242 outer.remove();
243 } );
244  
245 } );