You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

555 lines
18 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. /**
  16. * Tests Ext.data.Store functionality
  17. * @author Ed Spencer
  18. */
  19. (function() {
  20. var suite = Ext.test.session.getSuite('Ext.layout.VBoxLayout'),
  21. assert = Y.Assert;
  22. function buildFakeChild(config) {
  23. config = config || {};
  24. Ext.applyIf(config, {
  25. getWidth: function() {
  26. return 10;
  27. },
  28. getHeight: function() {
  29. return 10;
  30. },
  31. getSize: function() {
  32. return {
  33. height: 10,
  34. width : 10
  35. };
  36. },
  37. margins: {
  38. top : 0,
  39. right : 0,
  40. bottom: 0,
  41. left : 0
  42. }
  43. });
  44. return config;
  45. }
  46. function buildLayout(config) {
  47. config = config || {};
  48. Ext.applyIf(config, {
  49. padding: {
  50. top : 0,
  51. right : 0,
  52. bottom: 0,
  53. left : 0
  54. }
  55. });
  56. return new Ext.layout.VBoxLayout(config);
  57. };
  58. suite.add(new Y.Test.Case({
  59. name: 'calculating flexed box sizes',
  60. setUp: function() {
  61. this.layout = buildLayout();
  62. this.items = [
  63. buildFakeChild({flex: 1}),
  64. buildFakeChild({flex: 1}),
  65. buildFakeChild({flex: 1}),
  66. buildFakeChild({flex: 1})
  67. ];
  68. this.targetSize = {
  69. height: 400,
  70. width : 100
  71. };
  72. },
  73. testEqualFlexHeights: function() {
  74. var calcs = this.layout.calculateChildBoxes(this.items, this.targetSize),
  75. boxes = calcs.boxes;
  76. assert.areEqual(100, boxes[0].height);
  77. assert.areEqual(100, boxes[1].height);
  78. assert.areEqual(100, boxes[2].height);
  79. assert.areEqual(100, boxes[3].height);
  80. },
  81. testDifferentFlexWidths: function() {
  82. this.items = [
  83. buildFakeChild({flex: 1}),
  84. buildFakeChild({flex: 2}),
  85. buildFakeChild({flex: 3}),
  86. buildFakeChild({flex: 4})
  87. ];
  88. var calcs = this.layout.calculateChildBoxes(this.items, this.targetSize),
  89. boxes = calcs.boxes;
  90. assert.areEqual(40, boxes[0].height);
  91. assert.areEqual(80, boxes[1].height);
  92. assert.areEqual(120, boxes[2].height);
  93. assert.areEqual(160, boxes[3].height);
  94. },
  95. testMarginsAccountedFor: function() {
  96. var items = [
  97. buildFakeChild({flex: 1, margins: {left: 0, right: 0, top: 10, bottom: 10}}),
  98. buildFakeChild({flex: 1, margins: {left: 0, right: 0, top: 10, bottom: 10}}),
  99. buildFakeChild({flex: 1, margins: {left: 0, right: 0, top: 10, bottom: 10}}),
  100. buildFakeChild({flex: 1, margins: {left: 0, right: 0, top: 10, bottom: 10}})
  101. ];
  102. var calcs = this.layout.calculateChildBoxes(items, this.targetSize),
  103. boxes = calcs.boxes;
  104. assert.areEqual(80, boxes[0].height);
  105. assert.areEqual(80, boxes[1].height);
  106. assert.areEqual(80, boxes[2].height);
  107. assert.areEqual(80, boxes[3].height);
  108. },
  109. testPaddingAccountedFor: function() {
  110. this.layout = buildLayout({
  111. padding: {
  112. top : 10,
  113. right : 10,
  114. bottom: 10,
  115. left : 10
  116. }
  117. });
  118. var calcs = this.layout.calculateChildBoxes(this.items, this.targetSize),
  119. boxes = calcs.boxes;
  120. //400px available internally, minus 20px total left + right padding = 380 / 4
  121. assert.areEqual(95, boxes[0].height);
  122. assert.areEqual(95, boxes[1].height);
  123. assert.areEqual(95, boxes[2].height);
  124. assert.areEqual(95, boxes[3].height);
  125. },
  126. //one of the items is passed both a width and a flex - the flex should be ignored
  127. testHeightDominatesFlex: function() {
  128. var items = [
  129. buildFakeChild({flex: 1, height: 250, getHeight: function() {return 250;}}),
  130. buildFakeChild({flex: 1}),
  131. buildFakeChild({flex: 1}),
  132. buildFakeChild({flex: 1})
  133. ];
  134. var calcs = this.layout.calculateChildBoxes(items, this.targetSize),
  135. boxes = calcs.boxes;
  136. assert.areEqual(250, boxes[0].height);
  137. assert.areEqual(50, boxes[1].height);
  138. assert.areEqual(50, boxes[2].height);
  139. assert.areEqual(50, boxes[3].height);
  140. },
  141. testHeightPropertyDominatesGetHeight: function() {
  142. var layout = buildLayout({
  143. pack : 'start',
  144. align: 'stretch'
  145. });
  146. var items = [
  147. {
  148. title: 'Panel 1',
  149. flex: 1,
  150. html: 'flex : 1',
  151. frame: true,
  152. margins: {top: 0, left: 0, right: 0, bottom: 0},
  153. getHeight: function() {return 10;},
  154. getWidth: function() {return 10;}
  155. }, {
  156. title: 'Panel 2',
  157. height: 100,
  158. html: 'width : 100',
  159. frame: true,
  160. margins: {top: 0, left: 0, right: 0, bottom: 0},
  161. getWidth: function() {return 10;},
  162. //NOTE: this should be ignored by HBox because we have a different configured width property
  163. getHeight: function() {return 10;}
  164. }, {
  165. title: 'Panel 3',
  166. flex: 2,
  167. html: 'flex : 2',
  168. frame: true,
  169. margins: {top: 0, left: 0, right: 0, bottom: 0},
  170. getHeight: function() {return 10;},
  171. getWidth: function() {return 10;}
  172. }
  173. ];
  174. var targetSize = {
  175. height: 1628,
  176. width : 630
  177. };
  178. var calcs = layout.calculateChildBoxes(items, targetSize),
  179. boxes = calcs.boxes;
  180. assert.areEqual(0, boxes[0].top);
  181. assert.areEqual(510, boxes[1].top);
  182. assert.areEqual(610, boxes[2].top);
  183. }
  184. }));
  185. suite.add(new Y.Test.Case({
  186. name: 'minHeight of items',
  187. setUp: function() {
  188. this.layout = buildLayout();
  189. this.layout.beforeCt = {
  190. getWidth: function() {
  191. return 0;
  192. },
  193. createChild: Ext.emptyFn
  194. };
  195. this.layout.afterCt = {
  196. getWidth: function() {
  197. return 0;
  198. },
  199. createChild: Ext.emptyFn
  200. };
  201. this.items = [
  202. buildFakeChild({height: 100, minHeight: 100}),
  203. buildFakeChild({height: 200, minHeight: 120}),
  204. buildFakeChild({height: 200, minHeight: 120}),
  205. buildFakeChild({height: 200, minHeight: 120})
  206. ];
  207. },
  208. testAvailableWidthIsSufficient: function() {
  209. var targetSize = {
  210. height: 700,
  211. width : 25
  212. };
  213. var calcs = this.layout.calculateChildBoxes(this.items, targetSize),
  214. boxes = calcs.boxes;
  215. assert.areEqual(0, boxes[0].top);
  216. assert.areEqual(100, boxes[1].top);
  217. assert.areEqual(300, boxes[2].top);
  218. assert.areEqual(500, boxes[3].top);
  219. assert.areEqual(100, boxes[0].height);
  220. assert.areEqual(200, boxes[1].height);
  221. assert.areEqual(200, boxes[2].height);
  222. assert.areEqual(200, boxes[3].height);
  223. },
  224. testHasShortfall: function() {
  225. var targetSize = {
  226. height: 500,
  227. width : 25
  228. };
  229. var calcs = this.layout.calculateChildBoxes(this.items, targetSize),
  230. boxes = calcs.boxes;
  231. assert.areEqual(100, boxes[0].height);
  232. assert.areEqual(133, boxes[1].height);
  233. assert.areEqual(133, boxes[2].height);
  234. assert.areEqual(134, boxes[3].height);
  235. assert.areEqual(0, boxes[0].top);
  236. assert.areEqual(100, boxes[1].top);
  237. assert.areEqual(233, boxes[2].top);
  238. assert.areEqual(366, boxes[3].top);
  239. },
  240. testTooNarrow: function() {
  241. var targetSize = {
  242. height: 400,
  243. width : 25
  244. };
  245. var calcs = this.layout.calculateChildBoxes(this.items, targetSize),
  246. boxes = calcs.boxes;
  247. assert.areEqual(0, boxes[0].top);
  248. assert.areEqual(100, boxes[1].top);
  249. assert.areEqual(220, boxes[2].top);
  250. assert.areEqual(340, boxes[3].top);
  251. assert.areEqual(100, boxes[0].height);
  252. assert.areEqual(120, boxes[1].height);
  253. assert.areEqual(120, boxes[2].height);
  254. assert.areEqual(120, boxes[3].height);
  255. }
  256. }));
  257. suite.add(new Y.Test.Case({
  258. name: 'aligning',
  259. setUp: function() {
  260. this.items = [
  261. buildFakeChild({flex: 1, getWidth: function() {return 10;}}),
  262. buildFakeChild({flex: 1, getWidth: function() {return 20;}}),
  263. buildFakeChild({flex: 1, getWidth: function() {return 30;}}),
  264. buildFakeChild({flex: 1, getWidth: function() {return 40;}})
  265. ];
  266. this.targetSize = {
  267. height: 400,
  268. width : 100
  269. };
  270. },
  271. testLeft: function() {
  272. this.layout = buildLayout({
  273. align: 'left'
  274. });
  275. var calcs = this.layout.calculateChildBoxes(this.items, this.targetSize),
  276. boxes = calcs.boxes;
  277. assert.areEqual(0, boxes[0].left);
  278. assert.areEqual(0, boxes[1].left);
  279. assert.areEqual(0, boxes[2].left);
  280. assert.areEqual(0, boxes[3].left);
  281. },
  282. testMiddle: function() {
  283. this.layout = buildLayout({
  284. align: 'center'
  285. });
  286. var calcs = this.layout.calculateChildBoxes(this.items, this.targetSize),
  287. boxes = calcs.boxes;
  288. assert.areEqual(45, boxes[0].left);
  289. assert.areEqual(40, boxes[1].left);
  290. assert.areEqual(35, boxes[2].left);
  291. assert.areEqual(30, boxes[3].left);
  292. },
  293. testStretch: function() {
  294. this.layout = buildLayout({
  295. align: 'stretch'
  296. });
  297. var calcs = this.layout.calculateChildBoxes(this.items, this.targetSize),
  298. boxes = calcs.boxes;
  299. assert.areEqual(0, boxes[0].left);
  300. assert.areEqual(0, boxes[1].left);
  301. assert.areEqual(0, boxes[2].left);
  302. assert.areEqual(0, boxes[3].left);
  303. assert.areEqual(100, boxes[0].width);
  304. assert.areEqual(100, boxes[1].width);
  305. assert.areEqual(100, boxes[2].width);
  306. assert.areEqual(100, boxes[3].width);
  307. },
  308. testStretchMax: function() {
  309. this.layout = buildLayout({
  310. align: 'stretchmax'
  311. });
  312. var calcs = this.layout.calculateChildBoxes(this.items, this.targetSize),
  313. boxes = calcs.boxes;
  314. assert.areEqual(0, boxes[0].left);
  315. assert.areEqual(0, boxes[1].left);
  316. assert.areEqual(0, boxes[2].left);
  317. assert.areEqual(0, boxes[3].left);
  318. assert.areEqual(40, boxes[0].width);
  319. assert.areEqual(40, boxes[1].width);
  320. assert.areEqual(40, boxes[2].width);
  321. assert.areEqual(40, boxes[3].width);
  322. }
  323. }));
  324. suite.add(new Y.Test.Case({
  325. name: 'packing',
  326. setUp: function() {
  327. this.items = [
  328. buildFakeChild({getSize: function() {return {width: 10, height: 10};}}),
  329. buildFakeChild({getSize: function() {return {width: 10, height: 20};}}),
  330. buildFakeChild({getSize: function() {return {width: 10, height: 30};}}),
  331. buildFakeChild({getSize: function() {return {width: 10, height: 40};}})
  332. ];
  333. this.targetSize = {
  334. height: 400,
  335. width : 100
  336. };
  337. },
  338. testPackStart: function() {
  339. this.layout = buildLayout({
  340. pack: 'start'
  341. });
  342. var calcs = this.layout.calculateChildBoxes(this.items, this.targetSize),
  343. boxes = calcs.boxes;
  344. assert.areEqual(0, boxes[0].top);
  345. assert.areEqual(10, boxes[1].top);
  346. assert.areEqual(30, boxes[2].top);
  347. assert.areEqual(60, boxes[3].top);
  348. },
  349. testPackCenter: function() {
  350. this.layout = buildLayout({
  351. pack: 'center'
  352. });
  353. var calcs = this.layout.calculateChildBoxes(this.items, this.targetSize),
  354. boxes = calcs.boxes;
  355. assert.areEqual(150, boxes[0].top);
  356. assert.areEqual(160, boxes[1].top);
  357. assert.areEqual(180, boxes[2].top);
  358. assert.areEqual(210, boxes[3].top);
  359. },
  360. testPackEnd: function() {
  361. this.layout = buildLayout({
  362. pack: 'end'
  363. });
  364. var calcs = this.layout.calculateChildBoxes(this.items, this.targetSize),
  365. boxes = calcs.boxes;
  366. assert.areEqual(300, boxes[0].top);
  367. assert.areEqual(310, boxes[1].top);
  368. assert.areEqual(330, boxes[2].top);
  369. assert.areEqual(360, boxes[3].top);
  370. }
  371. }));
  372. suite.add(new Y.Test.Case({
  373. name: 'meta data from calculated box sizes',
  374. setUp: function() {
  375. this.layout = buildLayout();
  376. this.items = [
  377. buildFakeChild({getWidth: function() {return 50;}, flex: 1}),
  378. buildFakeChild({getWidth: function() {return 60;}, flex: 1}),
  379. buildFakeChild({getWidth: function() {return 10;}, flex: 1}),
  380. buildFakeChild({getWidth: function() {return 80;}, flex: 1})
  381. ];
  382. this.targetSize = {
  383. height: 400,
  384. width : 100
  385. };
  386. },
  387. testMaxHeight: function() {
  388. var calcs = this.layout.calculateChildBoxes(this.items, this.targetSize),
  389. meta = calcs.meta;
  390. assert.areEqual(80, meta.maxWidth);
  391. }
  392. }));
  393. suite.add(new Y.Test.Case({
  394. name: 'update innerCt size',
  395. setUp: function() {
  396. this.layout = buildLayout({
  397. align : 'stretch',
  398. padding: {
  399. top : 0,
  400. bottom: 0,
  401. left : 10,
  402. right : 20
  403. }
  404. });
  405. //fake the values that are calculated during onLayout
  406. this.layoutTargetLastSize = {
  407. width : 100,
  408. height: 400
  409. };
  410. this.childBoxCache = {
  411. meta: {
  412. maxWidth: 150
  413. }
  414. };
  415. },
  416. testMaintainsWidthForAlignStretch: function() {
  417. var layout = this.layout,
  418. width, height;
  419. //a fake innerCt element that we can intercept calls to setSize on
  420. layout.innerCt = {
  421. setSize: function(widthArg, heightArg) {
  422. width = widthArg;
  423. height = heightArg;
  424. }
  425. };
  426. layout.updateInnerCtSize(this.layoutTargetLastSize, this.childBoxCache);
  427. assert.areSame(100, width);
  428. assert.areSame(400, height);
  429. },
  430. //if aligning middle, increase height to accomodate the tallest child
  431. testIncreasesWidthForAlignMiddle: function() {
  432. this.layout = buildLayout({
  433. align : 'middle',
  434. padding: {
  435. top : 0,
  436. bottom: 0,
  437. left : 10,
  438. right : 20
  439. }
  440. });
  441. var layout = this.layout,
  442. width, height;
  443. //a fake innerCt element that we can intercept calls to setSize on
  444. layout.innerCt = {
  445. setSize: function(widthArg, heightArg) {
  446. width = widthArg;
  447. height = heightArg;
  448. }
  449. };
  450. layout.updateInnerCtSize(this.layoutTargetLastSize, this.childBoxCache);
  451. assert.areSame(180, width);
  452. assert.areSame(400, height);
  453. }
  454. }));
  455. })();