Compute analytics timeframe dynamically
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { resolveMaxCount } from '../lib/analytics';
|
||||
import { resolveMaxCount, resolveTimelineHours } from '../lib/analytics';
|
||||
|
||||
describe('resolveMaxCount', () => {
|
||||
it('defaults to 1 for empty input', () => {
|
||||
@@ -14,3 +14,20 @@ describe('resolveMaxCount', () => {
|
||||
expect(resolveMaxCount([0])).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('resolveTimelineHours', () => {
|
||||
it('uses fallback when data is missing', () => {
|
||||
expect(resolveTimelineHours([], 12)).toBe(12);
|
||||
});
|
||||
|
||||
it('calculates rounded hours from timestamps', () => {
|
||||
const start = new Date('2024-01-01T10:00:00Z').toISOString();
|
||||
const end = new Date('2024-01-01T21:00:00Z').toISOString();
|
||||
expect(resolveTimelineHours([start, end], 12)).toBe(11);
|
||||
});
|
||||
|
||||
it('never returns less than 1', () => {
|
||||
const start = new Date('2024-01-01T10:00:00Z').toISOString();
|
||||
expect(resolveTimelineHours([start, start], 12)).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user