1 | import React from 'react';
|
2 | import { useChannelSettings } from './useChannelSettings';
|
3 | import { renderHook } from '@testing-library/react-hooks';
|
4 | import { ProviderPyramid } from 'ProviderPyramid';
|
5 | import { selectedChannel } from 'variables';
|
6 |
|
7 | describe('useChannelSettings', () => {
|
8 | it('returns all channel settings', () => {
|
9 | const { result } = renderHook(() => useChannelSettings(), {
|
10 | wrapper: ProviderPyramid
|
11 | });
|
12 |
|
13 | expect(result.current).toStrictEqual(selectedChannel.settings);
|
14 | });
|
15 |
|
16 | it('sets pricesIncVat to true if it does not exist on settings', () => {
|
17 | const mockChannel = {
|
18 | ...selectedChannel,
|
19 | settings: { ...selectedChannel.settings, pricesIncVat: false }
|
20 | };
|
21 |
|
22 |
|
23 | {
|
24 | const wrapper = ({ children }) => (
|
25 | <ProviderPyramid selectedChannel={mockChannel}>
|
26 | {children}
|
27 | </ProviderPyramid>
|
28 | );
|
29 | const { result } = renderHook(() => useChannelSettings(), {
|
30 | wrapper
|
31 | });
|
32 |
|
33 | expect(result.current.pricesIncVat).toBe(false);
|
34 | }
|
35 |
|
36 |
|
37 | {
|
38 | delete mockChannel.settings.pricesIncVat;
|
39 | const wrapper = ({ children }) => (
|
40 | <ProviderPyramid selectedChannel={mockChannel}>
|
41 | {children}
|
42 | </ProviderPyramid>
|
43 | );
|
44 | const { result } = renderHook(() => useChannelSettings(), {
|
45 | wrapper
|
46 | });
|
47 |
|
48 | expect(result.current.pricesIncVat).toBe(true);
|
49 | }
|
50 | });
|
51 | });
|