@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,42 @@
1
+ import React from 'react';
2
+ import { render } from '../../test-utils';
3
+ import 'jest-styled-components';
4
+ import { COLORS } from '../../styles';
5
+ import AccordionMenu from '../AccordionMenu';
6
+
7
+ const accordionItems = [
8
+ {
9
+ id: 'test1_id',
10
+ title: 'Item label with text 1',
11
+ children: <div>content test1</div>,
12
+ },
13
+ {
14
+ id: 'test2_id',
15
+ title: 'Item label with text 2',
16
+ children: <div>content test2</div>,
17
+ },
18
+ ];
19
+
20
+ describe('<AccordionMenu />', () => {
21
+ it('Check correct text placed on labels', async () => {
22
+ const { queryByText } = render(<AccordionMenu items={accordionItems} onSelect={() => {}}></AccordionMenu>);
23
+ expect(queryByText('Item label with text 1')).toBeDefined();
24
+ expect(queryByText('Item label with text 2')).toBeDefined();
25
+ expect(queryByText('content test1')).toBeNull();
26
+ });
27
+
28
+ it('Check item label element color and label', async () => {
29
+ const { container } = render(<AccordionMenu items={accordionItems} onSelect={() => {}}></AccordionMenu>);
30
+ const headerItem = container.querySelector('#test2_id');
31
+ expect(headerItem).toBeDefined();
32
+ expect(headerItem?.textContent).toContain('Item label with text 2');
33
+ });
34
+
35
+ it('Check expanded item text', async () => {
36
+ const { container } = render(<AccordionMenu items={accordionItems} onSelect={() => {}} selectedItems={['test1_id']}></AccordionMenu>);
37
+ const headerItem = container.querySelector('#test1_id');
38
+ //check item expanded
39
+ expect(headerItem?.children[1]).toBeDefined();
40
+ expect(headerItem?.children[1]?.textContent).toContain('content test1');
41
+ });
42
+ });
@@ -0,0 +1,150 @@
1
+ import React from 'react';
2
+ import ContentAccordion, {
3
+ ContentAccordionItem,
4
+ ContentAccordionItemContentBody, ContentAccordionItemContentFooter,
5
+ ContentAccordionItemContentHeader, ContentAccordionItemHeader, ContentAccordionWrapper
6
+ } from '../ContentAccordion';
7
+ import {fireEvent, render} from '../../test-utils';
8
+ import {Size} from '../../types';
9
+
10
+ describe('ContentAccordion', () => {
11
+ const contentAccordionItemsWithBody = [
12
+ {
13
+ id: '1',
14
+ title: 'Item 1',
15
+ body: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
16
+ },
17
+ {
18
+ id: '2',
19
+ title: 'Item 2',
20
+ body: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
21
+ active: true
22
+ },
23
+ {
24
+ id: '3',
25
+ title: 'Item 3',
26
+ body: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
27
+ disabled: true
28
+ },
29
+ {
30
+ id: '4',
31
+ title: 'Item 4',
32
+ body: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
33
+ }
34
+ ];
35
+
36
+ const contentAccordionItemsWithBodyAndHeaderAndFooter = [
37
+ {
38
+ id: '1',
39
+ title: 'Item 1',
40
+ body: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
41
+ header: 'Header 1',
42
+ footer: <span/>,
43
+ },
44
+ {
45
+ id: '2',
46
+ title: 'Item 2',
47
+ body: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
48
+ header: 'Header 2',
49
+ footer: <span/>,
50
+ },
51
+ {
52
+ id: '3',
53
+ title: 'Item 3',
54
+ body: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
55
+ header: 'Header 3',
56
+ footer: <span/>,
57
+ disabled: true
58
+ },
59
+ {
60
+ id: '4',
61
+ title: 'Item 4',
62
+ body: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
63
+ header: 'Header 4',
64
+ footer: <span/>,
65
+ }
66
+ ];
67
+
68
+ it('should render items in correct state', () => {
69
+ const wrapper = render(<ContentAccordion items={contentAccordionItemsWithBody}/>);
70
+
71
+ expect(wrapper.container.querySelectorAll(`${ContentAccordionItem}`).length).toBe(4);
72
+ expect(wrapper.container.querySelectorAll(`${ContentAccordionItem}.disabled`).length).toBe(1);
73
+ expect(wrapper.container.querySelectorAll(`${ContentAccordionItem}.disabled`)[0].id).toBe('item_3');
74
+ expect(wrapper.container.querySelectorAll(`${ContentAccordionItem}.active`).length).toBe(1);
75
+ expect(wrapper.container.querySelectorAll(`${ContentAccordionItem}.active`)[0].id).toBe('item_2');
76
+ });
77
+
78
+ it('should not render header if not provided', () => {
79
+ const wrapper = render(<ContentAccordion items={contentAccordionItemsWithBody}/>);
80
+
81
+ expect(wrapper.container.querySelectorAll(`${ContentAccordionItemContentBody}`).length).toBe(4);
82
+ expect(wrapper.container.querySelectorAll(`${ContentAccordionItemContentHeader}`).length).toBe(0);
83
+ });
84
+
85
+ it('should not render footer if not provided', () => {
86
+ const wrapper = render(<ContentAccordion items={contentAccordionItemsWithBody}/>);
87
+
88
+ expect(wrapper.container.querySelectorAll(`${ContentAccordionItemContentBody}`).length).toBe(4);
89
+ expect(wrapper.container.querySelectorAll(`${ContentAccordionItemContentFooter}`).length).toBe(0);
90
+ });
91
+
92
+ it('should render body, header, and footer if all are provided', () => {
93
+ const wrapper = render(<ContentAccordion items={contentAccordionItemsWithBodyAndHeaderAndFooter}/>);
94
+
95
+ expect(wrapper.container.querySelectorAll(`${ContentAccordionItem}`).length).toBe(4);
96
+ expect(wrapper.container.querySelectorAll(`${ContentAccordionItemContentBody}`).length).toBe(4);
97
+ expect(wrapper.container.querySelectorAll(`${ContentAccordionItemContentHeader}`).length).toBe(4);
98
+ expect(wrapper.container.querySelectorAll(`${ContentAccordionItemContentFooter}`).length).toBe(4);
99
+ });
100
+
101
+ it('should set correct size class name for small accordion', () => {
102
+ const wrapper = render(<ContentAccordion items={contentAccordionItemsWithBodyAndHeaderAndFooter}
103
+ size={Size.Small}/>);
104
+ expect(wrapper.container.querySelectorAll(`${ContentAccordionWrapper}.small`).length).toBe(1);
105
+ });
106
+
107
+ it('should set correct size class name for medium accordion', () => {
108
+ const wrapper = render(<ContentAccordion items={contentAccordionItemsWithBodyAndHeaderAndFooter}
109
+ size={Size.Medium}/>);
110
+ expect(wrapper.container.querySelectorAll(`${ContentAccordionWrapper}.medium`).length).toBe(1);
111
+ });
112
+
113
+ it('should set correct size class name for large accordion', () => {
114
+ const wrapper = render(<ContentAccordion items={contentAccordionItemsWithBodyAndHeaderAndFooter}
115
+ size={Size.Large}/>);
116
+ expect(wrapper.container.querySelectorAll(`${ContentAccordionWrapper}.large`).length).toBe(1);
117
+ });
118
+
119
+ it('should change active state when item header is clicked', () => {
120
+ const wrapper = render(<ContentAccordion items={contentAccordionItemsWithBody} multi={false}/>);
121
+ const itemHeader = wrapper.container.querySelectorAll(`${ContentAccordionItemHeader}`)[3];
122
+
123
+ fireEvent.click(itemHeader);
124
+
125
+ expect(wrapper.container.querySelectorAll(`${ContentAccordionItem}.active`).length).toBe(1);
126
+ expect(wrapper.container.querySelectorAll(`${ContentAccordionItem}.active`)[0].id).toBe('item_4');
127
+ });
128
+
129
+ it('should not change active state when disabled item header is clicked', () => {
130
+ const wrapper = render(<ContentAccordion items={contentAccordionItemsWithBody} multi={false}/>);
131
+ const itemHeader = wrapper.container.querySelectorAll(`${ContentAccordionItemHeader}`)[2];
132
+
133
+ fireEvent.click(itemHeader);
134
+
135
+ expect(wrapper.container.querySelectorAll(`${ContentAccordionItem}.active`).length).toBe(1);
136
+ expect(wrapper.container.querySelectorAll(`${ContentAccordionItem}.active`)[0].id).toBe('item_2');
137
+ });
138
+
139
+ it('should append active items if multi property is true', () => {
140
+ const wrapper = render(<ContentAccordion items={contentAccordionItemsWithBody} multi={true}/>);
141
+ const itemHeader = wrapper.container.querySelectorAll(`${ContentAccordionItemHeader}`)[3];
142
+
143
+ fireEvent.click(itemHeader);
144
+
145
+ expect(wrapper.container.querySelectorAll(`${ContentAccordionItem}.active`).length).toBe(2);
146
+ expect(wrapper.container.querySelectorAll(`${ContentAccordionItem}.active`)[0].id).toBe('item_2');
147
+ expect(wrapper.container.querySelectorAll(`${ContentAccordionItem}.active`)[1].id).toBe('item_4');
148
+ });
149
+
150
+ });
@@ -0,0 +1,27 @@
1
+ import React from 'react';
2
+ import { render } from '../../test-utils';
3
+ import '@testing-library/jest-dom';
4
+ import { AuthPage, Size, SystemIcons } from '../..';
5
+ import 'jest-styled-components';
6
+
7
+
8
+
9
+
10
+ describe('<AuthPage />', () => {
11
+ it('Renders AuthPage component', async () => {
12
+ const { getByText, container, getByTestId } = render(
13
+ <AuthPage
14
+ screenSetsContainerId="gigya_test"
15
+ panel={{
16
+ title: 'Sign in header',
17
+ content: 'Sign in information',
18
+ }}
19
+ />,
20
+ );
21
+ //expect gygia container displayed
22
+ expect(container.querySelector('[id="gigya_test"]')).toBeTruthy();
23
+ //expect sign in header and info text displayed
24
+ expect(getByText('Sign in header')).toBeTruthy();
25
+ expect(getByText('Sign in information')).toBeTruthy();
26
+ });
27
+ });
@@ -0,0 +1,47 @@
1
+ import React from 'react';
2
+ import { render } from '../../test-utils';
3
+ import { Banner } from '../index';
4
+ import 'jest-styled-components';
5
+ import { COLORS } from '../../styles';
6
+
7
+
8
+
9
+
10
+ describe('<Banner />', () => {
11
+ it('Renders warning banner', async () => {
12
+ const { queryByText, getByTestId } = render(
13
+ <Banner type="warning" testId="TestBanner">
14
+ <h2>TestBanner</h2>
15
+ </Banner>,
16
+ );
17
+ expect(queryByText('TestHeader')).toBeDefined();
18
+ expect(getByTestId('TestBanner')).toHaveStyleRule('background', COLORS.bg_surface_warning);
19
+ });
20
+ it('Renders critial banner', async () => {
21
+ const { queryByText, getByTestId } = render(
22
+ <Banner type="critical" testId="TestBanner">
23
+ <h2>TestBanner</h2>
24
+ </Banner>,
25
+ );
26
+ expect(queryByText('TestHeader')).toBeDefined();
27
+ expect(getByTestId('TestBanner')).toHaveStyleRule('background', COLORS.bg_surface_critical);
28
+ });
29
+ it('Renders positive banner', async () => {
30
+ const { queryByText, getByTestId } = render(
31
+ <Banner type="positive" testId="TestBanner">
32
+ <h2>TestBanner</h2>
33
+ </Banner>,
34
+ );
35
+ expect(queryByText('TestHeader')).toBeDefined();
36
+ expect(getByTestId('TestBanner')).toHaveStyleRule('background', COLORS.bg_surface_positive);
37
+ });
38
+ it('Renders default banner', async () => {
39
+ const { queryByText, getByTestId } = render(
40
+ <Banner testId="TestBanner">
41
+ <h2>TestBanner</h2>
42
+ </Banner>,
43
+ );
44
+ expect(queryByText('TestHeader')).toBeDefined();
45
+ expect(getByTestId('TestBanner')).toHaveStyleRule('background', COLORS.bg_surface_primary);
46
+ });
47
+ });
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+ import { render } from '../../test-utils';
3
+ import { OverviewBanner } from '../index';
4
+ import 'jest-styled-components';
5
+ import { COLORS } from '../../styles';
6
+
7
+
8
+
9
+
10
+ describe('<OverviewBanner />', () => {
11
+ it('Renders', async () => {
12
+ const { queryByText, getByTestId } = render(
13
+ <OverviewBanner testId="TestBanner">
14
+ <h2>TestHeader</h2>
15
+ </OverviewBanner>,
16
+ );
17
+ expect(queryByText('TestHeader')).toBeDefined();
18
+ expect(getByTestId('TestBanner')).toHaveStyleRule('background-color', COLORS.primary_20);
19
+ });
20
+ });
@@ -0,0 +1,78 @@
1
+ import React from 'react';
2
+ import { render } from '../../test-utils';
3
+ import { Breadcrumb } from '../index';
4
+ import '@testing-library/jest-dom';
5
+ import { Size } from '../../types';
6
+
7
+ const items = [
8
+ { label: 'test1', url: 'http://laerdal_test.com', callback: (id?: string) => {} },
9
+ { label: 'test2', url: 'http://laerdal_test1.com', callback: (id?: string) => {} },
10
+ { label: 'test3', url: 'http://laerdal_test2.com', callback: (id?: string) => {} },
11
+ { label: 'test4', url: 'http://laerdal_test3.com', callback: (id?: string) => {} },
12
+ ];
13
+
14
+
15
+
16
+ describe('<Breadcrumb />', () => {
17
+ it('Renders with no values', async () => {
18
+ const { getByTestId, container } = render(<Breadcrumb items={[]} />);
19
+ //main container is displayed
20
+ expect(getByTestId('breacrumbContainer')).toBeDefined();
21
+ //home link is displayed
22
+ expect(container.querySelector('[id="homelink"]')).toBeDefined();
23
+ });
24
+
25
+ it('Renders with home icon and no values', async () => {
26
+ const { getByTestId, container } = render(<Breadcrumb items={[]} homeIcon={true} />);
27
+ expect(getByTestId('breacrumbContainer')).toBeDefined();
28
+ //home icon is displayed
29
+ expect(container.querySelector('[id="homeIcon"]')).toBeDefined();
30
+
31
+ //because a size was not provided, small icons width will be set (20px)
32
+ const svg = container.querySelector('svg');
33
+ expect(svg).toHaveAttribute('width', '20px');
34
+ });
35
+
36
+ it('Render breadcrumb with two values ', async () => {
37
+ const options = items.slice(0, 2);
38
+ const { getByTestId, container } = render(<Breadcrumb lastItemAsLabel={true} items={options} size={Size.Medium} />);
39
+ expect(getByTestId('breacrumbContainer')).toBeDefined();
40
+ //check breadcrumbs displayed correctly - only one link defined for this scenario
41
+ const linkItem = container.querySelector('a[id*="link-item"]');
42
+ expect(linkItem).toBeDefined();
43
+ expect(linkItem).toHaveTextContent(options[0].label);
44
+
45
+ //query breadcrumb chrevron separators
46
+ const breadcrumbSeparators = container.querySelectorAll('.chevronicon');
47
+ expect(breadcrumbSeparators).toBeDefined();
48
+ expect(breadcrumbSeparators).toHaveLength(2);
49
+
50
+ //medium size provided
51
+ const svg = container.querySelector('svg');
52
+ expect(svg).toHaveAttribute('width', '24px');
53
+
54
+ const lastItem = container.querySelector('label');
55
+ expect(lastItem).toBeDefined();
56
+ expect(lastItem).toHaveTextContent(options[options.length - 1].label);
57
+ });
58
+
59
+ it('Render more than 3 items', async () => {
60
+ const { container, getByText } = render(<Breadcrumb lastItemAsLabel={true} items={items} size={Size.XSmall} />);
61
+
62
+ //having more than 2 item show more dropdown selector should be displayed
63
+ //because home page button is not provided, only one button should be rendered
64
+ const showMoreBtn = container.querySelector('button');
65
+ expect(showMoreBtn).toBeDefined();
66
+ //in this scenario, first option label is not displayed, so only one link item available
67
+ const linkItem = container.querySelectorAll('a[id*="link-item"]');
68
+ expect(linkItem).toHaveLength(1);
69
+
70
+ //links not displayed for first two items, but these are defined as dropdown options
71
+ expect(getByText(items[0].label)).toBeDefined();
72
+ expect(getByText(items[1].label)).toBeDefined();
73
+
74
+ //xs size provided
75
+ const svg = container.querySelector('svg');
76
+ expect(svg).toHaveAttribute('width', '16px');
77
+ });
78
+ });
@@ -0,0 +1,32 @@
1
+ import React from 'react';
2
+ import {act, render} from '../../test-utils';
3
+ import {BackButton} from '../index';
4
+ import {Size} from '../../types'
5
+ import 'jest-styled-components';
6
+
7
+
8
+
9
+
10
+ describe('<BackButton />', () => {
11
+ it('should render back button', function () {
12
+ const {queryByText} = render(<BackButton size={Size.Small}>Back Button</BackButton>);
13
+ expect(queryByText('Back Button')).toBeDefined();
14
+ });
15
+ it('should call action on click', function () {
16
+ const clickMock = jest.fn(() => {});
17
+ const component = render(<BackButton size={Size.Small} onClick={clickMock}>Back Button</BackButton>);
18
+ act(() => {
19
+ component.getByText('Back Button').click();
20
+ });
21
+ expect(clickMock).toBeCalled();
22
+ });
23
+ it('should not call action on click when disabled', function () {
24
+ const clickMock = jest.fn(() => {});
25
+ const component = render(<BackButton size={Size.Small} disabled={true} onClick={clickMock}>Back Button</BackButton>);
26
+ act(() => {
27
+ component.getByText('Back Button').click();
28
+ });
29
+ expect(clickMock).toBeCalledTimes(0);
30
+ });
31
+
32
+ });
@@ -0,0 +1,45 @@
1
+ import React from 'react';
2
+ import { render } from '../../test-utils';
3
+ import { Button } from '../index';
4
+ import 'jest-styled-components';
5
+ import { COLORS } from '../../styles';
6
+ import { Size } from '../..';
7
+
8
+
9
+
10
+
11
+ describe('<Button />', () => {
12
+ it('Renders primary button', async () => {
13
+ const { queryByText, getByTestId } = render(
14
+ <Button variant="primary" testId="TestButton" size={Size.Large}>
15
+ TestButton
16
+ </Button>,
17
+ );
18
+ expect(queryByText('TestButton')).toBeDefined();
19
+ /*expect(getByTestId('TestButton')).toHaveStyleRule('background-color', COLORS.primary);
20
+ expect(getByTestId('TestButton')).toHaveStyleRule('cursor', 'pointer');
21
+ expect(getByTestId('TestButton')).toHaveStyleRule('color', 'white');*/
22
+ });
23
+ it('Renders secondary button', async () => {
24
+ const { queryByText, getByTestId } = render(
25
+ <Button variant="secondary" testId="TestButton">
26
+ TestButton
27
+ </Button>,
28
+ );
29
+ expect(queryByText('TestButton')).toBeDefined();
30
+ /*expect(getByTestId('TestButton')).toHaveStyleRule('color', COLORS.primary);
31
+ expect(getByTestId('TestButton')).toHaveStyleRule('border-color', COLORS.primary);
32
+ expect(getByTestId('TestButton')).toHaveStyleRule('background-color', 'white');*/
33
+ });
34
+ it('Renders tertiary button', async () => {
35
+ const { queryByText, getByTestId } = render(
36
+ <Button variant="tertiary" testId="TestButton">
37
+ TestButton
38
+ </Button>,
39
+ );
40
+ expect(queryByText('TestButton')).toBeDefined();
41
+ /*expect(getByTestId('TestButton')).toHaveStyleRule('background-color', 'white');
42
+ expect(getByTestId('TestButton')).toHaveStyleRule('border-color', COLORS.neutral_100);
43
+ expect(getByTestId('TestButton')).toHaveStyleRule('color', COLORS.primary);*/
44
+ });
45
+ });
@@ -0,0 +1,119 @@
1
+ import React from 'react';
2
+ import { fireEvent, render } from '../../test-utils';
3
+ import { DualFunctionButton } from '../index';
4
+ import '@testing-library/jest-dom';
5
+ import { Size, SystemIcons } from '../..';
6
+ import 'jest-styled-components';
7
+
8
+
9
+
10
+
11
+ describe('<DualButton />', () => {
12
+ it('Renders checkbox button', async () => {
13
+ const dropdownItems = [
14
+ { value: 'Item 1', icon: undefined },
15
+ { value: 'Item 2', icon: undefined, disabled: true },
16
+ ];
17
+ const { getByText, container, getByTestId } = render(
18
+ <DualFunctionButton
19
+ dropdownCustomizationProps={{
20
+ items: dropdownItems,
21
+ itemsType: 'checkbox',
22
+ multiSelect: true,
23
+ pinTopItem: true,
24
+ actionLabel: 'Custom Action',
25
+ action: () => {},
26
+ onValueUpdate: (vals) => {},
27
+ scrollable: true,
28
+ }}
29
+ id="test"
30
+ size={Size.Small}
31
+ variant="primary">
32
+ Dual button checkbox test
33
+ </DualFunctionButton>,
34
+ );
35
+ //expect button name defined
36
+ expect(getByText('Dual button checkbox test')).toBeTruthy();
37
+ //expect all items displayed
38
+ expect(getByText('Item 1')).toBeTruthy();
39
+ expect(getByText('Item 2')).toBeTruthy();
40
+
41
+ //check that checkbox controls are displayed
42
+ expect(getByText('Item 1').closest('label')).toHaveClass('checkbox-label');
43
+ expect(getByText('Item 2').closest('label')).toHaveClass('checkbox-label');
44
+
45
+ //expect item 2 to be disabled
46
+ expect(getByText('Item 2').closest('div')).toHaveAttribute('disabled');
47
+
48
+ //expect the toggle button to be defined
49
+ expect(getByTestId('options_toggleBtn')).toBeTruthy();
50
+
51
+ //expect select all displayed as pin top item is set as "true"
52
+ expect(document.body.querySelector('[id*="checkbox_selectall"]')).toBeTruthy();
53
+ });
54
+
55
+ it('Renders normal dual button', async () => {
56
+ const dropdownItems = [
57
+ { value: 'Item 1', icon: undefined },
58
+ { value: 'Item 2', icon: undefined },
59
+ ];
60
+ const { getByText, container, getByTestId } = render(
61
+ <DualFunctionButton
62
+ dropdownCustomizationProps={{
63
+ items: dropdownItems,
64
+ itemsType: 'normal',
65
+ multiSelect: true,
66
+ action: () => {},
67
+ onValueUpdate: (vals) => {},
68
+ scrollable: true,
69
+ }}
70
+ id="test"
71
+ size={Size.Small}
72
+ variant="primary">
73
+ Dual button test
74
+ </DualFunctionButton>,
75
+ );
76
+ //check that the dual button text defined
77
+ expect(getByText('Dual button test')).toBeTruthy();
78
+ expect(getByText('Item 1')).toBeTruthy();
79
+ expect(getByText('Item 2')).toBeTruthy();
80
+ //check that none of the items disabled
81
+ expect(getByText('Item 1').closest('div')).not.toHaveAttribute('disabled');
82
+ expect(getByText('Item 2').closest('div')).not.toHaveAttribute('disabled');
83
+ expect(getByTestId('options_toggleBtn')).toBeTruthy();
84
+
85
+ //two options available
86
+ expect(document.body.querySelectorAll('button[tabindex="-1"]')).toHaveLength(2);
87
+ });
88
+
89
+ it('Renders radio-button type dual button', async () => {
90
+ const dropdownItems = [
91
+ { value: 'Item 1', icon: undefined, disabled: true },
92
+ { value: 'Item 2', icon: undefined, disabled: true },
93
+ ];
94
+ const { getByText, container, getByTestId } = render(
95
+ <DualFunctionButton
96
+ dropdownCustomizationProps={{
97
+ items: dropdownItems,
98
+ itemsType: 'radio',
99
+ multiSelect: true,
100
+ action: () => {},
101
+ onValueUpdate: (vals) => {},
102
+ scrollable: true,
103
+ }}
104
+ id="test"
105
+ size={Size.Small}
106
+ variant="primary">
107
+ Dual button test radio
108
+ </DualFunctionButton>,
109
+ );
110
+ //check that the dual button text defined
111
+ expect(getByText('Dual button test radio')).toBeTruthy();
112
+ expect(getByText('Item 1')).toBeTruthy();
113
+ expect(getByText('Item 2')).toBeTruthy();
114
+
115
+ //check that radio buttons displayed
116
+ expect(getByText('Item 1').closest('div')).toHaveClass('radio-button-label');
117
+ expect(getByText('Item 2').closest('div')).toHaveClass('radio-button-label');
118
+ });
119
+ });
@@ -0,0 +1,71 @@
1
+ import React from 'react';
2
+ import {act, render} from '../../../test-utils';
3
+ import {
4
+ HorizontalCard,
5
+ HorizontalCardDropdownButton,
6
+ HorizontalCardIconButton, HorizontalCardLinearProgression, HorizontalCardTag,
7
+ HorizontalCardToggleButton
8
+ } from '../index';
9
+ import {SystemIcons} from '../../../icons';
10
+
11
+
12
+
13
+ describe('HorizontalCard', () => {
14
+ const action = jest.fn();
15
+
16
+ const actions: (HorizontalCardIconButton | HorizontalCardToggleButton | HorizontalCardDropdownButton)[] = [
17
+ {componentType: 'icon', action: action, icon: <SystemIcons.Share/>},
18
+ {componentType: 'icon', action: action, icon: <SystemIcons.OpenNewWindow/>}
19
+ ]
20
+
21
+ const tags: HorizontalCardTag[] = [{label: 'label 1'}, {label: 'label 2'}, {label: 'label 3'}];
22
+
23
+ const progress: HorizontalCardLinearProgression = {max: 100, value: 30};
24
+
25
+ beforeEach(() => {
26
+ action.mockReset();
27
+ });
28
+
29
+ it('should render title', async () => {
30
+ const {queryByText} = render(<HorizontalCard title={'title'}/>)
31
+
32
+ expect(queryByText('title')).toBeDefined()
33
+ });
34
+
35
+ it('should render tags', async () => {
36
+
37
+ const {queryByText} = render(<HorizontalCard title={'title'} tags={tags}/>)
38
+
39
+ expect(queryByText('label 1')).toBeDefined()
40
+ expect(queryByText('label 2')).toBeDefined()
41
+ expect(queryByText('label 3')).toBeDefined()
42
+ });
43
+
44
+ it('should render actions', async () => {
45
+ const {container} = render(<HorizontalCard title={'title'} actions={actions}/>)
46
+
47
+ expect(container.querySelectorAll('button')).toHaveLength(2)
48
+ });
49
+
50
+ it('should call action on component click', async () => {
51
+ const {container} = render(<HorizontalCard title={'title'} action={action}/>)
52
+
53
+ act(() => {
54
+ // @ts-ignore
55
+ container.querySelector('.clickable').click();
56
+ });
57
+
58
+ expect(action).toHaveBeenCalled()
59
+ });
60
+
61
+ it('should call action on button press', async () => {
62
+ const {container} = render(<HorizontalCard title={'title'} actions={actions}/>)
63
+
64
+ act(() => {
65
+ container.querySelectorAll('button').forEach(a => a.click());
66
+ });
67
+
68
+ expect(action).toHaveBeenCalledTimes(2)
69
+ });
70
+
71
+ });