-
-
Notifications
You must be signed in to change notification settings - Fork 656
/
useAvgTimeToProduction.test.ts
34 lines (31 loc) · 1.2 KB
/
useAvgTimeToProduction.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { useAvgTimeToProduction } from './useAvgTimeToProduction';
import { renderHook } from '@testing-library/react-hooks';
describe('useAvgTimeToProduction', () => {
test('returns 0 when projectsData is empty', () => {
const projectsData = {};
const { result } = renderHook(() =>
useAvgTimeToProduction(projectsData),
);
expect(result.current).toBe(0);
});
test('calculates result.current time to production correctly', () => {
const projectsData = {
project1: [{ timeToProduction: 10 }, { timeToProduction: 20 }],
project2: [{ timeToProduction: 15 }, { timeToProduction: 25 }],
} as any;
const { result } = renderHook(() =>
useAvgTimeToProduction(projectsData),
);
expect(result.current).toBe(17.5);
});
test('ignores projects without time to production data', () => {
const projectsData = {
project1: [{ timeToProduction: 10 }, { timeToProduction: 20 }],
project2: [],
} as any;
const { result } = renderHook(() =>
useAvgTimeToProduction(projectsData),
);
expect(result.current).toBe(7.5);
});
});