@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.
- package/dist/Accordion/__tests__/AccordionMenu.test.tsx +42 -0
- package/dist/Accordion/__tests__/ContentAccordion.test.tsx +150 -0
- package/dist/AuthPage/__tests__/AuthPage.test.tsx +27 -0
- package/dist/Banners/__tests__/Banner.test.tsx +47 -0
- package/dist/Banners/__tests__/OverviewBanner.test.tsx +20 -0
- package/dist/Breadcrumb/__tests__/Breadcrumb.test.tsx +78 -0
- package/dist/Button/__tests__/BackButton.test.tsx +32 -0
- package/dist/Button/__tests__/Button.test.tsx +45 -0
- package/dist/Button/__tests__/DualButton.test.tsx +119 -0
- package/dist/Card/HorizontalCard/__tests__/HorizontalCard.test.tsx +71 -0
- package/dist/Card/HorizontalCard/__tests__/VerticalCard.test.tsx +124 -0
- package/dist/Card/__tests__/Card.test.tsx +146 -0
- package/dist/Chips/__tests__/ActionChip.test.tsx +94 -0
- package/dist/Chips/__tests__/ChoiceChips.test.tsx +79 -0
- package/dist/Chips/__tests__/FilterChip.test.tsx +95 -0
- package/dist/Chips/__tests__/InputChip.test.tsx +155 -0
- package/dist/ChipsInput/__tests__/ChipDropdownInput.test.tsx +100 -0
- package/dist/ChipsInput/__tests__/ChipInputFields.test.tsx +155 -0
- package/dist/Dropdown/__tests__/DropdownFilter.test.tsx +39 -0
- package/dist/Footer/__tests__/Footer.test.tsx +182 -0
- package/dist/GlobalNavigationBar/__tests__/Logo.test.tsx +39 -0
- package/dist/GlobalNavigationBar/desktop/__tests__/DesktopActions.test.tsx +108 -0
- package/dist/GlobalNavigationBar/desktop/__tests__/ExtendedMainMenu.test.tsx +28 -0
- package/dist/GlobalNavigationBar/desktop/__tests__/MainMenu.test.tsx +55 -0
- package/dist/GlobalNavigationBar/desktop/__tests__/RightSideNav.test.tsx +45 -0
- package/dist/GlobalNavigationBar/desktop/__tests__/UserMenu.test.tsx +125 -0
- package/dist/GlobalNavigationBar/mobile/__tests__/MobileMenu.test.tsx +317 -0
- package/dist/GlobalNavigationBar/mobile/__tests__/MobileMenuContent.test.tsx +294 -0
- package/dist/GlobalNavigationBar/mobile/__tests__/MobileMenuHeader.test.tsx +195 -0
- package/dist/InputFields/__tests__/NumberField.test.tsx +67 -0
- package/dist/InputFields/__tests__/NumberInput.test.tsx +68 -0
- package/dist/InputFields/__tests__/QuickSearch.test.tsx +42 -0
- package/dist/LinearProgress/__tests__/LinearProgress.test.tsx +25 -0
- package/dist/List/__tests__/ListRow.test.tsx +18 -0
- package/dist/LoadingPage/__tests__/GlobalLoadingPage.test.tsx +23 -0
- package/dist/Modals/__tests__/Modal.test.tsx +169 -0
- package/dist/Modals/__tests__/ModalContainer.test.tsx +77 -0
- package/dist/Modals/__tests__/ModalContent.test.tsx +126 -0
- package/dist/NavItem/__tests__/NavItem.test.ts +6 -0
- package/dist/NotificationDot/__tests__/NotificationDot.test.tsx +33 -0
- package/dist/Paginator/__tests__/Paginator.test.tsx +39 -0
- package/dist/Popover/__tests__/Popover.test.tsx +64 -0
- package/dist/ProfileButton/__tests__/ProfileButton.test.tsx +31 -0
- package/dist/QuizButton/__tests__/QuizButton.test.tsx +53 -0
- package/dist/SegmentControl/__tests__/SegmentControl.test.tsx +145 -0
- package/dist/SideMenu/__tests__/SideMenu.test.tsx +99 -0
- package/dist/Switcher/__tests__/SwitcherMenuItem.tsx +14 -0
- package/dist/Table/__tests__/Table.test.tsx +499 -0
- package/dist/Tabs/__tests__/HorizontalTabs.test.tsx +95 -0
- package/dist/Tabs/__tests__/TabLink.test.tsx +40 -0
- package/dist/Tabs/__tests__/Tablist.test.tsx +37 -0
- package/dist/Tag/__tests__/Tag.test.tsx +86 -0
- package/dist/Toasters/__tests__/Toast.test.tsx +74 -0
- package/dist/Toggles/__tests__/ToggleButton.test.tsx +53 -0
- package/dist/Toggles/__tests__/ToggleSwitch.test.tsx +87 -0
- package/dist/Tooltips/__tests__/TooltipWrapper.test.tsx +16 -0
- package/dist/styles/react-datepicker.css +766 -0
- package/package.json +4 -3
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { fireEvent, render } from '../../../test-utils';
|
|
3
|
+
import 'jest-styled-components';
|
|
4
|
+
import { Card } from '../..';
|
|
5
|
+
import { COLORS } from '../../../styles';
|
|
6
|
+
import { SystemIcons } from '../../../icons';
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
describe('<Card />',()=>{
|
|
10
|
+
it('renders top section', async () => {
|
|
11
|
+
const{getByTestId} = render(
|
|
12
|
+
<Card topSectionProps={{disabled: false}} disabled/>
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
expect(getByTestId('card-topSection')).toBeDefined();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('renders middle section', async () => {
|
|
19
|
+
const{getByTestId} = render(
|
|
20
|
+
<Card middleSectionProps={{title:'title',disabled:false}} disabled/>
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
expect(getByTestId('card-middleSection')).toBeDefined();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('renders bottom section', async () => {
|
|
27
|
+
const{getByTestId} = render(
|
|
28
|
+
<Card bottomSectionProps={{disabled:false}} disabled/>
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
expect(getByTestId('card-bottomSection')).toBeDefined();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('fires card clicked event on click', async () => {
|
|
35
|
+
const cardClicked = jest.fn();
|
|
36
|
+
const{getByTestId} = render(
|
|
37
|
+
<Card bottomSectionProps={{disabled:false}} disabled={false} onCardClicked={cardClicked}/>
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
fireEvent.click(getByTestId('card-wrapper'));
|
|
41
|
+
expect(cardClicked).toBeCalledTimes(1);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('fires card clicked event on keyDown', async () => {
|
|
45
|
+
const cardClicked = jest.fn();
|
|
46
|
+
const{getByTestId} = render(
|
|
47
|
+
<Card bottomSectionProps={{disabled:false}} disabled={false} onCardClicked={cardClicked}/>
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
fireEvent.keyDown(getByTestId('card-wrapper'), {key: 'Enter', code: 'Enter', charCode: 13});
|
|
51
|
+
expect(cardClicked).toBeCalledTimes(1);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('renders tag in top section', async () => {
|
|
55
|
+
const{getByText} = render(
|
|
56
|
+
<Card topSectionProps={{disabled: false, tagLabel:'test_label'}} disabled/>
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
expect(getByText('test_label')).toBeDefined();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('renders checkbox in top section', async () => {
|
|
63
|
+
const{getByTestId} = render(
|
|
64
|
+
<Card topSectionProps={{disabled: false, selected: true}} disabled/>
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
expect(getByTestId('card-topSection-checkbox')).toBeDefined();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('renders highlight ribbon in top section', async () => {
|
|
71
|
+
const{getByTestId, getByText} = render(
|
|
72
|
+
<Card topSectionProps={{disabled: false, highlightRibbonText:'testRibbon', highlightRibbonBgColor:'red'}} disabled={false}/>
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
expect(getByText('testRibbon')).toBeDefined();
|
|
76
|
+
expect(getByTestId('card-topSection-ribbon')).toHaveStyleRule('background-color','red');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('renders title ,description and category label in middle section', async () => {
|
|
80
|
+
const{getByText} = render(
|
|
81
|
+
<Card middleSectionProps={{title:'testTitle', disabled: false, description:'testDescription', categoryLabel:'testCatLabel'}} disabled={false}/>
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
expect(getByText('testTitle')).toBeDefined();
|
|
85
|
+
expect(getByText('testDescription')).toBeDefined();
|
|
86
|
+
expect(getByText('testCatLabel')).toBeDefined();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('renders tags in middle section', async () => {
|
|
90
|
+
const{getByText} = render(
|
|
91
|
+
<Card middleSectionProps={{title:'testTitle', disabled: false, tags:[{label:'testTag'}], row2Tags:[{label:'testTag2'}]}} disabled={false}/>
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
expect(getByText('testTitle')).toBeDefined();
|
|
95
|
+
expect(getByText('testTag2')).toBeDefined();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('renders note text in bottom section', async () => {
|
|
99
|
+
const{getByText} = render(
|
|
100
|
+
<Card bottomSectionProps={{disabled: false, noteLeft:'leftNote', noteRight:'rightNote'}} disabled={false}/>
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
expect(getByText('leftNote')).toBeDefined();
|
|
104
|
+
expect(getByText('rightNote')).toBeDefined();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('renders author in bottom section', async () => {
|
|
108
|
+
const{getByText,getByTestId} = render(
|
|
109
|
+
<Card bottomSectionProps={{disabled: true, authorName:'testAuthor'}} disabled={true}/>
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
expect(getByText('testAuthor')).toBeDefined();
|
|
113
|
+
expect(getByTestId('card-bottomSection-author')).toBeDefined();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('renders actions in bottom section', async () => {
|
|
117
|
+
const{getByText,getByTestId} = render(
|
|
118
|
+
<Card bottomSectionProps={{disabled: true, authorName:'testAuthor', actions:[{icon:<SystemIcons.Add/>,onClick:()=>{}}]}} disabled={true}/>
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
expect(getByText('testAuthor')).toBeDefined();
|
|
122
|
+
expect(getByTestId('card-bottomSection-author')).toBeDefined();
|
|
123
|
+
});
|
|
124
|
+
})
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { fireEvent, getByRole, render } from '../../test-utils';
|
|
3
|
+
import 'jest-styled-components';
|
|
4
|
+
import { Card } from '../..';
|
|
5
|
+
import { COLORS } from '../../styles';
|
|
6
|
+
import { SystemIcons } from '../../icons';
|
|
7
|
+
|
|
8
|
+
describe('<Card />',()=>{
|
|
9
|
+
it('renders top section', async () => {
|
|
10
|
+
const{getByTestId} = render(
|
|
11
|
+
<Card topSectionProps={{disabled: false}} disabled/>
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
expect(getByTestId('card-topSection')).toBeDefined();
|
|
15
|
+
//expect(getByTestId('card-middleSection')).toBeDefined();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('renders middle section', async () => {
|
|
19
|
+
const{getByTestId} = render(
|
|
20
|
+
<Card middleSectionProps={{title:'title',disabled:false}} disabled/>
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
expect(getByTestId('card-middleSection')).toBeDefined();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('renders bottom section', async () => {
|
|
27
|
+
const{getByTestId} = render(
|
|
28
|
+
<Card bottomSectionProps={{disabled:false}} disabled/>
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
expect(getByTestId('card-bottomSection')).toBeDefined();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('fires card clicked event on click', async () => {
|
|
35
|
+
const cardClicked = jest.fn();
|
|
36
|
+
const{getByTestId} = render(
|
|
37
|
+
<Card bottomSectionProps={{disabled:false}} disabled={false} onCardClicked={cardClicked}/>
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
fireEvent.click(getByTestId('card-wrapper'));
|
|
41
|
+
expect(cardClicked).toBeCalledTimes(1);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('fires card clicked event on keyDown', async () => {
|
|
45
|
+
const cardClicked = jest.fn();
|
|
46
|
+
const{getByTestId} = render(
|
|
47
|
+
<Card bottomSectionProps={{disabled:false}} disabled={false} onCardClicked={cardClicked}/>
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
fireEvent.keyDown(getByTestId('card-wrapper'), {key: 'Enter', code: 'Enter', charCode: 13});
|
|
51
|
+
expect(cardClicked).toBeCalledTimes(1);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('renders tag in top section', async () => {
|
|
55
|
+
const{getByText} = render(
|
|
56
|
+
<Card topSectionProps={{disabled: false, tagLabel:'test_label'}} disabled/>
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
expect(getByText('test_label')).toBeDefined();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('renders checkbox in top section', async () => {
|
|
63
|
+
const{getByTestId} = render(
|
|
64
|
+
<Card topSectionProps={{disabled: false, selected: true}} disabled/>
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
expect(getByTestId('card-topSection-checkbox')).toBeDefined();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('renders highlight ribbon in top section', async () => {
|
|
71
|
+
const{getByTestId, getByText} = render(
|
|
72
|
+
<Card topSectionProps={{disabled: false, highlightRibbonText:'testRibbon', highlightRibbonBgColor:'red'}} disabled={false}/>
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
expect(getByText('testRibbon')).toBeDefined();
|
|
76
|
+
expect(getByTestId('card-topSection-ribbon')).toHaveStyleRule('background-color','red');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('renders title ,description and category label in middle section', async () => {
|
|
80
|
+
const{getByText} = render(
|
|
81
|
+
<Card middleSectionProps={{title:'testTitle', disabled: false, description:'testDescription', categoryLabel:'testCatLabel'}} disabled={false}/>
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
expect(getByText('testTitle')).toBeDefined();
|
|
85
|
+
expect(getByText('testDescription')).toBeDefined();
|
|
86
|
+
expect(getByText('testCatLabel')).toBeDefined();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('renders tags in middle section', async () => {
|
|
90
|
+
const{getByText} = render(
|
|
91
|
+
<Card middleSectionProps={{title:'testTitle', disabled: false, tags:[{label:'testTag'}], row2Tags:[{label:'testTag2'}]}} disabled={false}/>
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
expect(getByText('testTitle')).toBeDefined();
|
|
95
|
+
expect(getByText('testTag2')).toBeDefined();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('renders note text in bottom section', async () => {
|
|
99
|
+
const{getByText} = render(
|
|
100
|
+
<Card bottomSectionProps={{disabled: false, noteLeft:'leftNote', noteRight:'rightNote'}} disabled={false}/>
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
expect(getByText('leftNote')).toBeDefined();
|
|
104
|
+
expect(getByText('rightNote')).toBeDefined();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('renders author in bottom section', async () => {
|
|
108
|
+
const{getByText,getByTestId} = render(
|
|
109
|
+
<Card bottomSectionProps={{disabled: true, authorName:'testAuthor'}} disabled={true}/>
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
expect(getByText('testAuthor')).toBeDefined();
|
|
113
|
+
expect(getByTestId('card-bottomSection-author')).toBeDefined();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('renders actions in bottom section', async () => {
|
|
117
|
+
const{getByText,getByTestId} = render(
|
|
118
|
+
<Card bottomSectionProps={{disabled: true, authorName:'testAuthor', actions:[{icon:<SystemIcons.Add/>,onClick:()=>{}}]}} disabled={true}/>
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
expect(getByText('testAuthor')).toBeDefined();
|
|
122
|
+
expect(getByTestId('card-bottomSection-author')).toBeDefined();
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('fires leftButton click event on click', async () => {
|
|
126
|
+
const leftButtonClicked = jest.fn();
|
|
127
|
+
const{getByRole} = render(
|
|
128
|
+
<Card bottomSectionProps={{disabled: true,
|
|
129
|
+
authorName:'testAuthor',
|
|
130
|
+
actions:[],
|
|
131
|
+
leftButton: {
|
|
132
|
+
variant: 'tertiary',
|
|
133
|
+
buttonText: 'button',
|
|
134
|
+
onClick: (e) => {
|
|
135
|
+
e.stopPropagation();
|
|
136
|
+
leftButtonClicked();
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}}
|
|
140
|
+
disabled={true}/>
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
fireEvent.click(getByRole('button'));
|
|
144
|
+
expect(leftButtonClicked).toBeCalledTimes(1);
|
|
145
|
+
});
|
|
146
|
+
})
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import {ActionChip} from '../index';
|
|
3
|
+
import {act, fireEvent, render} from '../../test-utils';
|
|
4
|
+
import { SystemIcons } from '../../icons';
|
|
5
|
+
|
|
6
|
+
describe('ActionChip', () => {
|
|
7
|
+
|
|
8
|
+
it('should render', () => {
|
|
9
|
+
const wrapper = render(<ActionChip text={'label'}/>);
|
|
10
|
+
|
|
11
|
+
expect(wrapper.queryByText('label')).toBeInTheDocument();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('should render icon', () => {
|
|
15
|
+
const wrapper = render(<ActionChip text={'label'} icon={<SystemIcons.Book/>}/>);
|
|
16
|
+
|
|
17
|
+
expect(wrapper.queryByLabelText('Book')).toBeInTheDocument();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should be focusable if it is not disabled and onClick is defined', () => {
|
|
21
|
+
const wrapper = render(<ActionChip text={'label'} icon={<SystemIcons.Book/>} onClick={jest.fn()}/>);
|
|
22
|
+
|
|
23
|
+
expect(wrapper.container.querySelector('[tabindex="0"]')).toBeInTheDocument();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should not be focusable if it is disabled', () => {
|
|
27
|
+
const wrapper = render(<ActionChip text={'label'} icon={<SystemIcons.Book/>} disabled={true} onClick={jest.fn()}/>);
|
|
28
|
+
|
|
29
|
+
expect(wrapper.container.querySelector('[tabindex="-1"]')).toBeInTheDocument();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should not be focusable if it is not interactive', () => {
|
|
33
|
+
const wrapper = render(<ActionChip text={'label'} icon={<SystemIcons.Book/>}/>);
|
|
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(<ActionChip text={'label'} icon={<SystemIcons.Book/>} onClick={onClickSpy}/>);
|
|
41
|
+
|
|
42
|
+
act(() => {
|
|
43
|
+
wrapper.getByText('label').click();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
expect(onClickSpy).toHaveBeenCalled();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('should call onClick when Enter is pressed', () => {
|
|
50
|
+
const onClickSpy = jest.fn();
|
|
51
|
+
const wrapper = render(<ActionChip text={'label'} icon={<SystemIcons.Book/>} onClick={onClickSpy}/>);
|
|
52
|
+
|
|
53
|
+
act(() => {
|
|
54
|
+
fireEvent.keyDown(wrapper.getByText('label'), {key: 'Enter', code: 'Enter'});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
expect(onClickSpy).toHaveBeenCalled();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('should call onClick when Space is pressed', () => {
|
|
61
|
+
const onClickSpy = jest.fn();
|
|
62
|
+
const wrapper = render(<ActionChip text={'label'} icon={<SystemIcons.Book/>} onClick={onClickSpy}/>);
|
|
63
|
+
|
|
64
|
+
act(() => {
|
|
65
|
+
fireEvent.keyDown(wrapper.getByText('label'), {key: ' '});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
expect(onClickSpy).toHaveBeenCalled();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('should not call onClick when its clicked if disabled', () => {
|
|
72
|
+
const onClickSpy = jest.fn();
|
|
73
|
+
const wrapper = render(<ActionChip text={'label'} icon={<SystemIcons.Book/>} disabled={true} onClick={onClickSpy}/>);
|
|
74
|
+
|
|
75
|
+
act(() => {
|
|
76
|
+
wrapper.getByText('label').click();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
expect(onClickSpy).not.toHaveBeenCalled();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('should not call onClick when Enter is pressed if disabled', () => {
|
|
83
|
+
const onClickSpy = jest.fn();
|
|
84
|
+
const wrapper = render(<ActionChip text={'label'} icon={<SystemIcons.Book/>} disabled={true} onClick={onClickSpy}/>);
|
|
85
|
+
|
|
86
|
+
act(() => {
|
|
87
|
+
fireEvent.keyDown(wrapper.getByText('label'), {key: 'Enter', code: 'Enter'});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
expect(onClickSpy).not.toHaveBeenCalled();
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import {ChoiceChips} from '../index';
|
|
3
|
+
import {render, act, fireEvent} from '../../test-utils';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
describe('ChoiceChips', () => {
|
|
9
|
+
|
|
10
|
+
it('should render chips', () => {
|
|
11
|
+
|
|
12
|
+
const wrapper = render(<ChoiceChips selected={'1'}
|
|
13
|
+
values={[{value: '1', label: 'label'}, {value: '2', label: 'label 2'}]}/>);
|
|
14
|
+
|
|
15
|
+
expect(wrapper.queryAllByRole('radio')).toHaveLength(2);
|
|
16
|
+
expect(wrapper.queryByText('label')).toBeInTheDocument();
|
|
17
|
+
expect(wrapper.queryByText('label 2')).toBeInTheDocument();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should call onClick when chip is clicked', () => {
|
|
21
|
+
const onClickSpy = jest.fn();
|
|
22
|
+
|
|
23
|
+
const wrapper = render(<ChoiceChips selected={'1'}
|
|
24
|
+
onClick={onClickSpy}
|
|
25
|
+
values={[{value: '1', label: 'label'}, {value: '2', label: 'label 2'}]}/>);
|
|
26
|
+
|
|
27
|
+
act(() => {
|
|
28
|
+
wrapper.getByText('label 2').click()
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
expect(onClickSpy).toHaveBeenCalledWith({value: '2', label: 'label 2'});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should call onClick when enter is pressed on focused chip', () => {
|
|
35
|
+
const onClickSpy = jest.fn();
|
|
36
|
+
|
|
37
|
+
const wrapper = render(<ChoiceChips selected={'1'}
|
|
38
|
+
onClick={onClickSpy}
|
|
39
|
+
values={[{value: '1', label: 'label'}, {value: '2', label: 'label 2'}]}/>);
|
|
40
|
+
|
|
41
|
+
act(() => {
|
|
42
|
+
fireEvent.keyDown(wrapper.getByText('label 2'), {key: 'Enter', code: 'Enter'});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
expect(onClickSpy).toHaveBeenCalledWith({value: '2', label: 'label 2'});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('should not call onClick when chip is clicked if its disabled', () => {
|
|
49
|
+
const onClickSpy = jest.fn();
|
|
50
|
+
|
|
51
|
+
const wrapper = render(<ChoiceChips selected={'1'}
|
|
52
|
+
disabled={true}
|
|
53
|
+
onClick={onClickSpy}
|
|
54
|
+
values={[{value: '1', label: 'label'}, {value: '2', label: 'label 2'}]}/>);
|
|
55
|
+
|
|
56
|
+
act(() => {
|
|
57
|
+
wrapper.getByText('label 2').click()
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
expect(onClickSpy).not.toHaveBeenCalled();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('should render selected chip with default class others with outline class', () => {
|
|
64
|
+
const onClickSpy = jest.fn();
|
|
65
|
+
|
|
66
|
+
const wrapper = render(<ChoiceChips selected={'1'}
|
|
67
|
+
onClick={onClickSpy}
|
|
68
|
+
values={[{value: '1', label: 'label'}, {value: '2', label: 'label 2'}]}/>);
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
act(() => {
|
|
72
|
+
wrapper.getByText('label 2').click()
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
expect(wrapper.queryAllByRole('radio')[0]).toHaveClass('outline');
|
|
76
|
+
expect(wrapper.queryAllByRole('radio')[1]).toHaveClass('default')
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
})
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import {FilterChip} from '../index';
|
|
3
|
+
import {act, fireEvent, render} from '../../test-utils';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
describe('FilterChip', () => {
|
|
9
|
+
|
|
10
|
+
it('should render', () => {
|
|
11
|
+
const wrapper = render(<FilterChip selected={false} text={'label'}/>);
|
|
12
|
+
|
|
13
|
+
expect(wrapper.queryByText('label')).toBeInTheDocument();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should render icon when selected', () => {
|
|
17
|
+
const wrapper = render(<FilterChip selected={true} text={'label'}/>);
|
|
18
|
+
|
|
19
|
+
expect(wrapper.queryByLabelText('Checkmark')).toBeInTheDocument();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('should be focusable if it is not disabled and onClick is defined', () => {
|
|
23
|
+
const wrapper = render(<FilterChip selected={false} text={'label'} onClick={jest.fn()}/>);
|
|
24
|
+
|
|
25
|
+
expect(wrapper.container.querySelector('[tabindex="0"]')).toBeInTheDocument();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should not be focusable if it is disabled', () => {
|
|
29
|
+
const wrapper = render(<FilterChip selected={false} text={'label'} disabled={true} onClick={jest.fn()}/>);
|
|
30
|
+
|
|
31
|
+
expect(wrapper.container.querySelector('[tabindex="-1"]')).toBeInTheDocument();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should not be focusable if it is not interactive', () => {
|
|
35
|
+
const wrapper = render(<FilterChip selected={false} text={'label'}/>);
|
|
36
|
+
|
|
37
|
+
expect(wrapper.container.querySelector('[tabindex="-1"]')).toBeInTheDocument();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('should call onClick when its clicked', () => {
|
|
41
|
+
const onClickSpy = jest.fn();
|
|
42
|
+
const wrapper = render(<FilterChip selected={false} text={'label'} onClick={onClickSpy}/>);
|
|
43
|
+
|
|
44
|
+
act(() => {
|
|
45
|
+
wrapper.getByText('label').click();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
expect(onClickSpy).toHaveBeenCalled();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('should call onClick when Enter is pressed', () => {
|
|
52
|
+
const onClickSpy = jest.fn();
|
|
53
|
+
const wrapper = render(<FilterChip selected={false} text={'label'} 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(<FilterChip selected={false} text={'label'} onClick={onClickSpy}/>);
|
|
65
|
+
|
|
66
|
+
act(() => {
|
|
67
|
+
fireEvent.keyDown(wrapper.getByText('label'), {key: ' ', code: 'Space'});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
expect(onClickSpy).toHaveBeenCalled();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('should not call onClick when its clicked if disabled', () => {
|
|
74
|
+
const onClickSpy = jest.fn();
|
|
75
|
+
const wrapper = render(<FilterChip selected={false} text={'label'} disabled={true} onClick={onClickSpy}/>);
|
|
76
|
+
|
|
77
|
+
act(() => {
|
|
78
|
+
wrapper.getByText('label').click();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
expect(onClickSpy).not.toHaveBeenCalled();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('should not call onClick when Enter is pressed if disabled', () => {
|
|
85
|
+
const onClickSpy = jest.fn();
|
|
86
|
+
const wrapper = render(<FilterChip selected={false} text={'label'} disabled={true} onClick={onClickSpy}/>);
|
|
87
|
+
|
|
88
|
+
act(() => {
|
|
89
|
+
fireEvent.keyDown(wrapper.getByText('label'), {key: 'Enter', code: 'Enter'});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
expect(onClickSpy).not.toHaveBeenCalled();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
});
|