AttachUtilSpec.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import {
  2. getNewAttachPoint
  3. } from 'lib/util/AttachUtil';
  4. describe('AttachUtil', function() {
  5. describe('#getNewAttachPoint', function() {
  6. it('should return new point\'s position delta for growing', function() {
  7. // given
  8. var point = {
  9. x: -2,
  10. y: 2
  11. };
  12. var oldBounds = {
  13. x: -2,
  14. y: -2,
  15. width: 4,
  16. height: 4
  17. };
  18. var newBounds = {
  19. x: -2,
  20. y: -2,
  21. width: 8,
  22. height: 8
  23. };
  24. // then
  25. expect(getNewAttachPoint(point, oldBounds, newBounds)).to.eql({ x: -2, y: 6 });
  26. });
  27. it('should return new point\'s position delta for shrinking', function() {
  28. // given
  29. var point = {
  30. x: -4,
  31. y: 4
  32. };
  33. var oldBounds = {
  34. x: -4,
  35. y: -4,
  36. width: 8,
  37. height: 8
  38. };
  39. var newBounds = {
  40. x: -4,
  41. y: -4,
  42. width: 4,
  43. height: 4
  44. };
  45. // then
  46. expect(getNewAttachPoint(point, oldBounds, newBounds)).to.eql({ x: -4, y: 0 });
  47. });
  48. it('should return new point\'s position delta', function() {
  49. // given
  50. var point = {
  51. x: 21,
  52. y: 12
  53. };
  54. var oldBounds = {
  55. x: 18,
  56. y: 8,
  57. width: 4,
  58. height: 4
  59. };
  60. var newBounds = {
  61. x: 18,
  62. y: 8,
  63. width: 10,
  64. height: 2
  65. };
  66. // then
  67. expect(getNewAttachPoint(point, oldBounds, newBounds)).to.eql({ x: 26, y: 10 });
  68. });
  69. });
  70. });