Skip to content

Commit

Permalink
Adds test for asTransactionRate method (elastic#122072)
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiopro authored and gbamparop committed Jan 12, 2022
1 parent f859f77 commit b61c0dd
Showing 1 changed file with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { asDuration, toMicroseconds, asMillisecondDuration } from './duration';
import { asDuration, asTransactionRate, toMicroseconds, asMillisecondDuration } from './duration';

describe('duration formatters', () => {
describe('asDuration', () => {
Expand Down Expand Up @@ -40,6 +40,57 @@ describe('duration formatters', () => {
});
});

describe('asTransactionRate', () => {
it.each([
[Infinity, 'N/A'],
[-Infinity, 'N/A'],
[null, 'N/A'],
[undefined, 'N/A'],
[NaN, 'N/A'],
])(
'displays the not available label when the number is not finite',
(value, formattedValue) => {
expect(asTransactionRate(value)).toBe(formattedValue);
}
);

it.each([
[0, '0 tpm'],
[0.005, '< 0.1 tpm'],
])(
'displays the correct label when the number is positive and less than 1',
(value, formattedValue) => {
expect(asTransactionRate(value)).toBe(formattedValue);
}
);

it.each([
[1, '1.0 tpm'],
[10, '10.0 tpm'],
[100, '100.0 tpm'],
[1000, '1,000.0 tpm'],
[1000000, '1,000,000.0 tpm'],
])(
'displays the correct label when the number is integer and has zero decimals',
(value, formattedValue) => {
expect(asTransactionRate(value)).toBe(formattedValue);
}
);

it.each([
[1.23, '1.2 tpm'],
[12.34, '12.3 tpm'],
[123.45, '123.5 tpm'],
[1234.56, '1,234.6 tpm'],
[1234567.89, '1,234,567.9 tpm'],
])(
'displays the correct label when the number is positive and has decimal part',
(value, formattedValue) => {
expect(asTransactionRate(value)).toBe(formattedValue);
}
);
});

describe('asMilliseconds', () => {
it('converts to formatted decimal milliseconds', () => {
expect(asMillisecondDuration(0)).toEqual('0 ms');
Expand Down

0 comments on commit b61c0dd

Please sign in to comment.