alignment.e2e.js 6.9 KB

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