cursor.unit.js 3.4 KB

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