3fc6b5cca3b273708f614b429a74acb24a423a7a287c7361d965954804fde4b9c0d504bf1a6d583921984a450dd4ba1b17948523db98dc7e4ca67969d8370e 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. describe('WalkontableBorder', function () {
  2. var $table,
  3. $container,
  4. $wrapper,
  5. debug = false;
  6. beforeEach(function () {
  7. $container = $('<div></div>');
  8. $wrapper = $('<div></div>');
  9. $container.width(100).height(200);
  10. $table = $('<table></table>');
  11. $container.append($wrapper);
  12. $wrapper.append($table);
  13. $container.appendTo('body');
  14. createDataArray();
  15. });
  16. afterEach(function () {
  17. if (!debug) {
  18. $('.wtHolder').remove();
  19. }
  20. $container.remove();
  21. });
  22. it('should add/remove border to selection when cell is clicked', function () {
  23. var wt = new Walkontable.Core({
  24. table: $table[0],
  25. data: getData,
  26. totalRows: 5,
  27. totalColumns: 5,
  28. selections: [new Walkontable.Selection({
  29. border: {
  30. width: 1,
  31. color: 'red'
  32. }
  33. })],
  34. onCellMouseDown: function onCellMouseDown(event, coords, TD) {
  35. wt.selections.current.clear();
  36. wt.selections.current.add(coords);
  37. wt.draw();
  38. }
  39. });
  40. shimSelectionProperties(wt);
  41. wt.draw();
  42. var $td1 = $table.find('tbody tr:eq(1) td:eq(0)');
  43. var $td2 = $table.find('tbody tr:eq(2) td:eq(1)');
  44. var $top = $(wt.selections.current.getBorder(wt).top);
  45. var $right = $(wt.selections.current.getBorder(wt).right);
  46. var $bottom = $(wt.selections.current.getBorder(wt).bottom);
  47. var $left = $(wt.selections.current.getBorder(wt).left);
  48. $td1.simulate('mousedown');
  49. expect($top.css('height')).toBe('1px');
  50. expect($top.position().top).toBe(23);
  51. expect($top.position().left).toBe(0);
  52. expect($right.css('width')).toBe('1px');
  53. expect($right.position().top).toBe(23);
  54. expect($right.position().left).toBe(49);
  55. expect($bottom.css('height')).toBe('1px');
  56. expect($bottom.position().top).toBe(46);
  57. expect($bottom.position().left).toBe(0);
  58. expect($left.css('width')).toBe('1px');
  59. expect($left.position().top).toBe(23);
  60. expect($left.position().left).toBe(0);
  61. $td2.simulate('mousedown');
  62. expect($top.css('height')).toBe('1px');
  63. expect($top.position().top).toBe(46);
  64. expect($top.position().left).toBe(49);
  65. expect($right.css('width')).toBe('1px');
  66. expect($right.position().top).toBe(46);
  67. expect($right.position().left).toBe(99);
  68. expect($bottom.css('height')).toBe('1px');
  69. expect($bottom.position().top).toBe(69);
  70. expect($bottom.position().left).toBe(49);
  71. expect($left.css('width')).toBe('1px');
  72. expect($left.position().top).toBe(46);
  73. expect($left.position().left).toBe(49);
  74. });
  75. it('should add/remove corner to selection when cell is clicked', function () {
  76. var wt = new Walkontable.Core({
  77. table: $table[0],
  78. data: getData,
  79. totalRows: 5,
  80. totalColumns: 5,
  81. selections: [new Walkontable.Selection({
  82. border: {
  83. width: 2,
  84. color: 'green',
  85. cornerVisible: function cornerVisible() {
  86. return true;
  87. }
  88. }
  89. }), new Walkontable.Selection({})],
  90. onCellMouseDown: function onCellMouseDown(event, coords, TD) {
  91. wt.selections.current.clear();
  92. wt.selections.current.add(coords);
  93. wt.draw();
  94. }
  95. });
  96. shimSelectionProperties(wt);
  97. wt.draw();
  98. var $td1 = $table.find('tbody tr:eq(1) td:eq(0)');
  99. var $td2 = $table.find('tbody tr:eq(2) td:eq(1)');
  100. var $corner = $(wt.selections.current.getBorder(wt).corner);
  101. $td1.simulate('mousedown');
  102. expect($corner.css('width')).toBe('5px');
  103. expect($corner.css('height')).toBe('5px');
  104. expect($corner.position().top).toBe(42);
  105. expect($corner.position().left).toBe(45);
  106. $td2.simulate('mousedown');
  107. expect($corner.css('width')).toBe('5px');
  108. expect($corner.css('height')).toBe('5px');
  109. expect($corner.position().top).toBe(65);
  110. expect($corner.position().left).toBe(95);
  111. });
  112. it('should move the fill handle / corner border to the left, if in the position it would overlap the container (e.g.: far-right)', function () {
  113. $container.css({
  114. overflow: 'hidden',
  115. width: '200px'
  116. });
  117. var wt = new Walkontable.Core({
  118. table: $table[0],
  119. data: getData,
  120. totalRows: 5,
  121. totalColumns: 4,
  122. selections: [new Walkontable.Selection({
  123. border: {
  124. width: 2,
  125. color: 'green',
  126. cornerVisible: function cornerVisible() {
  127. return true;
  128. }
  129. }
  130. }), new Walkontable.Selection({})],
  131. onCellMouseDown: function onCellMouseDown(event, coords, TD) {
  132. wt.selections.current.clear();
  133. wt.selections.current.add(coords);
  134. wt.draw();
  135. }
  136. });
  137. shimSelectionProperties(wt);
  138. wt.draw();
  139. var $td1 = $table.find('tbody tr:eq(1) td:eq(0)');
  140. var $td2 = $table.find('tbody tr:eq(3) td:eq(3)');
  141. var $td3 = $table.find('tbody tr:eq(2) td:eq(1)');
  142. var $corner = $(wt.selections.current.getBorder(wt).corner);
  143. $td1.simulate('mousedown');
  144. expect($corner.css('width')).toBe('5px');
  145. expect($corner.css('height')).toBe('5px');
  146. expect($corner.position().top).toBe(42);
  147. expect($corner.position().left).toBe(45);
  148. expect($container[0].clientWidth === $container[0].scrollWidth).toBe(true);
  149. $td2.simulate('mousedown');
  150. expect($corner.css('width')).toBe('5px');
  151. expect($corner.css('height')).toBe('5px');
  152. expect($corner.position().top).toBe(88);
  153. expect($corner.position().left).toBe(193);
  154. expect($container[0].clientWidth === $container[0].scrollWidth).toBe(true);
  155. $td3.simulate('mousedown');
  156. expect($corner.css('width')).toBe('5px');
  157. expect($corner.css('height')).toBe('5px');
  158. expect($corner.position().top).toBe(65);
  159. expect($corner.position().left).toBe(95);
  160. expect($container[0].clientWidth === $container[0].scrollWidth).toBe(true);
  161. });
  162. });