utils.spec.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import {DataCategory} from 'sentry/types';
  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, DataCategory.ERRORS)).toBe('0');
  11. expect(formatUsageWithUnits(1000, DataCategory.ERRORS)).toBe('1,000');
  12. expect(formatUsageWithUnits(MILLION, DataCategory.ERRORS)).toBe('1,000,000');
  13. expect(formatUsageWithUnits(BILLION, DataCategory.ERRORS)).toBe('1,000,000,000');
  14. expect(formatUsageWithUnits(0, DataCategory.ERRORS, {isAbbreviated: true})).toBe('0');
  15. expect(formatUsageWithUnits(1000, DataCategory.ERRORS, {isAbbreviated: true})).toBe(
  16. '1K'
  17. );
  18. expect(
  19. formatUsageWithUnits(MILLION, DataCategory.ERRORS, {isAbbreviated: true})
  20. ).toBe('1M');
  21. expect(
  22. formatUsageWithUnits(1.234 * MILLION, DataCategory.ERRORS, {
  23. isAbbreviated: true,
  24. })
  25. ).toBe('1.2M');
  26. expect(
  27. formatUsageWithUnits(1.234 * BILLION, DataCategory.ERRORS, {
  28. isAbbreviated: true,
  29. })
  30. ).toBe('1.23B');
  31. });
  32. it('returns correct strings for Transactions', function () {
  33. expect(formatUsageWithUnits(0, DataCategory.TRANSACTIONS)).toBe('0');
  34. expect(formatUsageWithUnits(1000, DataCategory.TRANSACTIONS)).toBe('1,000');
  35. expect(formatUsageWithUnits(MILLION, DataCategory.TRANSACTIONS)).toBe('1,000,000');
  36. expect(formatUsageWithUnits(BILLION, DataCategory.TRANSACTIONS)).toBe(
  37. '1,000,000,000'
  38. );
  39. expect(
  40. formatUsageWithUnits(0, DataCategory.TRANSACTIONS, {isAbbreviated: true})
  41. ).toBe('0');
  42. expect(
  43. formatUsageWithUnits(1000, DataCategory.TRANSACTIONS, {isAbbreviated: true})
  44. ).toBe('1K');
  45. expect(
  46. formatUsageWithUnits(MILLION, DataCategory.TRANSACTIONS, {isAbbreviated: true})
  47. ).toBe('1M');
  48. expect(
  49. formatUsageWithUnits(1.234 * MILLION, DataCategory.TRANSACTIONS, {
  50. isAbbreviated: true,
  51. })
  52. ).toBe('1.2M');
  53. expect(
  54. formatUsageWithUnits(1.234 * BILLION, DataCategory.TRANSACTIONS, {
  55. isAbbreviated: true,
  56. })
  57. ).toBe('1.23B');
  58. });
  59. it('returns correct strings for Attachments', function () {
  60. expect(formatUsageWithUnits(0, DataCategory.ATTACHMENTS)).toBe('0 GB');
  61. expect(formatUsageWithUnits(MILLION, DataCategory.ATTACHMENTS)).toBe('0 GB');
  62. expect(formatUsageWithUnits(BILLION, DataCategory.ATTACHMENTS)).toBe('1 GB');
  63. expect(formatUsageWithUnits(1.234 * BILLION, DataCategory.ATTACHMENTS)).toBe(
  64. '1.23 GB'
  65. );
  66. expect(formatUsageWithUnits(1234 * GIGABYTE, DataCategory.ATTACHMENTS)).toBe(
  67. '1,234 GB'
  68. );
  69. expect(formatUsageWithUnits(0, DataCategory.ATTACHMENTS, {isAbbreviated: true})).toBe(
  70. '0 GB'
  71. );
  72. expect(
  73. formatUsageWithUnits(MILLION, DataCategory.ATTACHMENTS, {isAbbreviated: true})
  74. ).toBe('0 GB');
  75. expect(
  76. formatUsageWithUnits(BILLION, DataCategory.ATTACHMENTS, {isAbbreviated: true})
  77. ).toBe('1 GB');
  78. expect(
  79. formatUsageWithUnits(1.234 * BILLION, DataCategory.ATTACHMENTS, {
  80. isAbbreviated: true,
  81. })
  82. ).toBe('1 GB');
  83. expect(
  84. formatUsageWithUnits(1234 * BILLION, DataCategory.ATTACHMENTS, {
  85. isAbbreviated: true,
  86. })
  87. ).toBe('1K GB');
  88. expect(
  89. formatUsageWithUnits(0, DataCategory.ATTACHMENTS, {
  90. useUnitScaling: true,
  91. })
  92. ).toBe('0 B');
  93. expect(
  94. formatUsageWithUnits(1000, DataCategory.ATTACHMENTS, {
  95. useUnitScaling: true,
  96. })
  97. ).toBe('1 KB');
  98. expect(
  99. formatUsageWithUnits(MILLION, DataCategory.ATTACHMENTS, {
  100. useUnitScaling: true,
  101. })
  102. ).toBe('1 MB');
  103. expect(
  104. formatUsageWithUnits(1.234 * MILLION, DataCategory.ATTACHMENTS, {
  105. useUnitScaling: true,
  106. })
  107. ).toBe('1.23 MB');
  108. expect(
  109. formatUsageWithUnits(1.234 * BILLION, DataCategory.ATTACHMENTS, {
  110. useUnitScaling: true,
  111. })
  112. ).toBe('1.23 GB');
  113. expect(
  114. formatUsageWithUnits(1234 * BILLION, DataCategory.ATTACHMENTS, {
  115. useUnitScaling: true,
  116. })
  117. ).toBe('1.23 TB');
  118. });
  119. });