UndoRedo.e2e.js 84 KB

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