@zohodesk/components 1.6.31 → 1.6.34
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/CHANGELOG.md +13 -0
- package/assets/Appearance/light/mode/Component_LightMode.module.css +1 -1
- package/es/Accordion/__tests__/Accordion.spec.js +117 -3
- package/es/Accordion/__tests__/AccordionItem.spec.js +118 -6
- package/es/Accordion/__tests__/__snapshots__/Accordion.spec.js.snap +344 -2
- package/es/Accordion/__tests__/__snapshots__/AccordionItem.spec.js.snap +155 -3
- package/es/Animation/__tests__/Animation.spec.js +28 -4
- package/es/Animation/__tests__/__snapshots__/Animation.spec.js.snap +92 -2
- package/es/Button/css/Button.module.css +2 -3
- package/es/CheckBox/CheckBox.js +1 -1
- package/es/CheckBox/__tests__/__snapshots__/CheckBox.spec.js.snap +1 -1
- package/es/DateTime/DateTime.module.css +2 -2
- package/es/DateTime/__tests__/CalendarView.spec.js +70 -3
- package/es/DateTime/__tests__/DateTime.spec.js +89 -6
- package/es/DateTime/__tests__/DateTimePopupFooter.spec.js +20 -2
- package/es/DateTime/__tests__/DateTimePopupHeader.spec.js +29 -2
- package/es/DateTime/__tests__/DateWidget.spec.js +34 -2
- package/es/DateTime/__tests__/DaysRow.spec.js +19 -3
- package/es/DateTime/__tests__/Time.spec.js +50 -3
- package/es/DateTime/__tests__/YearView.spec.js +60 -3
- package/es/DateTime/__tests__/__snapshots__/CalendarView.spec.js.snap +2907 -170
- package/es/DateTime/__tests__/__snapshots__/DateTime.spec.js.snap +4392 -108
- package/es/DateTime/__tests__/__snapshots__/DateTimePopupFooter.spec.js.snap +67 -1
- package/es/DateTime/__tests__/__snapshots__/DateTimePopupHeader.spec.js.snap +187 -1
- package/es/DateTime/__tests__/__snapshots__/DateWidget.spec.js.snap +265 -1
- package/es/DateTime/__tests__/__snapshots__/DaysRow.spec.js.snap +155 -2
- package/es/DateTime/__tests__/__snapshots__/Time.spec.js.snap +522 -5
- package/es/DateTime/__tests__/__snapshots__/YearView.spec.js.snap +540 -0
- package/es/DropBox/DropBoxElement/css/DropBoxElement.module.css +1 -4
- package/es/Heading/Heading.module.css +1 -1
- package/es/Heading/__tests__/Heading.spec.js +57 -3
- package/es/Heading/__tests__/__snapshots__/Heading.spec.js.snap +87 -14
- package/es/ListItem/__tests__/ListContainer.spec.js +228 -1
- package/es/ListItem/__tests__/ListItem.spec.js +359 -1
- package/es/ListItem/__tests__/ListItemWithAvatar.spec.js +390 -1
- package/es/ListItem/__tests__/ListItemWithCheckBox.spec.js +214 -1
- package/es/ListItem/__tests__/ListItemWithIcon.spec.js +303 -1
- package/es/ListItem/__tests__/ListItemWithRadio.spec.js +230 -1
- package/es/ListItem/__tests__/__snapshots__/ListContainer.spec.js.snap +602 -0
- package/es/ListItem/__tests__/__snapshots__/ListItem.spec.js.snap +1807 -0
- package/es/ListItem/__tests__/__snapshots__/ListItemWithAvatar.spec.js.snap +2703 -0
- package/es/ListItem/__tests__/__snapshots__/ListItemWithCheckBox.spec.js.snap +2909 -0
- package/es/ListItem/__tests__/__snapshots__/ListItemWithIcon.spec.js.snap +2009 -0
- package/es/ListItem/__tests__/__snapshots__/ListItemWithRadio.spec.js.snap +3070 -0
- package/es/MultiSelect/MultiSelect.module.css +1 -2
- package/es/MultiSelect/__tests__/AdvancedGroupMultiSelect.spec.js +671 -1
- package/es/MultiSelect/__tests__/AdvancedMultiSelect.spec.js +730 -1
- package/es/MultiSelect/__tests__/EmptyState.spec.js +268 -1
- package/es/MultiSelect/__tests__/MultiSelect.spec.js +889 -2
- package/es/MultiSelect/__tests__/MultiSelectHeader.spec.js +50 -1
- package/es/MultiSelect/__tests__/MultiSelectWithAvatar.spec.js +487 -1
- package/es/MultiSelect/__tests__/SelectedOptions.spec.js +291 -1
- package/es/MultiSelect/__tests__/Suggestions.spec.js +370 -2
- package/es/MultiSelect/__tests__/__snapshots__/AdvancedGroupMultiSelect.spec.js.snap +11785 -0
- package/es/MultiSelect/__tests__/__snapshots__/AdvancedMultiSelect.spec.js.snap +12083 -0
- package/es/MultiSelect/__tests__/__snapshots__/EmptyState.spec.js.snap +253 -0
- package/es/MultiSelect/__tests__/__snapshots__/MultiSelect.spec.js.snap +14052 -0
- package/es/MultiSelect/__tests__/__snapshots__/MultiSelectHeader.spec.js.snap +136 -0
- package/es/MultiSelect/__tests__/__snapshots__/MultiSelectWithAvatar.spec.js.snap +11506 -0
- package/es/MultiSelect/__tests__/__snapshots__/SelectedOptions.spec.js.snap +1382 -0
- package/es/MultiSelect/__tests__/__snapshots__/Suggestions.spec.js.snap +3611 -0
- package/es/PopOver/__tests__/PopOver.spec.js +141 -2
- package/es/PopOver/__tests__/__snapshots__/PopOver.spec.js.snap +1260 -0
- package/es/ResponsiveDropBox/__tests__/ResponsiveDropBox.spec.js +212 -1
- package/es/ResponsiveDropBox/__tests__/__snapshots__/ResponsiveDropBox.spec.js.snap +1802 -0
- package/es/Tab/Tabs.module.css +1 -2
- package/es/Tab/__tests__/Tab.spec.js +249 -1
- package/es/Tab/__tests__/TabContent.spec.js +34 -1
- package/es/Tab/__tests__/TabContentWrapper.spec.js +72 -1
- package/es/Tab/__tests__/TabWrapper.spec.js +163 -1
- package/es/Tab/__tests__/Tabs.spec.js +681 -1
- package/es/Tab/__tests__/__snapshots__/Tab.spec.js.snap +1049 -0
- package/es/Tab/__tests__/__snapshots__/TabContent.spec.js.snap +99 -0
- package/es/Tab/__tests__/__snapshots__/TabContentWrapper.spec.js.snap +121 -0
- package/es/Tab/__tests__/__snapshots__/TabWrapper.spec.js.snap +2002 -0
- package/es/Tab/__tests__/__snapshots__/Tabs.spec.js.snap +11053 -0
- package/es/Textarea/Textarea.module.css +1 -1
- package/es/Tooltip/Tooltip.module.css +1 -2
- package/es/Tooltip/__tests__/Tooltip.spec.js +590 -0
- package/es/Tooltip/__tests__/__snapshots__/Tooltip.spec.js.snap +813 -0
- package/es/Typography/css/Typography.module.css +8 -7
- package/es/common/common.module.css +4 -4
- package/lib/Accordion/__tests__/Accordion.spec.js +122 -2
- package/lib/Accordion/__tests__/AccordionItem.spec.js +126 -4
- package/lib/Accordion/__tests__/__snapshots__/Accordion.spec.js.snap +344 -2
- package/lib/Accordion/__tests__/__snapshots__/AccordionItem.spec.js.snap +155 -3
- package/lib/Animation/__tests__/Animation.spec.js +31 -5
- package/lib/Animation/__tests__/__snapshots__/Animation.spec.js.snap +92 -2
- package/lib/Button/css/Button.module.css +2 -3
- package/lib/CheckBox/CheckBox.js +1 -1
- package/lib/CheckBox/__tests__/__snapshots__/CheckBox.spec.js.snap +1 -1
- package/lib/DateTime/DateTime.module.css +2 -2
- package/lib/DateTime/__tests__/CalendarView.spec.js +71 -2
- package/lib/DateTime/__tests__/DateTime.spec.js +92 -6
- package/lib/DateTime/__tests__/DateTimePopupFooter.spec.js +21 -1
- package/lib/DateTime/__tests__/DateTimePopupHeader.spec.js +30 -1
- package/lib/DateTime/__tests__/DateWidget.spec.js +35 -1
- package/lib/DateTime/__tests__/DaysRow.spec.js +20 -2
- package/lib/DateTime/__tests__/Time.spec.js +51 -2
- package/lib/DateTime/__tests__/YearView.spec.js +61 -2
- package/lib/DateTime/__tests__/__snapshots__/CalendarView.spec.js.snap +2907 -170
- package/lib/DateTime/__tests__/__snapshots__/DateTime.spec.js.snap +4392 -108
- package/lib/DateTime/__tests__/__snapshots__/DateTimePopupFooter.spec.js.snap +67 -1
- package/lib/DateTime/__tests__/__snapshots__/DateTimePopupHeader.spec.js.snap +187 -1
- package/lib/DateTime/__tests__/__snapshots__/DateWidget.spec.js.snap +265 -1
- package/lib/DateTime/__tests__/__snapshots__/DaysRow.spec.js.snap +155 -2
- package/lib/DateTime/__tests__/__snapshots__/Time.spec.js.snap +522 -5
- package/lib/DateTime/__tests__/__snapshots__/YearView.spec.js.snap +540 -0
- package/lib/DropBox/DropBoxElement/css/DropBoxElement.module.css +1 -4
- package/lib/Heading/Heading.module.css +1 -1
- package/lib/Heading/__tests__/Heading.spec.js +60 -4
- package/lib/Heading/__tests__/__snapshots__/Heading.spec.js.snap +87 -14
- package/lib/ListItem/__tests__/ListContainer.spec.js +229 -0
- package/lib/ListItem/__tests__/ListItem.spec.js +362 -0
- package/lib/ListItem/__tests__/ListItemWithAvatar.spec.js +391 -0
- package/lib/ListItem/__tests__/ListItemWithCheckBox.spec.js +215 -0
- package/lib/ListItem/__tests__/ListItemWithIcon.spec.js +304 -0
- package/lib/ListItem/__tests__/ListItemWithRadio.spec.js +231 -0
- package/lib/ListItem/__tests__/__snapshots__/ListContainer.spec.js.snap +602 -0
- package/lib/ListItem/__tests__/__snapshots__/ListItem.spec.js.snap +1807 -0
- package/lib/ListItem/__tests__/__snapshots__/ListItemWithAvatar.spec.js.snap +2703 -0
- package/lib/ListItem/__tests__/__snapshots__/ListItemWithCheckBox.spec.js.snap +2909 -0
- package/lib/ListItem/__tests__/__snapshots__/ListItemWithIcon.spec.js.snap +2009 -0
- package/lib/ListItem/__tests__/__snapshots__/ListItemWithRadio.spec.js.snap +3070 -0
- package/lib/MultiSelect/MultiSelect.module.css +1 -2
- package/lib/MultiSelect/__tests__/AdvancedGroupMultiSelect.spec.js +692 -0
- package/lib/MultiSelect/__tests__/AdvancedMultiSelect.spec.js +741 -0
- package/lib/MultiSelect/__tests__/EmptyState.spec.js +273 -0
- package/lib/MultiSelect/__tests__/MultiSelect.spec.js +910 -0
- package/lib/MultiSelect/__tests__/MultiSelectHeader.spec.js +51 -0
- package/lib/MultiSelect/__tests__/MultiSelectWithAvatar.spec.js +497 -0
- package/lib/MultiSelect/__tests__/SelectedOptions.spec.js +305 -0
- package/lib/MultiSelect/__tests__/Suggestions.spec.js +375 -0
- package/lib/MultiSelect/__tests__/__snapshots__/AdvancedGroupMultiSelect.spec.js.snap +11785 -0
- package/lib/MultiSelect/__tests__/__snapshots__/AdvancedMultiSelect.spec.js.snap +12083 -0
- package/lib/MultiSelect/__tests__/__snapshots__/EmptyState.spec.js.snap +253 -0
- package/lib/MultiSelect/__tests__/__snapshots__/MultiSelect.spec.js.snap +14052 -0
- package/lib/MultiSelect/__tests__/__snapshots__/MultiSelectHeader.spec.js.snap +136 -0
- package/lib/MultiSelect/__tests__/__snapshots__/MultiSelectWithAvatar.spec.js.snap +11506 -0
- package/lib/MultiSelect/__tests__/__snapshots__/SelectedOptions.spec.js.snap +1382 -0
- package/lib/MultiSelect/__tests__/__snapshots__/Suggestions.spec.js.snap +3611 -0
- package/lib/PopOver/__tests__/PopOver.spec.js +150 -1
- package/lib/PopOver/__tests__/__snapshots__/PopOver.spec.js.snap +1260 -0
- package/lib/ResponsiveDropBox/__tests__/ResponsiveDropBox.spec.js +213 -0
- package/lib/ResponsiveDropBox/__tests__/__snapshots__/ResponsiveDropBox.spec.js.snap +1802 -0
- package/lib/Tab/Tabs.module.css +1 -2
- package/lib/Tab/__tests__/Tab.spec.js +250 -0
- package/lib/Tab/__tests__/TabContent.spec.js +35 -0
- package/lib/Tab/__tests__/TabContentWrapper.spec.js +76 -0
- package/lib/Tab/__tests__/TabWrapper.spec.js +174 -0
- package/lib/Tab/__tests__/Tabs.spec.js +741 -0
- package/lib/Tab/__tests__/__snapshots__/Tab.spec.js.snap +1049 -0
- package/lib/Tab/__tests__/__snapshots__/TabContent.spec.js.snap +99 -0
- package/lib/Tab/__tests__/__snapshots__/TabContentWrapper.spec.js.snap +121 -0
- package/lib/Tab/__tests__/__snapshots__/TabWrapper.spec.js.snap +2002 -0
- package/lib/Tab/__tests__/__snapshots__/Tabs.spec.js.snap +11053 -0
- package/lib/Textarea/Textarea.module.css +1 -1
- package/lib/Tooltip/Tooltip.module.css +1 -2
- package/lib/Tooltip/__tests__/Tooltip.spec.js +629 -0
- package/lib/Tooltip/__tests__/__snapshots__/Tooltip.spec.js.snap +813 -0
- package/lib/Typography/css/Typography.module.css +8 -7
- package/lib/common/common.module.css +4 -4
- package/package.json +6 -5
|
@@ -11,12 +11,11 @@
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
.tooltipcont {
|
|
14
|
-
composes: d-overflow-hidden d-border-transparent d-border-solid from global;
|
|
14
|
+
composes: d-overflow-hidden d-border-transparent d-border-solid d-font-semibold from global;
|
|
15
15
|
color: var(--zdt_tooltip_default_text);
|
|
16
16
|
padding-block:0 ;
|
|
17
17
|
padding-inline: var(--zd_size10) ;
|
|
18
18
|
font-size: var(--zd_font_size13) ;
|
|
19
|
-
font-weight: var(--zd-fw-semibold);
|
|
20
19
|
word-break: break-word;
|
|
21
20
|
max-width: var(--zd_size420) ;
|
|
22
21
|
line-height: 1.5385;
|
|
@@ -0,0 +1,590 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { render, cleanup, act, fireEvent } from '@testing-library/react';
|
|
5
|
+
import Tooltip from "../Tooltip"; // Tooltip renders nothing until handleOver is called with a hovered element, so cases drive it through its ref.
|
|
6
|
+
// jsdom reports every size as 0, which collapses all placement branches, so sizes are stubbed to fixed values.
|
|
7
|
+
|
|
8
|
+
const containerSize = {
|
|
9
|
+
width: 1000,
|
|
10
|
+
height: 800
|
|
11
|
+
};
|
|
12
|
+
const tooltipSize = {
|
|
13
|
+
width: 100,
|
|
14
|
+
height: 40
|
|
15
|
+
};
|
|
16
|
+
const defaultRect = {
|
|
17
|
+
top: 300,
|
|
18
|
+
left: 400,
|
|
19
|
+
width: 50,
|
|
20
|
+
height: 20
|
|
21
|
+
};
|
|
22
|
+
const originalOffsetDescriptors = {
|
|
23
|
+
offsetWidth: Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'offsetWidth'),
|
|
24
|
+
offsetHeight: Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'offsetHeight')
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const restoreDescriptor = name => {
|
|
28
|
+
if (originalOffsetDescriptors[name]) {
|
|
29
|
+
Object.defineProperty(HTMLElement.prototype, name, originalOffsetDescriptors[name]);
|
|
30
|
+
} else {
|
|
31
|
+
delete HTMLElement.prototype[name];
|
|
32
|
+
}
|
|
33
|
+
}; // only the tooltip element is sized through the prototype; the hovered element and container are stubbed per instance
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
const isTooltipElement = element => element.classList.contains('tooltiptext');
|
|
37
|
+
|
|
38
|
+
const hoverTooltip = (attributes, {
|
|
39
|
+
rect = defaultRect,
|
|
40
|
+
tooltipProps,
|
|
41
|
+
element = {}
|
|
42
|
+
} = {}) => {
|
|
43
|
+
const target = document.createElement(element.tagName || 'div');
|
|
44
|
+
Object.entries(attributes).forEach(([name, value]) => target.setAttribute(name, value));
|
|
45
|
+
|
|
46
|
+
target.getBoundingClientRect = () => ({ ...rect,
|
|
47
|
+
right: rect.left + rect.width,
|
|
48
|
+
bottom: rect.top + rect.height
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
if (element.innerText !== undefined) {
|
|
52
|
+
target.innerText = element.innerText;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (element.isOverflowing) {
|
|
56
|
+
Object.defineProperty(target, 'scrollWidth', {
|
|
57
|
+
value: 200
|
|
58
|
+
});
|
|
59
|
+
Object.defineProperty(target, 'offsetWidth', {
|
|
60
|
+
value: 100
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const ref = /*#__PURE__*/React.createRef();
|
|
65
|
+
const utils = render( /*#__PURE__*/React.createElement(Tooltip, _extends({
|
|
66
|
+
ref: ref
|
|
67
|
+
}, tooltipProps)));
|
|
68
|
+
act(() => {
|
|
69
|
+
ref.current.observeElement();
|
|
70
|
+
});
|
|
71
|
+
act(() => {
|
|
72
|
+
ref.current.handleOver({
|
|
73
|
+
target
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
return { ...utils,
|
|
77
|
+
ref,
|
|
78
|
+
target
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
describe('Tooltip', () => {
|
|
83
|
+
beforeAll(() => {
|
|
84
|
+
Object.defineProperty(HTMLElement.prototype, 'offsetWidth', {
|
|
85
|
+
configurable: true,
|
|
86
|
+
|
|
87
|
+
get() {
|
|
88
|
+
return isTooltipElement(this) ? tooltipSize.width : 0;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
});
|
|
92
|
+
Object.defineProperty(HTMLElement.prototype, 'offsetHeight', {
|
|
93
|
+
configurable: true,
|
|
94
|
+
|
|
95
|
+
get() {
|
|
96
|
+
return isTooltipElement(this) ? tooltipSize.height : 0;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
afterAll(() => {
|
|
102
|
+
restoreDescriptor('offsetWidth');
|
|
103
|
+
restoreDescriptor('offsetHeight');
|
|
104
|
+
});
|
|
105
|
+
beforeEach(() => {
|
|
106
|
+
Object.defineProperty(document.body, 'offsetWidth', {
|
|
107
|
+
configurable: true,
|
|
108
|
+
value: containerSize.width
|
|
109
|
+
});
|
|
110
|
+
Object.defineProperty(document.body, 'offsetHeight', {
|
|
111
|
+
configurable: true,
|
|
112
|
+
value: containerSize.height
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
document.body.getBoundingClientRect = () => ({
|
|
116
|
+
left: 0,
|
|
117
|
+
top: 0,
|
|
118
|
+
...containerSize
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
afterEach(() => {
|
|
122
|
+
cleanup();
|
|
123
|
+
delete document.body.offsetWidth;
|
|
124
|
+
delete document.body.offsetHeight;
|
|
125
|
+
delete document.body.getBoundingClientRect;
|
|
126
|
+
document.documentElement.removeAttribute('dir');
|
|
127
|
+
});
|
|
128
|
+
test('Render with default props', () => {
|
|
129
|
+
const {
|
|
130
|
+
asFragment
|
|
131
|
+
} = render( /*#__PURE__*/React.createElement(Tooltip, null));
|
|
132
|
+
expect(asFragment()).toMatchSnapshot();
|
|
133
|
+
});
|
|
134
|
+
test('Render with dataId', () => {
|
|
135
|
+
const {
|
|
136
|
+
asFragment
|
|
137
|
+
} = hoverTooltip({
|
|
138
|
+
'data-title': 'Tooltip text'
|
|
139
|
+
}, {
|
|
140
|
+
tooltipProps: {
|
|
141
|
+
dataId: 'tooltip-dataId'
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
expect(asFragment()).toMatchSnapshot();
|
|
145
|
+
});
|
|
146
|
+
test('Render with customClass', () => {
|
|
147
|
+
const {
|
|
148
|
+
asFragment
|
|
149
|
+
} = hoverTooltip({
|
|
150
|
+
'data-title': 'Tooltip text'
|
|
151
|
+
}, {
|
|
152
|
+
tooltipProps: {
|
|
153
|
+
customClass: 'custom-tooltip'
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
expect(asFragment()).toMatchSnapshot();
|
|
157
|
+
}); // the title attribute is moved to data-title so the browser's own tooltip does not also appear
|
|
158
|
+
|
|
159
|
+
test('Render with title attribute only', () => {
|
|
160
|
+
const {
|
|
161
|
+
asFragment,
|
|
162
|
+
target
|
|
163
|
+
} = hoverTooltip({
|
|
164
|
+
title: 'Tooltip text'
|
|
165
|
+
});
|
|
166
|
+
expect(target.getAttribute('data-title')).toBe('Tooltip text');
|
|
167
|
+
expect(target.hasAttribute('title')).toBe(false);
|
|
168
|
+
expect(asFragment()).toMatchSnapshot();
|
|
169
|
+
});
|
|
170
|
+
test('Render with data-title', () => {
|
|
171
|
+
const {
|
|
172
|
+
asFragment
|
|
173
|
+
} = hoverTooltip({
|
|
174
|
+
'data-title': 'Tooltip text'
|
|
175
|
+
});
|
|
176
|
+
expect(asFragment()).toMatchSnapshot();
|
|
177
|
+
});
|
|
178
|
+
test('Render with data-title taking precedence over title', () => {
|
|
179
|
+
const {
|
|
180
|
+
asFragment
|
|
181
|
+
} = hoverTooltip({
|
|
182
|
+
'data-title': 'Data title',
|
|
183
|
+
title: 'Plain title'
|
|
184
|
+
});
|
|
185
|
+
expect(asFragment()).toMatchSnapshot();
|
|
186
|
+
});
|
|
187
|
+
test('Render with data-ishtml as true', () => {
|
|
188
|
+
const {
|
|
189
|
+
asFragment
|
|
190
|
+
} = hoverTooltip({
|
|
191
|
+
'data-title': '<b>Bold</b> text',
|
|
192
|
+
'data-ishtml': 'true'
|
|
193
|
+
});
|
|
194
|
+
expect(asFragment()).toMatchSnapshot();
|
|
195
|
+
}); // any non-empty data-ishtml value counts as html, including the string false
|
|
196
|
+
|
|
197
|
+
test('Render with data-ishtml as false', () => {
|
|
198
|
+
const {
|
|
199
|
+
asFragment
|
|
200
|
+
} = hoverTooltip({
|
|
201
|
+
'data-title': '<b>Bold</b> text',
|
|
202
|
+
'data-ishtml': 'false'
|
|
203
|
+
});
|
|
204
|
+
expect(asFragment()).toMatchSnapshot();
|
|
205
|
+
});
|
|
206
|
+
test('Render with data-tooltip-noarrow as true', () => {
|
|
207
|
+
const {
|
|
208
|
+
asFragment
|
|
209
|
+
} = hoverTooltip({
|
|
210
|
+
'data-title': 'Tooltip text',
|
|
211
|
+
'data-title-position': 'top',
|
|
212
|
+
'data-tooltip-noarrow': 'true'
|
|
213
|
+
});
|
|
214
|
+
expect(asFragment()).toMatchSnapshot();
|
|
215
|
+
}); // only the exact value true removes the arrow
|
|
216
|
+
|
|
217
|
+
test('Render with data-tooltip-noarrow as false', () => {
|
|
218
|
+
const {
|
|
219
|
+
asFragment
|
|
220
|
+
} = hoverTooltip({
|
|
221
|
+
'data-title': 'Tooltip text',
|
|
222
|
+
'data-title-position': 'top',
|
|
223
|
+
'data-tooltip-noarrow': 'false'
|
|
224
|
+
});
|
|
225
|
+
expect(asFragment()).toMatchSnapshot();
|
|
226
|
+
}); // pre is shown as pre-wrap and nowrap as normal, so those two render like pre-wrap and the default
|
|
227
|
+
|
|
228
|
+
const wraps = ['pre', 'pre-wrap', 'pre-line', 'nowrap', 'break-spaces'];
|
|
229
|
+
test.each(wraps)('Render with data-title-wrap as %s', wrap => {
|
|
230
|
+
const {
|
|
231
|
+
asFragment
|
|
232
|
+
} = hoverTooltip({
|
|
233
|
+
'data-title': 'Tooltip text',
|
|
234
|
+
'data-title-wrap': wrap
|
|
235
|
+
});
|
|
236
|
+
expect(asFragment()).toMatchSnapshot();
|
|
237
|
+
}); // bottom matches the default placement, including the flip above near the bottom edge
|
|
238
|
+
|
|
239
|
+
test('Render with no position below the target', () => {
|
|
240
|
+
const {
|
|
241
|
+
asFragment
|
|
242
|
+
} = hoverTooltip({
|
|
243
|
+
'data-title': 'Tooltip text'
|
|
244
|
+
}, {
|
|
245
|
+
rect: defaultRect
|
|
246
|
+
});
|
|
247
|
+
expect(asFragment()).toMatchSnapshot();
|
|
248
|
+
});
|
|
249
|
+
test('Render with no position near the bottom edge flipping above', () => {
|
|
250
|
+
const {
|
|
251
|
+
asFragment
|
|
252
|
+
} = hoverTooltip({
|
|
253
|
+
'data-title': 'Tooltip text'
|
|
254
|
+
}, {
|
|
255
|
+
rect: { ...defaultRect,
|
|
256
|
+
top: 770
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
expect(asFragment()).toMatchSnapshot();
|
|
260
|
+
});
|
|
261
|
+
test('Render with no position at the left screen edge', () => {
|
|
262
|
+
const {
|
|
263
|
+
asFragment
|
|
264
|
+
} = hoverTooltip({
|
|
265
|
+
'data-title': 'Tooltip text'
|
|
266
|
+
}, {
|
|
267
|
+
rect: {
|
|
268
|
+
top: 300,
|
|
269
|
+
left: 5,
|
|
270
|
+
width: 20,
|
|
271
|
+
height: 20
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
expect(asFragment()).toMatchSnapshot();
|
|
275
|
+
});
|
|
276
|
+
test('Render with no position at the right screen edge', () => {
|
|
277
|
+
const {
|
|
278
|
+
asFragment
|
|
279
|
+
} = hoverTooltip({
|
|
280
|
+
'data-title': 'Tooltip text'
|
|
281
|
+
}, {
|
|
282
|
+
rect: {
|
|
283
|
+
top: 300,
|
|
284
|
+
left: 960,
|
|
285
|
+
width: 30,
|
|
286
|
+
height: 20
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
expect(asFragment()).toMatchSnapshot();
|
|
290
|
+
});
|
|
291
|
+
test('Render with data-title-position as top with space above', () => {
|
|
292
|
+
const {
|
|
293
|
+
asFragment
|
|
294
|
+
} = hoverTooltip({
|
|
295
|
+
'data-title': 'Tooltip text',
|
|
296
|
+
'data-title-position': 'top'
|
|
297
|
+
}, {
|
|
298
|
+
rect: defaultRect
|
|
299
|
+
});
|
|
300
|
+
expect(asFragment()).toMatchSnapshot();
|
|
301
|
+
});
|
|
302
|
+
test('Render with data-title-position as top without space above', () => {
|
|
303
|
+
const {
|
|
304
|
+
asFragment
|
|
305
|
+
} = hoverTooltip({
|
|
306
|
+
'data-title': 'Tooltip text',
|
|
307
|
+
'data-title-position': 'top'
|
|
308
|
+
}, {
|
|
309
|
+
rect: { ...defaultRect,
|
|
310
|
+
top: 10
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
expect(asFragment()).toMatchSnapshot();
|
|
314
|
+
});
|
|
315
|
+
test('Render with data-title-position as top at the left screen edge', () => {
|
|
316
|
+
const {
|
|
317
|
+
asFragment
|
|
318
|
+
} = hoverTooltip({
|
|
319
|
+
'data-title': 'Tooltip text',
|
|
320
|
+
'data-title-position': 'top'
|
|
321
|
+
}, {
|
|
322
|
+
rect: {
|
|
323
|
+
top: 300,
|
|
324
|
+
left: 5,
|
|
325
|
+
width: 20,
|
|
326
|
+
height: 20
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
expect(asFragment()).toMatchSnapshot();
|
|
330
|
+
});
|
|
331
|
+
test('Render with data-title-position as top at the right screen edge', () => {
|
|
332
|
+
const {
|
|
333
|
+
asFragment
|
|
334
|
+
} = hoverTooltip({
|
|
335
|
+
'data-title': 'Tooltip text',
|
|
336
|
+
'data-title-position': 'top'
|
|
337
|
+
}, {
|
|
338
|
+
rect: {
|
|
339
|
+
top: 300,
|
|
340
|
+
left: 960,
|
|
341
|
+
width: 30,
|
|
342
|
+
height: 20
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
expect(asFragment()).toMatchSnapshot();
|
|
346
|
+
});
|
|
347
|
+
test('Render with data-title-position as bottom with space below', () => {
|
|
348
|
+
const {
|
|
349
|
+
asFragment
|
|
350
|
+
} = hoverTooltip({
|
|
351
|
+
'data-title': 'Tooltip text',
|
|
352
|
+
'data-title-position': 'bottom'
|
|
353
|
+
}, {
|
|
354
|
+
rect: defaultRect
|
|
355
|
+
});
|
|
356
|
+
expect(asFragment()).toMatchSnapshot();
|
|
357
|
+
});
|
|
358
|
+
test('Render with data-title-position as bottom without space below', () => {
|
|
359
|
+
const {
|
|
360
|
+
asFragment
|
|
361
|
+
} = hoverTooltip({
|
|
362
|
+
'data-title': 'Tooltip text',
|
|
363
|
+
'data-title-position': 'bottom'
|
|
364
|
+
}, {
|
|
365
|
+
rect: { ...defaultRect,
|
|
366
|
+
top: 770
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
expect(asFragment()).toMatchSnapshot();
|
|
370
|
+
});
|
|
371
|
+
test('Render with data-title-position as left with space on the left', () => {
|
|
372
|
+
const {
|
|
373
|
+
asFragment
|
|
374
|
+
} = hoverTooltip({
|
|
375
|
+
'data-title': 'Tooltip text',
|
|
376
|
+
'data-title-position': 'left'
|
|
377
|
+
}, {
|
|
378
|
+
rect: defaultRect
|
|
379
|
+
});
|
|
380
|
+
expect(asFragment()).toMatchSnapshot();
|
|
381
|
+
});
|
|
382
|
+
test('Render with data-title-position as left without space on the left', () => {
|
|
383
|
+
const {
|
|
384
|
+
asFragment
|
|
385
|
+
} = hoverTooltip({
|
|
386
|
+
'data-title': 'Tooltip text',
|
|
387
|
+
'data-title-position': 'left'
|
|
388
|
+
}, {
|
|
389
|
+
rect: { ...defaultRect,
|
|
390
|
+
left: 20
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
expect(asFragment()).toMatchSnapshot();
|
|
394
|
+
});
|
|
395
|
+
test('Render with data-title-position as left at the top screen edge', () => {
|
|
396
|
+
const {
|
|
397
|
+
asFragment
|
|
398
|
+
} = hoverTooltip({
|
|
399
|
+
'data-title': 'Tooltip text',
|
|
400
|
+
'data-title-position': 'left'
|
|
401
|
+
}, {
|
|
402
|
+
rect: { ...defaultRect,
|
|
403
|
+
top: 0
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
expect(asFragment()).toMatchSnapshot();
|
|
407
|
+
});
|
|
408
|
+
test('Render with data-title-position as left at the bottom screen edge', () => {
|
|
409
|
+
const {
|
|
410
|
+
asFragment
|
|
411
|
+
} = hoverTooltip({
|
|
412
|
+
'data-title': 'Tooltip text',
|
|
413
|
+
'data-title-position': 'left'
|
|
414
|
+
}, {
|
|
415
|
+
rect: { ...defaultRect,
|
|
416
|
+
top: 790
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
expect(asFragment()).toMatchSnapshot();
|
|
420
|
+
});
|
|
421
|
+
test('Render with data-title-position as right with space on the right', () => {
|
|
422
|
+
const {
|
|
423
|
+
asFragment
|
|
424
|
+
} = hoverTooltip({
|
|
425
|
+
'data-title': 'Tooltip text',
|
|
426
|
+
'data-title-position': 'right'
|
|
427
|
+
}, {
|
|
428
|
+
rect: defaultRect
|
|
429
|
+
});
|
|
430
|
+
expect(asFragment()).toMatchSnapshot();
|
|
431
|
+
});
|
|
432
|
+
test('Render with data-title-position as right without space on the right', () => {
|
|
433
|
+
const {
|
|
434
|
+
asFragment
|
|
435
|
+
} = hoverTooltip({
|
|
436
|
+
'data-title': 'Tooltip text',
|
|
437
|
+
'data-title-position': 'right'
|
|
438
|
+
}, {
|
|
439
|
+
rect: { ...defaultRect,
|
|
440
|
+
left: 930
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
expect(asFragment()).toMatchSnapshot();
|
|
444
|
+
}); // in rtl the left and right positions are swapped
|
|
445
|
+
|
|
446
|
+
test.each(['left', 'right'])('Render with data-title-position as %s in rtl', position => {
|
|
447
|
+
document.documentElement.setAttribute('dir', 'rtl');
|
|
448
|
+
const {
|
|
449
|
+
asFragment
|
|
450
|
+
} = hoverTooltip({
|
|
451
|
+
'data-title': 'Tooltip text',
|
|
452
|
+
'data-title-position': position
|
|
453
|
+
});
|
|
454
|
+
expect(asFragment()).toMatchSnapshot();
|
|
455
|
+
}); // the tooltip is skipped when the hovered text already shows the title, unless the text is cut off
|
|
456
|
+
// this first case stays hidden on purpose; the others each bypass that check
|
|
457
|
+
|
|
458
|
+
test('Render with title matching the element text', () => {
|
|
459
|
+
const {
|
|
460
|
+
asFragment
|
|
461
|
+
} = hoverTooltip({
|
|
462
|
+
'data-title': 'Save'
|
|
463
|
+
}, {
|
|
464
|
+
element: {
|
|
465
|
+
innerText: 'Save'
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
expect(asFragment()).toMatchSnapshot();
|
|
469
|
+
});
|
|
470
|
+
test('Render with title matching the element text and data-istitle', () => {
|
|
471
|
+
const {
|
|
472
|
+
asFragment
|
|
473
|
+
} = hoverTooltip({
|
|
474
|
+
'data-title': 'Save',
|
|
475
|
+
'data-istitle': 'true'
|
|
476
|
+
}, {
|
|
477
|
+
element: {
|
|
478
|
+
innerText: 'Save'
|
|
479
|
+
}
|
|
480
|
+
});
|
|
481
|
+
expect(asFragment()).toMatchSnapshot();
|
|
482
|
+
});
|
|
483
|
+
test('Render with title matching an overflowing element text', () => {
|
|
484
|
+
const {
|
|
485
|
+
asFragment
|
|
486
|
+
} = hoverTooltip({
|
|
487
|
+
'data-title': 'Save'
|
|
488
|
+
}, {
|
|
489
|
+
element: {
|
|
490
|
+
innerText: 'Save',
|
|
491
|
+
isOverflowing: true
|
|
492
|
+
}
|
|
493
|
+
});
|
|
494
|
+
expect(asFragment()).toMatchSnapshot();
|
|
495
|
+
});
|
|
496
|
+
test('Render with data-dottedTitle and an overflowing element text', () => {
|
|
497
|
+
const {
|
|
498
|
+
asFragment
|
|
499
|
+
} = hoverTooltip({
|
|
500
|
+
'data-title': 'Save',
|
|
501
|
+
'data-dottedTitle': 'Full saved title'
|
|
502
|
+
}, {
|
|
503
|
+
element: {
|
|
504
|
+
innerText: 'Save',
|
|
505
|
+
isOverflowing: true
|
|
506
|
+
}
|
|
507
|
+
});
|
|
508
|
+
expect(asFragment()).toMatchSnapshot();
|
|
509
|
+
}); // data-dottedTitle is ignored while the text is not cut off
|
|
510
|
+
|
|
511
|
+
test('Render with data-dottedTitle and a title different from the element text', () => {
|
|
512
|
+
const {
|
|
513
|
+
asFragment
|
|
514
|
+
} = hoverTooltip({
|
|
515
|
+
'data-title': 'Tooltip text',
|
|
516
|
+
'data-dottedTitle': 'Full saved title'
|
|
517
|
+
}, {
|
|
518
|
+
element: {
|
|
519
|
+
innerText: 'Other'
|
|
520
|
+
}
|
|
521
|
+
});
|
|
522
|
+
expect(asFragment()).toMatchSnapshot();
|
|
523
|
+
});
|
|
524
|
+
test('Render with title matching the text of an icon element', () => {
|
|
525
|
+
const {
|
|
526
|
+
asFragment
|
|
527
|
+
} = hoverTooltip({
|
|
528
|
+
title: 'Save'
|
|
529
|
+
}, {
|
|
530
|
+
element: {
|
|
531
|
+
tagName: 'i',
|
|
532
|
+
innerText: 'Save'
|
|
533
|
+
}
|
|
534
|
+
});
|
|
535
|
+
expect(asFragment()).toMatchSnapshot();
|
|
536
|
+
}); // the tooltip hides when the pointer leaves, a click or release happens, or an untitled element is hovered
|
|
537
|
+
|
|
538
|
+
test.each(['click', 'mouseup', 'mouseleave'])('Render with %s event on the hovered element', eventName => {
|
|
539
|
+
const {
|
|
540
|
+
asFragment,
|
|
541
|
+
container,
|
|
542
|
+
target
|
|
543
|
+
} = hoverTooltip({
|
|
544
|
+
'data-title': 'Tooltip text'
|
|
545
|
+
});
|
|
546
|
+
expect(container.textContent).toBe('Tooltip text');
|
|
547
|
+
fireEvent(target, new MouseEvent(eventName));
|
|
548
|
+
expect(container.textContent).toBe('');
|
|
549
|
+
expect(asFragment()).toMatchSnapshot();
|
|
550
|
+
});
|
|
551
|
+
test('Render with a following hover on an element without a title', () => {
|
|
552
|
+
const {
|
|
553
|
+
asFragment,
|
|
554
|
+
container,
|
|
555
|
+
ref
|
|
556
|
+
} = hoverTooltip({
|
|
557
|
+
'data-title': 'Tooltip text'
|
|
558
|
+
});
|
|
559
|
+
expect(container.textContent).toBe('Tooltip text');
|
|
560
|
+
act(() => {
|
|
561
|
+
ref.current.handleOver({
|
|
562
|
+
target: document.createElement('div')
|
|
563
|
+
});
|
|
564
|
+
});
|
|
565
|
+
expect(container.textContent).toBe('');
|
|
566
|
+
expect(asFragment()).toMatchSnapshot();
|
|
567
|
+
});
|
|
568
|
+
test('Render with a following hover on another titled element', () => {
|
|
569
|
+
const {
|
|
570
|
+
asFragment,
|
|
571
|
+
ref
|
|
572
|
+
} = hoverTooltip({
|
|
573
|
+
'data-title': 'Tooltip text'
|
|
574
|
+
});
|
|
575
|
+
const next = document.createElement('div');
|
|
576
|
+
next.setAttribute('data-title', 'Next tooltip text');
|
|
577
|
+
|
|
578
|
+
next.getBoundingClientRect = () => ({ ...defaultRect,
|
|
579
|
+
right: 450,
|
|
580
|
+
bottom: 320
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
act(() => {
|
|
584
|
+
ref.current.handleOver({
|
|
585
|
+
target: next
|
|
586
|
+
});
|
|
587
|
+
});
|
|
588
|
+
expect(asFragment()).toMatchSnapshot();
|
|
589
|
+
});
|
|
590
|
+
});
|