3bb24d56df56cd0a9234201e25ca9c7ed012f45ffc56abfeed1648cd461b25cb4c658eb93cfa5ab6fba04cafd8c73fca0059bd1c801240de487a6cc1152bba 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  1. describe('Core_view', () => {
  2. var id = 'testContainer';
  3. beforeEach(function() {
  4. this.$container = $(`<div id="${id}"></div>`).appendTo('body');
  5. });
  6. afterEach(function() {
  7. if (this.$container) {
  8. destroy();
  9. this.$container.remove();
  10. }
  11. });
  12. it('should focus cell after viewport is scrolled using down arrow', function() {
  13. this.$container[0].style.width = '400px';
  14. this.$container[0].style.height = '60px';
  15. handsontable({
  16. startRows: 20
  17. });
  18. selectCell(0, 0);
  19. keyDown('arrow_down');
  20. keyDown('arrow_down');
  21. keyDown('arrow_down');
  22. keyDown('arrow_down');
  23. expect(getSelected()).toEqual([4, 0, 4, 0]);
  24. keyDown('enter');
  25. expect(isEditorVisible()).toEqual(true);
  26. });
  27. it('should not render "undefined" class name', function() {
  28. this.$container[0].style.width = '501px';
  29. this.$container[0].style.height = '100px';
  30. this.$container[0].style.overflow = 'hidden';
  31. var hot = handsontable({
  32. startRows: 10,
  33. startCols: 5,
  34. colWidths: [47, 47, 47, 47, 47],
  35. rowHeaders: true,
  36. colHeaders: true,
  37. stretchH: 'all'
  38. });
  39. selectCell(0, 0);
  40. expect(this.$container.find('.undefined').length).toBe(0);
  41. });
  42. it('should scroll viewport when partially visible cell is clicked', function() {
  43. this.$container[0].style.width = '400px';
  44. this.$container[0].style.height = '60px';
  45. var hot = handsontable({
  46. data: Handsontable.helper.createSpreadsheetData(10, 3),
  47. height: 60
  48. });
  49. var htCore = getHtCore();
  50. var scrollTop = hot.rootElement.querySelector('.wtHolder').scrollTop;
  51. expect(scrollTop).toBe(0);
  52. expect(this.$container.height()).toEqual(60);
  53. expect(this.$container.find('.wtHolder .wtHider').height()).toBeGreaterThan(60);
  54. expect(htCore.find('tr:eq(0) td:eq(0)').html()).toEqual('A1');
  55. expect(htCore.find('tr:eq(1) td:eq(0)').html()).toEqual('A2');
  56. expect(htCore.find('tr:eq(2) td:eq(0)').html()).toEqual('A3');
  57. htCore.find('tr:eq(3) td:eq(0)').simulate('mousedown');
  58. expect(hot.rootElement.querySelector('.wtHolder').scrollTop).toBeGreaterThan(scrollTop);
  59. expect(getSelected()).toEqual([3, 0, 3, 0]);
  60. });
  61. it('should scroll viewport without cell selection', function() {
  62. this.$container[0].style.width = '400px';
  63. var hot1 = handsontable({
  64. data: Handsontable.helper.createSpreadsheetData(20, 20),
  65. height: 100
  66. });
  67. hot1.scrollViewportTo(10, 10);
  68. var wtHolder = this.$container.find('.ht_master .wtHolder');
  69. expect(wtHolder[0].scrollTop).toEqual(230);
  70. expect(wtHolder[0].scrollLeft).toEqual(500);
  71. });
  72. it('should not throw error while scrolling viewport to 0, 0 (empty data)', function() {
  73. this.$container[0].style.width = '400px';
  74. var hot1 = handsontable({
  75. data: [],
  76. height: 100
  77. });
  78. expect(() => {
  79. hot1.view.scrollViewport({row: 0, col: 0});
  80. }).not.toThrow();
  81. });
  82. it('should throw error while scrolling viewport below 0 (empty data)', function() {
  83. this.$container[0].style.width = '400px';
  84. var hot1 = handsontable({
  85. data: [],
  86. height: 100
  87. });
  88. expect(() => {
  89. hot1.view.scrollViewport({row: -1, col: 0});
  90. }).toThrow();
  91. expect(() => {
  92. hot1.view.scrollViewport({row: 0, col: -1});
  93. }).toThrow();
  94. expect(() => {
  95. hot1.view.scrollViewport({row: -1, col: -1});
  96. }).toThrow();
  97. });
  98. it('should scroll viewport, respecting fixed rows', function() {
  99. this.$container[0].style.width = '400px';
  100. this.$container[0].style.height = '60px';
  101. var hot = handsontable({
  102. data: Handsontable.helper.createSpreadsheetData(10, 9),
  103. fixedRowsTop: 1,
  104. height: 60
  105. });
  106. var htCore = getHtCore();
  107. var scrollTop = hot.rootElement.querySelector('.wtHolder').scrollTop;
  108. expect(scrollTop).toBe(0);
  109. expect(htCore.find('tr:eq(0) td:eq(0)').html()).toEqual('A1');
  110. expect(htCore.find('tr:eq(0) td:eq(1)').html()).toEqual('B1');
  111. expect(htCore.find('tr:eq(0) td:eq(2)').html()).toEqual('C1');
  112. selectCell(0, 0);
  113. keyDown('arrow_down');
  114. keyDown('arrow_down');
  115. keyDown('arrow_down');
  116. keyDown('arrow_down');
  117. expect(hot.rootElement.querySelector('.wtHolder').scrollTop).toBeGreaterThan(scrollTop);
  118. });
  119. it('should enable to change fixedRowsTop with updateSettings', function() {
  120. this.$container[0].style.width = '400px';
  121. this.$container[0].style.height = '60px';
  122. var HOT = handsontable({
  123. data: Handsontable.helper.createSpreadsheetData(10, 9),
  124. fixedRowsTop: 1,
  125. width: 200,
  126. height: 100
  127. });
  128. selectCell(0, 0);
  129. var htCore = getHtCore();
  130. var topClone = getTopClone();
  131. expect(topClone.find('tr').length).toEqual(1);
  132. expect(topClone.find('tr:eq(0) td:eq(0)').html()).toEqual('A1');
  133. expect(htCore.find('tr:eq(0) td:eq(0)').html()).toEqual('A1');
  134. expect(htCore.find('tr:eq(1) td:eq(0)').html()).toEqual('A2');
  135. expect(htCore.find('tr:eq(2) td:eq(0)').html()).toEqual('A3');
  136. expect(htCore.find('tr:eq(3) td:eq(0)').html()).toEqual('A4');
  137. keyDown('arrow_down');
  138. keyDown('arrow_down');
  139. keyDown('arrow_down');
  140. keyDown('arrow_down');
  141. expect(topClone.find('tr').length).toEqual(1);
  142. expect(topClone.find('tr:eq(0) td:eq(0)').html()).toEqual('A1');
  143. HOT.updateSettings({
  144. fixedRowsTop: 2
  145. });
  146. expect(topClone.find('tr').length).toEqual(2);
  147. expect(topClone.find('tr:eq(0) td:eq(0)').html()).toEqual('A1');
  148. expect(topClone.find('tr:eq(1) td:eq(0)').html()).toEqual('A2');
  149. expect(htCore.find('tr:eq(0) td:eq(0)').html()).toEqual('A1');
  150. expect(htCore.find('tr:eq(1) td:eq(0)').html()).toEqual('A2');
  151. expect(htCore.find('tr:eq(2) td:eq(0)').html()).toEqual('A3');
  152. expect(htCore.find('tr:eq(3) td:eq(0)').html()).toEqual('A4');
  153. });
  154. it('should scroll viewport, respecting fixed columns', function() {
  155. this.$container[0].style.width = '200px';
  156. this.$container[0].style.height = '100px';
  157. handsontable({
  158. data: Handsontable.helper.createSpreadsheetData(10, 9),
  159. fixedColumnsLeft: 1
  160. });
  161. var htCore = getHtCore();
  162. var leftClone = this.$container.find('.ht_clone_left');
  163. expect(leftClone.find('tr:eq(0) td').length).toEqual(1);
  164. expect(leftClone.find('tr:eq(0) td:eq(0)').html()).toEqual('A1');
  165. expect(leftClone.find('tr:eq(1) td:eq(0)').html()).toEqual('A2');
  166. expect(leftClone.find('tr:eq(2) td:eq(0)').html()).toEqual('A3');
  167. expect(htCore.find('tr:eq(0) td:eq(0)').html()).toEqual('A1');
  168. expect(htCore.find('tr:eq(1) td:eq(0)').html()).toEqual('A2');
  169. expect(htCore.find('tr:eq(2) td:eq(0)').html()).toEqual('A3');
  170. selectCell(0, 3);
  171. keyDown('arrow_right');
  172. keyDown('arrow_right');
  173. keyDown('arrow_right');
  174. keyDown('arrow_right');
  175. expect(leftClone.find('tr:eq(0) td:eq(0)').html()).toEqual('A1');
  176. expect(leftClone.find('tr:eq(1) td:eq(0)').html()).toEqual('A2');
  177. expect(leftClone.find('tr:eq(2) td:eq(0)').html()).toEqual('A3');
  178. });
  179. it('should enable to change fixedColumnsLeft with updateSettings', function() {
  180. this.$container[0].style.width = '200px';
  181. this.$container[0].style.height = '100px';
  182. var HOT = handsontable({
  183. data: Handsontable.helper.createSpreadsheetData(10, 9),
  184. fixedColumnsLeft: 1
  185. });
  186. selectCell(0, 0);
  187. var leftClone = this.$container.find('.ht_clone_left');
  188. expect(leftClone.find('tr:eq(0) td').length).toEqual(1);
  189. expect(leftClone.find('tr:eq(0) td:eq(0)').html()).toEqual('A1');
  190. expect(leftClone.find('tr:eq(1) td:eq(0)').html()).toEqual('A2');
  191. expect(leftClone.find('tr:eq(2) td:eq(0)').html()).toEqual('A3');
  192. keyDown('arrow_right');
  193. keyDown('arrow_right');
  194. keyDown('arrow_right');
  195. keyDown('arrow_right');
  196. expect(leftClone.find('tr:eq(0) td:eq(0)').html()).toEqual('A1');
  197. expect(leftClone.find('tr:eq(1) td:eq(0)').html()).toEqual('A2');
  198. expect(leftClone.find('tr:eq(2) td:eq(0)').html()).toEqual('A3');
  199. selectCell(0, 0);
  200. HOT.updateSettings({
  201. fixedColumnsLeft: 2
  202. });
  203. expect(leftClone.find('tr:eq(0) td').length).toEqual(2);
  204. expect(leftClone.find('tr:eq(0) td:eq(0)').html()).toEqual('A1');
  205. expect(leftClone.find('tr:eq(0) td:eq(1)').html()).toEqual('B1');
  206. expect(leftClone.find('tr:eq(1) td:eq(0)').html()).toEqual('A2');
  207. expect(leftClone.find('tr:eq(1) td:eq(1)').html()).toEqual('B2');
  208. expect(leftClone.find('tr:eq(2) td:eq(0)').html()).toEqual('A3');
  209. expect(leftClone.find('tr:eq(2) td:eq(1)').html()).toEqual('B3');
  210. });
  211. it('should not scroll viewport when last cell is clicked', () => {
  212. handsontable({
  213. startRows: 40
  214. });
  215. var lastScroll;
  216. $(window).scrollTop(10000);
  217. lastScroll = $(window).scrollTop();
  218. render(); // renders synchronously so we don't have to put stuff in waits/runs
  219. selectCell(39, 0);
  220. expect($(window).scrollTop()).toEqual(lastScroll);
  221. keyDown('arrow_right');
  222. expect(getSelected()).toEqual([39, 1, 39, 1]);
  223. expect($(window).scrollTop()).toEqual(lastScroll);
  224. });
  225. it('should not shrink table when width and height is not specified for container', function(done) {
  226. var initHeight;
  227. this.$container[0].style.overflow = 'hidden';
  228. this.$container.wrap('<div style="width: 50px;"></div>');
  229. handsontable({
  230. startRows: 10,
  231. startCols: 10
  232. });
  233. setTimeout(() => {
  234. initHeight = spec().$container.height();
  235. }, 250);
  236. setTimeout(() => {
  237. expect(spec().$container.height()).toEqual(initHeight);
  238. done();
  239. }, 500);
  240. });
  241. it('should allow height to be a number', function() {
  242. handsontable({
  243. startRows: 10,
  244. startCols: 10,
  245. height: 107
  246. });
  247. expect(this.$container.height()).toEqual(107);
  248. });
  249. it('should allow height to be a function', function() {
  250. handsontable({
  251. startRows: 10,
  252. startCols: 10,
  253. height() {
  254. return 107;
  255. }
  256. });
  257. expect(this.$container.height()).toEqual(107);
  258. });
  259. it('should allow width to be a number', function() {
  260. handsontable({
  261. startRows: 10,
  262. startCols: 10,
  263. width: 107,
  264. });
  265. expect(this.$container.width()).toEqual(107); // rootElement is full width but this should do the trick
  266. });
  267. it('should allow width to be a function', function() {
  268. handsontable({
  269. startRows: 10,
  270. startCols: 10,
  271. width() {
  272. return 107;
  273. }
  274. });
  275. expect(this.$container.width()).toEqual(107); // rootElement is full width but this should do the trick
  276. });
  277. it('should fire beforeRender event after table has been scrolled', function(done) {
  278. this.$container[0].style.width = '400px';
  279. this.$container[0].style.height = '60px';
  280. this.$container[0].style.overflow = 'hidden';
  281. var hot = handsontable({
  282. data: Handsontable.helper.createSpreadsheetData(100, 3)
  283. });
  284. var beforeRenderCallback = jasmine.createSpy('beforeRenderCallback');
  285. hot.addHook('beforeRender', beforeRenderCallback);
  286. this.$container.find('.ht_master .wtHolder').scrollTop(1000);
  287. setTimeout(() => {
  288. expect(beforeRenderCallback.calls.count()).toBe(1);
  289. done();
  290. }, 200);
  291. });
  292. it('should fire afterRender event after table has been scrolled', function(done) {
  293. this.$container[0].style.width = '400px';
  294. this.$container[0].style.height = '60px';
  295. this.$container[0].style.overflow = 'hidden';
  296. var hot = handsontable({
  297. data: Handsontable.helper.createSpreadsheetData(20, 3)
  298. });
  299. var afterRenderCallback = jasmine.createSpy('afterRenderCallback');
  300. hot.addHook('afterRender', afterRenderCallback);
  301. this.$container.find('.ht_master .wtHolder').first().scrollTop(1000);
  302. setTimeout(() => {
  303. expect(afterRenderCallback.calls.count()).toBe(1);
  304. done();
  305. }, 200);
  306. });
  307. it('should fire afterRender event after table physically rendered', function(done) {
  308. this.$container[0].style.width = '400px';
  309. this.$container[0].style.height = '60px';
  310. this.$container[0].style.overflow = 'hidden';
  311. var hot = handsontable({
  312. data: Handsontable.helper.createSpreadsheetData(20, 3)
  313. });
  314. hot.addHook('afterRender', () => {
  315. hot.view.wt.wtTable.holder.style.overflow = 'scroll';
  316. hot.view.wt.wtTable.holder.style.width = '220px';
  317. });
  318. this.$container.find('.ht_master .wtHolder').first().scrollTop(1000);
  319. setTimeout(() => {
  320. // after afterRender hook triggered element style shouldn't changed
  321. expect(hot.view.wt.wtTable.holder.style.overflow).toBe('scroll');
  322. expect(hot.view.wt.wtTable.holder.style.width).toBe('220px');
  323. done();
  324. }, 100);
  325. });
  326. // TODO fix these tests - https://github.com/handsontable/handsontable/issues/1559
  327. describe('maximumVisibleElementWidth', () => {
  328. it('should return maximum width until right edge of the viewport', () => {
  329. var hot = handsontable({
  330. startRows: 2,
  331. startCols: 10,
  332. width: 100,
  333. height: 100,
  334. });
  335. expect(hot.view.maximumVisibleElementWidth(0)).toEqual(100);
  336. });
  337. it('should return maximum width until right edge of the viewport (excluding the scrollbar)', () => {
  338. var hot = handsontable({
  339. startRows: 10,
  340. startCols: 10,
  341. width: 100,
  342. height: 100,
  343. });
  344. expect(hot.view.maximumVisibleElementWidth(200)).toBeLessThan(100);
  345. });
  346. });
  347. describe('maximumVisibleElementHeight', () => {
  348. it('should return maximum height until bottom edge of the viewport', () => {
  349. var hot = handsontable({
  350. startRows: 10,
  351. startCols: 2,
  352. width: 120,
  353. height: 100,
  354. });
  355. expect(hot.view.maximumVisibleElementHeight(0)).toEqual(100);
  356. });
  357. it('should return maximum height until bottom edge of the viewport (excluding the scrollbar)', () => {
  358. var hot = handsontable({
  359. startRows: 10,
  360. startCols: 10,
  361. width: 120,
  362. height: 100,
  363. });
  364. expect(hot.view.maximumVisibleElementHeight()).toBeLessThan(100);
  365. });
  366. });
  367. describe('fixed column row heights', () => {
  368. it('should be the same as the row heights in the main table', () => {
  369. var hot = handsontable({
  370. data: [['A', 'B', 'C', 'D'], ['a', 'b', 'c\nc', 'd'], ['aa', 'bb', 'cc', 'dd']],
  371. startRows: 3,
  372. startCols: 4,
  373. fixedColumnsLeft: 2,
  374. });
  375. expect(hot.getCell(1, 2).clientHeight).toEqual(hot.getCell(1, 1).clientHeight);
  376. hot.setDataAtCell(1, 2, 'c');
  377. expect(hot.getCell(1, 2).clientHeight).toEqual(hot.getCell(1, 1).clientHeight);
  378. });
  379. it('should be the same as the row heights in the main table (after scroll)', function() {
  380. var myData = Handsontable.helper.createSpreadsheetData(20, 4);
  381. myData[1][3] = 'very\nlong\ntext';
  382. myData[5][3] = 'very\nlong\ntext';
  383. myData[10][3] = 'very\nlong\ntext';
  384. myData[15][3] = 'very\nlong\ntext';
  385. var hot = handsontable({
  386. data: myData,
  387. startRows: 3,
  388. startCols: 4,
  389. fixedRowsTop: 2,
  390. fixedColumnsLeft: 2,
  391. width: 200,
  392. height: 200
  393. });
  394. var mainHolder = hot.view.wt.wtTable.holder;
  395. $(mainHolder).scrollTop(200);
  396. hot.render();
  397. var masterTD = this.$container.find('.ht_master tbody tr:eq(5) td:eq(1)')[0];
  398. var cloneTD = this.$container.find('.ht_clone_left tbody tr:eq(5) td:eq(1)')[0];
  399. expect(cloneTD.clientHeight).toEqual(masterTD.clientHeight);
  400. });
  401. it('should be the same as the row heights in the main table (after scroll, in corner)', function() {
  402. var myData = Handsontable.helper.createSpreadsheetData(20, 4);
  403. myData[1][3] = 'very\nlong\ntext';
  404. myData[5][3] = 'very\nlong\ntext';
  405. myData[10][3] = 'very\nlong\ntext';
  406. myData[15][3] = 'very\nlong\ntext';
  407. var hot = handsontable({
  408. data: myData,
  409. startRows: 3,
  410. startCols: 4,
  411. fixedRowsTop: 2,
  412. fixedColumnsLeft: 2,
  413. width: 200,
  414. height: 200
  415. });
  416. var rowHeight = hot.getCell(1, 3).clientHeight;
  417. var mainHolder = hot.view.wt.wtTable.holder;
  418. expect(this.$container.find('.ht_clone_top_left_corner tbody tr:eq(1) td:eq(1)')[0].clientHeight).toEqual(rowHeight);
  419. $(mainHolder).scrollTop(200);
  420. hot.render();
  421. expect(this.$container.find('.ht_clone_top_left_corner tbody tr:eq(1) td:eq(1)')[0].clientHeight).toEqual(rowHeight);
  422. });
  423. });
  424. describe('fixed column widths', () => {
  425. it('should set the columns width correctly after changes made during updateSettings', function() {
  426. var hot = handsontable({
  427. startRows: 2,
  428. fixedColumnsLeft: 2,
  429. columns: [{
  430. width: 50
  431. }, {
  432. width: 80
  433. }, {
  434. width: 110
  435. }, {
  436. width: 140
  437. }, {
  438. width: 30
  439. }, {
  440. width: 30
  441. }, {
  442. width: 30
  443. }]
  444. });
  445. var leftClone = this.$container.find('.ht_clone_left');
  446. expect(Handsontable.dom.outerWidth(leftClone.find('tbody tr:nth-child(1) td:nth-child(2)')[0])).toEqual(80);
  447. hot.updateSettings({
  448. manualColumnMove: [2, 0, 1],
  449. fixedColumnsLeft: 1
  450. });
  451. expect(leftClone.find('tbody tr:nth-child(1) td:nth-child(2)')[0]).toBe(undefined);
  452. hot.updateSettings({
  453. manualColumnMove: false,
  454. fixedColumnsLeft: 2
  455. });
  456. expect(Handsontable.dom.outerWidth(leftClone.find('tbody tr:nth-child(1) td:nth-child(2)')[0])).toEqual(80);
  457. });
  458. it('should set the columns width correctly after changes made during updateSettings when columns is a function', function() {
  459. var hot = handsontable({
  460. startCols: 7,
  461. startRows: 2,
  462. fixedColumnsLeft: 2,
  463. columns(column) {
  464. var colMeta = {};
  465. if (column === 0) {
  466. colMeta.width = 50;
  467. } else if (column === 1) {
  468. colMeta.width = 80;
  469. } else if (column === 2) {
  470. colMeta.width = 110;
  471. } else if (column === 3) {
  472. colMeta.width = 140;
  473. } else if ([4, 5, 6].indexOf(column) > -1) {
  474. colMeta.width = 30;
  475. } else {
  476. colMeta = null;
  477. }
  478. return colMeta;
  479. }
  480. });
  481. var leftClone = this.$container.find('.ht_clone_left');
  482. expect(Handsontable.dom.outerWidth(leftClone.find('tbody tr:nth-child(1) td:nth-child(2)')[0])).toEqual(80);
  483. hot.updateSettings({
  484. manualColumnMove: [2, 0, 1],
  485. fixedColumnsLeft: 1
  486. });
  487. expect(leftClone.find('tbody tr:nth-child(1) td:nth-child(2)')[0]).toBe(undefined);
  488. hot.updateSettings({
  489. manualColumnMove: false,
  490. fixedColumnsLeft: 2
  491. });
  492. expect(Handsontable.dom.outerWidth(leftClone.find('tbody tr:nth-child(1) td:nth-child(2)')[0])).toEqual(80);
  493. });
  494. });
  495. describe('stretchH', () => {
  496. it('should stretch all visible columns with the ratio appropriate to the container\'s width', function() {
  497. this.$container[0].style.width = '300px';
  498. var hot = handsontable({
  499. startRows: 5,
  500. startCols: 5,
  501. rowHeaders: true,
  502. colHeaders: true,
  503. stretchH: 'all'
  504. }),
  505. rowHeaderWidth = hot.view.wt.wtViewport.getRowHeaderWidth(),
  506. expectedCellWidth = (parseInt(this.$container[0].style.width, 10) - rowHeaderWidth) / 5;
  507. expect(getCell(0, 0).offsetWidth).toEqual(expectedCellWidth);
  508. expect(getCell(0, 1).offsetWidth).toEqual(expectedCellWidth);
  509. expect(getCell(0, 2).offsetWidth).toEqual(expectedCellWidth);
  510. expect(getCell(0, 3).offsetWidth).toEqual(expectedCellWidth);
  511. expect(getCell(0, 4).offsetWidth).toEqual(expectedCellWidth);
  512. this.$container[0].style.width = '';
  513. this.$container.wrap('<div class="temp_wrapper" style="width:400px;"></div>');
  514. hot.render();
  515. expectedCellWidth = (parseInt($('.temp_wrapper')[0].style.width, 10) - rowHeaderWidth) / 5;
  516. expect(getCell(0, 0).offsetWidth).toEqual(expectedCellWidth);
  517. expect(getCell(0, 1).offsetWidth).toEqual(expectedCellWidth);
  518. expect(getCell(0, 2).offsetWidth).toEqual(expectedCellWidth);
  519. expect(getCell(0, 3).offsetWidth).toEqual(expectedCellWidth);
  520. expect(getCell(0, 4).offsetWidth).toEqual(expectedCellWidth);
  521. this.$container.unwrap();
  522. });
  523. it('should stretch all visible columns with overflow hidden', function() {
  524. this.$container[0].style.width = '501px';
  525. this.$container[0].style.height = '100px';
  526. this.$container[0].style.overflow = 'hidden';
  527. var hot = handsontable({
  528. startRows: 10,
  529. startCols: 5,
  530. colWidths: [47, 47, 47, 47, 47],
  531. rowHeaders: true,
  532. colHeaders: true,
  533. stretchH: 'all'
  534. });
  535. var masterTH = this.$container[0].querySelectorAll('.ht_master thead tr th');
  536. var overlayTH = this.$container[0].querySelectorAll('.ht_clone_top thead tr th');
  537. expect(masterTH[0].offsetWidth).toEqual(50);
  538. expect(overlayTH[0].offsetWidth).toEqual(50);
  539. expect(masterTH[1].offsetWidth).toBeInArray([86, 87, 88, 90]);
  540. expect(overlayTH[1].offsetWidth).toBeInArray([86, 87, 88, 90]); // if you get 90, it means it is calculated before scrollbars were applied, or show scroll on scrolling is enabled
  541. expect(masterTH[2].offsetWidth).toEqual(overlayTH[2].offsetWidth);
  542. expect(masterTH[3].offsetWidth).toEqual(overlayTH[3].offsetWidth);
  543. expect(masterTH[4].offsetWidth).toEqual(overlayTH[4].offsetWidth);
  544. expect(masterTH[5].offsetWidth).toEqual(overlayTH[5].offsetWidth);
  545. });
  546. it('should respect stretched widths returned in beforeStretchingColumnWidth hook', function() {
  547. this.$container[0].style.width = '501px';
  548. this.$container[0].style.height = '100px';
  549. this.$container[0].style.overflow = 'hidden';
  550. var callbackSpy = jasmine.createSpy();
  551. callbackSpy.and.callFake((width, column) => {
  552. if (column === 1) {
  553. return 150;
  554. }
  555. return width;
  556. });
  557. var hot = handsontable({
  558. startRows: 2,
  559. startCols: 5,
  560. rowHeaders: true,
  561. colHeaders: true,
  562. stretchH: 'all',
  563. beforeStretchingColumnWidth: callbackSpy
  564. });
  565. var $columnHeaders = this.$container.find('thead tr:eq(0) th');
  566. expect($columnHeaders.eq(0).width()).toEqual(48);
  567. expect($columnHeaders.eq(1).width()).toEqual(73);
  568. expect($columnHeaders.eq(2).width()).toEqual(149);
  569. expect($columnHeaders.eq(3).width()).toEqual(74);
  570. expect($columnHeaders.eq(4).width()).toEqual(74);
  571. expect(callbackSpy).toHaveBeenCalled();
  572. // First cycle to check what columns has permanent width
  573. expect(callbackSpy.calls.argsFor(0)[0]).not.toBeDefined();
  574. expect(callbackSpy.calls.argsFor(0)[1]).toBe(0);
  575. expect(callbackSpy.calls.argsFor(1)[0]).not.toBeDefined();
  576. expect(callbackSpy.calls.argsFor(1)[1]).toBe(1);
  577. expect(callbackSpy.calls.argsFor(2)[0]).not.toBeDefined();
  578. expect(callbackSpy.calls.argsFor(2)[1]).toBe(2);
  579. expect(callbackSpy.calls.argsFor(3)[0]).not.toBeDefined();
  580. expect(callbackSpy.calls.argsFor(3)[1]).toBe(3);
  581. expect(callbackSpy.calls.argsFor(4)[0]).not.toBeDefined();
  582. expect(callbackSpy.calls.argsFor(4)[1]).toBe(4);
  583. // // Second cycle retrieve stretched width or permanent width
  584. expect(callbackSpy.calls.argsFor(5)[0]).toBe(75);
  585. expect(callbackSpy.calls.argsFor(6)[0]).toBe(75);
  586. expect(callbackSpy.calls.argsFor(7)[0]).toBe(75);
  587. expect(callbackSpy.calls.argsFor(8)[0]).toBe(75);
  588. expect(callbackSpy.calls.argsFor(9)[0]).toBe(75);
  589. });
  590. });
  591. });