utils.spec.tsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. import {DATA_CATEGORY_INFO} from 'sentry/constants';
  2. import {
  3. BILLION,
  4. formatUsageWithUnits,
  5. GIGABYTE,
  6. MILLION,
  7. } from 'sentry/views/organizationStats/utils';
  8. describe('formatUsageWithUnits', function () {
  9. it('returns correct strings for Errors', function () {
  10. expect(formatUsageWithUnits(0, DATA_CATEGORY_INFO.error.plural)).toBe('0');
  11. expect(formatUsageWithUnits(1000, DATA_CATEGORY_INFO.error.plural)).toBe('1,000');
  12. expect(formatUsageWithUnits(MILLION, DATA_CATEGORY_INFO.error.plural)).toBe(
  13. '1,000,000'
  14. );
  15. expect(formatUsageWithUnits(BILLION, DATA_CATEGORY_INFO.error.plural)).toBe(
  16. '1,000,000,000'
  17. );
  18. expect(
  19. formatUsageWithUnits(0, DATA_CATEGORY_INFO.error.plural, {isAbbreviated: true})
  20. ).toBe('0');
  21. expect(
  22. formatUsageWithUnits(1000, DATA_CATEGORY_INFO.error.plural, {isAbbreviated: true})
  23. ).toBe('1K');
  24. expect(
  25. formatUsageWithUnits(MILLION, DATA_CATEGORY_INFO.error.plural, {
  26. isAbbreviated: true,
  27. })
  28. ).toBe('1M');
  29. expect(
  30. formatUsageWithUnits(1.234 * MILLION, DATA_CATEGORY_INFO.error.plural, {
  31. isAbbreviated: true,
  32. })
  33. ).toBe('1.2M');
  34. expect(
  35. formatUsageWithUnits(1.234 * BILLION, DATA_CATEGORY_INFO.error.plural, {
  36. isAbbreviated: true,
  37. })
  38. ).toBe('1.23B');
  39. });
  40. it('returns correct strings for Transactions', function () {
  41. expect(formatUsageWithUnits(0, DATA_CATEGORY_INFO.transaction.plural)).toBe('0');
  42. expect(formatUsageWithUnits(1000, DATA_CATEGORY_INFO.transaction.plural)).toBe(
  43. '1,000'
  44. );
  45. expect(formatUsageWithUnits(MILLION, DATA_CATEGORY_INFO.transaction.plural)).toBe(
  46. '1,000,000'
  47. );
  48. expect(formatUsageWithUnits(BILLION, DATA_CATEGORY_INFO.transaction.plural)).toBe(
  49. '1,000,000,000'
  50. );
  51. expect(
  52. formatUsageWithUnits(0, DATA_CATEGORY_INFO.transaction.plural, {
  53. isAbbreviated: true,
  54. })
  55. ).toBe('0');
  56. expect(
  57. formatUsageWithUnits(1000, DATA_CATEGORY_INFO.transaction.plural, {
  58. isAbbreviated: true,
  59. })
  60. ).toBe('1K');
  61. expect(
  62. formatUsageWithUnits(MILLION, DATA_CATEGORY_INFO.transaction.plural, {
  63. isAbbreviated: true,
  64. })
  65. ).toBe('1M');
  66. expect(
  67. formatUsageWithUnits(1.234 * MILLION, DATA_CATEGORY_INFO.transaction.plural, {
  68. isAbbreviated: true,
  69. })
  70. ).toBe('1.2M');
  71. expect(
  72. formatUsageWithUnits(1.234 * BILLION, DATA_CATEGORY_INFO.transaction.plural, {
  73. isAbbreviated: true,
  74. })
  75. ).toBe('1.23B');
  76. });
  77. it('returns correct strings for Attachments', function () {
  78. expect(formatUsageWithUnits(0, DATA_CATEGORY_INFO.attachment.plural)).toBe('0 GB');
  79. expect(formatUsageWithUnits(MILLION, DATA_CATEGORY_INFO.attachment.plural)).toBe(
  80. '0 GB'
  81. );
  82. expect(formatUsageWithUnits(BILLION, DATA_CATEGORY_INFO.attachment.plural)).toBe(
  83. '1 GB'
  84. );
  85. expect(
  86. formatUsageWithUnits(1.234 * BILLION, DATA_CATEGORY_INFO.attachment.plural)
  87. ).toBe('1.23 GB');
  88. expect(
  89. formatUsageWithUnits(1234 * GIGABYTE, DATA_CATEGORY_INFO.attachment.plural)
  90. ).toBe('1,234 GB');
  91. expect(
  92. formatUsageWithUnits(0, DATA_CATEGORY_INFO.attachment.plural, {isAbbreviated: true})
  93. ).toBe('0 GB');
  94. expect(
  95. formatUsageWithUnits(MILLION, DATA_CATEGORY_INFO.attachment.plural, {
  96. isAbbreviated: true,
  97. })
  98. ).toBe('0 GB');
  99. expect(
  100. formatUsageWithUnits(BILLION, DATA_CATEGORY_INFO.attachment.plural, {
  101. isAbbreviated: true,
  102. })
  103. ).toBe('1 GB');
  104. expect(
  105. formatUsageWithUnits(1.234 * BILLION, DATA_CATEGORY_INFO.attachment.plural, {
  106. isAbbreviated: true,
  107. })
  108. ).toBe('1 GB');
  109. expect(
  110. formatUsageWithUnits(1234 * BILLION, DATA_CATEGORY_INFO.attachment.plural, {
  111. isAbbreviated: true,
  112. })
  113. ).toBe('1K GB');
  114. expect(
  115. formatUsageWithUnits(0, DATA_CATEGORY_INFO.attachment.plural, {
  116. useUnitScaling: true,
  117. })
  118. ).toBe('0 B');
  119. expect(
  120. formatUsageWithUnits(1000, DATA_CATEGORY_INFO.attachment.plural, {
  121. useUnitScaling: true,
  122. })
  123. ).toBe('1 KB');
  124. expect(
  125. formatUsageWithUnits(MILLION, DATA_CATEGORY_INFO.attachment.plural, {
  126. useUnitScaling: true,
  127. })
  128. ).toBe('1 MB');
  129. expect(
  130. formatUsageWithUnits(1.234 * MILLION, DATA_CATEGORY_INFO.attachment.plural, {
  131. useUnitScaling: true,
  132. })
  133. ).toBe('1.23 MB');
  134. expect(
  135. formatUsageWithUnits(1.234 * BILLION, DATA_CATEGORY_INFO.attachment.plural, {
  136. useUnitScaling: true,
  137. })
  138. ).toBe('1.23 GB');
  139. expect(
  140. formatUsageWithUnits(1234 * BILLION, DATA_CATEGORY_INFO.attachment.plural, {
  141. useUnitScaling: true,
  142. })
  143. ).toBe('1.23 TB');
  144. });
  145. });