cursor.unit.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import Cursor from 'handsontable/plugins/contextMenu/cursor';
  2. describe('ContextMenu', function () {
  3. describe('Cursor', function () {
  4. it('should initialize internal properties on construct (object literal)', function () {
  5. var coords = {
  6. top: 10,
  7. left: 50,
  8. width: 100,
  9. height: 200
  10. };
  11. var cursor = new Cursor(coords);
  12. expect(cursor.top).toBe(coords.top);
  13. expect(cursor.topRelative).toBeLessThan(coords.top + 1);
  14. expect(cursor.left).toBe(coords.left);
  15. expect(cursor.leftRelative).toBeLessThan(coords.left + 1);
  16. expect(cursor.scrollLeft).toBeGreaterThan(-1);
  17. expect(cursor.scrollTop).toBeGreaterThan(-1);
  18. expect(cursor.cellHeight).toBe(coords.height);
  19. expect(cursor.cellWidth).toBe(coords.width);
  20. });
  21. it('should returns boolean value related to if element fits above the cursor', function () {
  22. var coords = {
  23. top: 10,
  24. left: 50,
  25. width: 100,
  26. height: 200
  27. };
  28. var cursor = new Cursor(coords);
  29. var fakeElement = {
  30. offsetHeight: 9
  31. };
  32. expect(cursor.fitsAbove(fakeElement)).toBe(true);
  33. fakeElement.offsetHeight = 10;
  34. expect(cursor.fitsAbove(fakeElement)).toBe(true);
  35. fakeElement.offsetHeight = 11;
  36. expect(cursor.fitsAbove(fakeElement)).toBe(false);
  37. });
  38. it('should returns boolean value related to if element fits below the cursor', function () {
  39. var coords = {
  40. top: 10,
  41. left: 50,
  42. width: 100,
  43. height: 200
  44. };
  45. var cursor = new Cursor(coords);
  46. var fakeElement = {
  47. offsetHeight: 9
  48. };
  49. var viewportHeight = 100;
  50. expect(cursor.fitsBelow(fakeElement, viewportHeight)).toBe(true);
  51. fakeElement.offsetHeight = 90;
  52. expect(cursor.fitsBelow(fakeElement, viewportHeight)).toBe(true);
  53. fakeElement.offsetHeight = 91;
  54. expect(cursor.fitsBelow(fakeElement, viewportHeight)).toBe(false);
  55. });
  56. it('should returns boolean value related to if element fits on the right of the cursor', function () {
  57. var coords = {
  58. top: 10,
  59. left: 20,
  60. width: 30,
  61. height: 200
  62. };
  63. var cursor = new Cursor(coords);
  64. var fakeElement = {
  65. offsetWidth: 9
  66. };
  67. var viewportWidth = 100;
  68. expect(cursor.fitsOnRight(fakeElement, viewportWidth)).toBe(true);
  69. fakeElement.offsetWidth = 50;
  70. expect(cursor.fitsOnRight(fakeElement, viewportWidth)).toBe(true);
  71. fakeElement.offsetWidth = 51;
  72. expect(cursor.fitsOnRight(fakeElement, viewportWidth)).toBe(false);
  73. });
  74. it('should returns boolean value related to if element fits on the left of the cursor', function () {
  75. var coords = {
  76. top: 10,
  77. left: 50,
  78. width: 100,
  79. height: 200
  80. };
  81. var cursor = new Cursor(coords);
  82. var fakeElement = {
  83. offsetWidth: 9
  84. };
  85. expect(cursor.fitsOnLeft(fakeElement)).toBe(true);
  86. fakeElement.offsetWidth = 50;
  87. expect(cursor.fitsOnLeft(fakeElement)).toBe(true);
  88. fakeElement.offsetWidth = 51;
  89. expect(cursor.fitsOnLeft(fakeElement)).toBe(false);
  90. });
  91. });
  92. });