dd5590b2c1e0fc3248ff1ed95d641c842faa31da8eb75df09857849dac043294bf2de0d232b8179375a530318a61e364696b9ab346dd7f09685ac13ebe8a40 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. describe('MergeCells', () => {
  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. describe('mergeCells option', () => {
  13. it('should merge cell in startup', () => {
  14. var hot = handsontable({
  15. data: Handsontable.helper.createSpreadsheetObjectData(10, 5),
  16. mergeCells: [
  17. {row: 0, col: 0, rowspan: 2, colspan: 2}
  18. ]
  19. });
  20. var TD = hot.rootElement.querySelector('td');
  21. expect(TD.getAttribute('rowspan')).toBe('2');
  22. expect(TD.getAttribute('colspan')).toBe('2');
  23. });
  24. });
  25. describe('mergeCells updateSettings', () => {
  26. it('should allow to overwrite the initial settings using the updateSettings method', () => {
  27. var hot = handsontable({
  28. data: Handsontable.helper.createSpreadsheetObjectData(10, 10),
  29. mergeCells: [
  30. {row: 0, col: 0, rowspan: 2, colspan: 2}
  31. ]
  32. });
  33. var TD = hot.rootElement.querySelector('td');
  34. expect(TD.getAttribute('rowspan')).toBe('2');
  35. expect(TD.getAttribute('colspan')).toBe('2');
  36. updateSettings({
  37. mergeCells: [
  38. {row: 2, col: 2, rowspan: 2, colspan: 2}
  39. ]
  40. });
  41. TD = hot.rootElement.querySelector('td');
  42. expect(TD.getAttribute('rowspan')).toBe(null);
  43. expect(TD.getAttribute('colspan')).toBe(null);
  44. TD = getCell(2, 2);
  45. expect(TD.getAttribute('rowspan')).toBe('2');
  46. expect(TD.getAttribute('colspan')).toBe('2');
  47. });
  48. it('should allow resetting the merged cells by changing it to \'true\'', () => {
  49. var hot = handsontable({
  50. data: Handsontable.helper.createSpreadsheetObjectData(10, 10),
  51. mergeCells: [
  52. {row: 0, col: 0, rowspan: 2, colspan: 2}
  53. ]
  54. });
  55. var TD = hot.rootElement.querySelector('td');
  56. expect(TD.getAttribute('rowspan')).toBe('2');
  57. expect(TD.getAttribute('colspan')).toBe('2');
  58. updateSettings({
  59. mergeCells: true
  60. });
  61. TD = hot.rootElement.querySelector('td');
  62. expect(TD.getAttribute('rowspan')).toBe(null);
  63. expect(TD.getAttribute('colspan')).toBe(null);
  64. });
  65. it('should allow resetting and turning off the mergeCells plugin by changing mergeCells to \'false\'', () => {
  66. var hot = handsontable({
  67. data: Handsontable.helper.createSpreadsheetObjectData(10, 10),
  68. mergeCells: [
  69. {row: 0, col: 0, rowspan: 2, colspan: 2}
  70. ]
  71. });
  72. var TD = hot.rootElement.querySelector('td');
  73. expect(TD.getAttribute('rowspan')).toBe('2');
  74. expect(TD.getAttribute('colspan')).toBe('2');
  75. updateSettings({
  76. mergeCells: false
  77. });
  78. TD = hot.rootElement.querySelector('td');
  79. expect(TD.getAttribute('rowspan')).toBe(null);
  80. expect(TD.getAttribute('colspan')).toBe(null);
  81. });
  82. });
  83. describe('mergeCells copy', () => {
  84. it('should not copy text of cells that are merged into another cell', () => {
  85. var hot = handsontable({
  86. data: Handsontable.helper.createSpreadsheetObjectData(10, 5),
  87. mergeCells: [
  88. {row: 0, col: 0, rowspan: 2, colspan: 2}
  89. ]
  90. });
  91. expect(hot.getCopyableText(0, 0, 2, 2)).toBe('A1\t\tC1\n\t\tC2\nA3\tB3\tC3');
  92. });
  93. });
  94. describe('merged cells selection', () => {
  95. it('should select the whole range of cells which form a merged cell', function() {
  96. var hot = handsontable({
  97. data: Handsontable.helper.createSpreadsheetObjectData(4, 4),
  98. mergeCells: [
  99. {
  100. row: 0,
  101. col: 0,
  102. colspan: 4,
  103. rowspan: 1
  104. }
  105. ]
  106. });
  107. var $table = this.$container.find('table.htCore');
  108. var $td = $table.find('tr:eq(0) td:eq(0)');
  109. expect($td.attr('rowspan')).toEqual('1');
  110. expect($td.attr('colspan')).toEqual('4');
  111. expect(hot.getSelected()).toBeUndefined();
  112. hot.selectCell(0, 0);
  113. expect(hot.getSelected()).toEqual([0, 0, 0, 3]);
  114. deselectCell();
  115. hot.selectCell(0, 1);
  116. expect(hot.getSelected()).toEqual([0, 0, 0, 3]);
  117. });
  118. it('should always make a rectangular selection, when selecting merged and not merged cells', function() {
  119. var hot = handsontable({
  120. data: Handsontable.helper.createSpreadsheetObjectData(4, 4),
  121. mergeCells: [
  122. {
  123. row: 1,
  124. col: 1,
  125. colspan: 3,
  126. rowspan: 2
  127. }
  128. ]
  129. });
  130. var $table = this.$container.find('table.htCore');
  131. var $td = $table.find('tr:eq(1) td:eq(1)');
  132. expect($td.attr('rowspan')).toEqual('2');
  133. expect($td.attr('colspan')).toEqual('3');
  134. expect(hot.getSelected()).toBeUndefined();
  135. hot.selectCell(0, 0);
  136. expect(hot.getSelected()).toEqual([0, 0, 0, 0]);
  137. deselectCell();
  138. hot.selectCell(0, 0, 1, 1);
  139. expect(hot.getSelected()).not.toEqual([0, 0, 1, 1]);
  140. expect(hot.getSelected()).toEqual([0, 0, 2, 3]);
  141. deselectCell();
  142. hot.selectCell(0, 1, 1, 1);
  143. expect(hot.getSelected()).toEqual([0, 1, 2, 3]);
  144. });
  145. it('should not switch the selection start point when selecting from non-merged cells to merged cells', () => {
  146. var hot = handsontable({
  147. data: Handsontable.helper.createSpreadsheetObjectData(10, 10),
  148. mergeCells: [
  149. {row: 1, col: 1, rowspan: 3, colspan: 3},
  150. {row: 3, col: 4, rowspan: 2, colspan: 2}
  151. ]
  152. });
  153. $(hot.getCell(6, 6)).simulate('mousedown');
  154. expect(hot.getSelectedRange().from.col).toEqual(6);
  155. expect(hot.getSelectedRange().from.row).toEqual(6);
  156. $(hot.getCell(1, 1)).simulate('mouseenter');
  157. expect(hot.getSelectedRange().from.col).toEqual(6);
  158. expect(hot.getSelectedRange().from.row).toEqual(6);
  159. $(hot.getCell(3, 3)).simulate('mouseenter');
  160. expect(hot.getSelectedRange().from.col).toEqual(6);
  161. expect(hot.getSelectedRange().from.row).toEqual(6);
  162. $(hot.getCell(4, 4)).simulate('mouseenter');
  163. expect(hot.getSelectedRange().from.col).toEqual(6);
  164. expect(hot.getSelectedRange().from.row).toEqual(6);
  165. });
  166. it('should select cells in the correct direction when changing selections around a merged range', () => {
  167. var hot = handsontable({
  168. data: Handsontable.helper.createSpreadsheetObjectData(10, 10),
  169. mergeCells: [
  170. {row: 4, col: 4, rowspan: 2, colspan: 2}
  171. ]
  172. });
  173. hot.selectCell(5, 5, 5, 2);
  174. expect(hot.getSelectedRange().getDirection()).toEqual('SE-NW');
  175. hot.selectCell(4, 4, 2, 5);
  176. expect(hot.getSelectedRange().getDirection()).toEqual('SW-NE');
  177. hot.selectCell(4, 4, 5, 7);
  178. expect(hot.getSelectedRange().getDirection()).toEqual('NW-SE');
  179. hot.selectCell(4, 5, 7, 5);
  180. expect(hot.getSelectedRange().getDirection()).toEqual('NE-SW');
  181. });
  182. it('should not add an area class to the selected cell if a single merged cell is selected', () => {
  183. var hot = handsontable({
  184. data: Handsontable.helper.createSpreadsheetObjectData(6, 6),
  185. mergeCells: [
  186. {
  187. row: 1,
  188. col: 1,
  189. colspan: 3,
  190. rowspan: 2
  191. }
  192. ]
  193. });
  194. selectCell(1, 1);
  195. expect(getCell(1, 1).className.indexOf('area')).toEqual(-1);
  196. selectCell(1, 1, 4, 4);
  197. expect(getCell(1, 1).className.indexOf('area')).not.toEqual(-1);
  198. selectCell(1, 1);
  199. expect(getCell(1, 1).className.indexOf('area')).toEqual(-1);
  200. selectCell(0, 0);
  201. expect(getCell(1, 1).className.indexOf('area')).toEqual(-1);
  202. });
  203. });
  204. describe('merged cells scroll', () => {
  205. it('getCell should return merged cell parent', () => {
  206. var hot = handsontable({
  207. data: Handsontable.helper.createSpreadsheetObjectData(10, 5),
  208. mergeCells: [
  209. {row: 0, col: 0, rowspan: 2, colspan: 2}
  210. ],
  211. height: 100,
  212. width: 400
  213. });
  214. var mergedCellParent = hot.getCell(0, 0);
  215. var mergedCellHidden = hot.getCell(1, 1);
  216. expect(mergedCellHidden).toBe(mergedCellParent);
  217. });
  218. it('should scroll viewport to beginning of a merged cell when it\'s clicked', () => {
  219. var hot = handsontable({
  220. data: Handsontable.helper.createSpreadsheetObjectData(10, 5),
  221. mergeCells: [
  222. {row: 5, col: 0, rowspan: 2, colspan: 2}
  223. ],
  224. height: 100,
  225. width: 400
  226. });
  227. var mainHolder = hot.view.wt.wtTable.holder;
  228. mainHolder.scrollTop = 130;
  229. hot.render();
  230. expect(mainHolder.scrollTop).toBe(130);
  231. var TD = hot.getCell(5, 0);
  232. mouseDown(TD);
  233. mouseUp(TD);
  234. var mergedCellScrollTop = mainHolder.scrollTop;
  235. expect(mergedCellScrollTop).toBeLessThan(130);
  236. expect(mergedCellScrollTop).toBeGreaterThan(0);
  237. mainHolder.scrollTop = 0;
  238. hot.render();
  239. mainHolder.scrollTop = 130;
  240. hot.render();
  241. TD = hot.getCell(5, 2);
  242. mouseDown(TD);
  243. mouseUp(TD);
  244. var regularCellScrollTop = mainHolder.scrollTop;
  245. expect(mergedCellScrollTop).toBe(regularCellScrollTop);
  246. });
  247. it('should render whole merged cell even when most rows are not in the viewport - scrolled to top', () => {
  248. var hot = handsontable({
  249. data: Handsontable.helper.createSpreadsheetObjectData(40, 5),
  250. mergeCells: [
  251. {row: 1, col: 0, rowspan: 21, colspan: 2},
  252. {row: 21, col: 2, rowspan: 18, colspan: 2}
  253. ],
  254. height: 100,
  255. width: 400
  256. });
  257. expect(hot.countRenderedRows()).toBe(39);
  258. });
  259. it('should render whole merged cell even when most rows are not in the viewport - scrolled to bottom', () => {
  260. var hot = handsontable({
  261. data: Handsontable.helper.createSpreadsheetObjectData(40, 5),
  262. mergeCells: [
  263. {row: 1, col: 0, rowspan: 21, colspan: 2},
  264. {row: 21, col: 2, rowspan: 18, colspan: 2}
  265. ],
  266. height: 100,
  267. width: 400
  268. });
  269. var mainHolder = hot.view.wt.wtTable.holder;
  270. $(mainHolder).scrollTop(99999);
  271. hot.render();
  272. expect(hot.countRenderedRows()).toBe(39);
  273. });
  274. it('should render whole merged cell even when most columns are not in the viewport - scrolled to the left', () => {
  275. var hot = handsontable({
  276. data: Handsontable.helper.createSpreadsheetObjectData(5, 40),
  277. mergeCells: [
  278. {row: 0, col: 1, rowspan: 2, colspan: 21},
  279. {row: 2, col: 21, rowspan: 2, colspan: 18}
  280. ],
  281. height: 100,
  282. width: 400
  283. });
  284. expect(hot.countRenderedCols()).toBe(39);
  285. });
  286. it('should render whole merged cell even when most columns are not in the viewport - scrolled to the right', function() {
  287. var hot = handsontable({
  288. data: Handsontable.helper.createSpreadsheetObjectData(5, 40),
  289. mergeCells: [
  290. {row: 0, col: 1, rowspan: 2, colspan: 21},
  291. {row: 2, col: 21, rowspan: 2, colspan: 18}
  292. ],
  293. height: 100,
  294. width: 400
  295. });
  296. this.$container.scrollLeft(99999);
  297. hot.render();
  298. expect(hot.countRenderedCols()).toBe(39);
  299. });
  300. });
  301. describe('merge cells shift', () => {
  302. it('should shift the merged cells right, when inserting a column on the left side of them', () => {
  303. var hot = handsontable({
  304. data: Handsontable.helper.createSpreadsheetData(20, 20),
  305. mergeCells: [
  306. {row: 1, col: 1, rowspan: 2, colspan: 2},
  307. {row: 2, col: 5, rowspan: 2, colspan: 2}
  308. ],
  309. height: 400,
  310. width: 400
  311. });
  312. hot.alter('insert_col', 3, 2);
  313. expect(hot.mergeCells.mergedCellInfoCollection[0].col).toEqual(1);
  314. expect(hot.mergeCells.mergedCellInfoCollection[1].col).toEqual(6);
  315. });
  316. it('should shift the merged cells left, when removing a column on the left side of them', () => {
  317. var hot = handsontable({
  318. data: Handsontable.helper.createSpreadsheetData(20, 20),
  319. mergeCells: [
  320. {row: 1, col: 1, rowspan: 2, colspan: 2},
  321. {row: 2, col: 5, rowspan: 2, colspan: 2}
  322. ],
  323. height: 400,
  324. width: 400
  325. });
  326. hot.alter('remove_col', 3, 2);
  327. expect(hot.mergeCells.mergedCellInfoCollection[0].col).toEqual(1);
  328. expect(hot.mergeCells.mergedCellInfoCollection[1].col).toEqual(4);
  329. });
  330. it('should shift the merged cells down, when inserting a row above them', () => {
  331. var hot = handsontable({
  332. data: Handsontable.helper.createSpreadsheetData(20, 20),
  333. mergeCells: [
  334. {row: 1, col: 1, rowspan: 2, colspan: 2},
  335. {row: 5, col: 5, rowspan: 2, colspan: 2}
  336. ],
  337. height: 400,
  338. width: 400
  339. });
  340. hot.alter('insert_row', 3, 2);
  341. expect(hot.mergeCells.mergedCellInfoCollection[0].row).toEqual(1);
  342. expect(hot.mergeCells.mergedCellInfoCollection[1].row).toEqual(6);
  343. });
  344. it('should shift the merged cells down, when inserting a row above them', () => {
  345. var hot = handsontable({
  346. data: Handsontable.helper.createSpreadsheetData(20, 20),
  347. mergeCells: [
  348. {row: 1, col: 1, rowspan: 2, colspan: 2},
  349. {row: 5, col: 5, rowspan: 2, colspan: 2}
  350. ],
  351. height: 400,
  352. width: 400
  353. });
  354. hot.alter('remove_row', 3, 2);
  355. expect(hot.mergeCells.mergedCellInfoCollection[0].row).toEqual(1);
  356. expect(hot.mergeCells.mergedCellInfoCollection[1].row).toEqual(4);
  357. });
  358. });
  359. xdescribe('canMergeRange', () => {
  360. it('should return false if start and end cell is the same', () => {
  361. var hot = handsontable({
  362. data: Handsontable.helper.createSpreadsheetObjectData(10, 5)
  363. });
  364. var mergeCells = new Handsontable.plugins.MergeCells(hot);
  365. var coordsFrom = new WalkontableCellCoords(0, 1);
  366. var cellRange = new WalkontableCellRange(coordsFrom, coordsFrom, new WalkontableCellCoords(0, 1));
  367. var result = mergeCells.canMergeRange(cellRange);
  368. expect(result).toBe(false);
  369. });
  370. it('should return true for 2 consecutive cells in the same column', () => {
  371. var hot = handsontable({
  372. data: Handsontable.helper.createSpreadsheetObjectData(10, 5)
  373. });
  374. var mergeCells = new Handsontable.plugins.MergeCells(hot);
  375. var coordsFrom = new WalkontableCellCoords(0, 1);
  376. var cellRange = new WalkontableCellRange(coordsFrom, coordsFrom, new WalkontableCellCoords(1, 1));
  377. var result = mergeCells.canMergeRange(cellRange);
  378. expect(result).toBe(true);
  379. });
  380. it('should return true for 2 consecutive cells in the same row', () => {
  381. var hot = handsontable({
  382. data: Handsontable.helper.createSpreadsheetObjectData(10, 5)
  383. });
  384. var mergeCells = new Handsontable.MergeCells(hot);
  385. var coordsFrom = new WalkontableCellCoords(0, 1);
  386. var cellRange = new WalkontableCellRange(coordsFrom, coordsFrom, new WalkontableCellCoords(0, 2));
  387. var result = mergeCells.canMergeRange(cellRange);
  388. expect(result).toBe(true);
  389. });
  390. it('should return true for 4 neighboring cells', () => {
  391. var hot = handsontable({
  392. data: Handsontable.helper.createSpreadsheetObjectData(10, 5)
  393. });
  394. var mergeCells = new Handsontable.MergeCells(hot);
  395. var coordsFrom = new WalkontableCellCoords(0, 1);
  396. var cellRange = new WalkontableCellRange(coordsFrom, coordsFrom, new WalkontableCellCoords(1, 2));
  397. var result = mergeCells.canMergeRange(cellRange);
  398. expect(result).toBe(true);
  399. });
  400. });
  401. xdescribe('modifyTransform', () => {
  402. it('should not transform arrow right when entering a merged cell', () => {
  403. var mergeCellsSettings = [
  404. {row: 1, col: 1, rowspan: 3, colspan: 3}
  405. ];
  406. var coords = new WalkontableCellCoords(1, 0);
  407. var currentSelection = new WalkontableCellRange(coords, coords, coords);
  408. var mergeCells = new Handsontable.MergeCells(mergeCellsSettings);
  409. var inDelta = new WalkontableCellCoords(0, 1);
  410. mergeCells.modifyTransform('modifyTransformStart', currentSelection, inDelta);
  411. expect(inDelta).toEqual(new WalkontableCellCoords(0, 1));
  412. });
  413. it('should transform arrow right when leaving a merged cell', () => {
  414. var mergeCellsSettings = [
  415. {row: 1, col: 1, rowspan: 3, colspan: 3}
  416. ];
  417. var coords = new WalkontableCellCoords(1, 1);
  418. var currentSelection = new WalkontableCellRange(coords, coords, coords);
  419. var mergeCells = new Handsontable.MergeCells(mergeCellsSettings);
  420. var inDelta = new WalkontableCellCoords(0, 1);
  421. mergeCells.modifyTransform('modifyTransformStart', currentSelection, inDelta);
  422. expect(inDelta).toEqual(new WalkontableCellCoords(0, 3));
  423. });
  424. it('should transform arrow right when leaving a merged cell (return to desired row)', () => {
  425. var mergeCellsSettings = [
  426. {row: 1, col: 1, rowspan: 3, colspan: 3}
  427. ];
  428. var mergeCells = new Handsontable.MergeCells(mergeCellsSettings);
  429. var coords = new WalkontableCellCoords(2, 0);
  430. var currentSelection = new WalkontableCellRange(coords, coords, coords);
  431. var inDelta = new WalkontableCellCoords(0, 1);
  432. mergeCells.modifyTransform('modifyTransformStart', currentSelection, inDelta);
  433. expect(inDelta).toEqual(new WalkontableCellCoords(-1, 1));
  434. coords = new WalkontableCellCoords(1, 1);
  435. currentSelection = new WalkontableCellRange(coords, coords, coords);
  436. inDelta = new WalkontableCellCoords(0, 1);
  437. mergeCells.modifyTransform('modifyTransformStart', currentSelection, inDelta);
  438. expect(inDelta).toEqual(new WalkontableCellCoords(1, 3));
  439. });
  440. it('should transform arrow left when entering a merged cell', () => {
  441. var mergeCellsSettings = [
  442. {row: 1, col: 1, rowspan: 3, colspan: 3}
  443. ];
  444. var coords = new WalkontableCellCoords(1, 4);
  445. var currentSelection = new WalkontableCellRange(coords, coords, coords);
  446. var mergeCells = new Handsontable.MergeCells(mergeCellsSettings);
  447. var inDelta = new WalkontableCellCoords(0, -1);
  448. mergeCells.modifyTransform('modifyTransformStart', currentSelection, inDelta);
  449. expect(inDelta).toEqual(new WalkontableCellCoords(0, -3));
  450. });
  451. it('should not transform arrow left when leaving a merged cell', () => {
  452. var mergeCellsSettings = [
  453. {row: 1, col: 1, rowspan: 3, colspan: 3}
  454. ];
  455. var coords = new WalkontableCellCoords(1, 1);
  456. var currentSelection = new WalkontableCellRange(coords, coords, coords);
  457. var mergeCells = new Handsontable.MergeCells(mergeCellsSettings);
  458. var inDelta = new WalkontableCellCoords(0, -1);
  459. mergeCells.modifyTransform('modifyTransformStart', currentSelection, inDelta);
  460. expect(inDelta).toEqual(new WalkontableCellCoords(0, -1));
  461. });
  462. it('should transform arrow left when leaving a merged cell (return to desired row)', () => {
  463. var mergeCellsSettings = [
  464. {row: 1, col: 1, rowspan: 3, colspan: 3}
  465. ];
  466. var mergeCells = new Handsontable.MergeCells(mergeCellsSettings);
  467. var coords = new WalkontableCellCoords(2, 4);
  468. var currentSelection = new WalkontableCellRange(coords, coords, coords);
  469. var inDelta = new WalkontableCellCoords(0, -1);
  470. mergeCells.modifyTransform('modifyTransformStart', currentSelection, inDelta);
  471. expect(inDelta).toEqual(new WalkontableCellCoords(-1, -3));
  472. coords = new WalkontableCellCoords(1, 1);
  473. currentSelection = new WalkontableCellRange(coords, coords, coords);
  474. inDelta = new WalkontableCellCoords(0, -1);
  475. mergeCells.modifyTransform('modifyTransformStart', currentSelection, inDelta);
  476. expect(inDelta).toEqual(new WalkontableCellCoords(1, -1));
  477. });
  478. it('should not transform arrow down when entering a merged cell', () => {
  479. var mergeCellsSettings = [
  480. {row: 1, col: 1, rowspan: 3, colspan: 3}
  481. ];
  482. var coords = new WalkontableCellCoords(0, 1);
  483. var currentSelection = new WalkontableCellRange(coords, coords, coords);
  484. var mergeCells = new Handsontable.MergeCells(mergeCellsSettings);
  485. var inDelta = new WalkontableCellCoords(0, -1);
  486. mergeCells.modifyTransform('modifyTransformStart', currentSelection, inDelta);
  487. expect(inDelta).toEqual(new WalkontableCellCoords(0, -1));
  488. });
  489. it('should transform arrow down when leaving a merged cell', () => {
  490. var mergeCellsSettings = [
  491. {row: 1, col: 1, rowspan: 3, colspan: 3}
  492. ];
  493. var coords = new WalkontableCellCoords(1, 1);
  494. var currentSelection = new WalkontableCellRange(coords, coords, coords);
  495. var mergeCells = new Handsontable.MergeCells(mergeCellsSettings);
  496. var inDelta = new WalkontableCellCoords(1, 0);
  497. mergeCells.modifyTransform('modifyTransformStart', currentSelection, inDelta);
  498. expect(inDelta).toEqual(new WalkontableCellCoords(3, 0));
  499. });
  500. it('should transform arrow up when entering a merged cell', () => {
  501. var mergeCellsSettings = [
  502. {row: 1, col: 1, rowspan: 3, colspan: 3}
  503. ];
  504. var coords = new WalkontableCellCoords(4, 1);
  505. var currentSelection = new WalkontableCellRange(coords, coords, coords);
  506. var mergeCells = new Handsontable.MergeCells(mergeCellsSettings);
  507. var inDelta = new WalkontableCellCoords(-1, 0);
  508. mergeCells.modifyTransform('modifyTransformStart', currentSelection, inDelta);
  509. expect(inDelta).toEqual(new WalkontableCellCoords(-3, 0));
  510. });
  511. it('should not transform arrow up when leaving a merged cell', () => {
  512. var mergeCellsSettings = [
  513. {row: 1, col: 1, rowspan: 3, colspan: 3}
  514. ];
  515. var coords = new WalkontableCellCoords(1, 1);
  516. var currentSelection = new WalkontableCellRange(coords, coords, coords);
  517. var mergeCells = new Handsontable.MergeCells(mergeCellsSettings);
  518. var inDelta = new WalkontableCellCoords(-1, 0);
  519. mergeCells.modifyTransform('modifyTransformStart', currentSelection, inDelta);
  520. expect(inDelta).toEqual(new WalkontableCellCoords(-1, 0));
  521. });
  522. });
  523. describe('ContextMenu', () => {
  524. it('should disable `Merge cells` context menu item when context menu was triggered from corner header', () => {
  525. var hot = handsontable({
  526. data: Handsontable.helper.createSpreadsheetObjectData(10, 5),
  527. rowHeaders: true,
  528. colHeaders: true,
  529. contextMenu: true,
  530. mergeCells: true,
  531. });
  532. $('.ht_clone_top_left_corner .htCore').find('thead').find('th').eq(0).simulate('mousedown', {which: 3});
  533. contextMenu();
  534. expect($('.htContextMenu tbody td.htDisabled').text()).toBe([
  535. 'Insert column on the left',
  536. 'Insert column on the right',
  537. 'Remove row',
  538. 'Remove column',
  539. 'Undo',
  540. 'Redo',
  541. 'Read only',
  542. 'Alignment',
  543. 'Merge cells',
  544. ].join(''));
  545. });
  546. });
  547. });