FillHandle.spec.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814
  1. describe('FillHandle', () => {
  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 appear when fillHandle equals true', () => {
  13. handsontable({
  14. fillHandle: true
  15. });
  16. selectCell(2, 2);
  17. expect(isFillHandleVisible()).toBe(true);
  18. });
  19. it('should appear when fillHandle is enabled as `string` value', () => {
  20. handsontable({
  21. fillHandle: 'horizontal'
  22. });
  23. selectCell(2, 2);
  24. expect(isFillHandleVisible()).toBe(true);
  25. });
  26. it('should not change cell value (drag vertically when fillHandle option is set to `horizontal`)', function() {
  27. handsontable({
  28. data: [
  29. [1, 2, 3, 4, 5, 6],
  30. [7, 8, 9, 1, 2, 3],
  31. [4, 5, 6, 7, 8, 9],
  32. [1, 2, 3, 4, 5, 6]
  33. ],
  34. fillHandle: 'horizontal'
  35. });
  36. selectCell(0, 0);
  37. this.$container.find('.wtBorder.current.corner').simulate('mousedown');
  38. this.$container.find('tbody tr:eq(1) td:eq(0)').simulate('mouseover').simulate('mouseup');
  39. expect(getDataAtCell(1, 0)).toEqual(7);
  40. });
  41. it('should not change cell value (drag horizontally when fillHandle option is set to `vertical`)', function() {
  42. handsontable({
  43. data: [
  44. [1, 2, 3, 4, 5, 6],
  45. [7, 8, 9, 1, 2, 3],
  46. [4, 5, 6, 7, 8, 9],
  47. [1, 2, 3, 4, 5, 6]
  48. ],
  49. fillHandle: 'vertical'
  50. });
  51. selectCell(0, 0);
  52. this.$container.find('.wtBorder.current.corner').simulate('mousedown');
  53. this.$container.find('tbody tr:eq(0) td:eq(1)').simulate('mouseover').simulate('mouseup');
  54. expect(getDataAtCell(0, 1)).toEqual(2);
  55. });
  56. it('should work properly when fillHandle option is set to object with property `direction` set to `vertical`)', function() {
  57. handsontable({
  58. data: [
  59. [1, 2, 3, 4, 5, 6],
  60. [7, 8, 9, 1, 2, 3],
  61. [4, 5, 6, 7, 8, 9],
  62. [1, 2, 3, 4, 5, 6]
  63. ],
  64. fillHandle: {
  65. direction: 'vertical'
  66. }
  67. });
  68. selectCell(0, 0);
  69. this.$container.find('.wtBorder.current.corner').simulate('mousedown');
  70. this.$container.find('tbody tr:eq(0) td:eq(1)').simulate('mouseover').simulate('mouseup');
  71. expect(getDataAtCell(0, 1)).toEqual(2);
  72. selectCell(0, 0);
  73. this.$container.find('.wtBorder.current.corner').simulate('mousedown');
  74. this.$container.find('tbody tr:eq(1) td:eq(0)').simulate('mouseover').simulate('mouseup');
  75. expect(getDataAtCell(1, 0)).toEqual(1);
  76. });
  77. it('should work properly when fillHandle option is set to object with property `direction` set to `horizontal`)', function() {
  78. handsontable({
  79. data: [
  80. [1, 2, 3, 4, 5, 6],
  81. [7, 8, 9, 1, 2, 3],
  82. [4, 5, 6, 7, 8, 9],
  83. [1, 2, 3, 4, 5, 6]
  84. ],
  85. fillHandle: {
  86. direction: 'horizontal'
  87. }
  88. });
  89. selectCell(0, 0);
  90. this.$container.find('.wtBorder.current.corner').simulate('mousedown');
  91. this.$container.find('tbody tr:eq(0) td:eq(1)').simulate('mouseover').simulate('mouseup');
  92. expect(getDataAtCell(0, 1)).toEqual(1);
  93. selectCell(0, 0);
  94. this.$container.find('.wtBorder.current.corner').simulate('mousedown');
  95. this.$container.find('tbody tr:eq(1) td:eq(0)').simulate('mouseover').simulate('mouseup');
  96. expect(getDataAtCell(1, 0)).toEqual(7);
  97. });
  98. it('should not change cell value (drag when fillHandle is set to `false`)', function() {
  99. handsontable({
  100. data: [
  101. [1, 2, 3, 4, 5, 6],
  102. [7, 8, 9, 1, 2, 3],
  103. [4, 5, 6, 7, 8, 9],
  104. [1, 2, 3, 4, 5, 6]
  105. ],
  106. fillHandle: false
  107. });
  108. // checking drag vertically - should not change cell value
  109. selectCell(0, 0);
  110. this.$container.find('.wtBorder.current.corner').simulate('mousedown');
  111. this.$container.find('tbody tr:eq(0) td:eq(1)').simulate('mouseover').simulate('mouseup');
  112. expect(getDataAtCell(0, 1)).toEqual(2);
  113. // checking drag horizontally - should not change cell value
  114. selectCell(0, 0);
  115. this.$container.find('.wtBorder.current.corner').simulate('mousedown');
  116. this.$container.find('tbody tr:eq(0) td:eq(1)').simulate('mouseover').simulate('mouseup');
  117. expect(getDataAtCell(0, 1)).toEqual(2);
  118. });
  119. it('should work properly when using updateSettings', function() {
  120. var hot = handsontable({
  121. data: [
  122. [1, 2, 3, 4, 5, 6],
  123. [7, 8, 9, 1, 2, 3],
  124. [4, 5, 6, 7, 8, 9],
  125. [1, 2, 3, 4, 5, 6]
  126. ],
  127. fillHandle: 'horizontal'
  128. });
  129. updateSettings({ fillHandle: 'vertical' });
  130. // checking drag vertically - should change cell value
  131. selectCell(0, 0);
  132. this.$container.find('.wtBorder.current.corner').simulate('mousedown');
  133. this.$container.find('tbody tr:eq(0) td:eq(1)').simulate('mouseover').simulate('mouseup');
  134. expect(getDataAtCell(0, 1)).toEqual(2);
  135. updateSettings({ fillHandle: false });
  136. // checking drag vertically - should not change cell value
  137. selectCell(0, 1);
  138. this.$container.find('.wtBorder.current.corner').simulate('mousedown');
  139. this.$container.find('tbody tr:eq(1) td:eq(1)').simulate('mouseover').simulate('mouseup');
  140. expect(getDataAtCell(1, 1)).toEqual(8);
  141. // checking drag horizontally - should not change cell value
  142. selectCell(0, 1);
  143. this.$container.find('.wtBorder.current.corner').simulate('mousedown');
  144. this.$container.find('tbody tr:eq(0) td:eq(2)').simulate('mouseover').simulate('mouseup');
  145. expect(getDataAtCell(0, 2)).toEqual(3);
  146. });
  147. it('should appear when fillHandle is enabled as `object` value', () => {
  148. handsontable({
  149. fillHandle: {
  150. allowInsertRow: true
  151. }
  152. });
  153. selectCell(2, 2);
  154. expect(isFillHandleVisible()).toBe(true);
  155. });
  156. it('should not appear when fillHandle equals false', () => {
  157. handsontable({
  158. fillHandle: false
  159. });
  160. selectCell(2, 2);
  161. expect(isFillHandleVisible()).toBe(false);
  162. });
  163. it('should disappear when beginediting is triggered', () => {
  164. handsontable({
  165. fillHandle: true
  166. });
  167. selectCell(2, 2);
  168. keyDown('enter');
  169. expect(isFillHandleVisible()).toBe(false);
  170. });
  171. it('should appear when finishediting is triggered', () => {
  172. handsontable({
  173. fillHandle: true
  174. });
  175. selectCell(2, 2);
  176. keyDown('enter');
  177. keyDown('enter');
  178. expect(isFillHandleVisible()).toBe(true);
  179. });
  180. it('should not appear when fillHandle equals false and finishediting is triggered', () => {
  181. handsontable({
  182. fillHandle: false
  183. });
  184. selectCell(2, 2);
  185. keyDown('enter');
  186. keyDown('enter');
  187. expect(isFillHandleVisible()).toBe(false);
  188. });
  189. it('should appear when editor is discarded using the ESC key', () => {
  190. handsontable({
  191. fillHandle: true
  192. });
  193. selectCell(2, 2);
  194. keyDown('enter');
  195. keyDown('esc');
  196. expect(isFillHandleVisible()).toBe(true);
  197. });
  198. it('should add custom value after autofill', function() {
  199. handsontable({
  200. data: [
  201. [1, 2, 3, 4, 5, 6],
  202. [1, 2, 3, 4, 5, 6],
  203. [1, 2, 3, 4, 5, 6],
  204. [1, 2, 3, 4, 5, 6]
  205. ],
  206. beforeAutofill(start, end, data) {
  207. data[0][0] = 'test';
  208. }
  209. });
  210. selectCell(0, 0);
  211. this.$container.find('.wtBorder.corner').simulate('mousedown');
  212. this.$container.find('tr:eq(1) td:eq(0)').simulate('mouseover');
  213. this.$container.find('tr:eq(2) td:eq(0)').simulate('mouseover');
  214. this.$container.find('.wtBorder.corner').simulate('mouseup');
  215. expect(getSelected()).toEqual([0, 0, 2, 0]);
  216. expect(getDataAtCell(1, 0)).toEqual('test');
  217. });
  218. it('should use correct cell coordinates also when Handsontable is used inside a TABLE (#355)', function() {
  219. var $table = $('<table><tr><td></td></tr></table>').appendTo('body');
  220. this.$container.appendTo($table.find('td'));
  221. var ev;
  222. handsontable({
  223. data: [
  224. [1, 2, 3, 4, 5, 6],
  225. [1, 2, 3, 4, 5, 6],
  226. [1, 2, 3, 4, 5, 6],
  227. [1, 2, 3, 4, 5, 6]
  228. ],
  229. beforeAutofill(start, end, data) {
  230. data[0][0] = 'test';
  231. }
  232. });
  233. selectCell(1, 1);
  234. this.$container.find('.wtBorder.current.corner').simulate('mousedown');
  235. this.$container.find('tr:eq(1) td:eq(0)').simulate('mouseover');
  236. this.$container.find('tr:eq(2) td:eq(0)').simulate('mouseover');
  237. this.$container.find('tr:eq(2) td:eq(0)').simulate('mouseup');
  238. expect(getSelected()).toEqual([1, 1, 2, 1]);
  239. expect(getDataAtCell(2, 1)).toEqual('test');
  240. document.body.removeChild($table[0]);
  241. });
  242. it('should fill cells below until the end of content in the neighbouring column with current cell\'s data', function() {
  243. var hot = handsontable({
  244. data: [
  245. [1, 2, 3, 4, 5, 6],
  246. [1, 2, 3, 4, 5, 6],
  247. [1, 2, null, null, null, null],
  248. [1, 2, null, null, null, null]
  249. ]
  250. });
  251. selectCell(1, 3);
  252. var fillHandle = this.$container.find('.wtBorder.current.corner')[0];
  253. mouseDoubleClick(fillHandle);
  254. expect(getDataAtCell(2, 3)).toEqual(null);
  255. expect(getDataAtCell(3, 3)).toEqual(null);
  256. selectCell(1, 2);
  257. mouseDoubleClick(fillHandle);
  258. expect(getDataAtCell(2, 2)).toEqual(3);
  259. expect(getDataAtCell(3, 2)).toEqual(3);
  260. });
  261. it('should fill cells below until the end of content in the neighbouring column with the currently selected area\'s data', function() {
  262. var hot = handsontable({
  263. data: [
  264. [1, 2, 3, 4, 5, 6],
  265. [1, 2, 3, 4, 5, 6],
  266. [1, 2, null, null, null, null],
  267. [1, 2, null, null, null, null]
  268. ]
  269. });
  270. selectCell(1, 3, 1, 4);
  271. var fillHandle = this.$container.find('.wtBorder.area.corner')[0];
  272. mouseDoubleClick(fillHandle);
  273. expect(getDataAtCell(2, 3)).toEqual(null);
  274. expect(getDataAtCell(3, 3)).toEqual(null);
  275. expect(getDataAtCell(2, 4)).toEqual(null);
  276. expect(getDataAtCell(3, 4)).toEqual(null);
  277. selectCell(1, 2, 1, 3);
  278. mouseDoubleClick(fillHandle);
  279. expect(getDataAtCell(2, 2)).toEqual(3);
  280. expect(getDataAtCell(3, 2)).toEqual(3);
  281. expect(getDataAtCell(2, 3)).toEqual(4);
  282. expect(getDataAtCell(3, 3)).toEqual(4);
  283. });
  284. it('should add new row after dragging the handle to the last table row', function(done) {
  285. var hot = handsontable({
  286. data: [
  287. [1, 2, 'test', 4, 5, 6],
  288. [1, 2, 3, 4, 5, 6],
  289. [1, 2, 3, 4, 5, 6],
  290. [1, 2, 3, 4, 5, 6]
  291. ]
  292. });
  293. selectCell(0, 2);
  294. this.$container.find('.wtBorder.current.corner').simulate('mousedown');
  295. this.$container.find('tr:last-child td:eq(2)').simulate('mouseover');
  296. expect(hot.countRows()).toBe(4);
  297. setTimeout(() => {
  298. expect(hot.countRows()).toBe(5);
  299. spec().$container.find('tr:last-child td:eq(2)').simulate('mouseover');
  300. }, 300);
  301. setTimeout(() => {
  302. expect(hot.countRows()).toBe(6);
  303. done();
  304. }, 600);
  305. });
  306. it('should add new row after dragging the handle to the last table row (autoInsertRow as true)', function(done) {
  307. var hot = handsontable({
  308. data: [
  309. [1, 2, 'test', 4, 5, 6],
  310. [1, 2, 3, 4, 5, 6],
  311. [1, 2, 3, 4, 5, 6],
  312. [1, 2, 3, 4, 5, 6]
  313. ],
  314. fillHandle: {
  315. autoInsertRow: true,
  316. }
  317. });
  318. selectCell(0, 2);
  319. this.$container.find('.wtBorder.current.corner').simulate('mousedown');
  320. this.$container.find('tr:last-child td:eq(2)').simulate('mouseover');
  321. expect(hot.countRows()).toBe(4);
  322. setTimeout(() => {
  323. expect(hot.countRows()).toBe(5);
  324. spec().$container.find('tr:last-child td:eq(2)').simulate('mouseover');
  325. }, 300);
  326. setTimeout(() => {
  327. expect(hot.countRows()).toBe(6);
  328. done();
  329. }, 600);
  330. });
  331. it('should add new row after dragging the handle to the last table row (autoInsertRow as true, vertical)', function(done) {
  332. var hot = handsontable({
  333. data: [
  334. [1, 2, 'test', 4, 5, 6],
  335. [1, 2, 3, 4, 5, 6],
  336. [1, 2, 3, 4, 5, 6],
  337. [1, 2, 3, 4, 5, 6]
  338. ],
  339. fillHandle: {
  340. direction: 'vertical',
  341. autoInsertRow: true,
  342. }
  343. });
  344. selectCell(0, 2);
  345. this.$container.find('.wtBorder.current.corner').simulate('mousedown');
  346. this.$container.find('tr:last-child td:eq(2)').simulate('mouseover');
  347. expect(hot.countRows()).toBe(4);
  348. setTimeout(() => {
  349. expect(hot.countRows()).toBe(5);
  350. spec().$container.find('tr:last-child td:eq(2)').simulate('mouseover');
  351. }, 300);
  352. setTimeout(() => {
  353. expect(hot.countRows()).toBe(6);
  354. done();
  355. }, 600);
  356. });
  357. it('should not add new row after dragging the handle to the last table row (autoInsertRow as true, horizontal)', function(done) {
  358. var hot = handsontable({
  359. data: [
  360. [1, 2, 'test', 4, 5, 6],
  361. [1, 2, 3, 4, 5, 6],
  362. [1, 2, 3, 4, 5, 6],
  363. [1, 2, 3, 4, 5, 6]
  364. ],
  365. fillHandle: {
  366. direction: 'horizontal',
  367. autoInsertRow: true,
  368. }
  369. });
  370. selectCell(0, 2);
  371. this.$container.find('.wtBorder.current.corner').simulate('mousedown');
  372. this.$container.find('tr:last-child td:eq(2)').simulate('mouseover');
  373. expect(hot.countRows()).toBe(4);
  374. setTimeout(() => {
  375. expect(hot.countRows()).toBe(4);
  376. spec().$container.find('tr:last-child td:eq(2)').simulate('mouseover');
  377. }, 300);
  378. setTimeout(() => {
  379. expect(hot.countRows()).toBe(4);
  380. done();
  381. }, 600);
  382. });
  383. it('should not add new row after dragging the handle below the viewport when `autoInsertRow` is disabled', function(done) {
  384. var hot = handsontable({
  385. data: [
  386. [1, 2, 'test', 4, 5, 6],
  387. [1, 2, 3, 4, 5, 6],
  388. [1, 2, 3, 4, 5, 6],
  389. [1, 2, 3, 4, 5, 6]
  390. ],
  391. fillHandle: {
  392. autoInsertRow: false
  393. }
  394. });
  395. selectCell(0, 2);
  396. this.$container.find('.wtBorder.current.corner').simulate('mousedown');
  397. var ev = {};
  398. var $lastRow = this.$container.find('tr:last-child td:eq(2)');
  399. expect(hot.countRows()).toBe(4);
  400. ev.clientX = $lastRow.offset().left / 2;
  401. ev.clientY = $lastRow.offset().top + 50;
  402. $(document.documentElement).simulate('mousemove', ev);
  403. setTimeout(() => {
  404. expect(hot.countRows()).toBe(4);
  405. ev.clientY = $lastRow.offset().top + 150;
  406. $(document.documentElement).simulate('mousemove', ev);
  407. }, 300);
  408. setTimeout(() => {
  409. expect(hot.countRows()).toBe(4);
  410. done();
  411. }, 600);
  412. });
  413. it('should not add new rows if the current number of rows reaches the maxRows setting', function(done) {
  414. var hot = handsontable({
  415. data: [
  416. [1, 2, 'test', 4, 5, 6],
  417. [1, 2, 3, 4, 5, 6],
  418. [1, 2, 3, 4, 5, 6],
  419. [1, 2, 3, 4, 5, 6]
  420. ],
  421. maxRows: 5
  422. });
  423. selectCell(0, 2);
  424. this.$container.find('.wtBorder.current.corner').simulate('mousedown');
  425. this.$container.find('tr:last-child td:eq(2)').simulate('mouseover');
  426. expect(hot.countRows()).toBe(4);
  427. setTimeout(() => {
  428. expect(hot.countRows()).toBe(5);
  429. spec().$container.find('tr:last-child td:eq(2)').simulate('mouseover');
  430. }, 200);
  431. setTimeout(() => {
  432. expect(hot.countRows()).toBe(5);
  433. done();
  434. }, 400);
  435. });
  436. it('should add new row after dragging the handle below the viewport', function(done) {
  437. var hot = handsontable({
  438. data: [
  439. [1, 2, 'test', 4, 5, 6],
  440. [1, 2, 3, 4, 5, 6],
  441. [1, 2, 3, 4, 5, 6],
  442. [1, 2, 3, 4, 5, 6]
  443. ]
  444. });
  445. selectCell(0, 2);
  446. this.$container.find('.wtBorder.current.corner').simulate('mousedown');
  447. var ev = {};
  448. var $lastRow = this.$container.find('tr:last-child td:eq(2)');
  449. expect(hot.countRows()).toBe(4);
  450. ev.clientX = $lastRow.offset().left / 2;
  451. ev.clientY = $lastRow.offset().top + 50;
  452. $(document.documentElement).simulate('mousemove', ev);
  453. setTimeout(() => {
  454. expect(hot.countRows()).toBe(5);
  455. ev.clientY = $lastRow.offset().top + 150;
  456. $(document.documentElement).simulate('mousemove', ev);
  457. }, 300);
  458. setTimeout(() => {
  459. expect(hot.countRows()).toBe(6);
  460. done();
  461. }, 600);
  462. });
  463. it('should fill cells when dragging the handle to the headers', function() {
  464. var hot = handsontable({
  465. data: [
  466. [1, 2, 3, 4, 5, 6],
  467. [1, 2, 3, 4, 5, 6],
  468. [1, 2, 7, 4, 5, 6],
  469. [1, 2, 3, 4, 5, 6]
  470. ],
  471. colHeaders: true,
  472. rowHeaders: true
  473. });
  474. // col headers:
  475. selectCell(2, 2);
  476. this.$container.find('.wtBorder.current.corner').simulate('mousedown');
  477. var errors = 0;
  478. try {
  479. this.$container.find('thead tr:first-child th:eq(2)').simulate('mouseover').simulate('mouseup');
  480. } catch (err) {
  481. errors++;
  482. }
  483. expect(errors).toEqual(0);
  484. expect(getDataAtCell(1, 2)).toEqual(7);
  485. expect(getDataAtCell(0, 2)).toEqual(7);
  486. expect($('.fill').filter(function() { return $(this).css('display') !== 'none'; }).length).toEqual(0); // check if fill selection is refreshed
  487. // row headers:
  488. selectCell(2, 2);
  489. this.$container.find('.wtBorder.current.corner').simulate('mousedown');
  490. errors = 0;
  491. try {
  492. this.$container.find('tbody tr:nth(2) th:first-child').simulate('mouseover').simulate('mouseup');
  493. } catch (err) {
  494. errors++;
  495. }
  496. expect(errors).toEqual(0);
  497. expect(getDataAtCell(2, 1)).toEqual(7);
  498. expect(getDataAtCell(2, 0)).toEqual(7);
  499. expect($('.fill').filter(function() { return $(this).css('display') !== 'none'; }).length).toEqual(0); // check if fill selection is refreshed
  500. });
  501. it('should not add a new row if dragging from the last row upwards or sideways', function(done) {
  502. var mouseOverSpy = jasmine.createSpy('mouseOverSpy');
  503. var hot = handsontable({
  504. data: [
  505. [1, 2, 3, 4, 5, 6],
  506. [1, 2, 3, 4, 5, 6],
  507. [1, 2, 'test', 4, 5, 6],
  508. [1, 2, 3, 4, 5, 6]
  509. ],
  510. afterOnCellMouseOver: mouseOverSpy
  511. });
  512. selectCell(3, 2);
  513. this.$container.find('.wtBorder.current.corner').simulate('mousedown');
  514. this.$container.find('tr:nth-child(3) td:eq(2)').simulate('mouseover');
  515. setTimeout(() => {
  516. expect(hot.countRows()).toBe(4);
  517. selectCell(3, 2);
  518. spec().$container.find('.wtBorder.current.corner').simulate('mousedown');
  519. spec().$container.find('tr:nth-child(4) td:eq(3)').simulate('mouseover');
  520. }, 300);
  521. setTimeout(() => {
  522. expect(hot.countRows()).toBe(4);
  523. selectCell(3, 2);
  524. spec().$container.find('.wtBorder.current.corner').simulate('mousedown');
  525. spec().$container.find('tr:nth-child(4) td:eq(1)').simulate('mouseover');
  526. }, 500);
  527. setTimeout(() => {
  528. expect(hot.countRows()).toBe(4);
  529. done();
  530. }, 700);
  531. });
  532. it('should add new row after dragging the handle below the viewport', function(done) {
  533. var hot = handsontable({
  534. data: [
  535. [1, 2, 'test', 4, 5, 6],
  536. [1, 2, 3, 4, 5, 6],
  537. [1, 2, 3, 4, 5, 6],
  538. [1, 2, 3, 4, 5, 6]
  539. ]
  540. });
  541. selectCell(0, 2);
  542. this.$container.find('.wtBorder.current.corner').simulate('mousedown');
  543. var ev = {};
  544. var $lastRow = this.$container.find('tr:last-child td:eq(2)');
  545. expect(hot.countRows()).toBe(4);
  546. ev.clientX = $lastRow.offset().left / 2;
  547. ev.clientY = $lastRow.offset().top + 50;
  548. $(document.documentElement).simulate('mousemove', ev);
  549. setTimeout(() => {
  550. expect(hot.countRows()).toBe(5);
  551. ev.clientY = $lastRow.offset().top + 150;
  552. $(document.documentElement).simulate('mousemove', ev);
  553. }, 300);
  554. setTimeout(() => {
  555. expect(hot.countRows()).toBe(6);
  556. done();
  557. }, 600);
  558. });
  559. it('should not add new row after dragging the handle below the viewport (direction is set to horizontal)', function(done) {
  560. var hot = handsontable({
  561. data: [
  562. [1, 2, 'test', 4, 5, 6],
  563. [1, 2, 3, 4, 5, 6],
  564. [1, 2, 3, 4, 5, 6],
  565. [1, 2, 3, 4, 5, 6]
  566. ],
  567. fillHandle: {
  568. direction: 'horizontal',
  569. autoInsertRow: true
  570. }
  571. });
  572. selectCell(0, 2);
  573. this.$container.find('.wtBorder.current.corner').simulate('mousedown');
  574. var ev = {};
  575. var $lastRow = this.$container.find('tr:last-child td:eq(2)');
  576. expect(hot.countRows()).toBe(4);
  577. ev.clientX = $lastRow.offset().left / 2;
  578. ev.clientY = $lastRow.offset().top + 50;
  579. $(document.documentElement).simulate('mousemove', ev);
  580. setTimeout(() => {
  581. expect(hot.countRows()).toBe(4);
  582. done();
  583. }, 300);
  584. });
  585. describe('should works properly when two or more instances of Handsontable was initialized with other settings (#3257)', () => {
  586. var getData;
  587. var $container1;
  588. var $container2;
  589. beforeAll(() => {
  590. getData = function getData() {
  591. return [
  592. [1, 2, 3, 4, 5, 6],
  593. [7, 8, 9, 1, 2, 3],
  594. [4, 5, 6, 7, 8, 9],
  595. [1, 2, 3, 4, 5, 6]
  596. ];
  597. };
  598. $container1 = $('<div id="hot1"></div>').appendTo('body').handsontable({
  599. data: getData(),
  600. fillHandle: true
  601. });
  602. $container2 = $('<div id="hot2"></div>').appendTo('body').handsontable({
  603. data: getData(),
  604. fillHandle: 'horizontal'
  605. });
  606. });
  607. it('checking drag vertically on 1. instance of Handsontable - should change cell value', () => {
  608. $container1.handsontable('selectCell', 0, 0);
  609. $container1.find('.wtBorder.current.corner').simulate('mousedown');
  610. $container1.find('tbody tr:eq(1) td:eq(0)').simulate('mouseover').simulate('mouseup');
  611. expect($container1.handsontable('getDataAtCell', 1, 0)).toEqual(1);
  612. });
  613. describe('-> updating settings on 2. instance of Handsontable', () => {
  614. beforeAll(() => {
  615. $container2.handsontable('updateSettings', {fillHandle: 'vertical'});
  616. });
  617. it('checking drag vertically on 2. instance of Handsontable - should change cell value', () => {
  618. $container2.handsontable('selectCell', 0, 2);
  619. $container2.find('.wtBorder.current.corner').simulate('mousedown');
  620. $container2.find('tbody tr:eq(1) td:eq(2)').simulate('mouseover').simulate('mouseup');
  621. expect($container2.handsontable('getDataAtCell', 1, 2)).toEqual(3);
  622. });
  623. });
  624. afterAll(() => {
  625. // destroing containers
  626. $container1.handsontable('destroy');
  627. $container1.remove();
  628. $container2.handsontable('destroy');
  629. $container2.remove();
  630. });
  631. });
  632. });