formatYAxisValue.spec.tsx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import {formatYAxisValue} from './formatYAxisValue';
  2. describe('formatYAxisValue', () => {
  3. describe('integer', () => {
  4. it.each([
  5. [0, '0'],
  6. [17, '17'],
  7. [171, '171'],
  8. [17111, '17k'],
  9. [17_000_110, '17m'],
  10. [1_000_110_000, '1b'],
  11. ])('Formats %s as %s', (value, formattedValue) => {
  12. expect(formatYAxisValue(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(formatYAxisValue(value, 'number')).toEqual(formattedValue);
  21. });
  22. });
  23. describe('percentage', () => {
  24. it.each([
  25. [0, '0'],
  26. [0.00005, '0.005%'],
  27. [0.712, '71.2%'],
  28. [17.123, '1,712.3%'],
  29. [1, '100%'],
  30. ])('Formats %s as %s', (value, formattedValue) => {
  31. expect(formatYAxisValue(value, 'percentage')).toEqual(formattedValue);
  32. });
  33. });
  34. describe('duration', () => {
  35. it.each([
  36. [0, 'millisecond', '0'],
  37. [0.712, 'second', '712ms'],
  38. [1230, 'second', '20.5min'],
  39. ])('Formats %s as %s', (value, unit, formattedValue) => {
  40. expect(formatYAxisValue(value, 'duration', unit)).toEqual(formattedValue);
  41. });
  42. });
  43. describe('size', () => {
  44. it.each([
  45. [0, 'byte', '0'],
  46. [0.712, 'megabyte', '712 KB'],
  47. [1231, 'kibibyte', '1.2 MiB'],
  48. ])('Formats %s as %s', (value, unit, formattedValue) => {
  49. expect(formatYAxisValue(value, 'size', unit)).toEqual(formattedValue);
  50. });
  51. });
  52. describe('rate', () => {
  53. it.each([
  54. [0, '1/second', '0'],
  55. [-3, '1/second', '-3/s'],
  56. [0.712, '1/second', '0.712/s'],
  57. [12700, '1/second', '12.7K/s'],
  58. [0.0003, '1/second', '0.0003/s'],
  59. [0.00000153, '1/second', '0.00000153/s'],
  60. [0.35, '1/second', '0.35/s'],
  61. [10, '1/second', '10/s'],
  62. [10.0, '1/second', '10/s'],
  63. [1231, '1/minute', '1.231K/min'],
  64. [110000, '1/second', '110K/s'],
  65. [110001, '1/second', '110.001K/s'],
  66. [123456789, '1/second', '123.457M/s'],
  67. ])('Formats %s as %s', (value, unit, formattedValue) => {
  68. expect(formatYAxisValue(value, 'rate', unit)).toEqual(formattedValue);
  69. });
  70. });
  71. });