Files
ITWorx-Pulse-Public/apps/web/tests/unit/metricClient.test.ts
T
2026-09-30 01:14:48 +00:00

28 lines
1.2 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { rangeForPreset, rangeForSelection } from '../../src/metricClient';
describe('metric range selection', () => {
const now = new Date('2026-08-30T18:00:00.000Z');
it('supports the 30 day operator preset within the existing point budget', () => {
const range = rangeForPreset('30d', now);
expect(range.to).toBe(now.toISOString());
expect(Date.parse(range.to) - Date.parse(range.from)).toBe(30 * 24 * 60 * 60 * 1000);
expect(range.stepSeconds).toBeGreaterThanOrEqual(15);
});
it('turns a valid custom selection into an exact UTC range', () => {
const range = rangeForSelection('custom|2026-08-01T10:00:00.000Z|2026-08-02T10:00:00.000Z', now);
expect(range.from).toBe('2026-08-01T10:00:00.000Z');
expect(range.to).toBe('2026-08-02T10:00:00.000Z');
});
it('fails closed to one hour when a custom range is invalid', () => {
expect(rangeForSelection('custom|broken|2026-08-02T10:00:00.000Z', now)).toEqual(rangeForPreset('1h', now));
});
it('uses bounded recent history while live transport is paused', () => {
expect(rangeForSelection('paused', now)).toEqual(rangeForPreset('live', now));
});
});