UNPKG

1.5 kBJavaScriptView Raw
1import React from 'react';
2import { useChannelSettings } from './useChannelSettings';
3import { renderHook } from '@testing-library/react-hooks';
4import { ProviderPyramid } from 'ProviderPyramid';
5import { selectedChannel } from 'variables';
6
7describe('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 // incVat is false, so we should get false
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 // incVat does not exist, so we should get true
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});