ff2fbf42dd64758a6e81868a85f52cdd30f447c547c86cf6eb8e8638293016ee316951d55a638008dc508e8eaf6e573f4f42d7a2154aa764d0a5373f06daae 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. 'use strict';
  2. describe('CustomBorders', function () {
  3. var id = 'testContainer';
  4. beforeEach(function () {
  5. this.$container = $('<div id="' + id + '"></div>').appendTo('body');
  6. var wrapper = $('<div></div>').css({
  7. width: 400,
  8. height: 200,
  9. overflow: 'scroll'
  10. });
  11. this.$wrapper = this.$container.wrap(wrapper).parent();
  12. });
  13. afterEach(function () {
  14. if (this.$container) {
  15. destroy();
  16. this.$container.remove();
  17. }
  18. this.$wrapper.remove();
  19. });
  20. it('should draw custom borders for single td', function () {
  21. handsontable({
  22. data: Handsontable.helper.createSpreadsheetData(7, 7),
  23. colHeaders: true,
  24. rowHeaders: true,
  25. customBorders: [{
  26. row: 2,
  27. col: 2,
  28. left: {
  29. width: 2,
  30. color: 'red'
  31. },
  32. right: {
  33. width: 1,
  34. color: 'green'
  35. }
  36. }]
  37. });
  38. // [top,left, bottom, right]
  39. var borders = $('.wtBorder.border_row2col2');
  40. expect(borders.length).toEqual(20); // 4 times 5 elements (top,right, bottom, left, corner)
  41. expect(borders[0].className).toContain('hidden'); // hidden top
  42. expect(borders[1].style.backgroundColor).toEqual('red'); // left red
  43. expect(borders[1].style.width).toEqual('2px'); // left 2px width
  44. expect(borders[2].className).toContain('hidden'); // hidden bottom
  45. expect(borders[3].style.backgroundColor).toEqual('green'); // green right
  46. expect(borders[3].style.width).toEqual('1px'); // right 1px width
  47. });
  48. it('should draw custom borders for range', function () {
  49. handsontable({
  50. data: Handsontable.helper.createSpreadsheetData(7, 7),
  51. colHeaders: true,
  52. rowHeaders: true,
  53. customBorders: [{
  54. range: {
  55. from: {
  56. row: 1,
  57. col: 1
  58. },
  59. to: {
  60. row: 3,
  61. col: 4
  62. }
  63. },
  64. top: {
  65. width: 2,
  66. color: 'black'
  67. },
  68. left: {
  69. width: 2,
  70. color: 'red'
  71. },
  72. bottom: {
  73. width: 2,
  74. color: 'red'
  75. },
  76. right: {
  77. width: 3,
  78. color: 'black'
  79. }
  80. }]
  81. });
  82. for (var row = 1; row <= 3; row++) {
  83. for (var column = 1; column <= 4; column++) {
  84. if (row == 1) {
  85. var topRow = $('.wtBorder.border_row' + row + 'col' + column);
  86. expect(topRow.length).toEqual(20); // borders for all tables (main and hiders)
  87. expect(topRow[0].style.backgroundColor).toEqual('black');
  88. expect(topRow[0].style.height).toEqual('2px');
  89. }
  90. if (column == 1) {
  91. var leftColumn = $('.wtBorder.border_row' + row + 'col' + column);
  92. expect(leftColumn.length).toEqual(20); // borders for all tables (main and hiders)
  93. expect(leftColumn[1].style.backgroundColor).toEqual('red');
  94. expect(leftColumn[1].style.width).toEqual('2px');
  95. }
  96. if (row == 3) {
  97. var bottomRow = $('.wtBorder.border_row' + row + 'col' + column);
  98. expect(bottomRow.length).toEqual(20); // borders for all tables (main and hiders)
  99. expect(bottomRow[2].style.backgroundColor).toEqual('red');
  100. expect(bottomRow[2].style.height).toEqual('2px');
  101. }
  102. if (column == 4) {
  103. var rightColumn = $('.wtBorder.border_row' + row + 'col' + column);
  104. expect(rightColumn.length).toEqual(20); // borders for all tables (main and hiders)
  105. expect(rightColumn[3].style.backgroundColor).toEqual('black');
  106. expect(rightColumn[3].style.width).toEqual('3px');
  107. }
  108. }
  109. }
  110. });
  111. it('should draw top border from context menu options', function (done) {
  112. var hot = handsontable({
  113. data: Handsontable.helper.createSpreadsheetData(4, 4),
  114. contextMenu: true,
  115. customBorders: true
  116. });
  117. var defaultBorder = {
  118. color: '#000',
  119. width: 1
  120. },
  121. empty = {
  122. hide: true
  123. };
  124. contextMenu();
  125. var item = $('.htContextMenu .ht_master .htCore').find('tbody td').not('.htSeparator').eq(10);
  126. item.simulate('mouseover');
  127. setTimeout(function () {
  128. var contextSubMenu = $('.htContextMenuSub_' + item.text());
  129. var button = contextSubMenu.find('.ht_master .htCore tbody td').not('.htSeparator').eq(0);
  130. button.simulate('mousedown');
  131. // expect(getCellMeta(0,0).borders.hasOwnProperty('top')).toBe(true);
  132. expect(getCellMeta(0, 0).borders.top).toEqual(defaultBorder);
  133. expect(getCellMeta(0, 0).borders.left).toEqual(empty);
  134. expect(getCellMeta(0, 0).borders.bottom).toEqual(empty);
  135. expect(getCellMeta(0, 0).borders.right).toEqual(empty);
  136. done();
  137. }, 350);
  138. });
  139. it('should draw left border from context menu options', function (done) {
  140. var hot = handsontable({
  141. data: Handsontable.helper.createSpreadsheetData(4, 4),
  142. contextMenu: true,
  143. customBorders: true
  144. });
  145. var defaultBorder = {
  146. color: '#000',
  147. width: 1
  148. },
  149. empty = {
  150. hide: true
  151. };
  152. contextMenu();
  153. var item = $('.htContextMenu .ht_master .htCore').find('tbody td').not('.htSeparator').eq(10);
  154. item.simulate('mouseover');
  155. setTimeout(function () {
  156. var contextSubMenu = $('.htContextMenuSub_' + item.text());
  157. var button = contextSubMenu.find('.ht_master .htCore tbody td').not('.htSeparator').eq(3);
  158. button.simulate('mousedown');
  159. /* eslint-disable no-prototype-builtins */
  160. expect(getCellMeta(0, 0).borders.hasOwnProperty('left')).toBe(true);
  161. expect(getCellMeta(0, 0).borders.top).toEqual(empty);
  162. expect(getCellMeta(0, 0).borders.left).toEqual(defaultBorder);
  163. expect(getCellMeta(0, 0).borders.bottom).toEqual(empty);
  164. expect(getCellMeta(0, 0).borders.right).toEqual(empty);
  165. done();
  166. }, 350);
  167. });
  168. it('should draw right border from context menu options', function (done) {
  169. var hot = handsontable({
  170. data: Handsontable.helper.createSpreadsheetData(4, 4),
  171. contextMenu: true,
  172. customBorders: true
  173. });
  174. var defaultBorder = {
  175. color: '#000',
  176. width: 1
  177. },
  178. empty = {
  179. hide: true
  180. };
  181. contextMenu();
  182. var item = $('.htContextMenu .ht_master .htCore').find('tbody td').not('.htSeparator').eq(10);
  183. item.simulate('mouseover');
  184. setTimeout(function () {
  185. var contextSubMenu = $('.htContextMenuSub_' + item.text());
  186. var button = contextSubMenu.find('.ht_master .htCore tbody td').not('.htSeparator').eq(1);
  187. button.simulate('mousedown');
  188. /* eslint-disable no-prototype-builtins */
  189. expect(getCellMeta(0, 0).borders.hasOwnProperty('right')).toBe(true);
  190. expect(getCellMeta(0, 0).borders.top).toEqual(empty);
  191. expect(getCellMeta(0, 0).borders.left).toEqual(empty);
  192. expect(getCellMeta(0, 0).borders.bottom).toEqual(empty);
  193. expect(getCellMeta(0, 0).borders.right).toEqual(defaultBorder);
  194. done();
  195. }, 350);
  196. });
  197. it('should draw bottom border from context menu options', function (done) {
  198. var hot = handsontable({
  199. data: Handsontable.helper.createSpreadsheetData(4, 4),
  200. contextMenu: true,
  201. customBorders: true
  202. });
  203. var defaultBorder = {
  204. color: '#000',
  205. width: 1
  206. },
  207. empty = {
  208. hide: true
  209. };
  210. contextMenu();
  211. var item = $('.htContextMenu .ht_master .htCore').find('tbody td').not('.htSeparator').eq(10);
  212. item.simulate('mouseover');
  213. setTimeout(function () {
  214. var contextSubMenu = $('.htContextMenuSub_' + item.text());
  215. var button = contextSubMenu.find('.ht_master .htCore tbody td').not('.htSeparator').eq(2);
  216. button.simulate('mousedown');
  217. /* eslint-disable no-prototype-builtins */
  218. expect(getCellMeta(0, 0).borders.hasOwnProperty('right')).toBe(true);
  219. expect(getCellMeta(0, 0).borders.top).toEqual(empty);
  220. expect(getCellMeta(0, 0).borders.left).toEqual(empty);
  221. expect(getCellMeta(0, 0).borders.bottom).toEqual(defaultBorder);
  222. expect(getCellMeta(0, 0).borders.right).toEqual(empty);
  223. done();
  224. }, 350);
  225. });
  226. it('should remove all bottoms border from context menu options', function (done) {
  227. var hot = handsontable({
  228. data: Handsontable.helper.createSpreadsheetData(4, 4),
  229. contextMenu: true,
  230. customBorders: [{
  231. row: 0,
  232. col: 0,
  233. left: {
  234. width: 2,
  235. color: 'red'
  236. },
  237. right: {
  238. width: 1,
  239. color: 'green'
  240. }
  241. }]
  242. });
  243. contextMenu();
  244. var item = $('.htContextMenu .ht_master .htCore').find('tbody td').not('.htSeparator').eq(10);
  245. item.simulate('mouseover');
  246. setTimeout(function () {
  247. var contextSubMenu = $('.htContextMenuSub_' + item.text());
  248. var button = contextSubMenu.find('.ht_master .htCore tbody td').not('.htSeparator').eq(4);
  249. button.simulate('mousedown');
  250. expect(getCellMeta(0, 0).borders).toBeUndefined();
  251. done();
  252. }, 350);
  253. });
  254. it('should disable `Borders` context menu item when menu was triggered from corner header', function () {
  255. var hot = handsontable({
  256. data: Handsontable.helper.createSpreadsheetObjectData(10, 5),
  257. rowHeaders: true,
  258. colHeaders: true,
  259. contextMenu: true,
  260. customBorders: true
  261. });
  262. $('.ht_clone_top_left_corner .htCore').find('thead').find('th').eq(0).simulate('mousedown', { which: 3 });
  263. contextMenu();
  264. expect($('.htContextMenu tbody td.htDisabled').text()).toBe(['Insert column on the left', 'Insert column on the right', 'Remove row', 'Remove column', 'Undo', 'Redo', 'Read only', 'Alignment', 'Borders'].join(''));
  265. });
  266. });