avatarCropper.spec.jsx 3.5 KB

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