@laerdal/life-react-components 6.0.0-dev.10.full → 6.0.0-dev.13.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 (62) 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/VerticalTabs.cjs +1 -0
  50. package/dist/Tabs/VerticalTabs.cjs.map +1 -1
  51. package/dist/Tabs/VerticalTabs.js +1 -0
  52. package/dist/Tabs/VerticalTabs.js.map +1 -1
  53. package/dist/Tabs/__tests__/HorizontalTabs.test.tsx +95 -0
  54. package/dist/Tabs/__tests__/TabLink.test.tsx +40 -0
  55. package/dist/Tabs/__tests__/Tablist.test.tsx +37 -0
  56. package/dist/Tag/__tests__/Tag.test.tsx +86 -0
  57. package/dist/Toasters/__tests__/Toast.test.tsx +74 -0
  58. package/dist/Toggles/__tests__/ToggleButton.test.tsx +53 -0
  59. package/dist/Toggles/__tests__/ToggleSwitch.test.tsx +87 -0
  60. package/dist/Tooltips/__tests__/TooltipWrapper.test.tsx +16 -0
  61. package/dist/styles/react-datepicker.css +766 -0
  62. package/package.json +4 -3
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import {render} from '../../test-utils';
3
+ import {ListRow} from '../index';
4
+ import {Size} from '../../types';
5
+ import {SystemIcons} from '../../icons';
6
+
7
+ describe('<ListRow />', () => {
8
+ it('Renders', async () => {
9
+ const {getByText} = render(
10
+ <ListRow
11
+ icon={<SystemIcons.Institute/>}
12
+ mainText={'Laerdal Medical AS'}
13
+ size={Size.Small}
14
+ disabled={false}/>,
15
+ );
16
+ expect(getByText('Laerdal Medical AS')).toBeDefined();
17
+ });
18
+ });
@@ -0,0 +1,23 @@
1
+ import React from 'react';
2
+ import { render } from '../../test-utils';
3
+ import { GlobalLoadingPage } from '../index';
4
+ import 'jest-styled-components';
5
+ import { COLORS } from '../../styles';
6
+
7
+
8
+
9
+
10
+ describe('<GlobalLoadingPage />', () => {
11
+ it('Renders GlobalLoadingPage', async () => {
12
+ const optionalMessage = 'This is the optional message';
13
+ const { queryByText, getByTestId } = render(<GlobalLoadingPage optionalMessage={optionalMessage} />);
14
+ expect(queryByText(optionalMessage)).toBeDefined();
15
+ expect(getByTestId('TestLoadingMain')).toBeDefined();
16
+ expect(getByTestId('TestLoadingMain')).toHaveStyleRule('background-color', COLORS.primary_20);
17
+ expect(getByTestId('TestLoadingMain')).toHaveStyleRule('height', '100%');
18
+ expect(getByTestId('TestLoadingLogoAndMessage')).toBeDefined();
19
+ expect(getByTestId('TestLoadingLogoAndMessage')).toHaveStyleRule('position', 'absolute');
20
+ expect(getByTestId('TestLoadingLogoAndMessage')).toHaveStyleRule('align-items', 'center');
21
+ expect(getByTestId('TestLoadingLogoAndMessage')).toHaveStyleRule('bottom', '36px');
22
+ });
23
+ });
@@ -0,0 +1,169 @@
1
+ import * as React from 'react';
2
+ import {render} from '../../test-utils';
3
+ import 'jest-styled-components';
4
+ import {ModalDialog} from '..';
5
+ import {Size, SystemIcons} from '../..';
6
+
7
+
8
+
9
+ describe('<ModalDialog />', () => {
10
+ let mountingDiv: HTMLElement;
11
+
12
+ beforeEach(() => {
13
+ //being rendered as a React.Portal we need to have the 'root' div defined
14
+ mountingDiv = document.createElement('div');
15
+ mountingDiv.id = 'root';
16
+ document.body.appendChild(mountingDiv);
17
+ });
18
+
19
+ afterEach(() => {
20
+ document.body.removeChild(mountingDiv);
21
+ });
22
+
23
+ it('Check modal not rendered when isModalOpen is false', async () => {
24
+ const {container, getByText} = render(
25
+ <ModalDialog
26
+ key="smallModalWithoutImage"
27
+ title={'Header'}
28
+ size={Size.Small}
29
+ isModalOpen={false}
30
+ closeAction={() => {
31
+ }}
32
+ submitAction={() => {
33
+ }}
34
+ />,
35
+ );
36
+ //check modal portal not exists when modal not opened
37
+ expect(container.querySelector('.ReactModalPortal')).toBeNull();
38
+ });
39
+
40
+ it('Check modal visible, title and footer buttons displayed correctly', async () => {
41
+ const {container, getByText} = render(
42
+ <ModalDialog
43
+ key="smallModalWithoutImage"
44
+
45
+ title={'Header'}
46
+ size={Size.Small}
47
+ isModalOpen={true}
48
+ closeAction={() => {
49
+ }}
50
+ submitAction={() => {
51
+ }}
52
+ buttons={[
53
+ {
54
+ action: () => {
55
+ },
56
+ text: 'Close',
57
+ variant: 'tertiary',
58
+ },
59
+ {
60
+ action: () => {
61
+ },
62
+ text: 'Save',
63
+ },
64
+ ]}
65
+ />,
66
+ );
67
+ //check modal portal defined
68
+ expect(container.querySelector('.ReactModalPortal')).toBeDefined();
69
+ //Check header and footer buttons
70
+ expect(getByText('Header')).toBeDefined();
71
+ expect(getByText('Close')).toBeDefined();
72
+ expect(getByText('Save')).toBeDefined();
73
+ });
74
+
75
+ it('Check tooltip, and link displayed without right footer buttons', async () => {
76
+ const {baseElement, getByText} = render(
77
+ <ModalDialog
78
+ key="smallModalWithoutImage"
79
+
80
+ title={'Header'}
81
+ size={Size.Small}
82
+ isModalOpen={true}
83
+ closeAction={() => {
84
+ }}
85
+ submitAction={() => {
86
+ }}
87
+ tooltip={'some test tooltip'}
88
+ leftFooterAction={{
89
+ id: 'test-link',
90
+ actionType: 'hyperlink',
91
+ text: 'Link',
92
+ href: 'http://test.com',
93
+ icon: <></>,
94
+ variant: 'default'
95
+ }}
96
+ />,
97
+ );
98
+ //check tooltip displayed
99
+ expect(getByText('some test tooltip').textContent).toBeDefined();
100
+ //check footer link displayed
101
+ expect(getByText('Link').children).toBeDefined();
102
+ });
103
+
104
+ it('Check note and footer note displayed', async () => {
105
+ const {baseElement, getByText} = render(
106
+ <ModalDialog
107
+ key="smallModalWithoutImage"
108
+
109
+ title={'Header'}
110
+ size={Size.Small}
111
+ isModalOpen={true}
112
+ closeAction={() => {
113
+ }}
114
+ submitAction={() => {
115
+ }}
116
+ leftFooterAction={{id: 'test-note', actionType: 'note', text: 'Test note', icon: <SystemIcons.Information/>}}
117
+ note={'Message text'}
118
+ state={'critical'}
119
+ />,
120
+ );
121
+ //check footer note text displayed
122
+ expect(getByText('Test note').textContent).toBeDefined();
123
+ //check note section added
124
+ expect(baseElement.querySelectorAll('section')?.length).toEqual(4);
125
+ //check note message displayed
126
+ expect(getByText('Message text').children).toBeDefined();
127
+ });
128
+
129
+ it('Check back button and close icon displayed', async () => {
130
+ const {baseElement, getByText, container} = render(
131
+ <ModalDialog
132
+ key="smallModalWithoutImage"
133
+
134
+ title={'Header'}
135
+ size={Size.Small}
136
+ backButton={() => {
137
+ }}
138
+ isModalOpen={true}
139
+ closeAction={() => {
140
+ }}
141
+ submitAction={() => {
142
+ }}
143
+ />,
144
+ );
145
+ //only 2 svg elements should be found in the header of the modal
146
+ expect(baseElement.querySelectorAll('svg')?.length).toEqual(2);
147
+ });
148
+
149
+ it('Check modal body displayed', async () => {
150
+ const {baseElement, getByText, container} = render(
151
+ <ModalDialog
152
+ key="smallModalWithoutImage"
153
+
154
+ title={'Header'}
155
+ size={Size.Small}
156
+ isModalOpen={true}
157
+ closeAction={() => {
158
+ }}
159
+ submitAction={() => {
160
+ }}>
161
+ <span>Inner modal text</span>
162
+ </ModalDialog>,
163
+ );
164
+ //Check all dialog sections are displayed
165
+ expect(baseElement.querySelectorAll('section')?.length).toEqual(3);
166
+ //Check that the second section (modal body) has the correct text
167
+ expect(baseElement.querySelectorAll('section')?.[1].textContent).toEqual('Inner modal text');
168
+ });
169
+ });
@@ -0,0 +1,77 @@
1
+ import * as React from 'react';
2
+ import {ModalContainer} from '../index';
3
+ import {act, fireEvent, render} from '../../test-utils';
4
+
5
+
6
+
7
+ describe('ModalContainer', () => {
8
+
9
+ let mountingDiv: HTMLElement;
10
+ const scrollToSpy = jest.fn();
11
+
12
+ beforeEach(() => {
13
+ //being rendered as a React.Portal we need to have the 'root' div defined
14
+ mountingDiv = document.createElement('div');
15
+ mountingDiv.id = 'root';
16
+ document.body.appendChild(mountingDiv);
17
+ window.scrollTo = scrollToSpy;
18
+ document.body.style.position = '';
19
+ document.body.style.left = '';
20
+ document.body.style.top = '';
21
+ document.body.style.right = '';
22
+
23
+ });
24
+
25
+ afterEach(() => {
26
+ document.body.removeChild(mountingDiv);
27
+ scrollToSpy.mockReset();
28
+ });
29
+
30
+ it('should not render content', () => {
31
+ const wrapper = render(<ModalContainer showModal={false} closeModal={jest.fn()} children={'text'}/>);
32
+
33
+ expect(wrapper.queryByText('text')).not.toBeInTheDocument();
34
+ });
35
+
36
+ it('should render children inside react modal', () => {
37
+ const wrapper = render(<ModalContainer showModal={true} closeModal={jest.fn()} children={'text'}/>);
38
+
39
+ expect(wrapper.queryByText('text')).toBeInTheDocument();
40
+ });
41
+
42
+ it('should call onClose when react modal closes', () => {
43
+ const onClose = jest.fn();
44
+ const wrapper = render(<ModalContainer showModal={true} closeModal={onClose} children={'text'}/>);
45
+
46
+ act(() => {
47
+ fireEvent.click(document.querySelector('.ReactModal__Overlay')!);
48
+ });
49
+
50
+ expect(onClose).toHaveBeenCalled();
51
+ });
52
+
53
+ it('should append custom styles when modal is mounted', () => {
54
+ const wrapper = render(<ModalContainer showModal={false} closeModal={jest.fn()} children={'text'}/>);
55
+
56
+ expect(document.querySelectorAll('[modal-custom-styling="active"]')).toHaveLength(1);
57
+ });
58
+
59
+ it('should prevent scroll when modal is open', () => {
60
+ Object.defineProperty(window, 'scrollY', {value: 5, writable: true});
61
+
62
+ const wrapper = render(<ModalContainer showModal={true} closeModal={jest.fn()} children={'text'}/>);
63
+
64
+ expect(document.body.style.top).toEqual('-5px');
65
+ expect(document.body.style.position).toEqual('fixed');
66
+ });
67
+
68
+ it('should not touch scroll if modal was not opened yet', async () => {
69
+ Object.defineProperty(window, 'scrollY', {value: 5, writable: true});
70
+
71
+ const wrapper = render(<ModalContainer showModal={false} closeModal={jest.fn()} children={'text'}/>);
72
+
73
+ expect(document.body.style.top).toBeFalsy();
74
+ expect(document.body.style.position).toBeFalsy();
75
+ });
76
+
77
+ });
@@ -0,0 +1,126 @@
1
+ import React from 'react';
2
+ import { render } from '../../test-utils';
3
+ import 'jest-styled-components';
4
+ import { ModalContent } from '..';
5
+ import { Size, SystemIcons } from '../..';
6
+
7
+
8
+
9
+ describe('<ModalContent />', () => {
10
+ let mountingDiv: HTMLElement;
11
+
12
+ beforeEach(() => {
13
+ //being rendered as a React.Portal we need to have the 'root' div defined
14
+ mountingDiv = document.createElement('div');
15
+ mountingDiv.id = 'root';
16
+ document.body.appendChild(mountingDiv);
17
+ });
18
+
19
+ afterEach(() => {
20
+ document.body.removeChild(mountingDiv);
21
+ });
22
+
23
+ it('Check modal not rendered when isModalOpen is false', async () => {
24
+ const { container, getByText } = render(
25
+ <ModalContent
26
+ key="smallModalWithoutImage"
27
+ title={'Header'}
28
+ size={Size.Small}
29
+ isModalOpen={false}
30
+ closeAction={() => {}}
31
+ />,
32
+ );
33
+ //check modal portal not exists when modal not opened
34
+ expect(container.querySelector('.ReactModalPortal')).toBeNull();
35
+ });
36
+
37
+ it('Check modal visible, title and footer buttons displayed correctly', async () => {
38
+ const { container, getByText } = render(
39
+ <ModalContent
40
+ key="smallModalWithoutImage"
41
+ title={'Header'}
42
+ size={Size.Small}
43
+ isModalOpen={true}
44
+ closeAction={() => {}}
45
+ footerActions={[
46
+ {
47
+ action: () => {},
48
+ text: 'Close',
49
+ variant: 'tertiary',
50
+ },
51
+ {
52
+ action: () => {},
53
+ text: 'Save',
54
+ },
55
+ ]}
56
+ />,
57
+ );
58
+ //check modal portal defined
59
+ expect(container.querySelector('.ReactModalPortal')).toBeDefined();
60
+ //Check header and footer buttons
61
+ expect(getByText('Header')).toBeDefined();
62
+ expect(getByText('Close')).toBeDefined();
63
+ expect(getByText('Save')).toBeDefined();
64
+ });
65
+
66
+ it('Check tooltip, and link displayed without right footer buttons', async () => {
67
+ const { baseElement, getByText } = render(
68
+ <ModalContent
69
+ key="smallModalWithoutImage"
70
+ title={'Header'}
71
+ size={Size.Small}
72
+ isModalOpen={true}
73
+ closeAction={() => {}}
74
+ tooltip={'some test tooltip'}
75
+ leftFooterAction={{ id: 'test-link', actionType: 'hyperlink', text: 'Link', href: 'http://test.com', icon: <></>, variant: 'default' }}
76
+ />,
77
+ );
78
+ //check tooltip displayed
79
+ expect(getByText('some test tooltip').textContent).toBeDefined();
80
+ //check footer link displayed
81
+ expect(getByText('Link').children).toBeDefined();
82
+ });
83
+
84
+ it('Check note and footer note displayed', async () => {
85
+ const { baseElement, getByText } = render(
86
+ <ModalContent
87
+ key="smallModalWithoutImage"
88
+ title={'Header'}
89
+ size={Size.Small}
90
+ isModalOpen={true}
91
+ closeAction={() => {}}
92
+ leftFooterAction={{ id: 'test-note', actionType: 'note', text: 'Test note', icon: <SystemIcons.Information /> }}
93
+ note={'Message text'}
94
+ />,
95
+ );
96
+ expect(getByText('Test note').textContent).toBeDefined();
97
+ expect(getByText('Message text').children).toBeDefined();
98
+ });
99
+
100
+ it('Check close button is displayed', async () => {
101
+ const {getByTestId } = render(
102
+ <ModalContent
103
+ key="smallModalWithoutImage"
104
+ title={'Header'}
105
+ size={Size.Small}
106
+ isModalOpen={true}
107
+ closeAction={() => {}}
108
+ />,
109
+ );
110
+ expect(getByTestId('content-modal-close-button')).toBeDefined();
111
+ });
112
+
113
+ it('Check modal body displayed', async () => {
114
+ const { baseElement, getByText, container } = render(
115
+ <ModalContent
116
+ key="smallModalWithoutImage"
117
+ title={'Header'}
118
+ size={Size.Small}
119
+ isModalOpen={true}
120
+ closeAction={() => {}}>
121
+ <span>Inner modal text</span>
122
+ </ModalContent>,
123
+ );
124
+ expect(getByText('Inner modal text')).toBeDefined();
125
+ });
126
+ });
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import styled from 'styled-components';
3
+
4
+ test('it works', () => {
5
+ expect(true).toBe(true);
6
+ });
@@ -0,0 +1,33 @@
1
+ import React from 'react';
2
+ import { render } from '../../test-utils';
3
+ import 'jest-styled-components';
4
+ import { NotificationDot } from '..';
5
+ import { Size } from '../../types';
6
+ import COLORS from '../../styles/colors';
7
+
8
+
9
+ describe('<NotificationDot />',()=>{
10
+ it('renders positive small notification dot', async () => {
11
+ const{getByTestId} = render(
12
+ <NotificationDot variant='positive' size={Size.Small} testId='testId'/>
13
+ );
14
+ expect(getByTestId('testId')).toHaveStyleRule('background-color',COLORS.bg_fill_positive);
15
+ expect(getByTestId('testId')).toHaveStyleRule('border', '2px solid ' + COLORS.bg_surface_default);
16
+ });
17
+
18
+ it('renders critical large notification dot', async () => {
19
+ const{getByTestId} = render(
20
+ <NotificationDot variant='critical' size={Size.Large} testId='testId'/>
21
+ );
22
+ expect(getByTestId('testId')).toHaveStyleRule('background-color',COLORS.bg_fill_critical);
23
+ expect(getByTestId('testId')).toHaveStyleRule('border', '3px solid ' + COLORS.bg_surface_default);
24
+ });
25
+
26
+ it('renders critical medium notification dot', async () => {
27
+ const{getByTestId} = render(
28
+ <NotificationDot variant='critical' testId='testId'/>
29
+ );
30
+ expect(getByTestId('testId')).toHaveStyleRule('background-color',COLORS.bg_fill_critical);
31
+ expect(getByTestId('testId')).toHaveStyleRule('border', '2px solid ' + COLORS.bg_surface_default);
32
+ });
33
+ });
@@ -0,0 +1,39 @@
1
+ import React from 'react';
2
+ import { render } from '../../test-utils';
3
+ import { Paginator } from '../index';
4
+ import { createMemoryHistory } from 'history';
5
+ import 'jest-styled-components';
6
+
7
+
8
+
9
+ describe('<Paginator />', () => {
10
+
11
+ const navProps = {
12
+ currentPath: '',
13
+ isActiveRoute: () => false,
14
+ navigate: (path: string, isExternal: boolean) => {}
15
+ };
16
+
17
+ it('Renders Paginator', async () => {
18
+ const history = createMemoryHistory();
19
+ const route = '/1';
20
+ history.push(route);
21
+ let curPage = 1;
22
+ const { queryByText, container } = render(
23
+ <Paginator pageCount={6} currentPage={1} baseUrl="" onPageChange={(page) => { curPage = page; }} />
24
+ );
25
+
26
+ expect(queryByText('1')).toBeDefined();
27
+ expect(container.querySelector('#paginator-left')).toBeDefined();
28
+ expect(container.querySelector('#paginator-right')).toBeDefined();
29
+ expect(queryByText('6')).toBeDefined();
30
+
31
+ // Click on stepper to the right. Expect to be taken from 1 to 2
32
+ (container.querySelector('#paginator-right') as HTMLElement)?.click();
33
+ expect(curPage).toBe(2);
34
+
35
+ // Click directly on 6. Expect to be taken to /6
36
+ queryByText('6')?.click();
37
+ expect(curPage).toBe(6);
38
+ });
39
+ });
@@ -0,0 +1,64 @@
1
+ import React from 'react';
2
+ import { render } from '../../test-utils';
3
+ import 'jest-styled-components';
4
+ import { Popover } from '../..';
5
+ import { SystemIcons } from '../../icons';
6
+ import { Position } from '../../types';
7
+
8
+
9
+ describe('<Popover />',()=>{
10
+ it('renders title', async () => {
11
+ const{getByText, queryByTestId} = render(
12
+ <Popover position={Position.Bottom} topSectionProps={{text:'sample title'}} mainContent={<></>} showOnClick={false}>
13
+ <></>
14
+ </Popover>
15
+ );
16
+
17
+ expect(getByText('sample title')).toBeDefined();
18
+ expect(queryByTestId('closeBtn')).toBeNull();
19
+ })
20
+
21
+ it('renders note and title', async () => {
22
+ const{getByText, queryByTestId} = render(
23
+ <Popover position={Position.Left} topSectionProps={{text:'sample title', note:'sample note'}} mainContent={<></>} showOnClick={false}>
24
+ <></>
25
+ </Popover>
26
+ );
27
+
28
+ expect(getByText('sample title')).toBeDefined();
29
+ expect(getByText('sample note')).toBeDefined();
30
+ expect(queryByTestId('closeBtn')).toBeNull();
31
+ })
32
+
33
+ it('renders close button', async () => {
34
+ const{getByTestId} = render(
35
+ <Popover position={Position.Bottom} topSectionProps={{text:'sample title'}} mainContent={<></>} showOnClick={true}>
36
+ <></>
37
+ </Popover>
38
+ );
39
+
40
+ expect(getByTestId('closeBtn')).toBeDefined();
41
+ })
42
+
43
+ it('renders text button', async () => {
44
+ const{getByTestId} = render(
45
+ <Popover position={Position.Right} bottomSectionProps={{textButton:{label:'sample button', icon:<SystemIcons.OpenNewWindow />, action:()=>{}}}} mainContent={<></>} showOnClick={true}>
46
+ <></>
47
+ </Popover>
48
+ );
49
+
50
+ expect(getByTestId('textBtn')).toBeDefined();
51
+ expect(getByTestId('iconBtn').children).toHaveLength(0);
52
+ })
53
+
54
+ it('renders icon button', async () => {
55
+ const{getByTestId, queryByTestId} = render(
56
+ <Popover position={Position.Right} bottomSectionProps={{iconButtons:[{label:'sample button', icon:<SystemIcons.OpenNewWindow />, action:()=>{}}]}} mainContent={<></>} showOnClick={true}>
57
+ <></>
58
+ </Popover>
59
+ );
60
+
61
+ expect(queryByTestId('textBtn')).toBeNull();
62
+ expect(getByTestId('iconBtn').children).toHaveLength(1);
63
+ })
64
+ })
@@ -0,0 +1,31 @@
1
+ import * as React from 'react';
2
+ import {ProfileButton} from '../index';
3
+ import {render} from '../../test-utils';
4
+
5
+
6
+
7
+ describe('ProfileButton', () => {
8
+
9
+ it('should render', () => {
10
+ const wrapper = render(<ProfileButton onClick={jest.fn()} initials={'initials'}/>);
11
+
12
+ expect(wrapper.queryByText('initials')).toBeInTheDocument();
13
+ });
14
+
15
+ it('should render image if portraitSrc is provided', () => {
16
+ const wrapper = render(<ProfileButton portraitSrc={'#'} onClick={jest.fn()}/>);
17
+
18
+
19
+ expect(wrapper.container.querySelector(`img`)).toBeInTheDocument();
20
+ expect(wrapper.queryByText('initials')).not.toBeInTheDocument();
21
+ });
22
+
23
+ it('should render initials if portraitSrc is not provided and initials are', () => {
24
+ const wrapper = render(<ProfileButton initials={'initials'} onClick={jest.fn()}/>);
25
+
26
+
27
+ expect(wrapper.container.querySelector(`img`)).not.toBeInTheDocument();
28
+ expect(wrapper.queryByText('initials')).toBeInTheDocument();
29
+ });
30
+
31
+ });
@@ -0,0 +1,53 @@
1
+ import React from 'react';
2
+ import { render } from '../../test-utils';
3
+ import 'jest-styled-components';
4
+ import { QuizButton } from '..';
5
+ import { Size } from '../../types';
6
+ import COLORS from '../../styles/colors';
7
+ import '@testing-library/jest-dom';
8
+
9
+
10
+ describe('<QuizButton />',()=>{
11
+ it('renders correct quiz button', async () => {
12
+ const{getByText, getByTestId} = render(
13
+ <QuizButton size={Size.Small} resultType={'correct'} text={'this is sample text'} type={'radio'} id={'1'}/>
14
+ );
15
+ expect(getByTestId('txtContainer')).toHaveTextContent('this is sample text');
16
+ expect(getByTestId('txtContainer')).toHaveClass('quiz-button-text');
17
+ expect(getByTestId('btnContainer')).toHaveClass('quiz-button-icon');
18
+ });
19
+
20
+ it('renders incorrect quiz button', async () => {
21
+ const{getByText, getByTestId} = render(
22
+ <QuizButton size={Size.Small} resultType={'incorrect'} text={'this is sample text'} type={'checkbox'} id={'1'}/>
23
+ );
24
+ expect(getByTestId('txtContainer')).toHaveTextContent('this is sample text');
25
+ expect(getByTestId('txtContainer')).toHaveClass('quiz-button-text');
26
+ expect(getByTestId('btnContainer')).toHaveClass('quiz-button-icon');
27
+ });
28
+
29
+ it('renders partial quiz button', async () => {
30
+ const{getByText, getByTestId} = render(
31
+ <QuizButton size={Size.Small} resultType={'partial'} text={'this is sample text'} type={'radio'} id={'1'}/>
32
+ );
33
+ expect(getByTestId('txtContainer')).toHaveTextContent('this is sample text');
34
+ expect(getByTestId('txtContainer')).toHaveClass('quiz-button-text');
35
+ expect(getByTestId('btnContainer')).toHaveClass('quiz-button-icon');
36
+ });
37
+
38
+ it('renders quiz button', async () => {
39
+ const{getByText, getByTestId} = render(
40
+ <QuizButton size={Size.Small} text={'this is sample text'} type={'checkbox'} id={'1'}/>
41
+ );
42
+ expect(getByText('this is sample text')).toHaveTextContent('this is sample text');
43
+ expect(getByTestId('txtContainer')).toHaveStyleRule('background',COLORS.accent1_20);
44
+ expect(getByTestId('btnContainer')).toHaveStyleRule('background',COLORS.accent1_100);
45
+ });
46
+
47
+ it('renders selected quiz button', async () => {
48
+ const{getByText} = render(
49
+ <QuizButton size={Size.Small} text={'this is sample text'} selected={true} type={'radio'} id={'1'}/>
50
+ );
51
+ expect(getByText('this is sample text')).toHaveTextContent('this is sample text');
52
+ });
53
+ });