9df38caacfc2d575ea06b6ee004376087f5292b5030f275a6eb10b4bb6feceb4c67bdd45855b5706db2b3c603093c715fdbcbec15518de26f6ef82642efd3f 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. 'use strict';
  2. describe('ContextMenu', 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('alignment', function () {
  14. it('should align text left', function (done) {
  15. var hot = handsontable({
  16. data: Handsontable.helper.createSpreadsheetData(4, 4),
  17. contextMenu: true,
  18. height: 100
  19. });
  20. contextMenu();
  21. var item = $('.htContextMenu .ht_master .htCore').find('tbody td').not('.htSeparator').eq(9);
  22. item.simulate('mouseover');
  23. setTimeout(function () {
  24. var contextSubMenu = $('.htContextMenuSub_' + item.text());
  25. var button = contextSubMenu.find('.ht_master .htCore tbody td').not('.htSeparator').eq(0);
  26. button.simulate('mousedown'); // Text left
  27. expect(getCellMeta(0, 0).className).toEqual('htLeft');
  28. expect(getCell(0, 0).className).toContain('htLeft');
  29. done();
  30. }, 350);
  31. });
  32. it('should align text center', function (done) {
  33. var hot = handsontable({
  34. data: Handsontable.helper.createSpreadsheetData(4, 4),
  35. contextMenu: true,
  36. height: 100
  37. });
  38. contextMenu();
  39. var item = $('.htContextMenu .ht_master .htCore').find('tbody td').not('.htSeparator').eq(9);
  40. item.simulate('mouseover');
  41. setTimeout(function () {
  42. var contextSubMenu = $('.htContextMenuSub_' + item.text());
  43. var button = contextSubMenu.find('.ht_master .htCore tbody td').not('.htSeparator').eq(1);
  44. button.simulate('mousedown'); // Text center
  45. expect(getCellMeta(0, 0).className).toEqual('htCenter');
  46. expect(getCell(0, 0).className).toContain('htCenter');
  47. done();
  48. }, 350);
  49. });
  50. it('should align text right', function (done) {
  51. var hot = handsontable({
  52. data: Handsontable.helper.createSpreadsheetData(4, 4),
  53. contextMenu: true,
  54. height: 100
  55. });
  56. contextMenu();
  57. var item = $('.htContextMenu .ht_master .htCore').find('tbody td').not('.htSeparator').eq(9);
  58. item.simulate('mouseover');
  59. setTimeout(function () {
  60. var contextSubMenu = $('.htContextMenuSub_' + item.text());
  61. var button = contextSubMenu.find('.ht_master .htCore tbody td').not('.htSeparator').eq(2);
  62. button.simulate('mousedown'); // Text right
  63. expect(getCellMeta(0, 0).className).toEqual('htRight');
  64. expect(getCell(0, 0).className).toContain('htRight');
  65. done();
  66. }, 350);
  67. });
  68. it('should justify text', function (done) {
  69. var hot = handsontable({
  70. data: Handsontable.helper.createSpreadsheetData(4, 4),
  71. contextMenu: true,
  72. height: 100
  73. });
  74. contextMenu();
  75. var item = $('.htContextMenu .ht_master .htCore').find('tbody td').not('.htSeparator').eq(9);
  76. item.simulate('mouseover');
  77. setTimeout(function () {
  78. var contextSubMenu = $('.htContextMenuSub_' + item.text());
  79. var button = contextSubMenu.find('.ht_master .htCore tbody td').not('.htSeparator').eq(3);
  80. button.simulate('mousedown'); // Text justify
  81. deselectCell();
  82. expect(getCellMeta(0, 0).className).toEqual('htJustify');
  83. expect(getCell(0, 0).className).toContain('htJustify');
  84. done();
  85. }, 350); // menu opens after 300ms
  86. });
  87. it('should vertical align text top', function (done) {
  88. var hot = handsontable({
  89. data: Handsontable.helper.createSpreadsheetData(4, 4),
  90. contextMenu: true,
  91. height: 100
  92. });
  93. contextMenu();
  94. var item = $('.htContextMenu .ht_master .htCore').find('tbody td').not('.htSeparator').eq(9);
  95. item.simulate('mouseover');
  96. setTimeout(function () {
  97. var contextSubMenu = $('.htContextMenuSub_' + item.text());
  98. var button = contextSubMenu.find('.ht_master .htCore tbody td').not('.htSeparator').eq(4);
  99. button.simulate('mousedown'); // Text top
  100. deselectCell();
  101. expect(getCellMeta(0, 0).className).toEqual('htTop');
  102. expect(getCell(0, 0).className).toContain('htTop');
  103. done();
  104. }, 350); // menu opens after 300ms
  105. });
  106. it('should vertical align text middle', function (done) {
  107. var hot = handsontable({
  108. data: Handsontable.helper.createSpreadsheetData(4, 4),
  109. contextMenu: true,
  110. height: 100
  111. });
  112. contextMenu();
  113. var item = $('.htContextMenu .ht_master .htCore').find('tbody td').not('.htSeparator').eq(9);
  114. item.simulate('mouseover');
  115. setTimeout(function () {
  116. var contextSubMenu = $('.htContextMenuSub_' + item.text());
  117. var button = contextSubMenu.find('.ht_master .htCore tbody td').not('.htSeparator').eq(5);
  118. button.simulate('mousedown'); // Text middle
  119. deselectCell();
  120. expect(getCellMeta(0, 0).className).toEqual('htMiddle');
  121. expect(getCell(0, 0).className).toContain('htMiddle');
  122. done();
  123. }, 350); // menu opens after 300ms
  124. });
  125. it('should vertical align text bottom', function (done) {
  126. var hot = handsontable({
  127. data: Handsontable.helper.createSpreadsheetData(4, 4),
  128. contextMenu: true,
  129. height: 100
  130. });
  131. contextMenu();
  132. var item = $('.htContextMenu .ht_master .htCore').find('tbody td').not('.htSeparator').eq(9);
  133. item.simulate('mouseover');
  134. setTimeout(function () {
  135. var contextSubMenu = $('.htContextMenuSub_' + item.text());
  136. var button = contextSubMenu.find('.ht_master .htCore tbody td').not('.htSeparator').eq(6);
  137. button.simulate('mousedown'); // Text bottom
  138. deselectCell();
  139. expect(getCellMeta(0, 0).className).toEqual('htBottom');
  140. expect(getCell(0, 0).className).toContain('htBottom');
  141. done();
  142. }, 350); // menu opens after 300ms
  143. });
  144. it('should trigger `afterSetCellMeta` callback after changing alignment by context menu', function (done) {
  145. var afterSetCellMetaCallback = jasmine.createSpy('afterSetCellMetaCallback');
  146. var hot = handsontable({
  147. data: Handsontable.helper.createSpreadsheetData(5, 5),
  148. rowHeaders: true,
  149. colHeaders: true,
  150. contextMenu: true,
  151. afterSetCellMeta: afterSetCellMetaCallback
  152. });
  153. selectCell(2, 3);
  154. contextMenu();
  155. var item = $('.htContextMenu .ht_master .htCore').find('tbody td').not('.htSeparator').eq(9);
  156. item.simulate('mouseover');
  157. setTimeout(function () {
  158. var contextSubMenu = $('.htContextMenuSub_' + item.text());
  159. var button = contextSubMenu.find('.ht_master .htCore tbody td').not('.htSeparator').eq(2);
  160. button.simulate('mousedown'); // Text bottom
  161. deselectCell();
  162. expect(afterSetCellMetaCallback).toHaveBeenCalledWith(2, 3, 'className', 'htRight', undefined, undefined);
  163. done();
  164. }, 350); // menu opens after 300ms
  165. });
  166. });
  167. });