Debian Codegraph @

tests/unit/resizable/events.js

raw symbols SCIP
1 define( [
2 "qunit",
3 "jquery",
4 "lib/helper",
5 "./helper",
6 "ui/widgets/resizable"
7 ], function( QUnit, $, helper, testHelper ) {
8 "use strict";
9
10 QUnit.module( "resizable: events", { afterEach: helper.moduleAfterEach } );
11
12 QUnit.test( "start", function( assert ) {
13
14 assert.expect( 5 );
15
16 var count = 0,
17 handle = ".ui-resizable-se";
18
19 $( "#resizable1" ).resizable( {
20 handles: "all",
21 start: function( event, ui ) {
22 assert.equal( ui.size.width, 100, "compare width" );
23 assert.equal( ui.size.height, 100, "compare height" );
24 assert.equal( ui.originalSize.width, 100, "compare original width" );
25 assert.equal( ui.originalSize.height, 100, "compare original height" );
26 count++;
27 }
28 } );
29
30 testHelper.drag( handle, 50, 50 );
31
32 assert.equal( count, 1, "start callback should happen exactly once" );
33
34 } );
35
36 QUnit.test( "resize", function( assert ) {
37
38 assert.expect( 9 );
39
40 var count = 0,
41 handle = ".ui-resizable-se";
42
43 $( "#resizable1" ).resizable( {
44 handles: "all",
45 resize: function( event, ui ) {
46 if ( count === 0 ) {
47 assert.equal( ui.size.width, 125, "compare width" );
48 assert.equal( ui.size.height, 125, "compare height" );
49 assert.equal( ui.originalSize.width, 100, "compare original width" );
50 assert.equal( ui.originalSize.height, 100, "compare original height" );
51 } else {
52 assert.equal( ui.size.width, 150, "compare width" );
53 assert.equal( ui.size.height, 150, "compare height" );
54 assert.equal( ui.originalSize.width, 100, "compare original width" );
55 assert.equal( ui.originalSize.height, 100, "compare original height" );
56 }
57 count++;
58 }
59 } );
60
61 testHelper.drag( handle, 50, 50 );
62
63 assert.equal( count, 2, "resize callback should happen exactly once per size adjustment" );
64
65 } );
66
67 QUnit.test( "resize (min/max dimensions)", function( assert ) {
68
69 assert.expect( 5 );
70
71 var count = 0,
72 handle = ".ui-resizable-se";
73
74 $( "#resizable1" ).resizable( {
75 handles: "all",
76 minWidth: 60,
77 minHeight: 60,
78 maxWidth: 100,
79 maxHeight: 100,
80 resize: function( event, ui ) {
81 assert.equal( ui.size.width, 60, "compare width" );
82 assert.equal( ui.size.height, 60, "compare height" );
83 assert.equal( ui.originalSize.width, 100, "compare original width" );
84 assert.equal( ui.originalSize.height, 100, "compare original height" );
85 count++;
86 }
87 } );
88
89 testHelper.drag( handle, -200, -200 );
90
91 assert.equal( count, 1, "resize callback should happen exactly once per size adjustment" );
92
93 } );
94
95 QUnit.test( "resize (containment)", function( assert ) {
96
97 assert.expect( 5 );
98
99 var count = 0,
100 handle = ".ui-resizable-se",
101 container = $( "#resizable1" ).wrap( "<div>" ).parent().css( {
102 height: "100px",
103 width: "100px"
104 } );
105
106 $( "#resizable1" ).resizable( {
107 handles: "all",
108 containment: container,
109 resize: function( event, ui ) {
110 assert.equal( ui.size.width, 10, "compare width" );
111 assert.equal( ui.size.height, 10, "compare height" );
112 assert.equal( ui.originalSize.width, 100, "compare original width" );
113 assert.equal( ui.originalSize.height, 100, "compare original height" );
114 count++;
115 }
116 } );
117
118 // Prove you can't resize outside containment by dragging southeast corner southeast
119 testHelper.drag( handle, 100, 100 );
120
121 // Prove you can't resize outside containment by dragging southeast corner northwest
122 testHelper.drag( handle, -200, -200 );
123
124 assert.equal( count, 1, "resize callback should happen exactly once per size adjustment" );
125
126 } );
127
128 QUnit.test( "resize (grid)", function( assert ) {
129
130 assert.expect( 5 );
131
132 var count = 0,
133 handle = ".ui-resizable-se";
134
135 $( "#resizable1" ).resizable( {
136 handles: "all",
137 grid: 50,
138 resize: function( event, ui ) {
139 assert.equal( ui.size.width, 150, "compare width" );
140 assert.equal( ui.size.height, 150, "compare height" );
141 assert.equal( ui.originalSize.width, 100, "compare original width" );
142 assert.equal( ui.originalSize.height, 100, "compare original height" );
143 count++;
144 }
145 } );
146
147 testHelper.drag( handle, 50, 50 );
148
149 assert.equal( count, 1, "resize callback should happen exactly once per grid-unit size adjustment" );
150
151 } );
152
153 QUnit.test( "resize, custom adjustment", function( assert ) {
154 assert.expect( 4 );
155
156 var handle = ".ui-resizable-se",
157 element = $( "#resizable1" ).resizable( {
158 resize: function( event, ui ) {
159 ui.size.width = 100;
160 ui.size.height = 200;
161 ui.position.left = 300;
162 ui.position.top = 400;
163 }
164 } );
165
166 testHelper.drag( handle, 50, 50 );
167
168 assert.equal( element.width(), 100, "resize event can control width" );
169 assert.equal( element.height(), 200, "resize event can control height" );
170 assert.equal( element.position().left, 300, "resize event can control left" );
171 assert.equal( element.position().top, 400, "resize event can control top" );
172 } );
173
174 QUnit.test( "stop", function( assert ) {
175
176 assert.expect( 5 );
177
178 var count = 0,
179 handle = ".ui-resizable-se";
180
181 $( "#resizable1" ).resizable( {
182 handles: "all",
183 stop: function( event, ui ) {
184 assert.equal( ui.size.width, 150, "compare width" );
185 assert.equal( ui.size.height, 150, "compare height" );
186 assert.equal( ui.originalSize.width, 100, "compare original width" );
187 assert.equal( ui.originalSize.height, 100, "compare original height" );
188 count++;
189 }
190 } );
191
192 testHelper.drag( handle, 50, 50 );
193
194 assert.equal( count, 1, "stop callback should happen exactly once" );
195
196 } );
197
198 QUnit.test( "resize (containment) works with parent with negative offset", function( assert ) {
199
200 assert.expect( 1 );
201
202 var widthBefore, widthAfter,
203 handle = ".ui-resizable-e",
204 target = $( "#resizable1" ),
205 absoluteContainer = target.wrap( "<div />" ).parent(),
206 fixedContainer = absoluteContainer.wrap( "<div />" ).parent(),
207 increaseWidthBy = 50;
208
209 // Position fixed container in window top left
210 fixedContainer.css( {
211 width: 400,
212 height: 100,
213 position: "fixed",
214 top: 0,
215 left: 0
216 } );
217
218 // Position absolute container within fixed on slightly outside window
219 absoluteContainer.css( {
220 width: 400,
221 height: 100,
222 position: "absolute",
223 top: 0,
224 left: -50
225 } );
226
227 // Set up resizable to be contained within absolute container
228 target.resizable( {
229 handles: "all",
230 containment: "parent"
231 } ).css( {
232 width: 300
233 } );
234
235 widthBefore = target.width();
236
237 testHelper.drag( handle, increaseWidthBy, 0 );
238
239 widthAfter = target.width();
240
241 assert.equal( widthAfter, ( widthBefore + increaseWidthBy ), "resizable width should be increased by the value dragged" );
242
243 } );
244
245 } );