@laerdal/life-react-components 6.0.0-dev.10.full → 6.0.0-dev.12.full

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/dist/Accordion/__tests__/AccordionMenu.test.tsx +42 -0
  2. package/dist/Accordion/__tests__/ContentAccordion.test.tsx +150 -0
  3. package/dist/AuthPage/__tests__/AuthPage.test.tsx +27 -0
  4. package/dist/Banners/__tests__/Banner.test.tsx +47 -0
  5. package/dist/Banners/__tests__/OverviewBanner.test.tsx +20 -0
  6. package/dist/Breadcrumb/__tests__/Breadcrumb.test.tsx +78 -0
  7. package/dist/Button/__tests__/BackButton.test.tsx +32 -0
  8. package/dist/Button/__tests__/Button.test.tsx +45 -0
  9. package/dist/Button/__tests__/DualButton.test.tsx +119 -0
  10. package/dist/Card/HorizontalCard/__tests__/HorizontalCard.test.tsx +71 -0
  11. package/dist/Card/HorizontalCard/__tests__/VerticalCard.test.tsx +124 -0
  12. package/dist/Card/__tests__/Card.test.tsx +146 -0
  13. package/dist/Chips/__tests__/ActionChip.test.tsx +94 -0
  14. package/dist/Chips/__tests__/ChoiceChips.test.tsx +79 -0
  15. package/dist/Chips/__tests__/FilterChip.test.tsx +95 -0
  16. package/dist/Chips/__tests__/InputChip.test.tsx +155 -0
  17. package/dist/ChipsInput/__tests__/ChipDropdownInput.test.tsx +100 -0
  18. package/dist/ChipsInput/__tests__/ChipInputFields.test.tsx +155 -0
  19. package/dist/Dropdown/__tests__/DropdownFilter.test.tsx +39 -0
  20. package/dist/Footer/__tests__/Footer.test.tsx +182 -0
  21. package/dist/GlobalNavigationBar/__tests__/Logo.test.tsx +39 -0
  22. package/dist/GlobalNavigationBar/desktop/__tests__/DesktopActions.test.tsx +108 -0
  23. package/dist/GlobalNavigationBar/desktop/__tests__/ExtendedMainMenu.test.tsx +28 -0
  24. package/dist/GlobalNavigationBar/desktop/__tests__/MainMenu.test.tsx +55 -0
  25. package/dist/GlobalNavigationBar/desktop/__tests__/RightSideNav.test.tsx +45 -0
  26. package/dist/GlobalNavigationBar/desktop/__tests__/UserMenu.test.tsx +125 -0
  27. package/dist/GlobalNavigationBar/mobile/__tests__/MobileMenu.test.tsx +317 -0
  28. package/dist/GlobalNavigationBar/mobile/__tests__/MobileMenuContent.test.tsx +294 -0
  29. package/dist/GlobalNavigationBar/mobile/__tests__/MobileMenuHeader.test.tsx +195 -0
  30. package/dist/InputFields/__tests__/NumberField.test.tsx +67 -0
  31. package/dist/InputFields/__tests__/NumberInput.test.tsx +68 -0
  32. package/dist/InputFields/__tests__/QuickSearch.test.tsx +42 -0
  33. package/dist/LinearProgress/__tests__/LinearProgress.test.tsx +25 -0
  34. package/dist/List/__tests__/ListRow.test.tsx +18 -0
  35. package/dist/LoadingPage/__tests__/GlobalLoadingPage.test.tsx +23 -0
  36. package/dist/Modals/__tests__/Modal.test.tsx +169 -0
  37. package/dist/Modals/__tests__/ModalContainer.test.tsx +77 -0
  38. package/dist/Modals/__tests__/ModalContent.test.tsx +126 -0
  39. package/dist/NavItem/__tests__/NavItem.test.ts +6 -0
  40. package/dist/NotificationDot/__tests__/NotificationDot.test.tsx +33 -0
  41. package/dist/Paginator/__tests__/Paginator.test.tsx +39 -0
  42. package/dist/Popover/__tests__/Popover.test.tsx +64 -0
  43. package/dist/ProfileButton/__tests__/ProfileButton.test.tsx +31 -0
  44. package/dist/QuizButton/__tests__/QuizButton.test.tsx +53 -0
  45. package/dist/SegmentControl/__tests__/SegmentControl.test.tsx +145 -0
  46. package/dist/SideMenu/__tests__/SideMenu.test.tsx +99 -0
  47. package/dist/Switcher/__tests__/SwitcherMenuItem.tsx +14 -0
  48. package/dist/Table/__tests__/Table.test.tsx +499 -0
  49. package/dist/Tabs/__tests__/HorizontalTabs.test.tsx +95 -0
  50. package/dist/Tabs/__tests__/TabLink.test.tsx +40 -0
  51. package/dist/Tabs/__tests__/Tablist.test.tsx +37 -0
  52. package/dist/Tag/__tests__/Tag.test.tsx +86 -0
  53. package/dist/Toasters/__tests__/Toast.test.tsx +74 -0
  54. package/dist/Toggles/__tests__/ToggleButton.test.tsx +53 -0
  55. package/dist/Toggles/__tests__/ToggleSwitch.test.tsx +87 -0
  56. package/dist/Tooltips/__tests__/TooltipWrapper.test.tsx +16 -0
  57. package/dist/styles/react-datepicker.css +766 -0
  58. package/package.json +4 -3
