formatChartValue.spec.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import {formatChartValue} from './formatChartValue';
  2. describe('formatChartValue', () => {
  3. describe('integer', () => {
  4. it.each([
  5. [0, '0'],
  6. [17, '17'],
  7. [1772313, '1,772,313'],
  8. ])('Formats %s as %s', (value, formattedValue) => {
  9. expect(formatChartValue(value, 'integer')).toEqual(formattedValue);
  10. });
  11. });
  12. describe('number', () => {
  13. it.each([
  14. [0, '0'],
  15. [17.1238, '17.124'],
  16. [1772313.1, '1,772,313.1'],
  17. ])('Formats %s as %s', (value, formattedValue) => {
  18. expect(formatChartValue(value, 'number')).toEqual(formattedValue);
  19. });
  20. });
  21. describe('percentage', () => {
  22. it.each([
  23. [0, '0%'],
  24. [0.712, '71.2%'],
  25. [17.123, '1,712.3%'],
  26. [1, '100%'],
  27. ])('Formats %s as %s', (value, formattedValue) => {
  28. expect(formatChartValue(value, 'percentage')).toEqual(formattedValue);
  29. });
  30. });
  31. describe('duration', () => {
  32. it.each([
  33. [0, 'millisecond', '0.00ms'],
  34. [0.712, 'second', '712.00ms'],
  35. [1231, 'second', '20.52min'],
  36. ])('Formats %s as %s', (value, unit, formattedValue) => {
  37. expect(formatChartValue(value, 'duration', unit)).toEqual(formattedValue);
  38. });
  39. });
  40. describe('size', () => {
  41. it.each([
  42. [0, 'byte', '0.0 B'],
  43. [0.712, 'megabyte', '712 KB'],
  44. [1231, 'kibibyte', '1.2 MiB'],
  45. ])('Formats %s as %s', (value, unit, formattedValue) => {
  46. expect(formatChartValue(value, 'size', unit)).toEqual(formattedValue);
  47. });
  48. });
  49. describe('rate', () => {
  50. it.each([
  51. [0, '1/second', '0/s'],
  52. [0.712, '1/second', '0.712/s'],
  53. [12712, '1/second', '12.7K/s'],
  54. [1231, '1/minute', '1.23K/min'],
  55. ])('Formats %s as %s', (value, unit, formattedValue) => {
  56. expect(formatChartValue(value, 'rate', unit)).toEqual(formattedValue);
  57. });
  58. });
  59. });