Skip to content

Commit baf9373

Browse files
committed
tests: add test coverages for hooks
1 parent d1396b8 commit baf9373

File tree

4 files changed

+47
-72
lines changed

4 files changed

+47
-72
lines changed

lib/PrivilegedDonorContacts/hooks/useCategoriesDictionary/index.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

lib/PrivilegedDonorContacts/hooks/useCategoriesDictionary/useCategoriesDictionary.js

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { QueryClient, QueryClientProvider } from 'react-query';
2+
3+
import { renderHook } from '@testing-library/react-hooks';
4+
import { useFetchPrivilegedContacts } from './useFetchPrivilegedContacts';
5+
import { DEFAULT_DATA } from '../constants';
6+
7+
const queryClient = new QueryClient();
8+
9+
const wrapper = ({ children }) => (
10+
<QueryClientProvider client={queryClient}>
11+
{children}
12+
</QueryClientProvider>
13+
);
14+
15+
describe('useFetchPrivilegedContacts', () => {
16+
it('should return default data if no privileged contact ids provided', () => {
17+
const { result } = renderHook(() => useFetchPrivilegedContacts(), { wrapper });
18+
19+
expect(result.current).toEqual({
20+
contacts: DEFAULT_DATA,
21+
isLoading: false,
22+
});
23+
});
24+
25+
it('should return data if privileged contact ids provided', () => {
26+
const { result } = renderHook(() => useFetchPrivilegedContacts(['1']), { wrapper });
27+
28+
expect(result.current).toEqual({
29+
contacts: DEFAULT_DATA,
30+
isLoading: true,
31+
});
32+
});
33+
});

lib/PrivilegedDonorContacts/hooks/useTranslatedCategories/useTranslatedCategories.test.js

Lines changed: 14 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -10,69 +10,24 @@ jest.mock('react-intl', () => ({
1010
useIntl: jest.fn(),
1111
}));
1212

13+
const mockCategories = [{
14+
id: '1',
15+
value: 'Category 1',
16+
}, {
17+
id: '2',
18+
value: 'Category 2',
19+
}];
20+
1321
describe('useTranslatedCategories', () => {
14-
// it('should return empty array if categories is not provided', () => {
15-
// const result = useTranslatedCategories();
22+
it('should return empty array if categories is not provided', () => {
23+
const { result } = renderHook(() => useTranslatedCategories());
1624

17-
// expect(result).toEqual([undefined]);
18-
// });
25+
expect(result.current).toEqual([undefined]);
26+
});
1927

2028
it('should return translated categories', () => {
21-
const categories = [{
22-
id: '1',
23-
value: 'Category 1',
24-
}, {
25-
id: '2',
26-
value: 'Category 2',
27-
}];
28-
const { result } = renderHook(() => useTranslatedCategories(categories));
29+
const { result } = renderHook(() => useTranslatedCategories(mockCategories));
2930

30-
console.log(result.current);
31-
32-
expect(result.current).toEqual([{
33-
id: '1',
34-
value: 'Category 1',
35-
}, {
36-
id: '2',
37-
value: 'Category 2',
38-
}]);
31+
expect(result.current).toEqual([mockCategories]);
3932
});
40-
41-
// it('should return translated categories', () => {
42-
// const categories = [{
43-
// id: '1',
44-
// value: 'Category 1',
45-
// }, {
46-
// id: '2',
47-
// value: 'Category 2',
48-
// }];
49-
// const result = useTranslatedCategories(categories);
50-
51-
// expect(result).toEqual([{
52-
// id: '1',
53-
// value: 'Category 1',
54-
// }, {
55-
// id: '2',
56-
// value: 'Category 2',
57-
// }]);
58-
// });
59-
60-
// it('should return translated categories', () => {
61-
// const categories = [{
62-
// id: '1',
63-
// value: 'Category 1',
64-
// }, {
65-
// id: '2',
66-
// value: 'Category 2',
67-
// }];
68-
// const result = useTranslatedCategories(categories);
69-
70-
// expect(result).toEqual([{
71-
// id: '1',
72-
// value: 'Category 1',
73-
// }, {
74-
// id: '2',
75-
// value: 'Category 2',
76-
// }]);
77-
// });
7833
});

0 commit comments

Comments
 (0)