@@ -0,0 +1,155 @@
1
+ import * as React from 'react';
2
+ import {InputChip} from '../index';
3
+ import {act, fireEvent, render} from '../../test-utils';
4
+ import {States} from '../../types';
5
+ import { SystemIcons } from '../../icons';
6
+
7
+
8
+
9
+
10
+ describe('InputChip', () => {
11
+
12
+ it('should render', () => {
13
+ const wrapper = render(<InputChip variant={States.Default} onRemove={jest.fn()} text={'label'}/>);
14
+
15
+ expect(wrapper.queryByText('label')).toBeInTheDocument();
16
+ });
17
+
18
+ it('should render icon', () => {
19
+ const wrapper = render(<InputChip variant={States.Default} onRemove={jest.fn()} text={'label'} icon={<SystemIcons.Book/>}/>);
20
+
21
+ expect(wrapper.queryByLabelText('Book')).toBeInTheDocument();
22
+ });
23
+
24
+ it('should be focusable if it is not disabled and onClick is defined', () => {
25
+ const wrapper = render(<InputChip variant={States.Default} onRemove={jest.fn()} text={'label'} icon={<SystemIcons.Book/>}
26
+ onClick={jest.fn()}/>);
27
+
28
+ expect(wrapper.container.querySelector('[tabindex="0"]')).toBeInTheDocument();
29
+ });
30
+
31
+ it('should not be focusable if it is disabled', () => {
32
+ const wrapper = render(<InputChip variant={States.Default} onRemove={jest.fn()} text={'label'} icon={<SystemIcons.Book/>}
33
+ disabled={true} onClick={jest.fn()}/>);
34
+
35
+ expect(wrapper.container.querySelector('[tabindex="-1"]')).toBeInTheDocument();
36
+ });
37
+
38
+ it('should call onClick when its clicked', () => {
39
+ const onClickSpy = jest.fn();
40
+ const wrapper = render(<InputChip variant={States.Default} onRemove={jest.fn()} text={'label'} icon={<SystemIcons.Book/>}
41
+ onClick={onClickSpy}/>);
42
+
43
+ act(() => {
44
+ wrapper.getByText('label').click();
45
+ });
46
+
47
+ expect(onClickSpy).toHaveBeenCalled();
48
+ });
49
+
50
+ it('should call onClick when Enter is pressed', () => {
51
+ const onClickSpy = jest.fn();
52
+ const wrapper = render(<InputChip variant={States.Default} onRemove={jest.fn()} text={'label'} icon={<SystemIcons.Book/>}
53
+ onClick={onClickSpy}/>);
54
+
55
+ act(() => {
56
+ fireEvent.keyDown(wrapper.getByText('label'), {key: 'Enter', code: 'Enter'});
57
+ });
58
+
59
+ expect(onClickSpy).toHaveBeenCalled();
60
+ });
61
+
62
+ it('should call onClick when Space is pressed', () => {
63
+ const onClickSpy = jest.fn();
64
+ const wrapper = render(<InputChip variant={States.Default} onRemove={jest.fn()} text={'label'} icon={<SystemIcons.Book/>}
65
+ onClick={onClickSpy}/>);
66
+
67
+ act(() => {
68
+ fireEvent.keyDown(wrapper.getByText('label'), {key: ' ', code: 'Space'});
69
+ });
70
+
71
+ expect(onClickSpy).toHaveBeenCalled();
72
+ });
73
+
74
+ it('should not call onClick when its clicked if disabled', () => {
75
+ const onClickSpy = jest.fn();
76
+ const wrapper = render(<InputChip variant={States.Default} onRemove={jest.fn()} text={'label'} icon={<SystemIcons.Book/>}
77
+ disabled={true} onClick={onClickSpy}/>);
78
+
79
+ act(() => {
80
+ wrapper.getByText('label').click();
81
+ });
82
+
83
+ expect(onClickSpy).not.toHaveBeenCalled();
84
+ });
85
+
86
+ it('should not call onClick when Enter is pressed if disabled', () => {
87
+ const onClickSpy = jest.fn();
88
+ const wrapper = render(<InputChip variant={States.Default} onRemove={jest.fn()} text={'label'} icon={<SystemIcons.Book/>}
89
+ disabled={true} onClick={onClickSpy}/>);
90
+
91
+ act(() => {
92
+ fireEvent.keyDown(wrapper.getByText('label'), {key: 'Enter', code: 'Enter'});
93
+ });
94
+
95
+ expect(onClickSpy).not.toHaveBeenCalled();
96
+ });
97
+
98
+ it('should call onRemove when remove is clicked', () => {
99
+ const onRemoveSpy = jest.fn();
100
+ const wrapper = render(<InputChip variant={States.Default} onRemove={onRemoveSpy} text={'label'} icon={<SystemIcons.Book/>}/>);
101
+
102
+ act(() => {
103
+ fireEvent.click(wrapper.getByLabelText('Close'));
104
+ });
105
+
106
+ expect(onRemoveSpy).toHaveBeenCalled();
107
+ });
108
+
109
+ it('should call onRemove when Enter is pressed on remove button', () => {
110
+ const onRemoveSpy = jest.fn();
111
+ const wrapper = render(<InputChip variant={States.Default} onRemove={onRemoveSpy} text={'label'} icon={<SystemIcons.Book/>}/>);
112
+
113
+ act(() => {
114
+ fireEvent.keyDown(wrapper.getByLabelText('Close'), {key: 'Enter', code: 'Enter'});
115
+ });
116
+
117
+ expect(onRemoveSpy).toHaveBeenCalled();
118
+ });
119
+
120
+ it('should call onRemove when Space is pressed on remove button', () => {
121
+ const onRemoveSpy = jest.fn();
122
+ const wrapper = render(<InputChip variant={States.Default} onRemove={onRemoveSpy} text={'label'} icon={<SystemIcons.Book/>}/>);
123
+
124
+ act(() => {
125
+ fireEvent.keyDown(wrapper.getByLabelText('Close'), {key: ' ', code: 'Space'});
126
+ });
127
+
128
+ expect(onRemoveSpy).toHaveBeenCalled();
129
+ });
130
+
131
+ it('should not call onRemove when remove is clicked and its disabled', () => {
132
+ const onRemoveSpy = jest.fn();
133
+ const wrapper = render(<InputChip variant={States.Default} onRemove={onRemoveSpy} disabled={true} text={'label'}
134
+ icon={<SystemIcons.Book/>}/>);
135
+
136
+ act(() => {
137
+ fireEvent.click(wrapper.getByLabelText('Close'));
138
+ });
139
+
140
+ expect(onRemoveSpy).not.toHaveBeenCalled();
141
+ });
142
+
143
+ it('should not call onRemove when Enter is pressed on remove button and it disabled', () => {
144
+ const onRemoveSpy = jest.fn();
145
+ const wrapper = render(<InputChip variant={States.Default} onRemove={onRemoveSpy} disabled={true} text={'label'}
146
+ icon={<SystemIcons.Book/>}/>);
147
+
148
+ act(() => {
149
+ fireEvent.keyDown(wrapper.getByLabelText('Close'), {key: 'Enter', code: 'Enter'});
150
+ });
151
+
152
+ expect(onRemoveSpy).not.toHaveBeenCalled();
153
+ });
154
+
155
+ });
@@ -0,0 +1,100 @@
1
+ import React from 'react';
2
+ import {act, fireEvent, render, RenderResult} from '../../test-utils';
3
+ import {ChipDropdownInput} from '../..';
4
+ import '../../../jest.setup';
5
+
6
+ const list = ['Contact', 'About', 'Base', 'Blog', 'Custom', 'Support', 'Tools'];
7
+
8
+
9
+
10
+ describe('<ChipDropdownInput />', () => {
11
+ it('Renders with no default values and no items available', async () => {
12
+ let componentResult: RenderResult;
13
+
14
+ //initial values are determined by using multiple hooks (useEffect)
15
+ //in order to be sure we get the last rendered version of the component, we need to wait for it
16
+ await act(async () => {
17
+ componentResult = render(
18
+ <ChipDropdownInput inputId="test_chip" list={[]} values={[]} onValueChange={(input) => {
19
+ }} placeholder="Search" altPlaceholder="" messageOnNoResults="No results found"/>,
20
+ );
21
+ });
22
+ //check correct placeholder displayed
23
+ expect(componentResult!.getByPlaceholderText('Search') as HTMLInputElement).toBeTruthy();
24
+ //check chip input with provided id rendered
25
+ expect(componentResult!.container.querySelector('input[id="test_chip"]')).toBeTruthy();
26
+ //check no initial value displayed
27
+ expect((componentResult!.getByPlaceholderText('Search') as HTMLInputElement).value).toBe('');
28
+ });
29
+
30
+ it('Renders with default values and items available', async () => {
31
+ let componentResult: RenderResult;
32
+ await act(async () => {
33
+ componentResult = render(
34
+ <ChipDropdownInput
35
+ inputId="test_chip"
36
+ list={list}
37
+ values={['Support']}
38
+ onValueChange={(input) => {
39
+ }}
40
+ placeholder="Search"
41
+ altPlaceholder="Type to search"
42
+ messageOnNoResults="No results found"
43
+ />,
44
+ );
45
+ });
46
+ //check alt placeholder displayed when list values
47
+ expect(componentResult!.getByPlaceholderText('Type to search') as HTMLInputElement).toBeTruthy();
48
+ //check correct initial value displayed
49
+ expect(componentResult!.getByText('Support')).toBeTruthy();
50
+ });
51
+
52
+ it('Renders dropdown on input click', async () => {
53
+ const wrapper = render(
54
+ <ChipDropdownInput
55
+ inputId="test_chip"
56
+ list={list}
57
+ values={['Support']}
58
+ onValueChange={(input) => {
59
+ }}
60
+ placeholder="Search"
61
+ altPlaceholder="Type to search"
62
+ messageOnNoResults="No results found"
63
+ />,
64
+ );
65
+
66
+ act(() => {
67
+ fireEvent.click(wrapper.getByPlaceholderText('Type to search'));
68
+ });
69
+
70
+ expect(wrapper.container.querySelector('.show')).toBeInTheDocument();
71
+ });
72
+
73
+ it('Renders dropdown and items are filtered by search criteria', () => {
74
+ const changeMock = jest.fn();
75
+
76
+ const wrapper = render(
77
+ <ChipDropdownInput
78
+ inputId="test_chip"
79
+ list={list}
80
+ values={[]}
81
+ onValueChange={changeMock}
82
+ placeholder="Search"
83
+ altPlaceholder="Type to search"
84
+ messageOnNoResults="No results found"
85
+ />,
86
+ );
87
+
88
+ act(() => {
89
+ fireEvent.change(wrapper.getByPlaceholderText('Search'), {target: {value: 'b'}});
90
+ });
91
+
92
+ list.filter((item) => item.toLowerCase().includes('b')).forEach((item) => {
93
+ expect(wrapper.queryByText(item)).toBeInTheDocument();
94
+ });
95
+
96
+ list.filter((item) => !item.toLowerCase().includes('b')).forEach((item) => {
97
+ expect(wrapper.queryByText(item)).not.toBeInTheDocument();
98
+ });
99
+ });
100
+ });
@@ -0,0 +1,155 @@
1
+ import React from 'react';
2
+ import { act, fireEvent, render, RenderResult } from '../../test-utils';
3
+ import { ChipInput, Size } from '../..';
4
+ import '../../../jest.setup';
5
+
6
+ const list = ['Contact', 'About', 'Base', 'Blog', 'Custom', 'Support', 'Tools'];
7
+
8
+
9
+
10
+ describe('<ChipInput />', () => {
11
+ it('Render component correctly', async () => {
12
+ let componentResult: RenderResult;
13
+
14
+ //initial values are determined by using multiple hooks (useEffect)
15
+ //in order to be sure we get the last rendered version of the component, we need to wait for it
16
+ await act(async () => {
17
+ componentResult = render(
18
+ <ChipInput size={Size.Medium} inputId="utest" values={[list[0]]} onValueChange={() => {}} placeholder="Plchd label" altPlaceholder="Alt plchd label" />,
19
+ );
20
+ });
21
+ //check element wrapper component rendered
22
+ expect(componentResult!.getByTestId('chip-input-container')).toBeTruthy();
23
+ //check correct placeholder displayed
24
+ expect(componentResult!.getByPlaceholderText('Alt plchd label') as HTMLInputElement).toBeTruthy();
25
+ //check chip input with provided id rendered
26
+ expect(componentResult!.container.querySelector('input[id="utest"]')).toBeTruthy();
27
+ });
28
+
29
+ it('Render component with correct size', async () => {
30
+ let componentResult: RenderResult;
31
+
32
+ await act(async () => {
33
+ componentResult = render(
34
+ <ChipInput size={Size.Small} inputId="utest" values={[list[0]]} onValueChange={() => {}} placeholder="Plchd label" altPlaceholder="Alt plchd label" />,
35
+ );
36
+ });
37
+ //check element wrapper component rendered
38
+ expect(componentResult!.getByTestId('chip-input-container')).toBeTruthy();
39
+
40
+ //check element has correct class size present
41
+ expect(componentResult!.getByTestId('chip-input-container')).toHaveClass('small');
42
+ });
43
+
44
+ it('Test component focused on click', async () => {
45
+ let componentResult: RenderResult;
46
+
47
+ //initial values are determined by using multiple hooks (useEffect)
48
+ //in order to be sure we get the last rendered version of the component, we need to wait for it
49
+ await act(async () => {
50
+ componentResult = render(
51
+ <ChipInput size={Size.Small} inputId="utest" values={[list[0]]} onValueChange={() => {}} placeholder="Plchd label" altPlaceholder="Alt plchd label" />,
52
+ );
53
+ });
54
+ //check element wrapper component rendered
55
+ expect(componentResult!.getByTestId('chip-input-container')).toBeTruthy();
56
+
57
+ //check focus not present
58
+ expect(componentResult!.getByPlaceholderText('Alt plchd label') as HTMLInputElement).not.toHaveFocus();
59
+
60
+ //trigger click for chip input
61
+ fireEvent.click(componentResult!.getByTestId('chip-input-container'));
62
+
63
+ //check focus present
64
+ expect(componentResult!.getByPlaceholderText('Alt plchd label') as HTMLInputElement).toHaveFocus();
65
+ });
66
+
67
+ it('Test component callbacks', async () => {
68
+ const onValueChange = jest.fn();
69
+ let componentResult: RenderResult;
70
+
71
+ //initial values are determined by using multiple hooks (useEffect)
72
+ //in order to be sure we get the last rendered version of the component, we need to wait for it
73
+ await act(async () => {
74
+ componentResult = render(
75
+ <ChipInput size={Size.Small} inputId="utest" values={[list[0]]} onValueChange={onValueChange} placeholder="Plchd label" altPlaceholder="Alt plchd label" />,
76
+ );
77
+ });
78
+
79
+ //mock scrollIntoView otherwise test will fail when selecting an item
80
+ window.HTMLElement.prototype.scrollIntoView = function () {};
81
+
82
+ const inputElem = componentResult!.getByPlaceholderText('Alt plchd label') as HTMLInputElement;
83
+
84
+ //check element wrapper component rendered
85
+ expect(componentResult!.getByTestId('chip-input-container')).toBeTruthy();
86
+
87
+ //trigger click for chip input
88
+ fireEvent.click(componentResult!.getByTestId('chip-input-container'));
89
+
90
+ //trigger value change
91
+ fireEvent.change(inputElem, { target: { value: list[1] } });
92
+
93
+ //pressing enter will automatically select the found item
94
+ fireEvent.keyDown(inputElem, { key: 'Enter', code: 'Enter', charCode: 13 });
95
+
96
+ expect(onValueChange).toHaveBeenCalledTimes(1);
97
+
98
+ //two items present, default and the new selected one
99
+ expect(componentResult!.container.querySelectorAll('.chip-icon')).toHaveLength(2);
100
+
101
+ //pressing on the x button, the item will be removed from selection
102
+ const removeItemElem = componentResult!.getByTestId('chip-input-container').querySelector('div.chip-icon') as HTMLDivElement;
103
+
104
+ fireEvent.click(removeItemElem);
105
+
106
+ //change callback should be called
107
+ expect(onValueChange).toHaveBeenCalledTimes(2);
108
+ //only one item should be present at the moment
109
+ expect(componentResult!.container.querySelectorAll('.chip-icon')).toHaveLength(1);
110
+
111
+ //expect that on pressing backspace the added item will be deleted
112
+ fireEvent.keyDown(inputElem, { key: 'Backspace', charCode: 8 });
113
+
114
+ //no item should be present at the moment
115
+ expect(componentResult!.container.querySelectorAll('.chip-icon')).toHaveLength(0);
116
+ });
117
+
118
+ it('Test component chips are removed when clear all button toggled', async () => {
119
+ const onValueChange = jest.fn();
120
+ let componentResult: RenderResult;
121
+
122
+ //initial values are determined by using multiple hooks (useEffect)
123
+ //in order to be sure we get the last rendered version of the component, we need to wait for it
124
+ await act(async () => {
125
+ componentResult = render(
126
+ <ChipInput size={Size.Small} inputId="utest" values={[list[0]]} onValueChange={onValueChange} placeholder="Plchd label" altPlaceholder="Alt plchd label" />,
127
+ );
128
+ });
129
+
130
+ //check element wrapper component rendered
131
+ expect(componentResult!.getByTestId('chip-input-container')).toBeTruthy();
132
+
133
+ //one item present, the default one
134
+ expect(componentResult!.container.querySelectorAll('.chip-icon')).toHaveLength(1);
135
+ const input = componentResult!.getByPlaceholderText('Alt plchd label') as HTMLInputElement;
136
+
137
+ const mockInputData = 'mock data';
138
+ //trigger value change
139
+ fireEvent.change(input, { target: { value: mockInputData } });
140
+
141
+ expect(input).toHaveValue(mockInputData);
142
+
143
+ //expect clear button to be displayed
144
+ expect(componentResult!.getByTestId('clear-btn-utest')).toBeTruthy();
145
+
146
+ //press on clear button
147
+ fireEvent.click(componentResult!.getByTestId('clear-btn-utest'));
148
+
149
+ //expect input to have no value
150
+ expect(input).toHaveValue('');
151
+
152
+ //one chip selected
153
+ expect(componentResult!.container.querySelectorAll('.chip-icon')).toHaveLength(1);
154
+ });
155
+ });
@@ -0,0 +1,39 @@
1
+ import React from 'react';
2
+ import { render } from '../../test-utils';
3
+ import { DropdownFilter } from '../index';
4
+
5
+ jest.mock('react-resize-detector', () => ({
6
+ // @ts-ignore
7
+ ...jest.requireActual('react-resize-detector'),
8
+ useResizeDetector: (object: any) => ({ height: 100, width: 120})
9
+ }));
10
+
11
+
12
+
13
+
14
+ const list = [{value: 'Contact'},
15
+ {value: 'About'},
16
+ {value: 'Base'},
17
+ {value: 'Blog'},
18
+ {value: 'Contact 3'},
19
+ {value: 'Custom'},
20
+ {value: 'Support'},
21
+ {value: 'Tools'}];
22
+
23
+ describe('<DropdownFilter />', () => {
24
+ it('Renders with no default value', async () => {
25
+ const { getByPlaceholderText } = render(<DropdownFilter id="Dropdown" list={list} placeholder="Placeholder" />);
26
+ expect((getByPlaceholderText('Placeholder') as HTMLInputElement).value).toBe('');
27
+ });
28
+
29
+ it('Renders with required input if specified', async () => {
30
+ const { getByPlaceholderText } = render(<DropdownFilter id="Dropdown" list={list} placeholder="Placeholder" required />);
31
+ expect((getByPlaceholderText('Placeholder') as HTMLInputElement).required).toBe(true);
32
+ });
33
+
34
+ it('Renders with inital value if specified', async () => {
35
+ const initialValue = 'Contact';
36
+ const { getByPlaceholderText } = render(<DropdownFilter id="Dropdown" list={list} placeholder="Placeholder" value={initialValue} />);
37
+ expect((getByPlaceholderText('Placeholder') as HTMLInputElement).value).toBe(initialValue);
38
+ });
39
+ });
@@ -0,0 +1,182 @@
1
+ import React from 'react';
2
+ import { fireEvent, render } from '../../test-utils';
3
+ import 'jest-styled-components';
4
+ import Footer from '../Footer';
5
+ import { COLORS } from '../../styles';
6
+ import SiteFooter from '../SiteFooter';
7
+ import FooterDropdownLinks from '../Components/FooterDropdownLinks';
8
+
9
+ const animate = require('animated-scroll-to');
10
+
11
+ jest.mock('react-resize-detector', () => ({
12
+ // @ts-ignore
13
+ ...jest.requireActual('react-resize-detector'),
14
+ useResizeDetector: (object: any) => ({ height: 100, width: 120})
15
+ }));
16
+
17
+ const scrollSpy = jest.fn()
18
+ animate.default = scrollSpy;
19
+
20
+ describe('<Footer />',()=>{
21
+ beforeEach(()=>scrollSpy.mockReset());
22
+
23
+ it('renders footer', async () => {
24
+ const{getByText} = render(
25
+ <Footer>
26
+ <div>Test Footer</div>
27
+ </Footer>
28
+ );
29
+
30
+ expect(getByText('Test Footer')).toBeDefined();
31
+ })
32
+
33
+ it('renders footer global content', async () => {
34
+ const{getByTestId} = render(
35
+ <Footer>
36
+ <div>Test Footer</div>
37
+ </Footer>
38
+ );
39
+
40
+ expect(getByTestId('footer-content')).toBeDefined();
41
+ expect(getByTestId('footer-content')).toHaveStyleRule('background-color',COLORS.primary_700);
42
+ expect(getByTestId('footer-content')).toHaveStyleRule('min-height','8px');
43
+ expect(getByTestId('footer-content')).toHaveStyleRule('color','white');
44
+ })
45
+
46
+ it('renders site footer', async () => {
47
+ const{getByTestId} = render(
48
+ <SiteFooter id='testFooter' toTopText='Scroll To Top'/>
49
+ );
50
+
51
+ expect(getByTestId('footer-container')).toBeDefined();
52
+ expect(getByTestId('footer-container')).toHaveStyleRule('background-color', COLORS.neutral_800);
53
+ expect(getByTestId('footer-container')).toHaveStyleRule('border-top', `8px solid ${COLORS.neutral_200}`);
54
+ })
55
+
56
+ it('renders site footer to top text', async () => {
57
+ const{getByText} = render(
58
+
59
+ <SiteFooter id='testFooter' toTopText='Scroll To Top'/>
60
+
61
+ );
62
+
63
+ expect(getByText('Scroll To Top')).toBeDefined();
64
+ })
65
+
66
+ it('performs navigation on click', async () => {
67
+ const{getByTestId} = render(
68
+
69
+ <SiteFooter id='testFooter' toTopText='Scroll To Top'/>
70
+
71
+ );
72
+
73
+ fireEvent.click(getByTestId('toTopNavigation'));
74
+ expect(scrollSpy).toHaveBeenCalledWith(0);
75
+ })
76
+
77
+ it('performs navigation on enter', async () => {
78
+ const{getByTestId} = render(
79
+
80
+ <SiteFooter id='testFooter' toTopText='Scroll To Top'/>
81
+
82
+ );
83
+
84
+ fireEvent.keyDown(getByTestId('toTopNavigation'), {key: 'Enter', code: 'Enter', charCode: 13});
85
+ expect(scrollSpy).toHaveBeenCalledWith(0);
86
+ })
87
+
88
+ it('does not performs navigation on key other than enter', async () => {
89
+ const{getByTestId} = render(
90
+
91
+ <SiteFooter id='testFooter' toTopText='Scroll To Top'/>
92
+
93
+ );
94
+
95
+ fireEvent.keyDown(getByTestId('toTopNavigation'), {key: 'A', code: 'KeyA'});
96
+ expect(scrollSpy).not.toHaveBeenCalled();
97
+ })
98
+
99
+ it('renders site footer copyright', async () => {
100
+ const{getByText} = render(
101
+
102
+ <SiteFooter id='testFooter' toTopText='Scroll To Top' copyrightText='this is copyright'/>
103
+
104
+ );
105
+
106
+ expect(getByText('this is copyright')).toBeDefined();
107
+ })
108
+
109
+ it('renders site footer links', async () => {
110
+ const{getByText} = render(
111
+
112
+ <SiteFooter id='testFooter' toTopText='Scroll To Top' bottomLinks={[{label:'testLabel', to:'target'}]}/>
113
+
114
+ );
115
+
116
+ expect(getByText('testLabel')).toBeDefined();
117
+ })
118
+
119
+ it('renders site footer nav section', async () => {
120
+ const{getByText} = render(
121
+
122
+ <SiteFooter id='testFooter' toTopText='Scroll To Top' navOptions={{sections:[{header:'headerText',links:[{label:'labelText',to:'target'}]}]}}/>
123
+
124
+ );
125
+
126
+ expect(getByText('headerText')).toBeDefined();
127
+ expect(getByText('labelText')).toBeDefined();
128
+ })
129
+
130
+ it('renders site footer newsletter and social section', async () => {
131
+ const signUpFn = jest.fn();
132
+
133
+ const{getByText, getByTestId, getByPlaceholderText} = render(
134
+
135
+ <SiteFooter id='testFooter' toTopText='Scroll To Top' includeNewsletterAndSocialSection={true}
136
+ placeholderEmailField='a@a.com' newsletterLabel='new news'
137
+ onNewsletterSignup={(e)=>signUpFn(e)}/>
138
+
139
+ );
140
+
141
+ expect(getByPlaceholderText('a@a.com')).toBeDefined();
142
+ expect(getByText('new news')).toBeDefined();
143
+
144
+ fireEvent.click(getByTestId('newsBtn'));
145
+ expect(signUpFn).toBeCalledTimes(1);
146
+ })
147
+
148
+ it('updates newsletter email', async () => {
149
+ const{getByText, getByPlaceholderText} = render(
150
+
151
+ <SiteFooter id='testFooter' toTopText='Scroll To Top' includeNewsletterAndSocialSection={true}
152
+ placeholderEmailField='a@a.com' newsletterLabel='new news' />
153
+
154
+ );
155
+
156
+ expect(getByPlaceholderText('a@a.com')).toBeDefined();
157
+ expect(getByText('new news')).toBeDefined();
158
+ fireEvent.change(getByPlaceholderText('a@a.com'), {target: {value: 'abc'}});
159
+ expect((getByPlaceholderText('a@a.com') as HTMLInputElement).value).toBe('abc');
160
+ })
161
+
162
+ it('renders site footer dropdown links', async () => {
163
+ const{getByText} = render(
164
+ <FooterDropdownLinks navSection={{header:'sample header', links:[{label:'labelText', to:'labelTarget'}]}} width={200}/>
165
+ );
166
+
167
+ expect(getByText('sample header')).toBeDefined();
168
+ expect(getByText('labelText')).toBeDefined();
169
+ })
170
+
171
+ it('opens dropdown links on mouse click', async () => {
172
+ const{getByRole} = render(
173
+ <FooterDropdownLinks navSection={{header:'sample header', links:[{label:'labelText', to:'labelTarget'}]}} width={200}/>
174
+ );
175
+
176
+ expect(getByRole('button')).toBeDefined();
177
+ fireEvent.click(getByRole('button'));
178
+ expect(getByRole('button').classList.contains('open')).toBe(true);
179
+ fireEvent.click(getByRole('button'));
180
+ expect(getByRole('button').classList.contains('open')).toBe(false);
181
+ })
182
+ })
@@ -0,0 +1,39 @@
1
+ import * as React from 'react';
2
+ import {act, fireEvent, render} from '../../test-utils';
3
+ import Logo from '../Logo';
4
+ import { NavigationProvider } from '../../Navigation';
5
+
6
+ describe('Logo', () => {
7
+
8
+ const navProps = {
9
+ currentPath: '',
10
+ isActiveRoute: () => false,
11
+ navigate: (path: string, isExternal: boolean) => {}
12
+ };
13
+
14
+
15
+ it('should render Laerdal logo', () => {
16
+ const wrapper = render(<NavigationProvider {...navProps}><Logo name={'name'}/></NavigationProvider>);
17
+
18
+ expect(wrapper.getByText('name')).toBeDefined();
19
+ expect(wrapper.getByText('Laerdal logo')).toBeDefined();
20
+ });
21
+
22
+ it('should render beta tag', () => {
23
+ const wrapper = render(<NavigationProvider {...navProps}><Logo name={'name'} showBetaTag={true}/></NavigationProvider>);
24
+
25
+ expect(wrapper.getByText('BETA')).toBeDefined();
26
+ });
27
+
28
+ it('should call onClick when logo is clicked', () => {
29
+ const onClickSpy = jest.fn();
30
+ const wrapper = render(<NavigationProvider {...navProps}><Logo name={'name'} onClick={onClickSpy}/></NavigationProvider>);
31
+
32
+ act(() => {
33
+ fireEvent.click(wrapper.container.querySelector('a')!);
34
+ });
35
+
36
+ expect(onClickSpy).toHaveBeenCalled();
37
+ });
38
+
39
+ });