formatTooltipValue.spec.tsx 1.9 KB

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