]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | describe("Ext.layout.container.Column", function() {\r |
2 | function createSuite(shrinkWrap) {\r | |
3 | var suiteName = 'Ext.layout.container.Column';\r | |
4 | \r | |
5 | if (shrinkWrap) {\r | |
6 | suiteName += ' (shrinkWrap:true)';\r | |
7 | }\r | |
8 | \r | |
9 | describe('wrapping with uneven heights', function() {\r | |
10 | // We must ensure that each row start clears to start of row.\r | |
11 | // Tall items would block it as below.\r | |
12 | // "Item 4" requires clear:left to begin at column zero.\r | |
13 | // +------------------------------- +\r | |
14 | // |+--------+ +--------+ +--------+|\r | |
15 | // || | | | | ||\r | |
16 | // || Item 1 | | Item 2 | | Item 3 ||\r | |
17 | // || | +--------+ +--------+|\r | |
18 | // || | +--------+ |\r | |
19 | // |+--------+ | | |\r | |
20 | // | | Item 4 | |\r | |
21 | // | | | |\r | |
22 | // | +--------+ |\r | |
23 | // +--------------------------------+\r | |
24 | it('should always wrap back to position zero', function() {\r | |
25 | var container = new Ext.container.Container({\r | |
26 | renderTo: document.body,\r | |
27 | width: 300,\r | |
28 | height: 500,\r | |
29 | layout: {\r | |
30 | type: 'column',\r | |
31 | columnCount: 3\r | |
32 | },\r | |
33 | defaultType: 'component',\r | |
34 | defaults: {\r | |
35 | columnWidth: 1/3\r | |
36 | },\r | |
37 | items: [{\r | |
38 | // This is a little taller.\r | |
39 | height: 110\r | |
40 | }, {\r | |
41 | height: 100\r | |
42 | }, {\r | |
43 | height: 100\r | |
44 | }, {\r | |
45 | height: 100\r | |
46 | }]\r | |
47 | }),\r | |
48 | item4 = container.items.items[3];\r | |
49 | \r | |
50 | // Item4 must have wrapped right back to first column\r | |
51 | expect(item4.getX()).toBe(0);\r | |
52 | container.destroy();\r | |
53 | });\r | |
54 | });\r | |
55 | \r | |
56 | describe(suiteName, function() {\r | |
57 | var panel,\r | |
58 | scrollbarSize = Ext.getScrollbarSize(),\r | |
59 | scrollbarWidth = scrollbarSize.width,\r | |
60 | scrollbarHeight = scrollbarSize.height;\r | |
61 | \r | |
62 | function makePanel(parentConfig, childConfig) {\r | |
63 | var items = [];\r | |
64 | \r | |
65 | if (!Ext.isArray(childConfig)) {\r | |
66 | childConfig = [childConfig];\r | |
67 | }\r | |
68 | \r | |
69 | Ext.each(childConfig, function(config) {\r | |
70 | items.push(Ext.apply({\r | |
71 | xtype: 'component',\r | |
72 | style: 'margin: 4px;'\r | |
73 | }, config));\r | |
74 | });\r | |
75 | \r | |
76 | panel = Ext.widget(Ext.apply({\r | |
77 | renderTo: document.body,\r | |
78 | xtype: 'panel',\r | |
79 | shrinkWrap: shrinkWrap || 2,\r | |
80 | layout: 'column',\r | |
81 | border: 0,\r | |
82 | bodyPadding: '6',\r | |
83 | items: items\r | |
84 | }, parentConfig));\r | |
85 | }\r | |
86 | \r | |
87 | afterEach(function() {\r | |
88 | panel.destroy();\r | |
89 | });\r | |
90 | \r | |
91 | describe("configured width and height", function() {\r | |
92 | var parentConfig = {\r | |
93 | height:100,\r | |
94 | width: 100\r | |
95 | };\r | |
96 | \r | |
97 | describe("child items with columnWidth", function() {\r | |
98 | beforeEach(function() {\r | |
99 | makePanel(parentConfig, [\r | |
100 | { height: 80, columnWidth: .25 },\r | |
101 | { height: 80, columnWidth: .25 },\r | |
102 | { height: 80, columnWidth: .5 }\r | |
103 | ]);\r | |
104 | });\r | |
105 | \r | |
106 | it("should width the child items correctly", function() {\r | |
107 | expect(panel.items.getAt(0).getWidth()).toBe(14);\r | |
108 | expect(panel.items.getAt(1).getWidth()).toBe(14);\r | |
109 | expect(panel.items.getAt(2).getWidth()).toBe(36);\r | |
110 | });\r | |
111 | \r | |
112 | });\r | |
113 | \r | |
114 | describe("child items with a combination of width and columnWidth", function() {\r | |
115 | beforeEach(function() {\r | |
116 | makePanel(parentConfig, [\r | |
117 | { height: 80, columnWidth: .5 },\r | |
118 | { height: 80, columnWidth: .5 },\r | |
119 | { height: 80, width: 36 }\r | |
120 | ]);\r | |
121 | });\r | |
122 | \r | |
123 | it("should width the child items correctly", function() {\r | |
124 | expect(panel.items.getAt(0).getWidth()).toBe(14);\r | |
125 | expect(panel.items.getAt(1).getWidth()).toBe(14);\r | |
126 | expect(panel.items.getAt(2).getWidth()).toBe(36);\r | |
127 | });\r | |
128 | });\r | |
129 | \r | |
130 | describe("wrapping items", function() {\r | |
131 | beforeEach(function() {\r | |
132 | makePanel(parentConfig, [\r | |
133 | { height: 36, columnWidth: .5 },\r | |
134 | { height: 36, columnWidth: .6 },\r | |
135 | { height: 36, width: 36 }\r | |
136 | ]);\r | |
137 | });\r | |
138 | \r | |
139 | it("should width the child items correctly", function() {\r | |
140 | expect(panel.items.getAt(0).getWidth()).toBe(14);\r | |
141 | expect(panel.items.getAt(1).getWidth()).toBe(18);\r | |
142 | expect(panel.items.getAt(2).getWidth()).toBe(36);\r | |
143 | });\r | |
144 | \r | |
145 | it("should wrap the last item", function() {\r | |
146 | expect(panel.items.getAt(2).getY() - panel.getY()).toBe(54);\r | |
147 | });\r | |
148 | });\r | |
149 | \r | |
150 | \r | |
151 | describe("overflow", function() {\r | |
152 | var overflowParentConfig = Ext.apply({}, {autoScroll: true}, parentConfig);\r | |
153 | \r | |
154 | describe("vertical", function() {\r | |
155 | beforeEach(function() {\r | |
156 | makePanel(overflowParentConfig, [\r | |
157 | { height: 36, width: 14 },\r | |
158 | { height: 180, columnWidth: 1 },\r | |
159 | { height: 36, width: 14 }\r | |
160 | ]);\r | |
161 | });\r | |
162 | \r | |
163 | it("should width the child items correctly", function() {\r | |
164 | expect(panel.items.getAt(0).getWidth()).toBe(14);\r | |
165 | expect(panel.items.getAt(1).getWidth()).toBe(36 - scrollbarWidth);\r | |
166 | expect(panel.items.getAt(2).getWidth()).toBe(14);\r | |
167 | });\r | |
168 | \r | |
169 | it("should have the correct scroll height", function() {\r | |
170 | expect(panel.body.dom.scrollHeight).toBe(200);\r | |
171 | });\r | |
172 | \r | |
173 | it("should not have horizontal overflow", function() {\r | |
174 | expect(panel.body.dom.scrollWidth).toBe(panel.getWidth() - scrollbarWidth);\r | |
175 | });\r | |
176 | });\r | |
177 | \r | |
178 | describe ("vertical overflow that triggers horizontal overflow", function() {\r | |
179 | beforeEach(function() {\r | |
180 | makePanel(overflowParentConfig, {width: 81 - scrollbarWidth, height: 180});\r | |
181 | });\r | |
182 | \r | |
183 | it("should have the correct scroll height", function() {\r | |
184 | expect(panel.body.dom.scrollHeight).toBe(200);\r | |
185 | });\r | |
186 | \r | |
187 | it("should have the correct scroll width", function() {\r | |
188 | expect(panel.body.dom.scrollWidth).toBe(panel.getWidth() - scrollbarWidth + 1);\r | |
189 | });\r | |
190 | });\r | |
191 | \r | |
192 | describe("horizontal", function() {\r | |
193 | beforeEach(function() {\r | |
194 | makePanel(overflowParentConfig, {height: 80 - scrollbarHeight, width: 180});\r | |
195 | });\r | |
196 | \r | |
197 | it("should have the correct scroll width", function() {\r | |
198 | expect(panel.body.dom.scrollWidth).toBe(200);\r | |
199 | });\r | |
200 | \r | |
201 | it("should not have vertical overflow", function() {\r | |
202 | expect(panel.body.dom.scrollHeight).toBe(panel.getHeight() - scrollbarHeight);\r | |
203 | });\r | |
204 | });\r | |
205 | \r | |
206 | describe("horizontal overflow that triggers vertical overflow", function() {\r | |
207 | beforeEach(function() {\r | |
208 | makePanel(overflowParentConfig, {height: 81 - scrollbarHeight, width: 180});\r | |
209 | });\r | |
210 | \r | |
211 | it("should have the correct scroll width", function() {\r | |
212 | expect(panel.body.dom.scrollWidth).toBe(200);\r | |
213 | });\r | |
214 | \r | |
215 | it("should have the correct scroll height", function() {\r | |
216 | expect(panel.body.dom.scrollHeight).toBe(panel.getHeight() - scrollbarHeight + 1);\r | |
217 | });\r | |
218 | });\r | |
219 | \r | |
220 | describe("vertical and horizontal", function() {\r | |
221 | beforeEach(function() {\r | |
222 | makePanel(overflowParentConfig, {height: 180, width: 180});\r | |
223 | });\r | |
224 | \r | |
225 | it("should have the correct scroll height", function() {\r | |
226 | expect(panel.body.dom.scrollHeight).toBe(200);\r | |
227 | });\r | |
228 | \r | |
229 | it("should have the correct scroll width", function() {\r | |
230 | expect(panel.body.dom.scrollWidth).toBe(200);\r | |
231 | });\r | |
232 | });\r | |
233 | \r | |
234 | });\r | |
235 | \r | |
236 | describe("autoScroll with no scrollbars", function() {\r | |
237 | var overflowParentConfig = Ext.apply({}, {autoScroll: true}, parentConfig);\r | |
238 | \r | |
239 | beforeEach(function() {\r | |
240 | makePanel(overflowParentConfig, [\r | |
241 | { height: 80, columnWidth: 1 }\r | |
242 | ]);\r | |
243 | });\r | |
244 | \r | |
245 | it("should not reserve space for a vertical scrollbar when sizing the child", function() {\r | |
246 | expect(panel.items.getAt(0).getWidth()).toBe(80);\r | |
247 | });\r | |
248 | });\r | |
249 | });\r | |
250 | \r | |
251 | describe("configured height, shrink wrap width", function() {\r | |
252 | var parentConfig = {\r | |
253 | height: 100,\r | |
254 | shrinkWrap: 1\r | |
255 | };\r | |
256 | \r | |
257 | describe("child items with columnWidth", function() {\r | |
258 | beforeEach(function() {\r | |
259 | makePanel(parentConfig, [\r | |
260 | { height: 80, columnWidth: .2, width: 32 },\r | |
261 | { height: 80, columnWidth: .8, html: '<div style="width:40px;"></div>' }\r | |
262 | ]);\r | |
263 | });\r | |
264 | \r | |
265 | it("should shrink wrap to the width of the child items", function() {\r | |
266 | expect(panel.getWidth()).toBe(100);\r | |
267 | });\r | |
268 | \r | |
269 | it("should not size the columns to their configured column widths", function() {\r | |
270 | expect(panel.items.getAt(0).getWidth()).toBe(32);\r | |
271 | expect(panel.items.getAt(1).getWidth()).toBe(40);\r | |
272 | });\r | |
273 | \r | |
274 | });\r | |
275 | \r | |
276 | describe("child items with columnWidth and container minWidth", function() {\r | |
277 | beforeEach(function() {\r | |
278 | makePanel({\r | |
279 | height: 100,\r | |
280 | shrinkWrap: 1,\r | |
281 | minWidth: 212\r | |
282 | }, [\r | |
283 | { height: 80, columnWidth: .4, width: 32 },\r | |
284 | { height: 80, columnWidth: .6, html: '<div style="width:40px;"></div>' }\r | |
285 | ]);\r | |
286 | });\r | |
287 | \r | |
288 | it("should size to the min width", function() {\r | |
289 | expect(panel.getWidth()).toBe(212);\r | |
290 | });\r | |
291 | \r | |
292 | it("should size the columns to their configured column widths", function() {\r | |
293 | expect(panel.items.getAt(0).getWidth()).toBe(72);\r | |
294 | expect(panel.items.getAt(1).getWidth()).toBe(112);\r | |
295 | });\r | |
296 | \r | |
297 | });\r | |
298 | });\r | |
299 | \r | |
300 | describe("configured width, shrink wrap height", function() {\r | |
301 | var parentConfig = {\r | |
302 | width: 100\r | |
303 | };\r | |
304 | \r | |
305 | describe("child items with columnWidth", function() {\r | |
306 | beforeEach(function() {\r | |
307 | makePanel(parentConfig, [\r | |
308 | { height: 80, columnWidth: .5 },\r | |
309 | { height: 80, columnWidth: .25 },\r | |
310 | { height: 80, columnWidth: .25 }\r | |
311 | ]);\r | |
312 | });\r | |
313 | \r | |
314 | it("should width the child items correctly", function() {\r | |
315 | expect(panel.items.getAt(0).getWidth()).toBe(36);\r | |
316 | expect(panel.items.getAt(1).getWidth()).toBe(14);\r | |
317 | expect(panel.items.getAt(2).getWidth()).toBe(14);\r | |
318 | });\r | |
319 | \r | |
320 | it("should shrink wrap the height", function() {\r | |
321 | expect(panel.getHeight()).toBe(100);\r | |
322 | });\r | |
323 | });\r | |
324 | \r | |
325 | describe("child items with a combination of width and columnWidth", function() {\r | |
326 | beforeEach(function() {\r | |
327 | makePanel(parentConfig, [\r | |
328 | { height: 80, columnWidth: .5 },\r | |
329 | { height: 80, width: 36 },\r | |
330 | { height: 80, columnWidth: .5 }\r | |
331 | ]);\r | |
332 | });\r | |
333 | \r | |
334 | it("should width the child items correctly", function() {\r | |
335 | expect(panel.items.getAt(0).getWidth()).toBe(14);\r | |
336 | expect(panel.items.getAt(1).getWidth()).toBe(36);\r | |
337 | expect(panel.items.getAt(2).getWidth()).toBe(14);\r | |
338 | });\r | |
339 | \r | |
340 | it("should shrink wrap the height", function() {\r | |
341 | expect(panel.getHeight()).toBe(100);\r | |
342 | });\r | |
343 | });\r | |
344 | \r | |
345 | describe("wrapping items", function() {\r | |
346 | beforeEach(function() {\r | |
347 | makePanel(parentConfig, [\r | |
348 | { height: 36, columnWidth: .5 },\r | |
349 | { height: 36, width: 36 },\r | |
350 | { height: 36, columnWidth: .6 }\r | |
351 | ]);\r | |
352 | });\r | |
353 | \r | |
354 | it("should width the child items correctly", function() {\r | |
355 | expect(panel.items.getAt(0).getWidth()).toBe(14);\r | |
356 | expect(panel.items.getAt(1).getWidth()).toBe(36);\r | |
357 | expect(panel.items.getAt(2).getWidth()).toBe(18);\r | |
358 | });\r | |
359 | \r | |
360 | it("should wrap the last item", function() {\r | |
361 | expect(panel.items.getAt(2).getY() - panel.getY()).toBe(54);\r | |
362 | });\r | |
363 | \r | |
364 | // TODO: https://sencha.jira.com/browse/EXTJSIV-5910\r | |
365 | xit("should shrink wrap the height", function() {\r | |
366 | expect(panel.getHeight()).toBe(100);\r | |
367 | });\r | |
368 | });\r | |
369 | \r | |
370 | describe("overflow", function() {\r | |
371 | var overflowParentConfig = Ext.apply({}, {autoScroll: true}, parentConfig);\r | |
372 | \r | |
373 | describe("horizontal", function() {\r | |
374 | beforeEach(function() {\r | |
375 | makePanel(overflowParentConfig, {height: 80 - scrollbarHeight, width: 180});\r | |
376 | });\r | |
377 | \r | |
378 | it("should have the correct scroll width", function() {\r | |
379 | expect(panel.body.dom.scrollWidth).toBe(200);\r | |
380 | });\r | |
381 | \r | |
382 | // TODO: https://sencha.jira.com/browse/EXTJSIV-5911\r | |
383 | xit("should not have vertical overflow", function() {\r | |
384 | expect(panel.body.dom.scrollHeight).toBe(panel.getHeight() - scrollbarHeight);\r | |
385 | });\r | |
386 | });\r | |
387 | });\r | |
388 | });\r | |
389 | \r | |
390 | describe("shrink wrap width and height", function() {\r | |
391 | var parentConfig = {\r | |
392 | shrinkWrap: true\r | |
393 | };\r | |
394 | \r | |
395 | describe("child items with columnWidth", function() {\r | |
396 | beforeEach(function() {\r | |
397 | makePanel(parentConfig, [\r | |
398 | { height: 80, columnWidth: .2, width: 32 },\r | |
399 | { height: 80, columnWidth: .8, html: '<div style="width:40px;"></div>' }\r | |
400 | ]);\r | |
401 | });\r | |
402 | \r | |
403 | it("should shrink wrap to the width of the child items", function() {\r | |
404 | expect(panel.getWidth()).toBe(100);\r | |
405 | });\r | |
406 | \r | |
407 | it("should not size the columns to their configured column widths", function() {\r | |
408 | expect(panel.items.getAt(0).getWidth()).toBe(32);\r | |
409 | expect(panel.items.getAt(1).getWidth()).toBe(40);\r | |
410 | });\r | |
411 | \r | |
412 | it("should shrink wrap the height", function() {\r | |
413 | expect(panel.getHeight()).toBe(100);\r | |
414 | });\r | |
415 | });\r | |
416 | \r | |
417 | describe("child items with columnWidth and container minWidth", function() {\r | |
418 | beforeEach(function() {\r | |
419 | makePanel({\r | |
420 | height: 100,\r | |
421 | shrinkWrap: 1,\r | |
422 | minWidth: 212\r | |
423 | }, [\r | |
424 | { height: 80, columnWidth: .4, width: 32 },\r | |
425 | { height: 80, columnWidth: .6, html: '<div style="width:40px;"></div>' }\r | |
426 | ]);\r | |
427 | });\r | |
428 | \r | |
429 | it("should size to the min width", function() {\r | |
430 | expect(panel.getWidth()).toBe(212);\r | |
431 | });\r | |
432 | \r | |
433 | it("should size the columns to their configured column widths", function() {\r | |
434 | expect(panel.items.getAt(0).getWidth()).toBe(72);\r | |
435 | expect(panel.items.getAt(1).getWidth()).toBe(112);\r | |
436 | });\r | |
437 | \r | |
438 | it("should shrink wrap the height", function() {\r | |
439 | expect(panel.getHeight()).toBe(100);\r | |
440 | });\r | |
441 | });\r | |
442 | });\r | |
443 | \r | |
444 | \r | |
445 | });\r | |
446 | }\r | |
447 | \r | |
448 | createSuite();\r | |
449 | createSuite(true);\r | |
450 | \r | |
451 | describe("shrink wrap of child items", function(){\r | |
452 | var ct;\r | |
453 | \r | |
454 | afterEach(function(){\r | |
455 | Ext.destroy(ct);\r | |
456 | });\r | |
457 | \r | |
458 | it("should shrink wrap children side by side", function(){\r | |
459 | ct = new Ext.container.Container({\r | |
460 | width: 400,\r | |
461 | height: 200,\r | |
462 | layout: 'column',\r | |
463 | renderTo: Ext.getBody(),\r | |
464 | defaultType: 'component',\r | |
465 | items: [{\r | |
466 | html: '<div style="width: 100px;"></div>'\r | |
467 | }, {\r | |
468 | html: '<div style="width: 100px;"></div>'\r | |
469 | }]\r | |
470 | });\r | |
471 | expect(ct.items.first().getWidth()).toBe(100);\r | |
472 | expect(ct.items.last().getWidth()).toBe(100);\r | |
473 | });\r | |
474 | \r | |
475 | it("should should stretch items after shrink wrapping", function(){\r | |
476 | ct = new Ext.container.Container({\r | |
477 | width: 400,\r | |
478 | height: 200,\r | |
479 | layout: 'column',\r | |
480 | renderTo: Ext.getBody(),\r | |
481 | defaultType: 'component',\r | |
482 | items: [{\r | |
483 | html: '<div style="width: 100px;"></div>'\r | |
484 | }, {\r | |
485 | columnWidth: 1\r | |
486 | }]\r | |
487 | });\r | |
488 | expect(ct.items.first().getWidth()).toBe(100);\r | |
489 | expect(ct.items.last().getWidth()).toBe(300);\r | |
490 | }); \r | |
491 | });\r | |
492 | \r | |
493 | describe("failure tests", function() {\r | |
494 | it("should work with a minHeight child", function(){\r | |
495 | var ct = new Ext.container.Container({\r | |
496 | renderTo: Ext.getBody(),\r | |
497 | width: 200,\r | |
498 | height: 100,\r | |
499 | layout: 'anchor',\r | |
500 | items: [{\r | |
501 | minHeight: 70,\r | |
502 | columnWidth: 1\r | |
503 | }]\r | |
504 | });\r | |
505 | expect(ct.items.first().getHeight()).toBe(70);\r | |
506 | ct.destroy();\r | |
507 | }); \r | |
508 | });\r | |
509 | \r | |
510 | describe("liquid layout", function() {\r | |
511 | it("should layout with liquidLayout items", function() {\r | |
512 | // https://sencha.jira.com/browse/EXTJS-15192\r | |
513 | var ct = Ext.create({\r | |
514 | xtype: 'container',\r | |
515 | renderTo: Ext.getBody(),\r | |
516 | width: 200,\r | |
517 | height: 100,\r | |
518 | layout: 'column',\r | |
519 | defaults: {\r | |
520 | xtype: 'button'\r | |
521 | },\r | |
522 | items: [\r | |
523 | { columnWidth: 1 },\r | |
524 | { width: 50 }\r | |
525 | ]\r | |
526 | });\r | |
527 | \r | |
528 | expect(ct.items.getAt(0).getWidth()).toBe(150);\r | |
529 | expect(ct.items.getAt(1).getWidth()).toBe(50);\r | |
530 | \r | |
531 | ct.destroy();\r | |
532 | });\r | |
533 | });\r | |
534 | });\r |