mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-02 23:20:39 +08:00

* feat: dynamic step size for the data for graphs * fix: remove console.log * chore: add jest globals * feat: add step size for dashboard * chore: undo .eslintignore
70 lines
1.5 KiB
TypeScript
70 lines
1.5 KiB
TypeScript
import { expect } from '@jest/globals';
|
|
import dayjs from 'dayjs';
|
|
import getStep, { DefaultStepSize, MaxDataPoints } from 'lib/getStep';
|
|
|
|
describe('lib/getStep', () => {
|
|
test('should return default step when the given range is less than 1 day', () => {
|
|
const start = dayjs();
|
|
const end = start.add(1, 'hour');
|
|
const startUnix = start.valueOf();
|
|
const endUnix = end.valueOf();
|
|
|
|
expect(
|
|
getStep({
|
|
start: startUnix / 1e3,
|
|
end: endUnix / 1e3,
|
|
inputFormat: 's',
|
|
}),
|
|
).toEqual(DefaultStepSize);
|
|
|
|
expect(
|
|
getStep({
|
|
start: startUnix,
|
|
end: endUnix,
|
|
inputFormat: 'ms',
|
|
}),
|
|
).toEqual(DefaultStepSize);
|
|
|
|
expect(
|
|
getStep({
|
|
start: startUnix * 1e6,
|
|
end: endUnix * 1e6,
|
|
inputFormat: 'ns',
|
|
}),
|
|
).toEqual(DefaultStepSize);
|
|
});
|
|
|
|
test('should return relevant step when the given range is greater than 1 day', () => {
|
|
const start = dayjs();
|
|
const end = start.add(1, 'Day').add(1, 'Second');
|
|
const startUnix = start.valueOf();
|
|
const endUnix = end.valueOf();
|
|
|
|
const expectedStepSize = Math.floor(end.diff(start, 's') / MaxDataPoints);
|
|
|
|
expect(
|
|
getStep({
|
|
start: startUnix / 1e3,
|
|
end: endUnix / 1e3,
|
|
inputFormat: 's',
|
|
}),
|
|
).toEqual(expectedStepSize);
|
|
|
|
expect(
|
|
getStep({
|
|
start: startUnix,
|
|
end: endUnix,
|
|
inputFormat: 'ms',
|
|
}),
|
|
).toEqual(expectedStepSize);
|
|
|
|
expect(
|
|
getStep({
|
|
start: startUnix * 1e6,
|
|
end: endUnix * 1e6,
|
|
inputFormat: 'ns',
|
|
}),
|
|
).toEqual(expectedStepSize);
|
|
});
|
|
});
|