aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/resizable/resizable_events.js
blob: d3851f72ed6b2908e5178948709acbfe9e3eaa21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/*
 * resizable_events.js
 */
(function($) {

module("resizable: events");

test("start", function() {

	expect(5);

	var count = 0,
		handle = ".ui-resizable-se";

	$("#resizable1").resizable({
		handles: "all",
		start: function(event, ui) {
			equal( ui.size.width, 100, "compare width" );
			equal( ui.size.height, 100, "compare height" );
			equal( ui.originalSize.width, 100, "compare original width" );
			equal( ui.originalSize.height, 100, "compare original height" );
			count++;
		}
	});

	TestHelpers.resizable.drag(handle, 50, 50);

	equal(count, 1, "start callback should happen exactly once");

});

test( "resize", function() {

	expect( 9 );

	var count = 0,
		handle = ".ui-resizable-se";

	$("#resizable1").resizable({
		handles: "all",
		resize: function( event, ui ) {
			if ( count === 0 ) {
				equal( ui.size.width, 125, "compare width" );
				equal( ui.size.height, 125, "compare height" );
				equal( ui.originalSize.width, 100, "compare original width" );
				equal( ui.originalSize.height, 100, "compare original height" );
			} else {
				equal( ui.size.width, 150, "compare width" );
				equal( ui.size.height, 150, "compare height" );
				equal( ui.originalSize.width, 100, "compare original width" );
				equal( ui.originalSize.height, 100, "compare original height" );
			}
			count++;
		}
	});

	TestHelpers.resizable.drag( handle, 50, 50 );

	equal( count, 2, "resize callback should happen exactly once per size adjustment" );

});

test( "resize (min/max dimensions)", function() {

	expect( 5 );

	var count = 0,
		handle = ".ui-resizable-se";

	$("#resizable1").resizable({
		handles: "all",
		minWidth: 60,
		minHeight: 60,
		maxWidth: 100,
		maxHeight: 100,
		resize: function( event, ui ) {
			equal( ui.size.width, 60, "compare width" );
			equal( ui.size.height, 60, "compare height" );
			equal( ui.originalSize.width, 100, "compare original width" );
			equal( ui.originalSize.height, 100, "compare original height" );
			count++;
		}
	});

	TestHelpers.resizable.drag( handle, -200, -200 );

	equal( count, 1, "resize callback should happen exactly once per size adjustment" );

});

test( "resize (containment)", function() {

	expect( 5 );

	var count = 0,
		handle = ".ui-resizable-se",
		container = $("#resizable1").wrap("<div>").parent().css({
			height: "100px",
			width: "100px"
		});

	$("#resizable1").resizable({
		handles: "all",
		containment: container,
		resize: function( event, ui ) {
			equal( ui.size.width, 10, "compare width" );
			equal( ui.size.height, 10, "compare height" );
			equal( ui.originalSize.width, 100, "compare original width" );
			equal( ui.originalSize.height, 100, "compare original height" );
			count++;
		}
	});

	// Prove you can't resize outside containment by dragging southeast corner southeast
	TestHelpers.resizable.drag( handle, 100, 100 );

	// Prove you can't resize outside containment by dragging southeast corner northwest
	TestHelpers.resizable.drag( handle, -200, -200 );

	equal( count, 1, "resize callback should happen exactly once per size adjustment" );

});

test("resize (grid)", function() {

	expect(5);

	var count = 0,
		handle = ".ui-resizable-se";

	$("#resizable1").resizable({
		handles: "all",
		grid: 50,
		resize: function(event, ui) {
			equal( ui.size.width, 150, "compare width" );
			equal( ui.size.height, 150, "compare height" );
			equal( ui.originalSize.width, 100, "compare original width" );
			equal( ui.originalSize.height, 100, "compare original height" );
			count++;
		}
	});

	TestHelpers.resizable.drag(handle, 50, 50);

	equal(count, 1, "resize callback should happen exactly once per grid-unit size adjustment");

});

test( "resize, custom adjustment", function() {
	expect( 4 );

	var handle = ".ui-resizable-se",
		element = $( "#resizable1" ).resizable({
			resize: function( event, ui ) {
				ui.size.width = 100;
				ui.size.height = 200;
				ui.position.left = 300;
				ui.position.top = 400;
			}
		});

	TestHelpers.resizable.drag( handle, 50, 50 );

	equal( element.width(), 100, "resize event can control width" );
	equal( element.height(), 200, "resize event can control height" );
	equal( element.position().left, 300, "resize event can control left" );
	equal( element.position().top, 400, "resize event can control top" );
});

test("stop", function() {

	expect(5);

	var count = 0,
		handle = ".ui-resizable-se";

	$("#resizable1").resizable({
		handles: "all",
		stop: function(event, ui) {
			equal( ui.size.width, 150, "compare width" );
			equal( ui.size.height, 150, "compare height" );
			equal( ui.originalSize.width, 100, "compare original width" );
			equal( ui.originalSize.height, 100, "compare original height" );
			count++;
		}
	});

	TestHelpers.resizable.drag(handle, 50, 50);

	equal(count, 1, "stop callback should happen exactly once");

});

test( "resize (containment) works with parent with negative offset", function() {

	expect( 1 );

	var widthBefore, widthAfter,
		handle = ".ui-resizable-e",
		target = $( "#resizable1" ),
		absoluteContainer = target.wrap( "<div />" ).parent(),
		fixedContainer = absoluteContainer.wrap( "<div />" ).parent(),
		increaseWidthBy = 50;

	// position fixed container in window top left
	fixedContainer.css({
		width: 400,
		height: 100,
		position: "fixed",
		top: 0,
		left: 0
	});

	// position absolute container within fixed on slightly outside window
	absoluteContainer.css({
		width: 400,
		height: 100,
		position: "absolute",
		top: 0,
		left: -50
	});

	// set up resizable to be contained within absolute container
	target.resizable({
		handles: "all",
		containment: "parent"
	}).css({
		width: 300
	});

	widthBefore = target.width();

	TestHelpers.resizable.drag( handle, increaseWidthBy, 0 );

	widthAfter = target.width();

	equal( widthAfter, ( widthBefore + increaseWidthBy ), "resizable width should be increased by the value dragged" );

});

})(jQuery);