selectCell.spec.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. describe('Core.selectCell', () => {
  2. beforeEach(function() {
  3. this.$container = $('<div id="testContainer"></div>').appendTo('body');
  4. });
  5. afterEach(function() {
  6. if (this.$container) {
  7. destroy();
  8. this.$container.remove();
  9. }
  10. });
  11. it('should mark single cell visually (default selectionMode, without headers)', () => {
  12. handsontable({
  13. data: Handsontable.helper.createSpreadsheetObjectData(6, 4),
  14. colHeaders: false,
  15. rowHeaders: false,
  16. });
  17. selectCell(2, 2);
  18. expect(`
  19. | : : : |
  20. | : : : |
  21. | : : # : |
  22. | : : : |
  23. | : : : |
  24. | : : : |
  25. `).toBeMatchToSelectionPattern();
  26. });
  27. it('should mark single cell visually (default selectionMode)', () => {
  28. handsontable({
  29. data: Handsontable.helper.createSpreadsheetObjectData(6, 4),
  30. colHeaders: true,
  31. rowHeaders: true,
  32. });
  33. selectCell(2, 2);
  34. expect(`
  35. | ║ : : - : |
  36. |===:===:===:===:===|
  37. | ║ : : : |
  38. | ║ : : : |
  39. | - ║ : : # : |
  40. | ║ : : : |
  41. | ║ : : : |
  42. | ║ : : : |
  43. `).toBeMatchToSelectionPattern();
  44. });
  45. it('should mark range of the cells visually (default selectionMode)', () => {
  46. handsontable({
  47. data: Handsontable.helper.createSpreadsheetObjectData(6, 4),
  48. colHeaders: true,
  49. rowHeaders: true,
  50. });
  51. selectCell(1, 2, 2, 3);
  52. expect(`
  53. | ║ : : - : - |
  54. |===:===:===:===:===|
  55. | ║ : : : |
  56. | - ║ : : A : 0 |
  57. | - ║ : : 0 : 0 |
  58. | ║ : : : |
  59. | ║ : : : |
  60. | ║ : : : |
  61. `).toBeMatchToSelectionPattern();
  62. });
  63. it('should mark single cell visually when selectionMode is set as `single', () => {
  64. handsontable({
  65. data: Handsontable.helper.createSpreadsheetObjectData(6, 4),
  66. selectionMode: 'single',
  67. colHeaders: true,
  68. rowHeaders: true,
  69. });
  70. selectCell(2, 2);
  71. expect(`
  72. | ║ : : - : |
  73. |===:===:===:===:===|
  74. | ║ : : : |
  75. | ║ : : : |
  76. | - ║ : : # : |
  77. | ║ : : : |
  78. | ║ : : : |
  79. | ║ : : : |
  80. `).toBeMatchToSelectionPattern();
  81. });
  82. it('should not mark the range of the cells visually when selectionMode is set as `single`', () => {
  83. handsontable({
  84. data: Handsontable.helper.createSpreadsheetObjectData(6, 4),
  85. selectionMode: 'single',
  86. colHeaders: true,
  87. rowHeaders: true,
  88. });
  89. selectCell(1, 2, 2, 3);
  90. expect(`
  91. | ║ : : - : |
  92. |===:===:===:===:===|
  93. | ║ : : : |
  94. | - ║ : : # : |
  95. | ║ : : : |
  96. | ║ : : : |
  97. | ║ : : : |
  98. | ║ : : : |
  99. `).toBeMatchToSelectionPattern();
  100. });
  101. it('should mark single cell visually when selectionMode is set as `range', () => {
  102. handsontable({
  103. data: Handsontable.helper.createSpreadsheetObjectData(6, 4),
  104. selectionMode: 'range',
  105. colHeaders: true,
  106. rowHeaders: true,
  107. });
  108. selectCell(2, 2);
  109. expect(`
  110. | ║ : : - : |
  111. |===:===:===:===:===|
  112. | ║ : : : |
  113. | ║ : : : |
  114. | - ║ : : # : |
  115. | ║ : : : |
  116. | ║ : : : |
  117. | ║ : : : |
  118. `).toBeMatchToSelectionPattern();
  119. });
  120. it('should mark the range of the cells visually when selectionMode is set as `range`', () => {
  121. handsontable({
  122. data: Handsontable.helper.createSpreadsheetObjectData(6, 4),
  123. selectionMode: 'range',
  124. colHeaders: true,
  125. rowHeaders: true,
  126. });
  127. selectCell(1, 2, 2, 3);
  128. expect(`
  129. | ║ : : - : - |
  130. |===:===:===:===:===|
  131. | ║ : : : |
  132. | - ║ : : A : 0 |
  133. | - ║ : : 0 : 0 |
  134. | ║ : : : |
  135. | ║ : : : |
  136. | ║ : : : |
  137. `).toBeMatchToSelectionPattern();
  138. });
  139. it('should mark the headers when whole column and row is selected', () => {
  140. handsontable({
  141. data: Handsontable.helper.createSpreadsheetObjectData(6, 4),
  142. colHeaders: true,
  143. rowHeaders: true,
  144. });
  145. selectCell(0, 2, 5, 3);
  146. expect(`
  147. | ║ : : - : - |
  148. |===:===:===:===:===|
  149. | - ║ : : A : 0 |
  150. | - ║ : : 0 : 0 |
  151. | - ║ : : 0 : 0 |
  152. | - ║ : : 0 : 0 |
  153. | - ║ : : 0 : 0 |
  154. | - ║ : : 0 : 0 |
  155. `).toBeMatchToSelectionPattern();
  156. selectCell(1, 0, 2, 3);
  157. expect(`
  158. | ║ - : - : - : - |
  159. |===:===:===:===:===|
  160. | ║ : : : |
  161. | - ║ A : 0 : 0 : 0 |
  162. | - ║ 0 : 0 : 0 : 0 |
  163. | ║ : : : |
  164. | ║ : : : |
  165. | ║ : : : |
  166. `).toBeMatchToSelectionPattern();
  167. });
  168. it('should not deselect current selection when sellectCell is called without arguments', () => {
  169. handsontable({
  170. data: Handsontable.helper.createSpreadsheetObjectData(6, 4),
  171. });
  172. selectCell(0, 0, 2, 2);
  173. expect(getSelected()).toEqual([[0, 0, 2, 2]]);
  174. selectCell();
  175. expect(getSelected()).toEqual([[0, 0, 2, 2]]);
  176. selectCell(1);
  177. expect(getSelected()).toEqual([[0, 0, 2, 2]]);
  178. });
  179. it('should not deselect current selection when sellectCell is called with one argument', () => {
  180. handsontable({
  181. data: Handsontable.helper.createSpreadsheetObjectData(6, 4),
  182. });
  183. let wasSelected = selectCell(0, 0, 2, 2);
  184. expect(getSelected()).toEqual([[0, 0, 2, 2]]);
  185. expect(wasSelected).toBe(true);
  186. wasSelected = selectCell(1);
  187. expect(getSelected()).toEqual([[0, 0, 2, 2]]);
  188. expect(wasSelected).toBe(false);
  189. });
  190. it('should not deselect current selection when sellectCell is called with negative values', () => {
  191. handsontable({
  192. data: Handsontable.helper.createSpreadsheetObjectData(6, 4),
  193. });
  194. let wasSelected = selectCell(0, 0, 2, 2);
  195. expect(getSelected()).toEqual([[0, 0, 2, 2]]);
  196. expect(wasSelected).toBe(true);
  197. wasSelected = selectCell(0, -1, 0, 0);
  198. expect(getSelected()).toEqual([[0, 0, 2, 2]]);
  199. expect(wasSelected).toBe(false);
  200. wasSelected = selectCell(-1, 0, 0, 0);
  201. expect(getSelected()).toEqual([[0, 0, 2, 2]]);
  202. expect(wasSelected).toBe(false);
  203. wasSelected = selectCell(0, 0, -1, 0);
  204. expect(getSelected()).toEqual([[0, 0, 2, 2]]);
  205. expect(wasSelected).toBe(false);
  206. wasSelected = selectCell(0, 0, 0, -1);
  207. expect(getSelected()).toEqual([[0, 0, 2, 2]]);
  208. expect(wasSelected).toBe(false);
  209. });
  210. it('should not deselect current selection when sellectCell is called with coordinates beyond the table data range', () => {
  211. handsontable({
  212. data: Handsontable.helper.createSpreadsheetObjectData(3, 4),
  213. });
  214. let wasSelected = selectCell(0, 0, 2, 2);
  215. expect(getSelected()).toEqual([[0, 0, 2, 2]]);
  216. expect(wasSelected).toBe(true);
  217. wasSelected = selectCell(3, 0);
  218. expect(getSelected()).toEqual([[0, 0, 2, 2]]);
  219. expect(wasSelected).toBe(false);
  220. wasSelected = selectCell(0, 4);
  221. expect(getSelected()).toEqual([[0, 0, 2, 2]]);
  222. expect(wasSelected).toBe(false);
  223. wasSelected = selectCell(0, 0, 3, 0);
  224. expect(getSelected()).toEqual([[0, 0, 2, 2]]);
  225. expect(wasSelected).toBe(false);
  226. wasSelected = selectCell(0, 0, 0, 4);
  227. expect(getSelected()).toEqual([[0, 0, 2, 2]]);
  228. expect(wasSelected).toBe(false);
  229. });
  230. it('should not deselect current selection when sellectCell is called with undefined column property', () => {
  231. handsontable({
  232. data: Handsontable.helper.createSpreadsheetObjectData(6, 4),
  233. });
  234. let wasSelected = selectCell(0, 0, 2, 2);
  235. expect(getSelected()).toEqual([[0, 0, 2, 2]]);
  236. expect(wasSelected).toBe(true);
  237. wasSelected = selectCell(0, 'notExistProp');
  238. expect(getSelected()).toEqual([[0, 0, 2, 2]]);
  239. expect(wasSelected).toBe(false);
  240. wasSelected = selectCell(0, 0, 0, 'notExistProp');
  241. expect(getSelected()).toEqual([[0, 0, 2, 2]]);
  242. expect(wasSelected).toBe(false);
  243. });
  244. it('should select only one cell when two arguments are passed', () => {
  245. handsontable({
  246. data: Handsontable.helper.createSpreadsheetObjectData(6, 4),
  247. });
  248. const wasSelected = selectCell(1, 1);
  249. expect(getSelected()).toEqual([[1, 1, 1, 1]]);
  250. expect(wasSelected).toBe(true);
  251. });
  252. it('should select only one cell when two arguments are passed (column property)', () => {
  253. handsontable({
  254. data: Handsontable.helper.createSpreadsheetObjectData(6, 4),
  255. });
  256. const wasSelected = selectCell(1, 'prop1');
  257. expect(getSelected()).toEqual([[1, 1, 1, 1]]);
  258. expect(wasSelected).toBe(true);
  259. });
  260. it('should select range of cells when at least the three arguments are passed', () => {
  261. handsontable({
  262. data: Handsontable.helper.createSpreadsheetObjectData(6, 4),
  263. });
  264. const wasSelected = selectCell(0, 0, 1);
  265. expect(getSelected()).toEqual([[0, 0, 1, 0]]);
  266. expect(wasSelected).toBe(true);
  267. });
  268. it('should select range of cells when at least the three arguments are passed (column property)', () => {
  269. handsontable({
  270. data: Handsontable.helper.createSpreadsheetObjectData(6, 4),
  271. });
  272. const wasSelected = selectCell(0, 'prop0', 1);
  273. expect(getSelected()).toEqual([[0, 0, 1, 0]]);
  274. expect(wasSelected).toBe(true);
  275. });
  276. it('should select range of cells when the four arguments are passed', () => {
  277. handsontable({
  278. data: Handsontable.helper.createSpreadsheetObjectData(6, 4),
  279. });
  280. const wasSelected = selectCell(1, 1, 2, 3);
  281. expect(getSelected()).toEqual([[1, 1, 2, 3]]);
  282. expect(wasSelected).toBe(true);
  283. });
  284. it('should select range of cells when the four arguments are passed (column property)', () => {
  285. handsontable({
  286. data: Handsontable.helper.createSpreadsheetObjectData(6, 4),
  287. });
  288. const wasSelected = selectCell(1, 'prop1', 2, 'prop3');
  289. expect(getSelected()).toEqual([[1, 1, 2, 3]]);
  290. expect(wasSelected).toBe(true);
  291. });
  292. it('should select range of cells when the coordinates are passed in reversed order (from right-bottom to left-top)', () => {
  293. handsontable({
  294. data: Handsontable.helper.createSpreadsheetObjectData(6, 4),
  295. });
  296. const wasSelected = selectCell(2, 3, 1, 1);
  297. expect(getSelected()).toEqual([[2, 3, 1, 1]]);
  298. expect(wasSelected).toBe(true);
  299. });
  300. it('should select range of cells when the coordinates are passed in reversed order (from right-bottom to left-top using column property)', () => {
  301. handsontable({
  302. data: Handsontable.helper.createSpreadsheetObjectData(6, 4),
  303. });
  304. const wasSelected = selectCell(2, 'prop3', 1, 'prop1');
  305. expect(getSelected()).toEqual([[2, 3, 1, 1]]);
  306. expect(wasSelected).toBe(true);
  307. });
  308. it('should select range of cells when the coordinates are passed in reversed order (from left-bottom to right-top)', () => {
  309. handsontable({
  310. data: Handsontable.helper.createSpreadsheetObjectData(6, 4),
  311. });
  312. const wasSelected = selectCell(2, 1, 1, 3);
  313. expect(getSelected()).toEqual([[2, 1, 1, 3]]);
  314. expect(wasSelected).toBe(true);
  315. });
  316. it('should select range of cells when the coordinates are passed in reversed order (from left-bottom to right-top using column property)', () => {
  317. handsontable({
  318. data: Handsontable.helper.createSpreadsheetObjectData(6, 4),
  319. });
  320. const wasSelected = selectCell(2, 'prop1', 1, 'prop3');
  321. expect(getSelected()).toEqual([[2, 1, 1, 3]]);
  322. expect(wasSelected).toBe(true);
  323. });
  324. it('should select range of cells when the coordinates are passed in reversed order (from right-top to left-bottom)', () => {
  325. handsontable({
  326. data: Handsontable.helper.createSpreadsheetObjectData(6, 4),
  327. });
  328. const wasSelected = selectCell(1, 3, 2, 1);
  329. expect(getSelected()).toEqual([[1, 3, 2, 1]]);
  330. expect(wasSelected).toBe(true);
  331. });
  332. it('should select range of cells when the coordinates are passed in reversed order (from right-top to left-bottom using column property)', () => {
  333. handsontable({
  334. data: Handsontable.helper.createSpreadsheetObjectData(6, 4),
  335. });
  336. const wasSelected = selectCell(1, 'prop3', 2, 'prop1');
  337. expect(getSelected()).toEqual([[1, 3, 2, 1]]);
  338. expect(wasSelected).toBe(true);
  339. });
  340. it('should by default scroll the viewport to the selected cell (bottom of the viewport)', () => {
  341. handsontable({
  342. data: Handsontable.helper.createSpreadsheetObjectData(20, 20),
  343. height: 300,
  344. width: 300,
  345. });
  346. selectCell(15, 0);
  347. expect(getCell(15, 0)).toBeVisibleAtBottomOfViewport();
  348. });
  349. it('should by default scroll the viewport to the selected cell using column props (bottom of the viewport)', () => {
  350. handsontable({
  351. data: Handsontable.helper.createSpreadsheetObjectData(20, 20),
  352. height: 300,
  353. width: 300,
  354. });
  355. selectCell(15, 'prop0');
  356. expect(getCell(15, 0)).toBeVisibleAtBottomOfViewport();
  357. });
  358. it('should by default scroll the viewport to the selected cell (right of the viewport)', () => {
  359. handsontable({
  360. data: Handsontable.helper.createSpreadsheetObjectData(20, 20),
  361. height: 300,
  362. width: 300,
  363. });
  364. selectCell(5, 15);
  365. expect(getCell(5, 15)).toBeVisibleAtRightOfViewport();
  366. });
  367. it('should by default scroll the viewport to the selected cell using column props (right of the viewport)', () => {
  368. handsontable({
  369. data: Handsontable.helper.createSpreadsheetObjectData(20, 20),
  370. height: 300,
  371. width: 300,
  372. });
  373. selectCell(5, 'prop15');
  374. expect(getCell(5, 15)).toBeVisibleAtRightOfViewport();
  375. });
  376. it('should by default scroll the viewport to the selected cell (left of the viewport)', () => {
  377. handsontable({
  378. data: Handsontable.helper.createSpreadsheetObjectData(20, 20),
  379. height: 300,
  380. width: 300,
  381. });
  382. selectCell(5, 15); // Scroll to the right of the table.
  383. selectCell(5, 0);
  384. expect(getCell(5, 0)).toBeVisibleAtLeftOfViewport();
  385. });
  386. it('should by default scroll the viewport to the selected cell using column props (left of the viewport)', () => {
  387. handsontable({
  388. data: Handsontable.helper.createSpreadsheetObjectData(20, 20),
  389. height: 300,
  390. width: 300,
  391. });
  392. selectCell(5, 15); // Scroll to the right of the table.
  393. selectCell(5, 'prop0');
  394. expect(getCell(5, 0)).toBeVisibleAtLeftOfViewport();
  395. });
  396. it('should by default scroll the viewport to the selected cell (top of the viewport)', () => {
  397. handsontable({
  398. data: Handsontable.helper.createSpreadsheetObjectData(20, 20),
  399. height: 300,
  400. width: 300,
  401. });
  402. selectCell(19, 0); // Scroll to the bottom of the table.
  403. selectCell(1, 0);
  404. expect(getCell(1, 0)).toBeVisibleAtTopOfViewport();
  405. });
  406. it('should by default scroll the viewport to the selected cell using column props (top of the viewport)', () => {
  407. handsontable({
  408. data: Handsontable.helper.createSpreadsheetObjectData(20, 20),
  409. height: 300,
  410. width: 300,
  411. });
  412. selectCell(19, 0); // Scroll to the bottom of the table.
  413. selectCell(1, 'prop0');
  414. expect(getCell(1, 0)).toBeVisibleAtTopOfViewport();
  415. });
  416. it('should not the scroll the viewport when `false` argument is passed', () => {
  417. handsontable({
  418. data: Handsontable.helper.createSpreadsheetObjectData(20, 20),
  419. height: 300,
  420. width: 300,
  421. });
  422. selectCell(15, 0, 15, 0, false);
  423. expect(getCell(15, 0)).not.toBeVisibleInViewport();
  424. });
  425. it('should by default change the listener to handsontable instance from the action was triggered', () => {
  426. const afterListen = jasmine.createSpy();
  427. handsontable({
  428. data: Handsontable.helper.createSpreadsheetObjectData(20, 20),
  429. height: 300,
  430. width: 300,
  431. afterListen,
  432. });
  433. selectCell(15, 0);
  434. expect(afterListen).toHaveBeenCalled();
  435. });
  436. it('should not change the listening state when `false` argument is passed', () => {
  437. const afterListen = jasmine.createSpy();
  438. handsontable({
  439. data: Handsontable.helper.createSpreadsheetObjectData(20, 20),
  440. height: 300,
  441. width: 300,
  442. afterListen,
  443. });
  444. selectCell(15, 0, 15, 0, true, false);
  445. expect(afterListen).not.toHaveBeenCalled();
  446. });
  447. it('should fire hooks with proper context', () => {
  448. const {
  449. afterSelection,
  450. afterSelectionByProp,
  451. afterSelectionEnd,
  452. afterSelectionEndByProp,
  453. beforeSetRangeStart,
  454. beforeSetRangeStartOnly,
  455. beforeSetRangeEnd,
  456. } = jasmine.createSpyObj('hooks', [
  457. 'afterSelection',
  458. 'afterSelectionByProp',
  459. 'afterSelectionEnd',
  460. 'afterSelectionEndByProp',
  461. 'beforeSetRangeStart',
  462. 'beforeSetRangeStartOnly',
  463. 'beforeSetRangeEnd',
  464. ]);
  465. const hot = handsontable({
  466. data: Handsontable.helper.createSpreadsheetObjectData(20, 20),
  467. height: 300,
  468. width: 300,
  469. afterSelection,
  470. afterSelectionByProp,
  471. afterSelectionEnd,
  472. afterSelectionEndByProp,
  473. beforeSetRangeStart,
  474. beforeSetRangeStartOnly,
  475. beforeSetRangeEnd,
  476. });
  477. selectCell(1, 2);
  478. expect(afterSelection.calls.first().object).toBe(hot);
  479. expect(afterSelectionByProp.calls.first().object).toBe(hot);
  480. expect(afterSelectionEnd.calls.first().object).toBe(hot);
  481. expect(afterSelectionEndByProp.calls.first().object).toBe(hot);
  482. expect(beforeSetRangeStartOnly.calls.first().object).toBe(hot);
  483. });
  484. it('should fire hooks with proper arguments when a single cell is selected', () => {
  485. const {
  486. afterSelection,
  487. afterSelectionByProp,
  488. afterSelectionEnd,
  489. afterSelectionEndByProp,
  490. beforeSetRangeStart,
  491. beforeSetRangeStartOnly,
  492. beforeSetRangeEnd,
  493. } = jasmine.createSpyObj('hooks', [
  494. 'afterSelection',
  495. 'afterSelectionByProp',
  496. 'afterSelectionEnd',
  497. 'afterSelectionEndByProp',
  498. 'beforeSetRangeStart',
  499. 'beforeSetRangeStartOnly',
  500. 'beforeSetRangeEnd',
  501. ]);
  502. handsontable({
  503. data: Handsontable.helper.createSpreadsheetObjectData(20, 20),
  504. height: 300,
  505. width: 300,
  506. afterSelection,
  507. afterSelectionByProp,
  508. afterSelectionEnd,
  509. afterSelectionEndByProp,
  510. beforeSetRangeStart,
  511. beforeSetRangeStartOnly,
  512. beforeSetRangeEnd,
  513. });
  514. selectCell(1, 2);
  515. expect(afterSelection.calls.count()).toBe(1);
  516. expect(afterSelection.calls.argsFor(0)).toEqual([1, 2, 1, 2, jasmine.any(Object), 0]);
  517. expect(afterSelectionByProp.calls.count()).toBe(1);
  518. expect(afterSelectionByProp.calls.argsFor(0)).toEqual([1, 'prop2', 1, 'prop2', jasmine.any(Object), 0]);
  519. expect(afterSelectionEnd.calls.count()).toBe(1);
  520. expect(afterSelectionEnd.calls.argsFor(0)).toEqual([1, 2, 1, 2, 0, void 0]);
  521. expect(afterSelectionEndByProp.calls.count()).toBe(1);
  522. expect(afterSelectionEndByProp.calls.argsFor(0)).toEqual([1, 'prop2', 1, 'prop2', 0, void 0]);
  523. expect(beforeSetRangeStart.calls.count()).toBe(0);
  524. expect(beforeSetRangeStartOnly.calls.count()).toBe(1);
  525. expect(beforeSetRangeStartOnly.calls.argsFor(0)[0].row).toBe(1);
  526. expect(beforeSetRangeStartOnly.calls.argsFor(0)[0].col).toBe(2);
  527. });
  528. it('should fire hooks with proper arguments when range of the cells are selected', () => {
  529. const {
  530. afterSelection,
  531. afterSelectionByProp,
  532. afterSelectionEnd,
  533. afterSelectionEndByProp,
  534. beforeSetRangeStart,
  535. beforeSetRangeStartOnly,
  536. beforeSetRangeEnd,
  537. } = jasmine.createSpyObj('hooks', [
  538. 'afterSelection',
  539. 'afterSelectionByProp',
  540. 'afterSelectionEnd',
  541. 'afterSelectionEndByProp',
  542. 'beforeSetRangeStart',
  543. 'beforeSetRangeStartOnly',
  544. 'beforeSetRangeEnd',
  545. ]);
  546. handsontable({
  547. data: Handsontable.helper.createSpreadsheetObjectData(20, 20),
  548. height: 300,
  549. width: 300,
  550. afterSelection,
  551. afterSelectionByProp,
  552. afterSelectionEnd,
  553. afterSelectionEndByProp,
  554. beforeSetRangeStart,
  555. beforeSetRangeStartOnly,
  556. beforeSetRangeEnd,
  557. });
  558. selectCell(1, 2, 2, 4);
  559. expect(afterSelection.calls.count()).toBe(1);
  560. expect(afterSelection.calls.argsFor(0)).toEqual([1, 2, 2, 4, jasmine.any(Object), 0]);
  561. expect(afterSelectionByProp.calls.count()).toBe(1);
  562. expect(afterSelectionByProp.calls.argsFor(0)).toEqual([1, 'prop2', 2, 'prop4', jasmine.any(Object), 0]);
  563. expect(afterSelectionEnd.calls.count()).toBe(1);
  564. expect(afterSelectionEnd.calls.argsFor(0)).toEqual([1, 2, 2, 4, 0, void 0]);
  565. expect(afterSelectionEndByProp.calls.count()).toBe(1);
  566. expect(afterSelectionEndByProp.calls.argsFor(0)).toEqual([1, 'prop2', 2, 'prop4', 0, void 0]);
  567. expect(beforeSetRangeStart.calls.count()).toBe(0);
  568. expect(beforeSetRangeStartOnly.calls.count()).toBe(1);
  569. expect(beforeSetRangeStartOnly.calls.argsFor(0)[0].row).toBe(1);
  570. expect(beforeSetRangeStartOnly.calls.argsFor(0)[0].col).toBe(2);
  571. });
  572. });