3 * Copyright(c) 2006-2010 Sencha Inc.
5 * http://www.sencha.com/license
8 * Tests Ext.data.Store functionality
12 var suite = Ext.test.session.getSuite('Ext.layout.VBoxLayout'),
15 function buildFakeChild(config) {
16 config = config || {};
19 getWidth: function() {
22 getHeight: function() {
42 function buildLayout(config) {
43 config = config || {};
54 return new Ext.layout.VBoxLayout(config);
57 suite.add(new Y.Test.Case({
58 name: 'calculating flexed box sizes',
61 this.layout = buildLayout();
64 buildFakeChild({flex: 1}),
65 buildFakeChild({flex: 1}),
66 buildFakeChild({flex: 1}),
67 buildFakeChild({flex: 1})
76 testEqualFlexHeights: function() {
77 var calcs = this.layout.calculateChildBoxes(this.items, this.targetSize),
80 assert.areEqual(100, boxes[0].height);
81 assert.areEqual(100, boxes[1].height);
82 assert.areEqual(100, boxes[2].height);
83 assert.areEqual(100, boxes[3].height);
86 testDifferentFlexWidths: function() {
88 buildFakeChild({flex: 1}),
89 buildFakeChild({flex: 2}),
90 buildFakeChild({flex: 3}),
91 buildFakeChild({flex: 4})
94 var calcs = this.layout.calculateChildBoxes(this.items, this.targetSize),
97 assert.areEqual(40, boxes[0].height);
98 assert.areEqual(80, boxes[1].height);
99 assert.areEqual(120, boxes[2].height);
100 assert.areEqual(160, boxes[3].height);
103 testMarginsAccountedFor: function() {
105 buildFakeChild({flex: 1, margins: {left: 0, right: 0, top: 10, bottom: 10}}),
106 buildFakeChild({flex: 1, margins: {left: 0, right: 0, top: 10, bottom: 10}}),
107 buildFakeChild({flex: 1, margins: {left: 0, right: 0, top: 10, bottom: 10}}),
108 buildFakeChild({flex: 1, margins: {left: 0, right: 0, top: 10, bottom: 10}})
111 var calcs = this.layout.calculateChildBoxes(items, this.targetSize),
114 assert.areEqual(80, boxes[0].height);
115 assert.areEqual(80, boxes[1].height);
116 assert.areEqual(80, boxes[2].height);
117 assert.areEqual(80, boxes[3].height);
120 testPaddingAccountedFor: function() {
121 this.layout = buildLayout({
130 var calcs = this.layout.calculateChildBoxes(this.items, this.targetSize),
133 //400px available internally, minus 20px total left + right padding = 380 / 4
134 assert.areEqual(95, boxes[0].height);
135 assert.areEqual(95, boxes[1].height);
136 assert.areEqual(95, boxes[2].height);
137 assert.areEqual(95, boxes[3].height);
140 //one of the items is passed both a width and a flex - the flex should be ignored
141 testHeightDominatesFlex: function() {
143 buildFakeChild({flex: 1, height: 250, getHeight: function() {return 250;}}),
144 buildFakeChild({flex: 1}),
145 buildFakeChild({flex: 1}),
146 buildFakeChild({flex: 1})
149 var calcs = this.layout.calculateChildBoxes(items, this.targetSize),
152 assert.areEqual(250, boxes[0].height);
153 assert.areEqual(50, boxes[1].height);
154 assert.areEqual(50, boxes[2].height);
155 assert.areEqual(50, boxes[3].height);
158 testHeightPropertyDominatesGetHeight: function() {
159 var layout = buildLayout({
170 margins: {top: 0, left: 0, right: 0, bottom: 0},
171 getHeight: function() {return 10;},
172 getWidth: function() {return 10;}
178 margins: {top: 0, left: 0, right: 0, bottom: 0},
179 getWidth: function() {return 10;},
181 //NOTE: this should be ignored by HBox because we have a different configured width property
182 getHeight: function() {return 10;}
188 margins: {top: 0, left: 0, right: 0, bottom: 0},
189 getHeight: function() {return 10;},
190 getWidth: function() {return 10;}
199 var calcs = layout.calculateChildBoxes(items, targetSize),
202 assert.areEqual(0, boxes[0].top);
203 assert.areEqual(510, boxes[1].top);
204 assert.areEqual(610, boxes[2].top);
208 suite.add(new Y.Test.Case({
209 name: 'minHeight of items',
212 this.layout = buildLayout();
214 this.layout.beforeCt = {
215 getWidth: function() {
218 createChild: Ext.emptyFn
221 this.layout.afterCt = {
222 getWidth: function() {
225 createChild: Ext.emptyFn
229 buildFakeChild({height: 100, minHeight: 100}),
230 buildFakeChild({height: 200, minHeight: 120}),
231 buildFakeChild({height: 200, minHeight: 120}),
232 buildFakeChild({height: 200, minHeight: 120})
236 testAvailableWidthIsSufficient: function() {
242 var calcs = this.layout.calculateChildBoxes(this.items, targetSize),
245 assert.areEqual(0, boxes[0].top);
246 assert.areEqual(100, boxes[1].top);
247 assert.areEqual(300, boxes[2].top);
248 assert.areEqual(500, boxes[3].top);
250 assert.areEqual(100, boxes[0].height);
251 assert.areEqual(200, boxes[1].height);
252 assert.areEqual(200, boxes[2].height);
253 assert.areEqual(200, boxes[3].height);
256 testHasShortfall: function() {
262 var calcs = this.layout.calculateChildBoxes(this.items, targetSize),
265 assert.areEqual(100, boxes[0].height);
266 assert.areEqual(133, boxes[1].height);
267 assert.areEqual(133, boxes[2].height);
268 assert.areEqual(134, boxes[3].height);
270 assert.areEqual(0, boxes[0].top);
271 assert.areEqual(100, boxes[1].top);
272 assert.areEqual(233, boxes[2].top);
273 assert.areEqual(366, boxes[3].top);
276 testTooNarrow: function() {
282 var calcs = this.layout.calculateChildBoxes(this.items, targetSize),
285 assert.areEqual(0, boxes[0].top);
286 assert.areEqual(100, boxes[1].top);
287 assert.areEqual(220, boxes[2].top);
288 assert.areEqual(340, boxes[3].top);
290 assert.areEqual(100, boxes[0].height);
291 assert.areEqual(120, boxes[1].height);
292 assert.areEqual(120, boxes[2].height);
293 assert.areEqual(120, boxes[3].height);
297 suite.add(new Y.Test.Case({
302 buildFakeChild({flex: 1, getWidth: function() {return 10;}}),
303 buildFakeChild({flex: 1, getWidth: function() {return 20;}}),
304 buildFakeChild({flex: 1, getWidth: function() {return 30;}}),
305 buildFakeChild({flex: 1, getWidth: function() {return 40;}})
314 testLeft: function() {
315 this.layout = buildLayout({
319 var calcs = this.layout.calculateChildBoxes(this.items, this.targetSize),
322 assert.areEqual(0, boxes[0].left);
323 assert.areEqual(0, boxes[1].left);
324 assert.areEqual(0, boxes[2].left);
325 assert.areEqual(0, boxes[3].left);
328 testMiddle: function() {
329 this.layout = buildLayout({
333 var calcs = this.layout.calculateChildBoxes(this.items, this.targetSize),
336 assert.areEqual(45, boxes[0].left);
337 assert.areEqual(40, boxes[1].left);
338 assert.areEqual(35, boxes[2].left);
339 assert.areEqual(30, boxes[3].left);
342 testStretch: function() {
343 this.layout = buildLayout({
347 var calcs = this.layout.calculateChildBoxes(this.items, this.targetSize),
350 assert.areEqual(0, boxes[0].left);
351 assert.areEqual(0, boxes[1].left);
352 assert.areEqual(0, boxes[2].left);
353 assert.areEqual(0, boxes[3].left);
355 assert.areEqual(100, boxes[0].width);
356 assert.areEqual(100, boxes[1].width);
357 assert.areEqual(100, boxes[2].width);
358 assert.areEqual(100, boxes[3].width);
361 testStretchMax: function() {
362 this.layout = buildLayout({
366 var calcs = this.layout.calculateChildBoxes(this.items, this.targetSize),
369 assert.areEqual(0, boxes[0].left);
370 assert.areEqual(0, boxes[1].left);
371 assert.areEqual(0, boxes[2].left);
372 assert.areEqual(0, boxes[3].left);
374 assert.areEqual(40, boxes[0].width);
375 assert.areEqual(40, boxes[1].width);
376 assert.areEqual(40, boxes[2].width);
377 assert.areEqual(40, boxes[3].width);
381 suite.add(new Y.Test.Case({
386 buildFakeChild({getSize: function() {return {width: 10, height: 10};}}),
387 buildFakeChild({getSize: function() {return {width: 10, height: 20};}}),
388 buildFakeChild({getSize: function() {return {width: 10, height: 30};}}),
389 buildFakeChild({getSize: function() {return {width: 10, height: 40};}})
398 testPackStart: function() {
399 this.layout = buildLayout({
403 var calcs = this.layout.calculateChildBoxes(this.items, this.targetSize),
406 assert.areEqual(0, boxes[0].top);
407 assert.areEqual(10, boxes[1].top);
408 assert.areEqual(30, boxes[2].top);
409 assert.areEqual(60, boxes[3].top);
412 testPackCenter: function() {
413 this.layout = buildLayout({
417 var calcs = this.layout.calculateChildBoxes(this.items, this.targetSize),
420 assert.areEqual(150, boxes[0].top);
421 assert.areEqual(160, boxes[1].top);
422 assert.areEqual(180, boxes[2].top);
423 assert.areEqual(210, boxes[3].top);
426 testPackEnd: function() {
427 this.layout = buildLayout({
431 var calcs = this.layout.calculateChildBoxes(this.items, this.targetSize),
434 assert.areEqual(300, boxes[0].top);
435 assert.areEqual(310, boxes[1].top);
436 assert.areEqual(330, boxes[2].top);
437 assert.areEqual(360, boxes[3].top);
441 suite.add(new Y.Test.Case({
442 name: 'meta data from calculated box sizes',
445 this.layout = buildLayout();
448 buildFakeChild({getWidth: function() {return 50;}, flex: 1}),
449 buildFakeChild({getWidth: function() {return 60;}, flex: 1}),
450 buildFakeChild({getWidth: function() {return 10;}, flex: 1}),
451 buildFakeChild({getWidth: function() {return 80;}, flex: 1})
460 testMaxHeight: function() {
461 var calcs = this.layout.calculateChildBoxes(this.items, this.targetSize),
464 assert.areEqual(80, meta.maxWidth);
468 suite.add(new Y.Test.Case({
469 name: 'update innerCt size',
472 this.layout = buildLayout({
482 //fake the values that are calculated during onLayout
483 this.layoutTargetLastSize = {
488 this.childBoxCache = {
495 testMaintainsWidthForAlignStretch: function() {
496 var layout = this.layout,
499 //a fake innerCt element that we can intercept calls to setSize on
501 setSize: function(widthArg, heightArg) {
507 layout.updateInnerCtSize(this.layoutTargetLastSize, this.childBoxCache);
509 assert.areSame(100, width);
510 assert.areSame(400, height);
513 //if aligning middle, increase height to accomodate the tallest child
514 testIncreasesWidthForAlignMiddle: function() {
515 this.layout = buildLayout({
525 var layout = this.layout,
528 //a fake innerCt element that we can intercept calls to setSize on
530 setSize: function(widthArg, heightArg) {
536 layout.updateInnerCtSize(this.layoutTargetLastSize, this.childBoxCache);
538 assert.areSame(180, width);
539 assert.areSame(400, height);