formatters.spec.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import {
  2. formatMetricUsingFixedUnit,
  3. formattingSupportedMetricUnits,
  4. } from 'sentry/utils/metrics/formatters';
  5. describe('formatMetricUsingFixedUnit', () => {
  6. it('should return the formatted value with the short form of the given unit', () => {
  7. expect(formatMetricUsingFixedUnit(123456, 'millisecond')).toBe('123,456ms');
  8. expect(formatMetricUsingFixedUnit(2.1231245, 'kibibyte')).toBe('2.12KiB');
  9. expect(formatMetricUsingFixedUnit(1222.1231245, 'megabyte')).toBe('1,222.12MB');
  10. });
  11. it.each(formattingSupportedMetricUnits.filter(unit => unit !== 'none'))(
  12. 'appends a unit (%s) for every supported one (except none)',
  13. unit => {
  14. expect(formatMetricUsingFixedUnit(1234.56, unit)).toMatch(/1,234\.56.+/);
  15. }
  16. );
  17. it('should not append a unit for unsupported units and "none"', () => {
  18. expect(formatMetricUsingFixedUnit(1234.56, 'randomunitname')).toBe('1,234.56');
  19. expect(formatMetricUsingFixedUnit(1234.56, 'none')).toBe('1,234.56');
  20. });
  21. it.each(['sum', 'count_unique', 'avg', 'max', 'p50', 'p75', 'p95', 'p99'])(
  22. 'should append a unit (%s) for every operation (except count)',
  23. op => {
  24. expect(formatMetricUsingFixedUnit(1234.56, 'second', op)).toMatch(/1,234\.56s/);
  25. }
  26. );
  27. it('should not append a unit for count operation', () => {
  28. expect(formatMetricUsingFixedUnit(1234.56, 'second', 'count')).toBe('1,234.56');
  29. });
  30. });