avatarCropper.spec.jsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import AvatarCropper from 'sentry/components/avatarCropper';
  3. describe('AvatarCropper', function () {
  4. const USER = {
  5. email: 'a@example.com',
  6. avatar: {
  7. avatarType: 'gravatar',
  8. avatarUuid: '2d641b5d-8c74-44de-9cb6-fbd54701b35e',
  9. },
  10. };
  11. describe('getDiffNW', function () {
  12. it(
  13. 'should return a negative diff when yDiff and xDiff ' +
  14. 'are positive (cropper is getting smaller)',
  15. function () {
  16. const cropper = mountWithTheme(
  17. <AvatarCropper model={USER} updateDataUrlState={function () {}} />
  18. ).instance();
  19. const diff = cropper.getDiffNW(4, 5);
  20. expect(diff).toEqual(-4.5);
  21. }
  22. );
  23. it(
  24. 'should return a positive diff when yDiff and xDiff ' +
  25. 'are negative (cropper is getting bigger)',
  26. function () {
  27. const cropper = mountWithTheme(
  28. <AvatarCropper model={USER} updateDataUrlState={function () {}} />
  29. ).instance();
  30. const diff = cropper.getDiffNW(-4, -5);
  31. expect(diff).toEqual(4.5);
  32. }
  33. );
  34. });
  35. describe('getDiffNE', function () {
  36. it(
  37. 'should return a positive diff when yDiff is negative and ' +
  38. 'xDiff is positive (cropper is getting bigger)',
  39. function () {
  40. const cropper = mountWithTheme(
  41. <AvatarCropper model={USER} updateDataUrlState={function () {}} />
  42. ).instance();
  43. const diff = cropper.getDiffNE(-4, 5);
  44. expect(diff).toEqual(4.5);
  45. }
  46. );
  47. it(
  48. 'should return a negative diff when yDiff is positive and ' +
  49. 'xDiff is negative (cropper is getting smaller)',
  50. function () {
  51. const cropper = mountWithTheme(
  52. <AvatarCropper model={USER} updateDataUrlState={function () {}} />
  53. ).instance();
  54. const diff = cropper.getDiffNE(4, -5);
  55. expect(diff).toEqual(-4.5);
  56. }
  57. );
  58. });
  59. describe('getDiffSE', function () {
  60. it(
  61. 'should return a positive diff when yDiff and ' +
  62. 'xDiff are positive (cropper is getting bigger)',
  63. function () {
  64. const cropper = mountWithTheme(
  65. <AvatarCropper model={USER} updateDataUrlState={function () {}} />
  66. ).instance();
  67. const diff = cropper.getDiffSE(4, 5);
  68. expect(diff).toEqual(4.5);
  69. }
  70. );
  71. it(
  72. 'should return a negative diff when yDiff and ' +
  73. 'xDiff are negative (cropper is getting smaller)',
  74. function () {
  75. const cropper = mountWithTheme(
  76. <AvatarCropper model={USER} updateDataUrlState={function () {}} />
  77. ).instance();
  78. const diff = cropper.getDiffSE(-4, -5);
  79. expect(diff).toEqual(-4.5);
  80. }
  81. );
  82. });
  83. describe('getDiffSW', function () {
  84. it(
  85. 'should return a positive diff when yDiff is positive and ' +
  86. 'xDiff is negative (cropper is getting bigger)',
  87. function () {
  88. const cropper = mountWithTheme(
  89. <AvatarCropper model={USER} updateDataUrlState={function () {}} />
  90. ).instance();
  91. const diff = cropper.getDiffSW(4, -5);
  92. expect(diff).toEqual(4.5);
  93. }
  94. );
  95. it(
  96. 'should return a negative diff when yDiff is negative and' +
  97. 'xDiff is positive (cropper is getting smaller)',
  98. function () {
  99. const cropper = mountWithTheme(
  100. <AvatarCropper model={USER} updateDataUrlState={function () {}} />
  101. ).instance();
  102. const diff = cropper.getDiffSW(-4, 5);
  103. expect(diff).toEqual(-4.5);
  104. }
  105. );
  106. });
  107. });