UndoRedo.e2e.js 84 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471
  1. 'use strict';
  2. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  3. describe('UndoRedo', function () {
  4. var id = 'testContainer';
  5. beforeEach(function () {
  6. this.$container = $('<div id="' + id + '"></div>').appendTo('body');
  7. });
  8. afterEach(function () {
  9. if (this.$container) {
  10. destroy();
  11. this.$container.remove();
  12. }
  13. });
  14. describe('core features', function () {
  15. describe('Array data', function () {
  16. describe('undo', function () {
  17. it('should undo single change', function () {
  18. handsontable({
  19. data: Handsontable.helper.createSpreadsheetData(2, 2)
  20. });
  21. var HOT = getInstance();
  22. setDataAtCell(0, 0, 'X1');
  23. expect(getDataAtCell(0, 0)).toBe('X1');
  24. HOT.undo();
  25. expect(getDataAtCell(0, 0)).toBe('A1');
  26. });
  27. it('should undo single change on cell with validator', function (done) {
  28. handsontable({
  29. data: Handsontable.helper.createSpreadsheetData(2, 2)
  30. });
  31. var HOT = getInstance();
  32. setDataAtCell(0, 0, 'X1');
  33. setTimeout(function () {
  34. expect(getDataAtCell(0, 0)).toBe('X1');
  35. HOT.undo();
  36. }, 200);
  37. setTimeout(function () {
  38. expect(getDataAtCell(0, 0)).toBe('A1');
  39. done();
  40. }, 400);
  41. });
  42. it('should undo creation of a single row', function () {
  43. var HOT = handsontable({
  44. data: Handsontable.helper.createSpreadsheetData(2, 2)
  45. });
  46. expect(countRows()).toEqual(2);
  47. alter('insert_row');
  48. expect(countRows()).toEqual(3);
  49. HOT.undo();
  50. expect(countRows()).toEqual(2);
  51. });
  52. it('should undo creation of multiple rows', function () {
  53. var HOT = handsontable({
  54. data: Handsontable.helper.createSpreadsheetData(2, 2)
  55. });
  56. expect(countRows()).toEqual(2);
  57. alter('insert_row', 0, 5);
  58. expect(countRows()).toEqual(7);
  59. HOT.undo();
  60. expect(countRows()).toEqual(2);
  61. });
  62. it('should undo creation of multiple rows with minSpareRows', function () {
  63. var HOT = handsontable({
  64. data: Handsontable.helper.createSpreadsheetData(2, 1),
  65. minSpareRows: 2
  66. });
  67. expect(getData()).toEqual([['A1'], ['A2'], [null], [null]]);
  68. setDataAtCell(2, 0, 'A3');
  69. setDataAtCell(4, 0, 'A4');
  70. expect(getData()).toEqual([['A1'], ['A2'], ['A3'], [null], ['A4'], [null], [null]]);
  71. HOT.undo();
  72. HOT.undo();
  73. expect(getData()).toEqual([['A1'], ['A2'], [null], [null]]);
  74. });
  75. it('should undo removal of single row', function () {
  76. var HOT = handsontable({
  77. data: Handsontable.helper.createSpreadsheetData(3, 2)
  78. });
  79. expect(countRows()).toEqual(3);
  80. expect(getDataAtCell(0, 0)).toEqual('A1');
  81. expect(getDataAtCell(0, 1)).toEqual('B1');
  82. expect(getDataAtCell(1, 0)).toEqual('A2');
  83. expect(getDataAtCell(1, 1)).toEqual('B2');
  84. expect(getDataAtCell(2, 0)).toEqual('A3');
  85. expect(getDataAtCell(2, 1)).toEqual('B3');
  86. alter('remove_row', 1);
  87. expect(countRows()).toEqual(2);
  88. expect(getDataAtCell(0, 0)).toEqual('A1');
  89. expect(getDataAtCell(0, 1)).toEqual('B1');
  90. expect(getDataAtCell(1, 0)).toEqual('A3');
  91. expect(getDataAtCell(1, 1)).toEqual('B3');
  92. HOT.undo();
  93. expect(countRows()).toEqual(3);
  94. expect(getDataAtCell(0, 0)).toEqual('A1');
  95. expect(getDataAtCell(0, 1)).toEqual('B1');
  96. expect(getDataAtCell(1, 0)).toEqual('A2');
  97. expect(getDataAtCell(1, 1)).toEqual('B2');
  98. expect(getDataAtCell(2, 0)).toEqual('A3');
  99. expect(getDataAtCell(2, 1)).toEqual('B3');
  100. });
  101. it('should undo removal of multiple rows', function () {
  102. var HOT = handsontable({
  103. data: Handsontable.helper.createSpreadsheetData(4, 2)
  104. });
  105. expect(countRows()).toEqual(4);
  106. expect(getDataAtCell(0, 0)).toEqual('A1');
  107. expect(getDataAtCell(0, 1)).toEqual('B1');
  108. expect(getDataAtCell(1, 0)).toEqual('A2');
  109. expect(getDataAtCell(1, 1)).toEqual('B2');
  110. expect(getDataAtCell(2, 0)).toEqual('A3');
  111. expect(getDataAtCell(2, 1)).toEqual('B3');
  112. expect(getDataAtCell(3, 0)).toEqual('A4');
  113. expect(getDataAtCell(3, 1)).toEqual('B4');
  114. alter('remove_row', 1, 2);
  115. expect(countRows()).toEqual(2);
  116. expect(getDataAtCell(0, 0)).toEqual('A1');
  117. expect(getDataAtCell(0, 1)).toEqual('B1');
  118. expect(getDataAtCell(1, 0)).toEqual('A4');
  119. expect(getDataAtCell(1, 1)).toEqual('B4');
  120. HOT.undo();
  121. expect(countRows()).toEqual(4);
  122. expect(getDataAtCell(0, 0)).toEqual('A1');
  123. expect(getDataAtCell(0, 1)).toEqual('B1');
  124. expect(getDataAtCell(1, 0)).toEqual('A2');
  125. expect(getDataAtCell(1, 1)).toEqual('B2');
  126. expect(getDataAtCell(2, 0)).toEqual('A3');
  127. expect(getDataAtCell(2, 1)).toEqual('B3');
  128. expect(getDataAtCell(3, 0)).toEqual('A4');
  129. expect(getDataAtCell(3, 1)).toEqual('B4');
  130. });
  131. it('should undo creation of a single column (colHeaders: undefined)', function () {
  132. var HOT = handsontable({
  133. data: Handsontable.helper.createSpreadsheetData(2, 3)
  134. });
  135. expect(countCols()).toEqual(3);
  136. alter('insert_col');
  137. expect(countCols()).toEqual(4);
  138. HOT.undo();
  139. expect(countCols()).toEqual(3);
  140. });
  141. it('should undo creation of a single column (colHeaders: true)', function () {
  142. var HOT = handsontable({
  143. data: Handsontable.helper.createSpreadsheetData(2, 3),
  144. colHeaders: true
  145. });
  146. expect(countCols()).toEqual(3);
  147. expect(getColHeader()).toEqual(['A', 'B', 'C']);
  148. alter('insert_col');
  149. expect(countCols()).toEqual(4);
  150. expect(getColHeader()).toEqual(['A', 'B', 'C', 'D']);
  151. HOT.undo();
  152. expect(countCols()).toEqual(3);
  153. expect(getColHeader()).toEqual(['A', 'B', 'C']);
  154. });
  155. it('should undo creation of a single column (colHeaders: Array)', function () {
  156. var HOT = handsontable({
  157. data: Handsontable.helper.createSpreadsheetData(2, 3),
  158. colHeaders: ['Header1', 'Header2', 'Header3']
  159. });
  160. expect(countCols()).toEqual(3);
  161. expect(getColHeader()).toEqual(['Header1', 'Header2', 'Header3']);
  162. alter('insert_col', 1);
  163. expect(countCols()).toEqual(4);
  164. expect(getColHeader()).toEqual(['Header1', 'B', 'Header2', 'Header3']);
  165. HOT.undo();
  166. expect(countCols()).toEqual(3);
  167. expect(getColHeader()).toEqual(['Header1', 'Header2', 'Header3']);
  168. });
  169. it('should undo creation of multiple columns (colHeaders: undefined)', function () {
  170. var HOT = handsontable({
  171. data: Handsontable.helper.createSpreadsheetData(2, 2)
  172. });
  173. expect(countCols()).toEqual(2);
  174. alter('insert_col', 1, 5);
  175. expect(countCols()).toEqual(7);
  176. HOT.undo();
  177. expect(countCols()).toEqual(2);
  178. });
  179. it('should undo creation of multiple columns (colHeaders: true)', function () {
  180. var HOT = handsontable({
  181. data: Handsontable.helper.createSpreadsheetData(2, 2),
  182. colHeaders: true
  183. });
  184. expect(countCols()).toEqual(2);
  185. expect(getColHeader()).toEqual(['A', 'B']);
  186. alter('insert_col', 1, 5);
  187. expect(countCols()).toEqual(7);
  188. expect(getColHeader()).toEqual(['A', 'B', 'C', 'D', 'E', 'F', 'G']);
  189. HOT.undo();
  190. expect(countCols()).toEqual(2);
  191. expect(getColHeader()).toEqual(['A', 'B']);
  192. });
  193. it('should undo creation of multiple columns (colHeaders: Array)', function () {
  194. var HOT = handsontable({
  195. data: Handsontable.helper.createSpreadsheetData(2, 2),
  196. colHeaders: ['Header1', 'Header2']
  197. });
  198. expect(countCols()).toEqual(2);
  199. expect(getColHeader()).toEqual(['Header1', 'Header2']);
  200. alter('insert_col', 1, 5);
  201. expect(countCols()).toEqual(7);
  202. expect(getColHeader()).toEqual(['Header1', 'B', 'C', 'D', 'E', 'F', 'Header2']);
  203. HOT.undo();
  204. expect(countCols()).toEqual(2);
  205. expect(getColHeader()).toEqual(['Header1', 'Header2']);
  206. });
  207. it('should undo creation of multiple columns with minSpareCols', function () {
  208. var HOT = handsontable({
  209. data: Handsontable.helper.createSpreadsheetData(1, 1),
  210. minSpareCols: 2
  211. });
  212. expect(getData()).toEqual([['A1', null, null]]);
  213. setDataAtCell(0, 1, 'B1');
  214. setDataAtCell(0, 3, 'C1');
  215. expect(getData()).toEqual([['A1', 'B1', null, 'C1', null, null]]);
  216. HOT.undo();
  217. HOT.undo();
  218. expect(getData()).toEqual([['A1', null, null]]);
  219. });
  220. it('should undo removal of single column (colHeaders: undefined)', function () {
  221. var HOT = handsontable({
  222. data: Handsontable.helper.createSpreadsheetData(2, 3)
  223. });
  224. expect(countCols()).toEqual(3);
  225. expect(getDataAtCell(0, 0)).toEqual('A1');
  226. expect(getDataAtCell(0, 1)).toEqual('B1');
  227. expect(getDataAtCell(0, 2)).toEqual('C1');
  228. expect(getDataAtCell(1, 0)).toEqual('A2');
  229. expect(getDataAtCell(1, 1)).toEqual('B2');
  230. expect(getDataAtCell(1, 2)).toEqual('C2');
  231. alter('remove_col', 1);
  232. expect(countCols()).toEqual(2);
  233. expect(getDataAtCell(0, 0)).toEqual('A1');
  234. expect(getDataAtCell(0, 1)).toEqual('C1');
  235. expect(getDataAtCell(1, 0)).toEqual('A2');
  236. expect(getDataAtCell(1, 1)).toEqual('C2');
  237. HOT.undo();
  238. expect(countCols()).toEqual(3);
  239. expect(getDataAtCell(0, 0)).toEqual('A1');
  240. expect(getDataAtCell(0, 1)).toEqual('B1');
  241. expect(getDataAtCell(0, 2)).toEqual('C1');
  242. expect(getDataAtCell(1, 0)).toEqual('A2');
  243. expect(getDataAtCell(1, 1)).toEqual('B2');
  244. expect(getDataAtCell(1, 2)).toEqual('C2');
  245. });
  246. it('should undo removal of single column (colHeaders: true)', function () {
  247. var HOT = handsontable({
  248. data: Handsontable.helper.createSpreadsheetData(2, 2),
  249. colHeaders: true
  250. });
  251. expect(countCols()).toEqual(2);
  252. expect(getDataAtCell(0, 0)).toEqual('A1');
  253. expect(getDataAtCell(0, 1)).toEqual('B1');
  254. expect(getDataAtCell(1, 0)).toEqual('A2');
  255. expect(getDataAtCell(1, 1)).toEqual('B2');
  256. expect(getColHeader()).toEqual(['A', 'B']);
  257. alter('remove_col');
  258. expect(countCols()).toEqual(1);
  259. expect(getDataAtCell(0, 0)).toEqual('A1');
  260. expect(getDataAtCell(0, 1)).toBeNull();
  261. expect(getDataAtCell(1, 0)).toEqual('A2');
  262. expect(getDataAtCell(1, 1)).toBeNull();
  263. expect(getColHeader()).toEqual(['A']);
  264. HOT.undo();
  265. expect(countCols()).toEqual(2);
  266. expect(getDataAtCell(0, 0)).toEqual('A1');
  267. expect(getDataAtCell(0, 1)).toEqual('B1');
  268. expect(getDataAtCell(1, 0)).toEqual('A2');
  269. expect(getDataAtCell(1, 1)).toEqual('B2');
  270. expect(getColHeader()).toEqual(['A', 'B']);
  271. });
  272. it('should undo removal of single column (colHeaders: Array)', function () {
  273. var HOT = handsontable({
  274. data: Handsontable.helper.createSpreadsheetData(2, 2),
  275. colHeaders: ['Header1', 'Header2']
  276. });
  277. expect(countCols()).toEqual(2);
  278. expect(getDataAtCell(0, 0)).toEqual('A1');
  279. expect(getDataAtCell(0, 1)).toEqual('B1');
  280. expect(getDataAtCell(1, 0)).toEqual('A2');
  281. expect(getDataAtCell(1, 1)).toEqual('B2');
  282. expect(getColHeader()).toEqual(['Header1', 'Header2']);
  283. alter('remove_col');
  284. expect(countCols()).toEqual(1);
  285. expect(getDataAtCell(0, 0)).toEqual('A1');
  286. expect(getDataAtCell(0, 1)).toBeNull();
  287. expect(getDataAtCell(1, 0)).toEqual('A2');
  288. expect(getDataAtCell(1, 1)).toBeNull();
  289. expect(getColHeader()).toEqual(['Header1']);
  290. HOT.undo();
  291. expect(countCols()).toEqual(2);
  292. expect(getDataAtCell(0, 0)).toEqual('A1');
  293. expect(getDataAtCell(0, 1)).toEqual('B1');
  294. expect(getDataAtCell(1, 0)).toEqual('A2');
  295. expect(getDataAtCell(1, 1)).toEqual('B2');
  296. expect(getColHeader()).toEqual(['Header1', 'Header2']);
  297. });
  298. it('should undo removal of multiple columns (colHeaders: undefined)', function () {
  299. var HOT = handsontable({
  300. data: Handsontable.helper.createSpreadsheetData(2, 4)
  301. });
  302. expect(countCols()).toEqual(4);
  303. expect(getDataAtCell(0, 0)).toEqual('A1');
  304. expect(getDataAtCell(0, 1)).toEqual('B1');
  305. expect(getDataAtCell(0, 2)).toEqual('C1');
  306. expect(getDataAtCell(0, 3)).toEqual('D1');
  307. expect(getDataAtCell(1, 0)).toEqual('A2');
  308. expect(getDataAtCell(1, 1)).toEqual('B2');
  309. expect(getDataAtCell(1, 2)).toEqual('C2');
  310. expect(getDataAtCell(1, 3)).toEqual('D2');
  311. alter('remove_col', 1, 2);
  312. expect(countCols()).toEqual(2);
  313. expect(getDataAtCell(0, 0)).toEqual('A1');
  314. expect(getDataAtCell(0, 1)).toEqual('D1');
  315. expect(getDataAtCell(0, 2)).toBeNull();
  316. expect(getDataAtCell(0, 3)).toBeNull();
  317. expect(getDataAtCell(1, 0)).toEqual('A2');
  318. expect(getDataAtCell(1, 1)).toEqual('D2');
  319. expect(getDataAtCell(1, 2)).toBeNull();
  320. expect(getDataAtCell(1, 3)).toBeNull();
  321. HOT.undo();
  322. expect(countCols()).toEqual(4);
  323. expect(getDataAtCell(0, 0)).toEqual('A1');
  324. expect(getDataAtCell(0, 1)).toEqual('B1');
  325. expect(getDataAtCell(0, 2)).toEqual('C1');
  326. expect(getDataAtCell(0, 3)).toEqual('D1');
  327. expect(getDataAtCell(1, 0)).toEqual('A2');
  328. expect(getDataAtCell(1, 1)).toEqual('B2');
  329. expect(getDataAtCell(1, 2)).toEqual('C2');
  330. expect(getDataAtCell(1, 3)).toEqual('D2');
  331. });
  332. it('should undo removal of multiple columns (colHeaders: true)', function () {
  333. var HOT = handsontable({
  334. data: Handsontable.helper.createSpreadsheetData(2, 4),
  335. colHeaders: true
  336. });
  337. expect(countCols()).toEqual(4);
  338. expect(getDataAtCell(0, 0)).toEqual('A1');
  339. expect(getDataAtCell(0, 1)).toEqual('B1');
  340. expect(getDataAtCell(0, 2)).toEqual('C1');
  341. expect(getDataAtCell(0, 3)).toEqual('D1');
  342. expect(getDataAtCell(1, 0)).toEqual('A2');
  343. expect(getDataAtCell(1, 1)).toEqual('B2');
  344. expect(getDataAtCell(1, 2)).toEqual('C2');
  345. expect(getDataAtCell(1, 3)).toEqual('D2');
  346. expect(getColHeader()).toEqual(['A', 'B', 'C', 'D']);
  347. alter('remove_col', 1, 3);
  348. expect(countCols()).toEqual(1);
  349. expect(getDataAtCell(0, 0)).toEqual('A1');
  350. expect(getDataAtCell(0, 1)).toBeNull();
  351. expect(getDataAtCell(0, 2)).toBeNull();
  352. expect(getDataAtCell(0, 3)).toBeNull();
  353. expect(getDataAtCell(1, 0)).toEqual('A2');
  354. expect(getDataAtCell(1, 1)).toBeNull();
  355. expect(getDataAtCell(1, 2)).toBeNull();
  356. expect(getDataAtCell(1, 3)).toBeNull();
  357. expect(getColHeader()).toEqual(['A']);
  358. HOT.undo();
  359. expect(countCols()).toEqual(4);
  360. expect(getDataAtCell(0, 0)).toEqual('A1');
  361. expect(getDataAtCell(0, 1)).toEqual('B1');
  362. expect(getDataAtCell(0, 2)).toEqual('C1');
  363. expect(getDataAtCell(0, 3)).toEqual('D1');
  364. expect(getDataAtCell(1, 0)).toEqual('A2');
  365. expect(getDataAtCell(1, 1)).toEqual('B2');
  366. expect(getDataAtCell(1, 2)).toEqual('C2');
  367. expect(getDataAtCell(1, 3)).toEqual('D2');
  368. expect(getColHeader()).toEqual(['A', 'B', 'C', 'D']);
  369. });
  370. it('should undo removal of multiple columns (colHeaders: Array)', function () {
  371. var HOT = handsontable({
  372. data: Handsontable.helper.createSpreadsheetData(2, 4),
  373. colHeaders: ['Header1', 'Header2', 'Header3', 'Header4']
  374. });
  375. expect(countCols()).toEqual(4);
  376. expect(getDataAtCell(0, 0)).toEqual('A1');
  377. expect(getDataAtCell(0, 1)).toEqual('B1');
  378. expect(getDataAtCell(0, 2)).toEqual('C1');
  379. expect(getDataAtCell(0, 3)).toEqual('D1');
  380. expect(getDataAtCell(1, 0)).toEqual('A2');
  381. expect(getDataAtCell(1, 1)).toEqual('B2');
  382. expect(getDataAtCell(1, 2)).toEqual('C2');
  383. expect(getDataAtCell(1, 3)).toEqual('D2');
  384. expect(getColHeader()).toEqual(['Header1', 'Header2', 'Header3', 'Header4']);
  385. alter('remove_col', 1, 2);
  386. expect(countCols()).toEqual(2);
  387. expect(getDataAtCell(0, 0)).toEqual('A1');
  388. expect(getDataAtCell(0, 1)).toEqual('D1');
  389. expect(getDataAtCell(0, 2)).toBeNull();
  390. expect(getDataAtCell(0, 3)).toBeNull();
  391. expect(getDataAtCell(1, 0)).toEqual('A2');
  392. expect(getDataAtCell(1, 1)).toEqual('D2');
  393. expect(getDataAtCell(1, 2)).toBeNull();
  394. expect(getDataAtCell(1, 3)).toBeNull();
  395. expect(getColHeader()).toEqual(['Header1', 'Header4']);
  396. HOT.undo();
  397. expect(countCols()).toEqual(4);
  398. expect(getDataAtCell(0, 0)).toEqual('A1');
  399. expect(getDataAtCell(0, 1)).toEqual('B1');
  400. expect(getDataAtCell(0, 2)).toEqual('C1');
  401. expect(getDataAtCell(0, 3)).toEqual('D1');
  402. expect(getDataAtCell(1, 0)).toEqual('A2');
  403. expect(getDataAtCell(1, 1)).toEqual('B2');
  404. expect(getDataAtCell(1, 2)).toEqual('C2');
  405. expect(getDataAtCell(1, 3)).toEqual('D2');
  406. expect(getColHeader()).toEqual(['Header1', 'Header2', 'Header3', 'Header4']);
  407. });
  408. it('should undo removal of multiple columns (with a used manualColumnMove)', function () {
  409. var HOT = handsontable({
  410. data: Handsontable.helper.createSpreadsheetData(2, 7),
  411. manualColumnMove: [3, 2, 0, 6, 1, 5, 4]
  412. });
  413. expect(countCols()).toEqual(7);
  414. expect(getDataAtRow(0)).toEqual(['D1', 'C1', 'A1', 'G1', 'B1', 'F1', 'E1']);
  415. alter('remove_col', 1, 3);
  416. expect(countCols()).toEqual(4);
  417. expect(getDataAtRow(0)).toEqual(['D1', 'B1', 'F1', 'E1']);
  418. // HOT.undo();
  419. //
  420. // expect(countCols()).toEqual(7);
  421. // expect(getDataAtRow(0)).toEqual(['D1', 'C1', 'A1', 'G1', 'B1', 'F1', 'E1']);
  422. });
  423. it('should undo multiple changes', function () {
  424. handsontable({
  425. data: Handsontable.helper.createSpreadsheetData(2, 2)
  426. });
  427. var HOT = getInstance();
  428. setDataAtCell(0, 0, 'X1');
  429. setDataAtCell(1, 0, 'X2');
  430. setDataAtCell(0, 1, 'Y1');
  431. setDataAtCell(1, 1, 'Y2');
  432. expect(getDataAtCell(0, 0)).toBe('X1');
  433. expect(getDataAtCell(1, 0)).toBe('X2');
  434. expect(getDataAtCell(0, 1)).toBe('Y1');
  435. expect(getDataAtCell(1, 1)).toBe('Y2');
  436. HOT.undo();
  437. expect(getDataAtCell(0, 0)).toBe('X1');
  438. expect(getDataAtCell(1, 0)).toBe('X2');
  439. expect(getDataAtCell(0, 1)).toBe('Y1');
  440. expect(getDataAtCell(1, 1)).toBe('B2');
  441. HOT.undo();
  442. expect(getDataAtCell(0, 0)).toBe('X1');
  443. expect(getDataAtCell(1, 0)).toBe('X2');
  444. expect(getDataAtCell(0, 1)).toBe('B1');
  445. expect(getDataAtCell(1, 1)).toBe('B2');
  446. HOT.undo();
  447. expect(getDataAtCell(0, 0)).toBe('X1');
  448. expect(getDataAtCell(1, 0)).toBe('A2');
  449. expect(getDataAtCell(0, 1)).toBe('B1');
  450. expect(getDataAtCell(1, 1)).toBe('B2');
  451. HOT.undo();
  452. expect(getDataAtCell(0, 0)).toBe('A1');
  453. expect(getDataAtCell(1, 0)).toBe('A2');
  454. expect(getDataAtCell(0, 1)).toBe('B1');
  455. expect(getDataAtCell(1, 1)).toBe('B2');
  456. HOT.undo();
  457. expect(getDataAtCell(0, 0)).toBe('A1');
  458. expect(getDataAtCell(1, 0)).toBe('A2');
  459. expect(getDataAtCell(0, 1)).toBe('B1');
  460. expect(getDataAtCell(1, 1)).toBe('B2');
  461. });
  462. it('should undo multiple changes in cells with validators', function (done) {
  463. handsontable({
  464. data: Handsontable.helper.createSpreadsheetData(2, 2)
  465. });
  466. var HOT = getInstance();
  467. setDataAtCell(0, 0, 'X1');
  468. setDataAtCell(1, 0, 'X2');
  469. setDataAtCell(0, 1, 'Y1');
  470. setDataAtCell(1, 1, 'Y2');
  471. setTimeout(function () {
  472. expect(getDataAtCell(0, 0)).toBe('X1');
  473. expect(getDataAtCell(1, 0)).toBe('X2');
  474. expect(getDataAtCell(0, 1)).toBe('Y1');
  475. expect(getDataAtCell(1, 1)).toBe('Y2');
  476. HOT.undo();
  477. }, 200);
  478. setTimeout(function () {
  479. expect(getDataAtCell(0, 0)).toBe('X1');
  480. expect(getDataAtCell(1, 0)).toBe('X2');
  481. expect(getDataAtCell(0, 1)).toBe('Y1');
  482. expect(getDataAtCell(1, 1)).toBe('B2');
  483. HOT.undo();
  484. }, 400);
  485. setTimeout(function () {
  486. expect(getDataAtCell(0, 0)).toBe('X1');
  487. expect(getDataAtCell(1, 0)).toBe('X2');
  488. expect(getDataAtCell(0, 1)).toBe('B1');
  489. expect(getDataAtCell(1, 1)).toBe('B2');
  490. HOT.undo();
  491. }, 600);
  492. setTimeout(function () {
  493. expect(getDataAtCell(0, 0)).toBe('X1');
  494. expect(getDataAtCell(1, 0)).toBe('A2');
  495. expect(getDataAtCell(0, 1)).toBe('B1');
  496. expect(getDataAtCell(1, 1)).toBe('B2');
  497. HOT.undo();
  498. }, 800);
  499. setTimeout(function () {
  500. expect(getDataAtCell(0, 0)).toBe('A1');
  501. expect(getDataAtCell(1, 0)).toBe('A2');
  502. expect(getDataAtCell(0, 1)).toBe('B1');
  503. expect(getDataAtCell(1, 1)).toBe('B2');
  504. HOT.undo();
  505. }, 1000);
  506. setTimeout(function () {
  507. expect(getDataAtCell(0, 0)).toBe('A1');
  508. expect(getDataAtCell(1, 0)).toBe('A2');
  509. expect(getDataAtCell(0, 1)).toBe('B1');
  510. expect(getDataAtCell(1, 1)).toBe('B2');
  511. done();
  512. }, 1200);
  513. });
  514. it('should undo multiple row creations', function () {
  515. var HOT = handsontable({
  516. data: Handsontable.helper.createSpreadsheetData(2, 2)
  517. });
  518. expect(countRows()).toEqual(2);
  519. alter('insert_row');
  520. alter('insert_row');
  521. alter('insert_row');
  522. alter('insert_row');
  523. expect(countRows()).toEqual(6);
  524. HOT.undo();
  525. expect(countRows()).toEqual(5);
  526. HOT.undo();
  527. expect(countRows()).toEqual(4);
  528. HOT.undo();
  529. expect(countRows()).toEqual(3);
  530. HOT.undo();
  531. expect(countRows()).toEqual(2);
  532. HOT.undo();
  533. expect(countRows()).toEqual(2);
  534. });
  535. it('should undo multiple row removals', function () {
  536. var HOT = handsontable({
  537. data: Handsontable.helper.createSpreadsheetData(4, 2)
  538. });
  539. expect(countRows()).toEqual(4);
  540. expect(getDataAtCell(0, 0)).toEqual('A1');
  541. expect(getDataAtCell(0, 1)).toEqual('B1');
  542. expect(getDataAtCell(1, 0)).toEqual('A2');
  543. expect(getDataAtCell(1, 1)).toEqual('B2');
  544. expect(getDataAtCell(2, 0)).toEqual('A3');
  545. expect(getDataAtCell(2, 1)).toEqual('B3');
  546. expect(getDataAtCell(3, 0)).toEqual('A4');
  547. expect(getDataAtCell(3, 1)).toEqual('B4');
  548. alter('remove_row');
  549. alter('remove_row');
  550. alter('remove_row');
  551. expect(countRows()).toEqual(1);
  552. expect(getDataAtCell(0, 0)).toEqual('A1');
  553. expect(getDataAtCell(0, 1)).toEqual('B1');
  554. HOT.undo();
  555. expect(countRows()).toEqual(2);
  556. expect(getDataAtCell(0, 0)).toEqual('A1');
  557. expect(getDataAtCell(0, 1)).toEqual('B1');
  558. expect(getDataAtCell(1, 0)).toEqual('A2');
  559. expect(getDataAtCell(1, 1)).toEqual('B2');
  560. HOT.undo();
  561. expect(countRows()).toEqual(3);
  562. expect(getDataAtCell(0, 0)).toEqual('A1');
  563. expect(getDataAtCell(0, 1)).toEqual('B1');
  564. expect(getDataAtCell(1, 0)).toEqual('A2');
  565. expect(getDataAtCell(1, 1)).toEqual('B2');
  566. expect(getDataAtCell(2, 0)).toEqual('A3');
  567. expect(getDataAtCell(2, 1)).toEqual('B3');
  568. HOT.undo();
  569. expect(countRows()).toEqual(4);
  570. expect(getDataAtCell(0, 0)).toEqual('A1');
  571. expect(getDataAtCell(0, 1)).toEqual('B1');
  572. expect(getDataAtCell(1, 0)).toEqual('A2');
  573. expect(getDataAtCell(1, 1)).toEqual('B2');
  574. expect(getDataAtCell(2, 0)).toEqual('A3');
  575. expect(getDataAtCell(2, 1)).toEqual('B3');
  576. expect(getDataAtCell(3, 0)).toEqual('A4');
  577. expect(getDataAtCell(3, 1)).toEqual('B4');
  578. HOT.undo();
  579. expect(countRows()).toEqual(4);
  580. expect(getDataAtCell(0, 0)).toEqual('A1');
  581. expect(getDataAtCell(0, 1)).toEqual('B1');
  582. expect(getDataAtCell(1, 0)).toEqual('A2');
  583. expect(getDataAtCell(1, 1)).toEqual('B2');
  584. expect(getDataAtCell(2, 0)).toEqual('A3');
  585. expect(getDataAtCell(2, 1)).toEqual('B3');
  586. expect(getDataAtCell(3, 0)).toEqual('A4');
  587. expect(getDataAtCell(3, 1)).toEqual('B4');
  588. });
  589. it('should undo changes only for table where the change actually took place', function () {
  590. this.$container2 = $('<div id="' + id + '-2"></div>').appendTo('body');
  591. var hot1 = handsontable({
  592. data: [[1], [2], [3]]
  593. });
  594. this.$container2.handsontable({
  595. data: [['A'], ['B'], ['C']]
  596. });
  597. var hot2 = this.$container2.handsontable('getInstance');
  598. hot1.setDataAtCell(0, 0, 4);
  599. expect(hot1.getDataAtCell(0, 0)).toEqual(4);
  600. expect(hot2.getDataAtCell(0, 0)).toEqual('A');
  601. hot2.undo();
  602. expect(hot2.getDataAtCell(0, 0)).toEqual('A');
  603. expect(hot1.getDataAtCell(0, 0)).toEqual(4);
  604. hot1.undo();
  605. expect(hot2.getDataAtCell(0, 0)).toEqual('A');
  606. expect(hot1.getDataAtCell(0, 0)).toEqual(1);
  607. hot2.destroy();
  608. this.$container2.remove();
  609. });
  610. });
  611. describe('redo', function () {
  612. it('should redo single change', function () {
  613. handsontable({
  614. data: Handsontable.helper.createSpreadsheetData(2, 2)
  615. });
  616. var HOT = getInstance();
  617. setDataAtCell(0, 0, 'new value');
  618. expect(getDataAtCell(0, 0)).toBe('new value');
  619. HOT.undo();
  620. expect(getDataAtCell(0, 0)).toBe('A1');
  621. HOT.redo();
  622. expect(getDataAtCell(0, 0)).toBe('new value');
  623. });
  624. it('should redo single change in cell with validator', function (done) {
  625. handsontable({
  626. data: Handsontable.helper.createSpreadsheetData(2, 2)
  627. });
  628. var HOT = getInstance();
  629. setDataAtCell(0, 0, 'new value');
  630. setTimeout(function () {
  631. expect(getDataAtCell(0, 0)).toBe('new value');
  632. HOT.undo();
  633. }, 200);
  634. setTimeout(function () {
  635. expect(getDataAtCell(0, 0)).toBe('A1');
  636. HOT.redo();
  637. }, 400);
  638. setTimeout(function () {
  639. expect(getDataAtCell(0, 0)).toBe('new value');
  640. done();
  641. }, 600);
  642. });
  643. it('should redo creation of a single row', function () {
  644. var HOT = handsontable({
  645. data: Handsontable.helper.createSpreadsheetData(2, 2)
  646. });
  647. expect(countRows()).toEqual(2);
  648. alter('insert_row');
  649. expect(countRows()).toEqual(3);
  650. HOT.undo();
  651. expect(countRows()).toEqual(2);
  652. HOT.redo();
  653. expect(countRows()).toEqual(3);
  654. });
  655. it('should redo creation of multiple rows', function () {
  656. var HOT = handsontable({
  657. data: Handsontable.helper.createSpreadsheetData(2, 2)
  658. });
  659. expect(countRows()).toEqual(2);
  660. alter('insert_row', 0, 5);
  661. expect(countRows()).toEqual(7);
  662. HOT.undo();
  663. expect(countRows()).toEqual(2);
  664. HOT.redo();
  665. expect(countRows()).toEqual(7);
  666. });
  667. it('should redo removal of single row', function () {
  668. var HOT = handsontable({
  669. data: Handsontable.helper.createSpreadsheetData(3, 2)
  670. });
  671. expect(countRows()).toEqual(3);
  672. expect(getDataAtCell(0, 0)).toEqual('A1');
  673. expect(getDataAtCell(0, 1)).toEqual('B1');
  674. expect(getDataAtCell(1, 0)).toEqual('A2');
  675. expect(getDataAtCell(1, 1)).toEqual('B2');
  676. expect(getDataAtCell(2, 0)).toEqual('A3');
  677. expect(getDataAtCell(2, 1)).toEqual('B3');
  678. alter('remove_row', 1);
  679. expect(countRows()).toEqual(2);
  680. expect(getDataAtCell(0, 0)).toEqual('A1');
  681. expect(getDataAtCell(0, 1)).toEqual('B1');
  682. expect(getDataAtCell(1, 0)).toEqual('A3');
  683. expect(getDataAtCell(1, 1)).toEqual('B3');
  684. HOT.undo();
  685. expect(countRows()).toEqual(3);
  686. expect(getDataAtCell(0, 0)).toEqual('A1');
  687. expect(getDataAtCell(0, 1)).toEqual('B1');
  688. expect(getDataAtCell(1, 0)).toEqual('A2');
  689. expect(getDataAtCell(1, 1)).toEqual('B2');
  690. expect(getDataAtCell(2, 0)).toEqual('A3');
  691. expect(getDataAtCell(2, 1)).toEqual('B3');
  692. HOT.redo();
  693. expect(countRows()).toEqual(2);
  694. expect(getDataAtCell(0, 0)).toEqual('A1');
  695. expect(getDataAtCell(0, 1)).toEqual('B1');
  696. expect(getDataAtCell(1, 0)).toEqual('A3');
  697. expect(getDataAtCell(1, 1)).toEqual('B3');
  698. });
  699. it('should redo removal of multiple rows', function () {
  700. var HOT = handsontable({
  701. data: Handsontable.helper.createSpreadsheetData(4, 2)
  702. });
  703. expect(countRows()).toEqual(4);
  704. expect(getDataAtCell(0, 0)).toEqual('A1');
  705. expect(getDataAtCell(0, 1)).toEqual('B1');
  706. expect(getDataAtCell(1, 0)).toEqual('A2');
  707. expect(getDataAtCell(1, 1)).toEqual('B2');
  708. expect(getDataAtCell(2, 0)).toEqual('A3');
  709. expect(getDataAtCell(2, 1)).toEqual('B3');
  710. expect(getDataAtCell(3, 0)).toEqual('A4');
  711. expect(getDataAtCell(3, 1)).toEqual('B4');
  712. alter('remove_row', 1, 2);
  713. expect(countRows()).toEqual(2);
  714. expect(getDataAtCell(0, 0)).toEqual('A1');
  715. expect(getDataAtCell(0, 1)).toEqual('B1');
  716. expect(getDataAtCell(1, 0)).toEqual('A4');
  717. expect(getDataAtCell(1, 1)).toEqual('B4');
  718. HOT.undo();
  719. expect(countRows()).toEqual(4);
  720. expect(getDataAtCell(0, 0)).toEqual('A1');
  721. expect(getDataAtCell(0, 1)).toEqual('B1');
  722. expect(getDataAtCell(1, 0)).toEqual('A2');
  723. expect(getDataAtCell(1, 1)).toEqual('B2');
  724. expect(getDataAtCell(2, 0)).toEqual('A3');
  725. expect(getDataAtCell(2, 1)).toEqual('B3');
  726. expect(getDataAtCell(3, 0)).toEqual('A4');
  727. expect(getDataAtCell(3, 1)).toEqual('B4');
  728. HOT.redo();
  729. expect(countRows()).toEqual(2);
  730. expect(getDataAtCell(0, 0)).toEqual('A1');
  731. expect(getDataAtCell(0, 1)).toEqual('B1');
  732. expect(getDataAtCell(1, 0)).toEqual('A4');
  733. expect(getDataAtCell(1, 1)).toEqual('B4');
  734. });
  735. it('should redo creation of a single column', function () {
  736. var HOT = handsontable({
  737. data: Handsontable.helper.createSpreadsheetData(2, 2)
  738. });
  739. expect(countCols()).toEqual(2);
  740. alter('insert_col');
  741. expect(countCols()).toEqual(3);
  742. HOT.undo();
  743. expect(countCols()).toEqual(2);
  744. HOT.redo();
  745. expect(countCols()).toEqual(3);
  746. });
  747. it('should redo creation of multiple columns', function () {
  748. var HOT = handsontable({
  749. data: Handsontable.helper.createSpreadsheetData(2, 2)
  750. });
  751. expect(countCols()).toEqual(2);
  752. alter('insert_col', 1, 5);
  753. expect(countCols()).toEqual(7);
  754. HOT.undo();
  755. expect(countCols()).toEqual(2);
  756. HOT.redo();
  757. expect(countCols()).toEqual(7);
  758. });
  759. it('should redo removal of single column', function () {
  760. var HOT = handsontable({
  761. data: Handsontable.helper.createSpreadsheetData(2, 2)
  762. });
  763. expect(countCols()).toEqual(2);
  764. expect(getDataAtCell(0, 0)).toEqual('A1');
  765. expect(getDataAtCell(0, 1)).toEqual('B1');
  766. expect(getDataAtCell(1, 0)).toEqual('A2');
  767. expect(getDataAtCell(1, 1)).toEqual('B2');
  768. alter('remove_col');
  769. expect(countCols()).toEqual(1);
  770. expect(getDataAtCell(0, 0)).toEqual('A1');
  771. expect(getDataAtCell(0, 1)).toBeNull();
  772. expect(getDataAtCell(1, 0)).toEqual('A2');
  773. expect(getDataAtCell(1, 1)).toBeNull();
  774. HOT.undo();
  775. expect(countCols()).toEqual(2);
  776. expect(getDataAtCell(0, 0)).toEqual('A1');
  777. expect(getDataAtCell(0, 1)).toEqual('B1');
  778. expect(getDataAtCell(1, 0)).toEqual('A2');
  779. expect(getDataAtCell(1, 1)).toEqual('B2');
  780. HOT.redo();
  781. expect(countCols()).toEqual(1);
  782. expect(getDataAtCell(0, 0)).toEqual('A1');
  783. expect(getDataAtCell(0, 1)).toBeNull();
  784. expect(getDataAtCell(1, 0)).toEqual('A2');
  785. expect(getDataAtCell(1, 1)).toBeNull();
  786. });
  787. it('should redo removal of multiple columns', function () {
  788. var HOT = handsontable({
  789. data: Handsontable.helper.createSpreadsheetData(2, 4)
  790. });
  791. expect(countCols()).toEqual(4);
  792. expect(getDataAtCell(0, 0)).toEqual('A1');
  793. expect(getDataAtCell(0, 1)).toEqual('B1');
  794. expect(getDataAtCell(0, 2)).toEqual('C1');
  795. expect(getDataAtCell(0, 3)).toEqual('D1');
  796. expect(getDataAtCell(1, 0)).toEqual('A2');
  797. expect(getDataAtCell(1, 1)).toEqual('B2');
  798. expect(getDataAtCell(1, 2)).toEqual('C2');
  799. expect(getDataAtCell(1, 3)).toEqual('D2');
  800. alter('remove_col', 1, 3);
  801. expect(countCols()).toEqual(1);
  802. expect(getDataAtCell(0, 0)).toEqual('A1');
  803. expect(getDataAtCell(0, 1)).toBeNull();
  804. expect(getDataAtCell(0, 2)).toBeNull();
  805. expect(getDataAtCell(0, 3)).toBeNull();
  806. expect(getDataAtCell(1, 0)).toEqual('A2');
  807. expect(getDataAtCell(1, 1)).toBeNull();
  808. expect(getDataAtCell(1, 2)).toBeNull();
  809. expect(getDataAtCell(1, 3)).toBeNull();
  810. HOT.undo();
  811. expect(countCols()).toEqual(4);
  812. expect(getDataAtCell(0, 0)).toEqual('A1');
  813. expect(getDataAtCell(0, 1)).toEqual('B1');
  814. expect(getDataAtCell(0, 2)).toEqual('C1');
  815. expect(getDataAtCell(0, 3)).toEqual('D1');
  816. expect(getDataAtCell(1, 0)).toEqual('A2');
  817. expect(getDataAtCell(1, 1)).toEqual('B2');
  818. expect(getDataAtCell(1, 2)).toEqual('C2');
  819. expect(getDataAtCell(1, 3)).toEqual('D2');
  820. HOT.redo();
  821. expect(countCols()).toEqual(1);
  822. expect(getDataAtCell(0, 0)).toEqual('A1');
  823. expect(getDataAtCell(0, 1)).toBeNull();
  824. expect(getDataAtCell(0, 2)).toBeNull();
  825. expect(getDataAtCell(0, 3)).toBeNull();
  826. expect(getDataAtCell(1, 0)).toEqual('A2');
  827. expect(getDataAtCell(1, 1)).toBeNull();
  828. expect(getDataAtCell(1, 2)).toBeNull();
  829. expect(getDataAtCell(1, 3)).toBeNull();
  830. });
  831. it('should redo multiple changes', function () {
  832. handsontable({
  833. data: Handsontable.helper.createSpreadsheetData(2, 2)
  834. });
  835. var HOT = getInstance();
  836. setDataAtCell(0, 0, 'X1');
  837. setDataAtCell(1, 0, 'X2');
  838. setDataAtCell(0, 1, 'Y1');
  839. setDataAtCell(1, 1, 'Y2');
  840. expect(getDataAtCell(0, 0)).toBe('X1');
  841. expect(getDataAtCell(1, 0)).toBe('X2');
  842. expect(getDataAtCell(0, 1)).toBe('Y1');
  843. expect(getDataAtCell(1, 1)).toBe('Y2');
  844. HOT.undo();
  845. HOT.undo();
  846. HOT.undo();
  847. HOT.undo();
  848. expect(getDataAtCell(0, 0)).toBe('A1');
  849. expect(getDataAtCell(1, 0)).toBe('A2');
  850. expect(getDataAtCell(0, 1)).toBe('B1');
  851. expect(getDataAtCell(1, 1)).toBe('B2');
  852. HOT.redo();
  853. expect(getDataAtCell(0, 0)).toBe('X1');
  854. expect(getDataAtCell(1, 0)).toBe('A2');
  855. expect(getDataAtCell(0, 1)).toBe('B1');
  856. expect(getDataAtCell(1, 1)).toBe('B2');
  857. HOT.redo();
  858. expect(getDataAtCell(0, 0)).toBe('X1');
  859. expect(getDataAtCell(1, 0)).toBe('X2');
  860. expect(getDataAtCell(0, 1)).toBe('B1');
  861. expect(getDataAtCell(1, 1)).toBe('B2');
  862. HOT.redo();
  863. expect(getDataAtCell(0, 0)).toBe('X1');
  864. expect(getDataAtCell(1, 0)).toBe('X2');
  865. expect(getDataAtCell(0, 1)).toBe('Y1');
  866. expect(getDataAtCell(1, 1)).toBe('B2');
  867. HOT.redo();
  868. expect(getDataAtCell(0, 0)).toBe('X1');
  869. expect(getDataAtCell(1, 0)).toBe('X2');
  870. expect(getDataAtCell(0, 1)).toBe('Y1');
  871. expect(getDataAtCell(1, 1)).toBe('Y2');
  872. HOT.redo();
  873. expect(getDataAtCell(0, 0)).toBe('X1');
  874. expect(getDataAtCell(1, 0)).toBe('X2');
  875. expect(getDataAtCell(0, 1)).toBe('Y1');
  876. expect(getDataAtCell(1, 1)).toBe('Y2');
  877. });
  878. it('should redo multiple changes in cell with validator', function (done) {
  879. var HOT = handsontable({
  880. data: Handsontable.helper.createSpreadsheetData(2, 2)
  881. });
  882. setDataAtCell(0, 0, 'X1');
  883. setDataAtCell(1, 0, 'X2');
  884. setDataAtCell(0, 1, 'Y1');
  885. setDataAtCell(1, 1, 'Y2');
  886. setTimeout(function () {
  887. expect(getDataAtCell(0, 0)).toBe('X1');
  888. expect(getDataAtCell(1, 0)).toBe('X2');
  889. expect(getDataAtCell(0, 1)).toBe('Y1');
  890. expect(getDataAtCell(1, 1)).toBe('Y2');
  891. HOT.undo();
  892. }, 200);
  893. setTimeout(function () {
  894. HOT.undo();
  895. }, 400);
  896. setTimeout(function () {
  897. HOT.undo();
  898. }, 600);
  899. setTimeout(function () {
  900. HOT.undo();
  901. }, 800);
  902. setTimeout(function () {
  903. expect(getDataAtCell(0, 0)).toBe('A1');
  904. expect(getDataAtCell(1, 0)).toBe('A2');
  905. expect(getDataAtCell(0, 1)).toBe('B1');
  906. expect(getDataAtCell(1, 1)).toBe('B2');
  907. HOT.redo();
  908. }, 1000);
  909. setTimeout(function () {
  910. expect(getDataAtCell(0, 0)).toBe('X1');
  911. expect(getDataAtCell(1, 0)).toBe('A2');
  912. expect(getDataAtCell(0, 1)).toBe('B1');
  913. expect(getDataAtCell(1, 1)).toBe('B2');
  914. HOT.redo();
  915. }, 1200);
  916. setTimeout(function () {
  917. expect(getDataAtCell(0, 0)).toBe('X1');
  918. expect(getDataAtCell(1, 0)).toBe('X2');
  919. expect(getDataAtCell(0, 1)).toBe('B1');
  920. expect(getDataAtCell(1, 1)).toBe('B2');
  921. HOT.redo();
  922. }, 1400);
  923. setTimeout(function () {
  924. expect(getDataAtCell(0, 0)).toBe('X1');
  925. expect(getDataAtCell(1, 0)).toBe('X2');
  926. expect(getDataAtCell(0, 1)).toBe('Y1');
  927. expect(getDataAtCell(1, 1)).toBe('B2');
  928. HOT.redo();
  929. }, 1600);
  930. setTimeout(function () {
  931. expect(getDataAtCell(0, 0)).toBe('X1');
  932. expect(getDataAtCell(1, 0)).toBe('X2');
  933. expect(getDataAtCell(0, 1)).toBe('Y1');
  934. expect(getDataAtCell(1, 1)).toBe('Y2');
  935. HOT.redo();
  936. }, 1800);
  937. setTimeout(function () {
  938. expect(getDataAtCell(0, 0)).toBe('X1');
  939. expect(getDataAtCell(1, 0)).toBe('X2');
  940. expect(getDataAtCell(0, 1)).toBe('Y1');
  941. expect(getDataAtCell(1, 1)).toBe('Y2');
  942. done();
  943. }, 2000);
  944. });
  945. it('should redo multiple row creations', function () {
  946. var HOT = handsontable({
  947. data: Handsontable.helper.createSpreadsheetData(2, 2)
  948. });
  949. expect(countRows()).toEqual(2);
  950. alter('insert_row');
  951. alter('insert_row');
  952. alter('insert_row');
  953. alter('insert_row');
  954. expect(countRows()).toEqual(6);
  955. HOT.undo();
  956. HOT.undo();
  957. HOT.undo();
  958. HOT.undo();
  959. expect(countRows()).toEqual(2);
  960. HOT.redo();
  961. expect(countRows()).toEqual(3);
  962. HOT.redo();
  963. expect(countRows()).toEqual(4);
  964. HOT.redo();
  965. expect(countRows()).toEqual(5);
  966. HOT.redo();
  967. expect(countRows()).toEqual(6);
  968. HOT.redo();
  969. expect(countRows()).toEqual(6);
  970. });
  971. it('should undo multiple row removals', function () {
  972. var HOT = handsontable({
  973. data: Handsontable.helper.createSpreadsheetData(4, 2)
  974. });
  975. expect(countRows()).toEqual(4);
  976. expect(getDataAtCell(0, 0)).toEqual('A1');
  977. expect(getDataAtCell(0, 1)).toEqual('B1');
  978. expect(getDataAtCell(1, 0)).toEqual('A2');
  979. expect(getDataAtCell(1, 1)).toEqual('B2');
  980. expect(getDataAtCell(2, 0)).toEqual('A3');
  981. expect(getDataAtCell(2, 1)).toEqual('B3');
  982. expect(getDataAtCell(3, 0)).toEqual('A4');
  983. expect(getDataAtCell(3, 1)).toEqual('B4');
  984. alter('remove_row');
  985. alter('remove_row');
  986. alter('remove_row');
  987. expect(countRows()).toEqual(1);
  988. expect(getDataAtCell(0, 0)).toEqual('A1');
  989. expect(getDataAtCell(0, 1)).toEqual('B1');
  990. HOT.undo();
  991. HOT.undo();
  992. HOT.undo();
  993. expect(countRows()).toEqual(4);
  994. expect(getDataAtCell(0, 0)).toEqual('A1');
  995. expect(getDataAtCell(0, 1)).toEqual('B1');
  996. expect(getDataAtCell(1, 0)).toEqual('A2');
  997. expect(getDataAtCell(1, 1)).toEqual('B2');
  998. expect(getDataAtCell(2, 0)).toEqual('A3');
  999. expect(getDataAtCell(2, 1)).toEqual('B3');
  1000. expect(getDataAtCell(3, 0)).toEqual('A4');
  1001. expect(getDataAtCell(3, 1)).toEqual('B4');
  1002. HOT.redo();
  1003. expect(countRows()).toEqual(3);
  1004. expect(getDataAtCell(0, 0)).toEqual('A1');
  1005. expect(getDataAtCell(0, 1)).toEqual('B1');
  1006. expect(getDataAtCell(1, 0)).toEqual('A2');
  1007. expect(getDataAtCell(1, 1)).toEqual('B2');
  1008. expect(getDataAtCell(2, 0)).toEqual('A3');
  1009. expect(getDataAtCell(2, 1)).toEqual('B3');
  1010. HOT.redo();
  1011. expect(countRows()).toEqual(2);
  1012. expect(getDataAtCell(0, 0)).toEqual('A1');
  1013. expect(getDataAtCell(0, 1)).toEqual('B1');
  1014. expect(getDataAtCell(1, 0)).toEqual('A2');
  1015. expect(getDataAtCell(1, 1)).toEqual('B2');
  1016. HOT.redo();
  1017. expect(countRows()).toEqual(1);
  1018. expect(getDataAtCell(0, 0)).toEqual('A1');
  1019. expect(getDataAtCell(0, 1)).toEqual('B1');
  1020. HOT.redo();
  1021. expect(countRows()).toEqual(1);
  1022. expect(getDataAtCell(0, 0)).toEqual('A1');
  1023. expect(getDataAtCell(0, 1)).toEqual('B1');
  1024. });
  1025. it('should redo changes only for table where the change actually took place', function () {
  1026. this.$container2 = $('<div id="' + id + '-2"></div>').appendTo('body');
  1027. var hot1 = handsontable({
  1028. data: [[1], [2], [3]]
  1029. });
  1030. this.$container2.handsontable({
  1031. data: [['A'], ['B'], ['C']]
  1032. });
  1033. var hot2 = this.$container2.handsontable('getInstance');
  1034. hot1.setDataAtCell(0, 0, 4);
  1035. expect(hot1.getDataAtCell(0, 0)).toEqual(4);
  1036. expect(hot2.getDataAtCell(0, 0)).toEqual('A');
  1037. hot1.undo();
  1038. expect(hot1.getDataAtCell(0, 0)).toEqual(1);
  1039. expect(hot2.getDataAtCell(0, 0)).toEqual('A');
  1040. hot2.redo();
  1041. expect(hot1.getDataAtCell(0, 0)).toEqual(1);
  1042. expect(hot2.getDataAtCell(0, 0)).toEqual('A');
  1043. hot1.redo();
  1044. expect(hot1.getDataAtCell(0, 0)).toEqual(4);
  1045. expect(hot2.getDataAtCell(0, 0)).toEqual('A');
  1046. hot2.destroy();
  1047. this.$container2.remove();
  1048. });
  1049. });
  1050. });
  1051. describe('Object data', function () {
  1052. function createObjectData() {
  1053. return [{ name: 'Timothy', surname: 'Dalton' }, { name: 'Sean', surname: 'Connery' }, { name: 'Roger', surname: 'Moore' }];
  1054. }
  1055. describe('undo', function () {
  1056. it('should undo single change', function () {
  1057. handsontable({
  1058. data: createObjectData()
  1059. });
  1060. var HOT = getInstance();
  1061. setDataAtRowProp(0, 0, 'Pearce');
  1062. expect(getDataAtRowProp(0, 0)).toBe('Pearce');
  1063. HOT.undo();
  1064. expect(getDataAtCell(0, 0)).toBe('Timothy');
  1065. });
  1066. it('should undo single change in cell with validator', function (done) {
  1067. handsontable({
  1068. data: createObjectData()
  1069. });
  1070. var HOT = getInstance();
  1071. setDataAtRowProp(0, 0, 'Pearce');
  1072. setTimeout(function () {
  1073. expect(getDataAtRowProp(0, 0)).toBe('Pearce');
  1074. HOT.undo();
  1075. }, 200);
  1076. setTimeout(function () {
  1077. expect(getDataAtCell(0, 0)).toBe('Timothy');
  1078. done();
  1079. }, 400);
  1080. });
  1081. it('should undo creation of a single row', function () {
  1082. var HOT = handsontable({
  1083. data: createObjectData().slice(0, 2)
  1084. });
  1085. expect(countRows()).toEqual(2);
  1086. alter('insert_row');
  1087. expect(countRows()).toEqual(3);
  1088. HOT.undo();
  1089. expect(countRows()).toEqual(2);
  1090. });
  1091. it('should undo creation of multiple rows', function () {
  1092. var HOT = handsontable({
  1093. data: createObjectData().slice(0, 2)
  1094. });
  1095. expect(countRows()).toEqual(2);
  1096. alter('insert_row', 0, 5);
  1097. expect(countRows()).toEqual(7);
  1098. HOT.undo();
  1099. expect(countRows()).toEqual(2);
  1100. });
  1101. it('should undo removal of single row', function () {
  1102. var HOT = handsontable({
  1103. data: createObjectData().slice(0, 2)
  1104. });
  1105. expect(countRows()).toEqual(2);
  1106. expect(getDataAtRowProp(0, 'name')).toEqual('Timothy');
  1107. expect(getDataAtRowProp(0, 'surname')).toEqual('Dalton');
  1108. expect(getDataAtRowProp(1, 'name')).toEqual('Sean');
  1109. expect(getDataAtRowProp(1, 'surname')).toEqual('Connery');
  1110. alter('remove_row');
  1111. expect(countRows()).toEqual(1);
  1112. expect(getDataAtRowProp(0, 'name')).toEqual('Timothy');
  1113. expect(getDataAtRowProp(0, 'surname')).toEqual('Dalton');
  1114. expect(getDataAtRowProp(1, 'name')).toBeNull();
  1115. expect(getDataAtRowProp(1, 'surname')).toBeNull();
  1116. HOT.undo();
  1117. expect(countRows()).toEqual(2);
  1118. expect(getDataAtRowProp(0, 'name')).toEqual('Timothy');
  1119. expect(getDataAtRowProp(0, 'surname')).toEqual('Dalton');
  1120. expect(getDataAtRowProp(1, 'name')).toEqual('Sean');
  1121. expect(getDataAtRowProp(1, 'surname')).toEqual('Connery');
  1122. });
  1123. it('should undo removal of multiple rows', function () {
  1124. var HOT = handsontable({
  1125. data: createObjectData()
  1126. });
  1127. expect(countRows()).toEqual(3);
  1128. expect(getDataAtRowProp(0, 'name')).toEqual('Timothy');
  1129. expect(getDataAtRowProp(0, 'surname')).toEqual('Dalton');
  1130. expect(getDataAtRowProp(1, 'name')).toEqual('Sean');
  1131. expect(getDataAtRowProp(1, 'surname')).toEqual('Connery');
  1132. expect(getDataAtRowProp(2, 'name')).toEqual('Roger');
  1133. expect(getDataAtRowProp(2, 'surname')).toEqual('Moore');
  1134. alter('remove_row', 1, 2);
  1135. expect(countRows()).toEqual(1);
  1136. expect(getDataAtRowProp(0, 'name')).toEqual('Timothy');
  1137. expect(getDataAtRowProp(0, 'surname')).toEqual('Dalton');
  1138. expect(getDataAtRowProp(1, 'name')).toBeNull();
  1139. expect(getDataAtRowProp(1, 'surname')).toBeNull();
  1140. expect(getDataAtRowProp(2, 'name')).toBeNull();
  1141. expect(getDataAtRowProp(2, 'surname')).toBeNull();
  1142. HOT.undo();
  1143. expect(countRows()).toEqual(3);
  1144. expect(getDataAtRowProp(0, 'name')).toEqual('Timothy');
  1145. expect(getDataAtRowProp(0, 'surname')).toEqual('Dalton');
  1146. expect(getDataAtRowProp(1, 'name')).toEqual('Sean');
  1147. expect(getDataAtRowProp(1, 'surname')).toEqual('Connery');
  1148. expect(getDataAtRowProp(2, 'name')).toEqual('Roger');
  1149. expect(getDataAtRowProp(2, 'surname')).toEqual('Moore');
  1150. });
  1151. it('should undo multiple changes', function () {
  1152. handsontable({
  1153. data: createObjectData().slice(0, 2)
  1154. });
  1155. var HOT = getInstance();
  1156. setDataAtRowProp(0, 'name', 'Pierce');
  1157. setDataAtRowProp(0, 'surname', 'Brosnan');
  1158. setDataAtRowProp(1, 'name', 'Daniel');
  1159. setDataAtRowProp(1, 'surname', 'Craig');
  1160. expect(getDataAtRowProp(0, 'name')).toBe('Pierce');
  1161. expect(getDataAtRowProp(0, 'surname')).toBe('Brosnan');
  1162. expect(getDataAtRowProp(1, 'name')).toBe('Daniel');
  1163. expect(getDataAtRowProp(1, 'surname')).toBe('Craig');
  1164. HOT.undo();
  1165. expect(getDataAtRowProp(0, 'name')).toBe('Pierce');
  1166. expect(getDataAtRowProp(0, 'surname')).toBe('Brosnan');
  1167. expect(getDataAtRowProp(1, 'name')).toBe('Daniel');
  1168. expect(getDataAtRowProp(1, 'surname')).toBe('Connery');
  1169. HOT.undo();
  1170. expect(getDataAtRowProp(0, 'name')).toBe('Pierce');
  1171. expect(getDataAtRowProp(0, 'surname')).toBe('Brosnan');
  1172. expect(getDataAtRowProp(1, 'name')).toBe('Sean');
  1173. expect(getDataAtRowProp(1, 'surname')).toBe('Connery');
  1174. HOT.undo();
  1175. expect(getDataAtRowProp(0, 'name')).toBe('Pierce');
  1176. expect(getDataAtRowProp(0, 'surname')).toBe('Dalton');
  1177. expect(getDataAtRowProp(1, 'name')).toBe('Sean');
  1178. expect(getDataAtRowProp(1, 'surname')).toBe('Connery');
  1179. HOT.undo();
  1180. expect(getDataAtRowProp(0, 'name')).toBe('Timothy');
  1181. expect(getDataAtRowProp(0, 'surname')).toBe('Dalton');
  1182. expect(getDataAtRowProp(1, 'name')).toBe('Sean');
  1183. expect(getDataAtRowProp(1, 'surname')).toBe('Connery');
  1184. HOT.undo();
  1185. expect(getDataAtRowProp(0, 'name')).toBe('Timothy');
  1186. expect(getDataAtRowProp(0, 'surname')).toBe('Dalton');
  1187. expect(getDataAtRowProp(1, 'name')).toBe('Sean');
  1188. expect(getDataAtRowProp(1, 'surname')).toBe('Connery');
  1189. });
  1190. it('should undo multiple changes in cells with validators', function (done) {
  1191. handsontable({
  1192. data: createObjectData().slice(0, 2)
  1193. });
  1194. var HOT = getInstance();
  1195. setDataAtRowProp(0, 'name', 'Pierce');
  1196. setDataAtRowProp(0, 'surname', 'Brosnan');
  1197. setDataAtRowProp(1, 'name', 'Daniel');
  1198. setDataAtRowProp(1, 'surname', 'Craig');
  1199. setTimeout(function () {
  1200. expect(getDataAtRowProp(0, 'name')).toBe('Pierce');
  1201. expect(getDataAtRowProp(0, 'surname')).toBe('Brosnan');
  1202. expect(getDataAtRowProp(1, 'name')).toBe('Daniel');
  1203. expect(getDataAtRowProp(1, 'surname')).toBe('Craig');
  1204. HOT.undo();
  1205. }, 200);
  1206. setTimeout(function () {
  1207. expect(getDataAtRowProp(0, 'name')).toBe('Pierce');
  1208. expect(getDataAtRowProp(0, 'surname')).toBe('Brosnan');
  1209. expect(getDataAtRowProp(1, 'name')).toBe('Daniel');
  1210. expect(getDataAtRowProp(1, 'surname')).toBe('Connery');
  1211. HOT.undo();
  1212. }, 400);
  1213. setTimeout(function () {
  1214. expect(getDataAtRowProp(0, 'name')).toBe('Pierce');
  1215. expect(getDataAtRowProp(0, 'surname')).toBe('Brosnan');
  1216. expect(getDataAtRowProp(1, 'name')).toBe('Sean');
  1217. expect(getDataAtRowProp(1, 'surname')).toBe('Connery');
  1218. HOT.undo();
  1219. }, 600);
  1220. setTimeout(function () {
  1221. expect(getDataAtRowProp(0, 'name')).toBe('Pierce');
  1222. expect(getDataAtRowProp(0, 'surname')).toBe('Dalton');
  1223. expect(getDataAtRowProp(1, 'name')).toBe('Sean');
  1224. expect(getDataAtRowProp(1, 'surname')).toBe('Connery');
  1225. HOT.undo();
  1226. }, 800);
  1227. setTimeout(function () {
  1228. expect(getDataAtRowProp(0, 'name')).toBe('Timothy');
  1229. expect(getDataAtRowProp(0, 'surname')).toBe('Dalton');
  1230. expect(getDataAtRowProp(1, 'name')).toBe('Sean');
  1231. expect(getDataAtRowProp(1, 'surname')).toBe('Connery');
  1232. HOT.undo();
  1233. }, 1000);
  1234. setTimeout(function () {
  1235. expect(getDataAtRowProp(0, 'name')).toBe('Timothy');
  1236. expect(getDataAtRowProp(0, 'surname')).toBe('Dalton');
  1237. expect(getDataAtRowProp(1, 'name')).toBe('Sean');
  1238. expect(getDataAtRowProp(1, 'surname')).toBe('Connery');
  1239. done();
  1240. }, 1200);
  1241. });
  1242. it('should undo multiple row creations', function () {
  1243. var HOT = handsontable({
  1244. data: createObjectData().slice(0, 2)
  1245. });
  1246. expect(countRows()).toEqual(2);
  1247. alter('insert_row');
  1248. alter('insert_row');
  1249. alter('insert_row');
  1250. alter('insert_row');
  1251. expect(countRows()).toEqual(6);
  1252. HOT.undo();
  1253. expect(countRows()).toEqual(5);
  1254. HOT.undo();
  1255. expect(countRows()).toEqual(4);
  1256. HOT.undo();
  1257. expect(countRows()).toEqual(3);
  1258. HOT.undo();
  1259. expect(countRows()).toEqual(2);
  1260. HOT.undo();
  1261. expect(countRows()).toEqual(2);
  1262. });
  1263. it('should undo multiple row removals', function () {
  1264. var HOT = handsontable({
  1265. data: createObjectData()
  1266. });
  1267. expect(countRows()).toEqual(3);
  1268. expect(getDataAtRowProp(0, 'name')).toEqual('Timothy');
  1269. expect(getDataAtRowProp(0, 'surname')).toEqual('Dalton');
  1270. expect(getDataAtRowProp(1, 'name')).toEqual('Sean');
  1271. expect(getDataAtRowProp(1, 'surname')).toEqual('Connery');
  1272. expect(getDataAtRowProp(2, 'name')).toEqual('Roger');
  1273. expect(getDataAtRowProp(2, 'surname')).toEqual('Moore');
  1274. alter('remove_row');
  1275. alter('remove_row');
  1276. expect(countRows()).toEqual(1);
  1277. expect(getDataAtRowProp(0, 'name')).toEqual('Timothy');
  1278. expect(getDataAtRowProp(0, 'surname')).toEqual('Dalton');
  1279. HOT.undo();
  1280. expect(countRows()).toEqual(2);
  1281. expect(getDataAtRowProp(0, 'name')).toEqual('Timothy');
  1282. expect(getDataAtRowProp(0, 'surname')).toEqual('Dalton');
  1283. expect(getDataAtRowProp(1, 'name')).toEqual('Sean');
  1284. expect(getDataAtRowProp(1, 'surname')).toEqual('Connery');
  1285. HOT.undo();
  1286. expect(countRows()).toEqual(3);
  1287. expect(getDataAtRowProp(0, 'name')).toEqual('Timothy');
  1288. expect(getDataAtRowProp(0, 'surname')).toEqual('Dalton');
  1289. expect(getDataAtRowProp(1, 'name')).toEqual('Sean');
  1290. expect(getDataAtRowProp(1, 'surname')).toEqual('Connery');
  1291. expect(getDataAtRowProp(2, 'name')).toEqual('Roger');
  1292. expect(getDataAtRowProp(2, 'surname')).toEqual('Moore');
  1293. HOT.undo();
  1294. expect(countRows()).toEqual(3);
  1295. expect(getDataAtRowProp(0, 'name')).toEqual('Timothy');
  1296. expect(getDataAtRowProp(0, 'surname')).toEqual('Dalton');
  1297. expect(getDataAtRowProp(1, 'name')).toEqual('Sean');
  1298. expect(getDataAtRowProp(1, 'surname')).toEqual('Connery');
  1299. expect(getDataAtRowProp(2, 'name')).toEqual('Roger');
  1300. expect(getDataAtRowProp(2, 'surname')).toEqual('Moore');
  1301. });
  1302. });
  1303. describe('redo', function () {
  1304. it('should redo single change', function () {
  1305. handsontable({
  1306. data: createObjectData()
  1307. });
  1308. var HOT = getInstance();
  1309. setDataAtRowProp(0, 0, 'Pearce');
  1310. expect(getDataAtRowProp(0, 0)).toBe('Pearce');
  1311. HOT.undo();
  1312. expect(getDataAtCell(0, 0)).toBe('Timothy');
  1313. HOT.redo();
  1314. expect(getDataAtRowProp(0, 0)).toBe('Pearce');
  1315. });
  1316. it('should redo single change in cell with validator', function (done) {
  1317. handsontable({
  1318. data: createObjectData()
  1319. });
  1320. var HOT = getInstance();
  1321. setDataAtRowProp(0, 0, 'Pearce');
  1322. setTimeout(function () {
  1323. expect(getDataAtRowProp(0, 0)).toBe('Pearce');
  1324. HOT.undo();
  1325. }, 200);
  1326. setTimeout(function () {
  1327. expect(getDataAtCell(0, 0)).toBe('Timothy');
  1328. HOT.redo();
  1329. }, 400);
  1330. setTimeout(function () {
  1331. expect(getDataAtRowProp(0, 0)).toBe('Pearce');
  1332. done();
  1333. }, 600);
  1334. });
  1335. it('should redo creation of a single row', function () {
  1336. var HOT = handsontable({
  1337. data: createObjectData().slice(0, 2)
  1338. });
  1339. expect(countRows()).toEqual(2);
  1340. alter('insert_row');
  1341. expect(countRows()).toEqual(3);
  1342. HOT.undo();
  1343. expect(countRows()).toEqual(2);
  1344. HOT.redo();
  1345. expect(countRows()).toEqual(3);
  1346. });
  1347. it('should redo creation of multiple rows', function () {
  1348. var HOT = handsontable({
  1349. data: createObjectData().slice(0, 2)
  1350. });
  1351. expect(countRows()).toEqual(2);
  1352. alter('insert_row', 0, 5);
  1353. expect(countRows()).toEqual(7);
  1354. HOT.undo();
  1355. expect(countRows()).toEqual(2);
  1356. HOT.redo();
  1357. expect(countRows()).toEqual(7);
  1358. });
  1359. it('should redo removal of single row', function () {
  1360. var HOT = handsontable({
  1361. data: createObjectData().slice(0, 2)
  1362. });
  1363. expect(countRows()).toEqual(2);
  1364. expect(getDataAtRowProp(0, 'name')).toEqual('Timothy');
  1365. expect(getDataAtRowProp(0, 'surname')).toEqual('Dalton');
  1366. expect(getDataAtRowProp(1, 'name')).toEqual('Sean');
  1367. expect(getDataAtRowProp(1, 'surname')).toEqual('Connery');
  1368. alter('remove_row');
  1369. expect(countRows()).toEqual(1);
  1370. expect(getDataAtRowProp(0, 'name')).toEqual('Timothy');
  1371. expect(getDataAtRowProp(0, 'surname')).toEqual('Dalton');
  1372. expect(getDataAtRowProp(1, 'name')).toBeNull();
  1373. expect(getDataAtRowProp(1, 'surname')).toBeNull();
  1374. HOT.undo();
  1375. expect(countRows()).toEqual(2);
  1376. expect(getDataAtRowProp(0, 'name')).toEqual('Timothy');
  1377. expect(getDataAtRowProp(0, 'surname')).toEqual('Dalton');
  1378. expect(getDataAtRowProp(1, 'name')).toEqual('Sean');
  1379. expect(getDataAtRowProp(1, 'surname')).toEqual('Connery');
  1380. HOT.redo();
  1381. expect(countRows()).toEqual(1);
  1382. expect(getDataAtRowProp(0, 'name')).toEqual('Timothy');
  1383. expect(getDataAtRowProp(0, 'surname')).toEqual('Dalton');
  1384. expect(getDataAtRowProp(1, 'name')).toBeNull();
  1385. expect(getDataAtRowProp(1, 'surname')).toBeNull();
  1386. });
  1387. it('should redo removal of multiple rows', function () {
  1388. var HOT = handsontable({
  1389. data: createObjectData()
  1390. });
  1391. expect(countRows()).toEqual(3);
  1392. expect(getDataAtRowProp(0, 'name')).toEqual('Timothy');
  1393. expect(getDataAtRowProp(0, 'surname')).toEqual('Dalton');
  1394. expect(getDataAtRowProp(1, 'name')).toEqual('Sean');
  1395. expect(getDataAtRowProp(1, 'surname')).toEqual('Connery');
  1396. expect(getDataAtRowProp(2, 'name')).toEqual('Roger');
  1397. expect(getDataAtRowProp(2, 'surname')).toEqual('Moore');
  1398. alter('remove_row', 1, 2);
  1399. expect(countRows()).toEqual(1);
  1400. expect(getDataAtRowProp(0, 'name')).toEqual('Timothy');
  1401. expect(getDataAtRowProp(0, 'surname')).toEqual('Dalton');
  1402. expect(getDataAtRowProp(1, 'name')).toBeNull();
  1403. expect(getDataAtRowProp(1, 'surname')).toBeNull();
  1404. expect(getDataAtRowProp(2, 'name')).toBeNull();
  1405. expect(getDataAtRowProp(2, 'surname')).toBeNull();
  1406. HOT.undo();
  1407. expect(countRows()).toEqual(3);
  1408. expect(getDataAtRowProp(0, 'name')).toEqual('Timothy');
  1409. expect(getDataAtRowProp(0, 'surname')).toEqual('Dalton');
  1410. expect(getDataAtRowProp(1, 'name')).toEqual('Sean');
  1411. expect(getDataAtRowProp(1, 'surname')).toEqual('Connery');
  1412. expect(getDataAtRowProp(2, 'name')).toEqual('Roger');
  1413. expect(getDataAtRowProp(2, 'surname')).toEqual('Moore');
  1414. HOT.redo();
  1415. expect(countRows()).toEqual(1);
  1416. expect(getDataAtRowProp(0, 'name')).toEqual('Timothy');
  1417. expect(getDataAtRowProp(0, 'surname')).toEqual('Dalton');
  1418. expect(getDataAtRowProp(1, 'name')).toBeNull();
  1419. expect(getDataAtRowProp(1, 'surname')).toBeNull();
  1420. expect(getDataAtRowProp(2, 'name')).toBeNull();
  1421. expect(getDataAtRowProp(2, 'surname')).toBeNull();
  1422. });
  1423. it('should redo multiple changes', function () {
  1424. handsontable({
  1425. data: createObjectData().slice(0, 2)
  1426. });
  1427. var HOT = getInstance();
  1428. setDataAtRowProp(0, 'name', 'Pierce');
  1429. setDataAtRowProp(0, 'surname', 'Brosnan');
  1430. setDataAtRowProp(1, 'name', 'Daniel');
  1431. setDataAtRowProp(1, 'surname', 'Craig');
  1432. expect(getDataAtRowProp(0, 'name')).toBe('Pierce');
  1433. expect(getDataAtRowProp(0, 'surname')).toBe('Brosnan');
  1434. expect(getDataAtRowProp(1, 'name')).toBe('Daniel');
  1435. expect(getDataAtRowProp(1, 'surname')).toBe('Craig');
  1436. HOT.undo();
  1437. HOT.undo();
  1438. HOT.undo();
  1439. HOT.undo();
  1440. expect(getDataAtRowProp(0, 'name')).toBe('Timothy');
  1441. expect(getDataAtRowProp(0, 'surname')).toBe('Dalton');
  1442. expect(getDataAtRowProp(1, 'name')).toBe('Sean');
  1443. expect(getDataAtRowProp(1, 'surname')).toBe('Connery');
  1444. HOT.redo();
  1445. expect(getDataAtRowProp(0, 'name')).toBe('Pierce');
  1446. expect(getDataAtRowProp(0, 'surname')).toBe('Dalton');
  1447. expect(getDataAtRowProp(1, 'name')).toBe('Sean');
  1448. expect(getDataAtRowProp(1, 'surname')).toBe('Connery');
  1449. HOT.redo();
  1450. expect(getDataAtRowProp(0, 'name')).toBe('Pierce');
  1451. expect(getDataAtRowProp(0, 'surname')).toBe('Brosnan');
  1452. expect(getDataAtRowProp(1, 'name')).toBe('Sean');
  1453. expect(getDataAtRowProp(1, 'surname')).toBe('Connery');
  1454. HOT.redo();
  1455. expect(getDataAtRowProp(0, 'name')).toBe('Pierce');
  1456. expect(getDataAtRowProp(0, 'surname')).toBe('Brosnan');
  1457. expect(getDataAtRowProp(1, 'name')).toBe('Daniel');
  1458. expect(getDataAtRowProp(1, 'surname')).toBe('Connery');
  1459. HOT.redo();
  1460. expect(getDataAtRowProp(0, 'name')).toBe('Pierce');
  1461. expect(getDataAtRowProp(0, 'surname')).toBe('Brosnan');
  1462. expect(getDataAtRowProp(1, 'name')).toBe('Daniel');
  1463. expect(getDataAtRowProp(1, 'surname')).toBe('Craig');
  1464. HOT.redo();
  1465. expect(getDataAtRowProp(0, 'name')).toBe('Pierce');
  1466. expect(getDataAtRowProp(0, 'surname')).toBe('Brosnan');
  1467. expect(getDataAtRowProp(1, 'name')).toBe('Daniel');
  1468. expect(getDataAtRowProp(1, 'surname')).toBe('Craig');
  1469. });
  1470. it('should redo multiple changes in cells with validators', function (done) {
  1471. handsontable({
  1472. data: createObjectData().slice(0, 2)
  1473. });
  1474. var HOT = getInstance();
  1475. setDataAtRowProp(0, 'name', 'Pierce');
  1476. setDataAtRowProp(0, 'surname', 'Brosnan');
  1477. setDataAtRowProp(1, 'name', 'Daniel');
  1478. setDataAtRowProp(1, 'surname', 'Craig');
  1479. setTimeout(function () {
  1480. expect(getDataAtRowProp(0, 'name')).toBe('Pierce');
  1481. expect(getDataAtRowProp(0, 'surname')).toBe('Brosnan');
  1482. expect(getDataAtRowProp(1, 'name')).toBe('Daniel');
  1483. expect(getDataAtRowProp(1, 'surname')).toBe('Craig');
  1484. HOT.undo();
  1485. }, 200);
  1486. setTimeout(function () {
  1487. HOT.undo();
  1488. }, 400);
  1489. setTimeout(function () {
  1490. HOT.undo();
  1491. }, 600);
  1492. setTimeout(function () {
  1493. HOT.undo();
  1494. }, 800);
  1495. setTimeout(function () {
  1496. expect(getDataAtRowProp(0, 'name')).toBe('Timothy');
  1497. expect(getDataAtRowProp(0, 'surname')).toBe('Dalton');
  1498. expect(getDataAtRowProp(1, 'name')).toBe('Sean');
  1499. expect(getDataAtRowProp(1, 'surname')).toBe('Connery');
  1500. HOT.redo();
  1501. }, 1000);
  1502. setTimeout(function () {
  1503. expect(getDataAtRowProp(0, 'name')).toBe('Pierce');
  1504. expect(getDataAtRowProp(0, 'surname')).toBe('Dalton');
  1505. expect(getDataAtRowProp(1, 'name')).toBe('Sean');
  1506. expect(getDataAtRowProp(1, 'surname')).toBe('Connery');
  1507. HOT.redo();
  1508. }, 1200);
  1509. setTimeout(function () {
  1510. expect(getDataAtRowProp(0, 'name')).toBe('Pierce');
  1511. expect(getDataAtRowProp(0, 'surname')).toBe('Brosnan');
  1512. expect(getDataAtRowProp(1, 'name')).toBe('Sean');
  1513. expect(getDataAtRowProp(1, 'surname')).toBe('Connery');
  1514. HOT.redo();
  1515. }, 1400);
  1516. setTimeout(function () {
  1517. expect(getDataAtRowProp(0, 'name')).toBe('Pierce');
  1518. expect(getDataAtRowProp(0, 'surname')).toBe('Brosnan');
  1519. expect(getDataAtRowProp(1, 'name')).toBe('Daniel');
  1520. expect(getDataAtRowProp(1, 'surname')).toBe('Connery');
  1521. HOT.redo();
  1522. }, 1600);
  1523. setTimeout(function () {
  1524. expect(getDataAtRowProp(0, 'name')).toBe('Pierce');
  1525. expect(getDataAtRowProp(0, 'surname')).toBe('Brosnan');
  1526. expect(getDataAtRowProp(1, 'name')).toBe('Daniel');
  1527. expect(getDataAtRowProp(1, 'surname')).toBe('Craig');
  1528. HOT.redo();
  1529. }, 1800);
  1530. setTimeout(function () {
  1531. expect(getDataAtRowProp(0, 'name')).toBe('Pierce');
  1532. expect(getDataAtRowProp(0, 'surname')).toBe('Brosnan');
  1533. expect(getDataAtRowProp(1, 'name')).toBe('Daniel');
  1534. expect(getDataAtRowProp(1, 'surname')).toBe('Craig');
  1535. done();
  1536. }, 2000);
  1537. });
  1538. it('should redo multiple row creations', function () {
  1539. var HOT = handsontable({
  1540. data: createObjectData().slice(0, 2)
  1541. });
  1542. expect(countRows()).toEqual(2);
  1543. alter('insert_row');
  1544. alter('insert_row');
  1545. alter('insert_row');
  1546. alter('insert_row');
  1547. expect(countRows()).toEqual(6);
  1548. HOT.undo();
  1549. HOT.undo();
  1550. HOT.undo();
  1551. HOT.undo();
  1552. expect(countRows()).toEqual(2);
  1553. HOT.redo();
  1554. expect(countRows()).toEqual(3);
  1555. HOT.redo();
  1556. expect(countRows()).toEqual(4);
  1557. HOT.redo();
  1558. expect(countRows()).toEqual(5);
  1559. HOT.redo();
  1560. expect(countRows()).toEqual(6);
  1561. HOT.redo();
  1562. expect(countRows()).toEqual(6);
  1563. });
  1564. it('should undo multiple row removals', function () {
  1565. var HOT = handsontable({
  1566. data: createObjectData()
  1567. });
  1568. expect(countRows()).toEqual(3);
  1569. expect(getDataAtRowProp(0, 'name')).toEqual('Timothy');
  1570. expect(getDataAtRowProp(0, 'surname')).toEqual('Dalton');
  1571. expect(getDataAtRowProp(1, 'name')).toEqual('Sean');
  1572. expect(getDataAtRowProp(1, 'surname')).toEqual('Connery');
  1573. expect(getDataAtRowProp(2, 'name')).toEqual('Roger');
  1574. expect(getDataAtRowProp(2, 'surname')).toEqual('Moore');
  1575. alter('remove_row');
  1576. alter('remove_row');
  1577. expect(countRows()).toEqual(1);
  1578. expect(getDataAtRowProp(0, 'name')).toEqual('Timothy');
  1579. expect(getDataAtRowProp(0, 'surname')).toEqual('Dalton');
  1580. HOT.undo();
  1581. HOT.undo();
  1582. HOT.undo();
  1583. expect(countRows()).toEqual(3);
  1584. expect(getDataAtRowProp(0, 'name')).toEqual('Timothy');
  1585. expect(getDataAtRowProp(0, 'surname')).toEqual('Dalton');
  1586. expect(getDataAtRowProp(1, 'name')).toEqual('Sean');
  1587. expect(getDataAtRowProp(1, 'surname')).toEqual('Connery');
  1588. expect(getDataAtRowProp(2, 'name')).toEqual('Roger');
  1589. expect(getDataAtRowProp(2, 'surname')).toEqual('Moore');
  1590. HOT.redo();
  1591. expect(countRows()).toEqual(2);
  1592. expect(getDataAtRowProp(0, 'name')).toEqual('Timothy');
  1593. expect(getDataAtRowProp(0, 'surname')).toEqual('Dalton');
  1594. expect(getDataAtRowProp(1, 'name')).toEqual('Sean');
  1595. expect(getDataAtRowProp(1, 'surname')).toEqual('Connery');
  1596. HOT.redo();
  1597. expect(countRows()).toEqual(1);
  1598. expect(getDataAtRowProp(0, 'name')).toEqual('Timothy');
  1599. expect(getDataAtRowProp(0, 'surname')).toEqual('Dalton');
  1600. HOT.redo();
  1601. expect(countRows()).toEqual(1);
  1602. expect(getDataAtRowProp(0, 'name')).toEqual('Timothy');
  1603. expect(getDataAtRowProp(0, 'surname')).toEqual('Dalton');
  1604. });
  1605. });
  1606. });
  1607. });
  1608. describe('plugin features', function () {
  1609. describe('cell alignment', function () {
  1610. it('should undo a sequence of aligning cells', function () {
  1611. var hot = handsontable({
  1612. data: Handsontable.helper.createSpreadsheetData(9, 9),
  1613. contextMenu: true,
  1614. colWidths: [50, 50, 50, 50, 50, 50, 50, 50, 50],
  1615. rowHeights: [50, 50, 50, 50, 50, 50, 50, 50, 50]
  1616. });
  1617. // top 3 rows center
  1618. selectCell(0, 0, 2, 8);
  1619. hot.getPlugin('contextMenu').executeCommand('alignment:center');
  1620. // middle 3 rows unchanged - left
  1621. // bottom 3 rows right
  1622. selectCell(6, 0, 8, 8);
  1623. hot.getPlugin('contextMenu').executeCommand('alignment:right');
  1624. // left 3 columns - middle
  1625. selectCell(0, 0, 8, 2);
  1626. hot.getPlugin('contextMenu').executeCommand('alignment:middle');
  1627. // middle 3 columns unchanged - top
  1628. // right 3 columns - bottom
  1629. selectCell(0, 6, 8, 8);
  1630. hot.getPlugin('contextMenu').executeCommand('alignment:bottom');
  1631. var cellMeta = hot.getCellMeta(0, 0);
  1632. expect(cellMeta.className.indexOf('htCenter')).toBeGreaterThan(-1);
  1633. expect(cellMeta.className.indexOf('htMiddle')).toBeGreaterThan(-1);
  1634. cellMeta = hot.getCellMeta(0, 7);
  1635. expect(cellMeta.className.indexOf('htCenter')).toBeGreaterThan(-1);
  1636. expect(cellMeta.className.indexOf('htBottom')).toBeGreaterThan(-1);
  1637. cellMeta = hot.getCellMeta(5, 1);
  1638. expect(cellMeta.className.indexOf('htMiddle')).toBeGreaterThan(-1);
  1639. cellMeta = hot.getCellMeta(5, 7);
  1640. expect(cellMeta.className.indexOf('htBottom')).toBeGreaterThan(-1);
  1641. cellMeta = hot.getCellMeta(7, 1);
  1642. expect(cellMeta.className.indexOf('htRight')).toBeGreaterThan(-1);
  1643. expect(cellMeta.className.indexOf('htMiddle')).toBeGreaterThan(-1);
  1644. cellMeta = hot.getCellMeta(7, 5);
  1645. expect(cellMeta.className.indexOf('htRight')).toBeGreaterThan(-1);
  1646. cellMeta = hot.getCellMeta(7, 7);
  1647. expect(cellMeta.className.indexOf('htRight')).toBeGreaterThan(-1);
  1648. expect(cellMeta.className.indexOf('htBottom')).toBeGreaterThan(-1);
  1649. hot.undo();
  1650. cellMeta = hot.getCellMeta(0, 7);
  1651. expect(cellMeta.className.indexOf('htCenter')).toBeGreaterThan(-1);
  1652. expect(cellMeta.className.indexOf('htBottom')).toEqual(-1);
  1653. cellMeta = hot.getCellMeta(5, 7);
  1654. expect(cellMeta.className.indexOf('htBottom')).toEqual(-1);
  1655. cellMeta = hot.getCellMeta(7, 7);
  1656. expect(cellMeta.className.indexOf('htRight')).toBeGreaterThan(-1);
  1657. expect(cellMeta.className.indexOf('htBottom')).toEqual(-1);
  1658. hot.undo();
  1659. cellMeta = hot.getCellMeta(0, 0);
  1660. expect(cellMeta.className.indexOf('htCenter')).toBeGreaterThan(-1);
  1661. expect(cellMeta.className.indexOf('htMiddle')).toEqual(-1);
  1662. cellMeta = hot.getCellMeta(5, 1);
  1663. expect(cellMeta.className.indexOf('htMiddle')).toEqual(-1);
  1664. cellMeta = hot.getCellMeta(7, 1);
  1665. expect(cellMeta.className.indexOf('htRight')).toBeGreaterThan(-1);
  1666. expect(cellMeta.className.indexOf('htMiddle')).toEqual(-1);
  1667. hot.undo();
  1668. cellMeta = hot.getCellMeta(7, 1);
  1669. expect(cellMeta.className.indexOf('htRight')).toEqual(-1);
  1670. expect(cellMeta.className.indexOf('htMiddle')).toEqual(-1);
  1671. cellMeta = hot.getCellMeta(7, 5);
  1672. expect(cellMeta.className.indexOf('htRight')).toEqual(-1);
  1673. cellMeta = hot.getCellMeta(7, 7);
  1674. expect(cellMeta.className.indexOf('htRight')).toEqual(-1);
  1675. expect(cellMeta.className.indexOf('htBottom')).toEqual(-1);
  1676. hot.undo();
  1677. // check if all cells are either non-adjusted or adjusted to the left (as default)
  1678. var finish;
  1679. for (var i = 0; i < 9; i++) {
  1680. for (var j = 0; j < 9; j++) {
  1681. cellMeta = hot.getCellMeta(i, j);
  1682. finish = cellMeta.className === void 0 || cellMeta.className.trim() === '' || cellMeta.className.trim() === 'htLeft';
  1683. expect(finish).toBe(true);
  1684. }
  1685. }
  1686. });
  1687. it('should redo a sequence of aligning cells', function () {
  1688. var hot = handsontable({
  1689. data: Handsontable.helper.createSpreadsheetData(9, 9),
  1690. contextMenu: true,
  1691. colWidths: [50, 50, 50, 50, 50, 50, 50, 50, 50],
  1692. rowHeights: [50, 50, 50, 50, 50, 50, 50, 50, 50]
  1693. });
  1694. // top 3 rows center
  1695. selectCell(0, 0, 2, 8);
  1696. hot.getPlugin('contextMenu').executeCommand('alignment:center');
  1697. // middle 3 rows unchanged - left
  1698. // bottom 3 rows right
  1699. selectCell(6, 0, 8, 8);
  1700. hot.getPlugin('contextMenu').executeCommand('alignment:right');
  1701. // left 3 columns - middle
  1702. selectCell(0, 0, 8, 2);
  1703. hot.getPlugin('contextMenu').executeCommand('alignment:middle');
  1704. // middle 3 columns unchanged - top
  1705. // right 3 columns - bottom
  1706. selectCell(0, 6, 8, 8);
  1707. hot.getPlugin('contextMenu').executeCommand('alignment:bottom');
  1708. var cellMeta = hot.getCellMeta(0, 0);
  1709. expect(cellMeta.className.indexOf('htCenter')).toBeGreaterThan(-1);
  1710. expect(cellMeta.className.indexOf('htMiddle')).toBeGreaterThan(-1);
  1711. cellMeta = hot.getCellMeta(0, 7);
  1712. expect(cellMeta.className.indexOf('htCenter')).toBeGreaterThan(-1);
  1713. expect(cellMeta.className.indexOf('htBottom')).toBeGreaterThan(-1);
  1714. cellMeta = hot.getCellMeta(5, 1);
  1715. expect(cellMeta.className.indexOf('htMiddle')).toBeGreaterThan(-1);
  1716. cellMeta = hot.getCellMeta(5, 7);
  1717. expect(cellMeta.className.indexOf('htBottom')).toBeGreaterThan(-1);
  1718. cellMeta = hot.getCellMeta(7, 1);
  1719. expect(cellMeta.className.indexOf('htRight')).toBeGreaterThan(-1);
  1720. expect(cellMeta.className.indexOf('htMiddle')).toBeGreaterThan(-1);
  1721. cellMeta = hot.getCellMeta(7, 5);
  1722. expect(cellMeta.className.indexOf('htRight')).toBeGreaterThan(-1);
  1723. cellMeta = hot.getCellMeta(7, 7);
  1724. expect(cellMeta.className.indexOf('htRight')).toBeGreaterThan(-1);
  1725. expect(cellMeta.className.indexOf('htBottom')).toBeGreaterThan(-1);
  1726. hot.undo();
  1727. hot.undo();
  1728. hot.undo();
  1729. hot.undo();
  1730. // check if all cells are either non-adjusted or adjusted to the left (as default)
  1731. var finish;
  1732. for (var i = 0; i < 9; i++) {
  1733. for (var j = 0; j < 9; j++) {
  1734. cellMeta = hot.getCellMeta(i, j);
  1735. finish = cellMeta.className === void 0 || cellMeta.className.trim() === '' || cellMeta.className.trim() === 'htLeft';
  1736. expect(finish).toBe(true);
  1737. }
  1738. }
  1739. hot.redo();
  1740. cellMeta = hot.getCellMeta(0, 0);
  1741. expect(cellMeta.className.indexOf('htCenter')).toBeGreaterThan(-1);
  1742. cellMeta = hot.getCellMeta(1, 5);
  1743. expect(cellMeta.className.indexOf('htCenter')).toBeGreaterThan(-1);
  1744. cellMeta = hot.getCellMeta(2, 8);
  1745. expect(cellMeta.className.indexOf('htCenter')).toBeGreaterThan(-1);
  1746. hot.redo();
  1747. cellMeta = hot.getCellMeta(6, 0);
  1748. expect(cellMeta.className.indexOf('htRight')).toBeGreaterThan(-1);
  1749. cellMeta = hot.getCellMeta(7, 5);
  1750. expect(cellMeta.className.indexOf('htRight')).toBeGreaterThan(-1);
  1751. cellMeta = hot.getCellMeta(8, 8);
  1752. expect(cellMeta.className.indexOf('htRight')).toBeGreaterThan(-1);
  1753. hot.redo();
  1754. cellMeta = hot.getCellMeta(0, 0);
  1755. expect(cellMeta.className.indexOf('htMiddle')).toBeGreaterThan(-1);
  1756. expect(cellMeta.className.indexOf('htCenter')).toBeGreaterThan(-1);
  1757. cellMeta = hot.getCellMeta(5, 1);
  1758. expect(cellMeta.className.indexOf('htMiddle')).toBeGreaterThan(-1);
  1759. cellMeta = hot.getCellMeta(8, 2);
  1760. expect(cellMeta.className.indexOf('htMiddle')).toBeGreaterThan(-1);
  1761. expect(cellMeta.className.indexOf('htRight')).toBeGreaterThan(-1);
  1762. hot.redo();
  1763. cellMeta = hot.getCellMeta(0, 6);
  1764. expect(cellMeta.className.indexOf('htBottom')).toBeGreaterThan(-1);
  1765. expect(cellMeta.className.indexOf('htCenter')).toBeGreaterThan(-1);
  1766. cellMeta = hot.getCellMeta(5, 7);
  1767. expect(cellMeta.className.indexOf('htBottom')).toBeGreaterThan(-1);
  1768. cellMeta = hot.getCellMeta(8, 8);
  1769. expect(cellMeta.className.indexOf('htBottom')).toBeGreaterThan(-1);
  1770. expect(cellMeta.className.indexOf('htRight')).toBeGreaterThan(-1);
  1771. });
  1772. });
  1773. it('should exposed new methods when plugin is enabled', function () {
  1774. var hot = handsontable({
  1775. undo: false
  1776. });
  1777. expect(hot.undo).toBeUndefined();
  1778. expect(hot.redo).toBeUndefined();
  1779. expect(hot.isUndoAvailable).toBeUndefined();
  1780. expect(hot.isRedoAvailable).toBeUndefined();
  1781. expect(hot.clearUndo).toBeUndefined();
  1782. updateSettings({
  1783. undo: true
  1784. });
  1785. expect(_typeof(hot.undo)).toEqual('function');
  1786. expect(_typeof(hot.redo)).toEqual('function');
  1787. expect(_typeof(hot.isUndoAvailable)).toEqual('function');
  1788. expect(_typeof(hot.isRedoAvailable)).toEqual('function');
  1789. expect(_typeof(hot.clearUndo)).toEqual('function');
  1790. });
  1791. it('should remove exposed methods when plugin is disbaled', function () {
  1792. var hot = handsontable({
  1793. undo: true
  1794. });
  1795. expect(_typeof(hot.undo)).toEqual('function');
  1796. expect(_typeof(hot.redo)).toEqual('function');
  1797. expect(_typeof(hot.isUndoAvailable)).toEqual('function');
  1798. expect(_typeof(hot.isRedoAvailable)).toEqual('function');
  1799. expect(_typeof(hot.clearUndo)).toEqual('function');
  1800. updateSettings({
  1801. undo: false
  1802. });
  1803. expect(hot.undo).toBeUndefined();
  1804. expect(hot.redo).toBeUndefined();
  1805. expect(hot.isUndoAvailable).toBeUndefined();
  1806. expect(hot.isRedoAvailable).toBeUndefined();
  1807. expect(hot.clearUndo).toBeUndefined();
  1808. });
  1809. describe('Keyboard shortcuts', function () {
  1810. it('should undo single change after hitting CTRL+Z', function () {
  1811. handsontable({
  1812. data: Handsontable.helper.createSpreadsheetData(2, 2)
  1813. });
  1814. var HOT = getInstance();
  1815. selectCell(0, 0);
  1816. setDataAtCell(0, 0, 'new value');
  1817. this.$container.simulate('keydown', { ctrlKey: true, keyCode: 'Z'.charCodeAt(0) });
  1818. expect(getDataAtCell(0, 0)).toBe('A1');
  1819. });
  1820. it('should redo single change after hitting CTRL+Y', function () {
  1821. handsontable({
  1822. data: Handsontable.helper.createSpreadsheetData(2, 2)
  1823. });
  1824. var HOT = getInstance();
  1825. selectCell(0, 0);
  1826. setDataAtCell(0, 0, 'new value');
  1827. expect(getDataAtCell(0, 0)).toBe('new value');
  1828. HOT.undo();
  1829. expect(getDataAtCell(0, 0)).toBe('A1');
  1830. this.$container.simulate('keydown', { ctrlKey: true, keyCode: 'Y'.charCodeAt(0) });
  1831. expect(getDataAtCell(0, 0)).toBe('new value');
  1832. });
  1833. it('should redo single change after hitting CTRL+SHIFT+Z', function () {
  1834. handsontable({
  1835. data: Handsontable.helper.createSpreadsheetData(2, 2)
  1836. });
  1837. var HOT = getInstance();
  1838. selectCell(0, 0);
  1839. setDataAtCell(0, 0, 'new value');
  1840. expect(getDataAtCell(0, 0)).toBe('new value');
  1841. HOT.undo();
  1842. expect(getDataAtCell(0, 0)).toBe('A1');
  1843. this.$container.simulate('keydown', { ctrlKey: true, shiftKey: true, keyCode: 'Z'.charCodeAt(0) });
  1844. expect(getDataAtCell(0, 0)).toBe('new value');
  1845. });
  1846. });
  1847. });
  1848. describe('Hooks', function () {
  1849. it('should fire a `beforeUndo` hook after the undo process begins', function (done) {
  1850. var beforeUndoSpy = jasmine.createSpy('beforeUndo');
  1851. var hot = handsontable({
  1852. data: Handsontable.helper.createSpreadsheetData(2, 2)
  1853. });
  1854. var hookData = null;
  1855. hot.addHook('beforeUndo', beforeUndoSpy);
  1856. hot.addHook('beforeUndo', function (data) {
  1857. hookData = data;
  1858. });
  1859. alter('remove_row', 1);
  1860. setTimeout(function () {
  1861. hot.undo();
  1862. }, 10);
  1863. setTimeout(function () {
  1864. expect(beforeUndoSpy.calls.count()).toEqual(1);
  1865. expect(hookData).not.toBe(null);
  1866. expect(hookData.actionType).toEqual('remove_row');
  1867. expect(hookData.data).toEqual([['A2', 'B2']]);
  1868. done();
  1869. }, 100);
  1870. });
  1871. it('should fire a `beforeRedo` hook before the redo process begins', function (done) {
  1872. var beforeRedoSpy = jasmine.createSpy('beforeRedo');
  1873. var hot = handsontable({
  1874. data: Handsontable.helper.createSpreadsheetData(2, 2)
  1875. });
  1876. var hookData = null;
  1877. hot.addHook('beforeRedo', beforeRedoSpy);
  1878. hot.addHook('beforeRedo', function (data) {
  1879. hookData = data;
  1880. });
  1881. alter('remove_row', 1);
  1882. setTimeout(function () {
  1883. hot.undo();
  1884. hot.redo();
  1885. }, 10);
  1886. setTimeout(function () {
  1887. expect(beforeRedoSpy.calls.count()).toEqual(1);
  1888. expect(hookData).not.toBe(null);
  1889. expect(hookData.actionType).toEqual('remove_row');
  1890. expect(hookData.data).toEqual([['A2', 'B2']]);
  1891. done();
  1892. }, 100);
  1893. });
  1894. it('should fire a `afterRedo` hook after the redo process begins', function (done) {
  1895. var afterRedoSpy = jasmine.createSpy('afterRedo');
  1896. var hot = handsontable({
  1897. data: Handsontable.helper.createSpreadsheetData(2, 2)
  1898. });
  1899. var hookData = null;
  1900. hot.addHook('beforeRedo', afterRedoSpy);
  1901. hot.addHook('beforeRedo', function (data) {
  1902. hookData = data;
  1903. });
  1904. alter('remove_row', 1);
  1905. setTimeout(function () {
  1906. hot.undo();
  1907. hot.redo();
  1908. }, 10);
  1909. setTimeout(function () {
  1910. expect(afterRedoSpy.calls.count()).toEqual(1);
  1911. expect(hookData).not.toBe(null);
  1912. expect(hookData.actionType).toEqual('remove_row');
  1913. expect(hookData.data).toEqual([['A2', 'B2']]);
  1914. done();
  1915. }, 100);
  1916. });
  1917. });
  1918. });