@salesforce/design-system-react 0.10.50-alpha.1 → 0.10.50

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 (69) hide show
  1. package/components/accordion/__tests__/accordion.browser-test.jsx +302 -0
  2. package/components/alert/__tests__/alert.browser-test.jsx +100 -0
  3. package/components/app-launcher/__tests__/app-launcher.browser-test.jsx +228 -0
  4. package/components/app-launcher/__tests__/expandable-section.browser-test.jsx +144 -0
  5. package/components/app-launcher/__tests__/link.browser-test.jsx +107 -0
  6. package/components/app-launcher/__tests__/tile.browser-test.jsx +267 -0
  7. package/components/avatar/__tests__/avatar.browser-test.jsx +207 -0
  8. package/components/builder-header/__tests__/builder-header.browser-test.jsx +53 -0
  9. package/components/button/__tests__/button.browser-test.jsx +226 -0
  10. package/components/button-group/__tests__/button-group.browser-test.jsx +144 -0
  11. package/components/button-stateful/__tests__/button-stateful.browser-test.jsx +125 -0
  12. package/components/card/__tests__/card.browser-test.jsx +255 -0
  13. package/components/carousel/__tests__/carousel.browser-test.jsx +527 -0
  14. package/components/color-picker/__tests__/color-picker.browser-test.jsx +767 -0
  15. package/components/combobox/__tests__/combobox.browser-test.jsx +654 -0
  16. package/components/data-table/__tests__/data-table.browser-test.jsx +1051 -0
  17. package/components/date-picker/__tests__/__snapshots__/datepicker.dom-snapshot-test.jsx.snap +4429 -0
  18. package/components/date-picker/__tests__/date-picker.browser-test.jsx +497 -0
  19. package/components/date-picker/__tests__/datepicker.dom-snapshot-test.jsx +109 -0
  20. package/components/docked-composer/__tests__/docked-composer.browser-test.jsx +83 -0
  21. package/components/expandable-section/__tests__/expandable-section.browser-test.jsx +133 -0
  22. package/components/expression/__tests__/expression.browser-test.jsx +255 -0
  23. package/components/filter/__tests__/filter.browser-test.jsx +147 -0
  24. package/components/forms/input/__tests__/inline.browser-test.jsx +164 -0
  25. package/components/global-header/__tests__/global-header.browser-test.jsx +177 -0
  26. package/components/global-navigation-bar/__tests__/global-navigation-bar.browser-test.jsx +464 -0
  27. package/components/icon/__tests__/icon.browser-test.jsx +214 -0
  28. package/components/illustration/__tests__/illustration.browser-test.jsx +177 -0
  29. package/components/input/__tests__/input.browser-test.jsx +612 -0
  30. package/components/location-map/__tests__/location-map.browser-test.jsx +158 -0
  31. package/components/lookup/__tests__/lookup.browser-test.jsx +353 -0
  32. package/components/media-object/__tests__/media-object.browser-test.jsx +87 -0
  33. package/components/menu-dropdown/__tests__/dropdown.browser-test.jsx +588 -0
  34. package/components/menu-picklist/__tests__/menupicklist.snapshot-old-test.jsx +41 -0
  35. package/components/menu-picklist/__tests__/picklist-base.browser-test.jsx +275 -0
  36. package/components/modal/__tests__/modal.browser-test.jsx +333 -0
  37. package/components/notification/__tests__/notification.browser-test.jsx +113 -0
  38. package/components/page-header/__tests__/page-header.browser-test.jsx +161 -0
  39. package/components/panel/__tests__/__snapshots__/filtering.dom-snapshot-test.jsx.snap +298 -0
  40. package/components/panel/__tests__/filtering.dom-snapshot-test.jsx +9 -0
  41. package/components/pill/__tests__/pill.browser-test.jsx +308 -0
  42. package/components/pill-container/__tests__/pill-container.browser-test.jsx +186 -0
  43. package/components/popover/__tests__/popover.browser-test.jsx +327 -0
  44. package/components/progress-indicator/__tests__/progress-indicator.browser-test.jsx +335 -0
  45. package/components/radio-button-group/__tests__/radio-button-group.browser-test.jsx +122 -0
  46. package/components/radio-group/__tests__/radio-group.browser-test.jsx +119 -0
  47. package/components/setup-assistant/__tests__/setup-assistant.browser-test.jsx +77 -0
  48. package/components/slider/__tests__/slider.browser-test.jsx +389 -0
  49. package/components/spinner/__tests__/spinner.browser-test.jsx +57 -0
  50. package/components/split-view/__tests__/split-view.listbox.browser-test.jsx +225 -0
  51. package/components/split-view/__tests__/split-view.listbox.header.browser-test.jsx +158 -0
  52. package/components/split-view/__tests__/split-view.listbox.unread.browser-test.jsx +114 -0
  53. package/components/tabs/__tests__/tabs.browser-test.jsx +458 -0
  54. package/components/textarea/__tests__/textarea.browser-test.jsx +175 -0
  55. package/components/time-picker/__tests__/time-picker.browser-test.jsx +46 -0
  56. package/components/toast/__tests__/toast.browser-test.jsx +118 -0
  57. package/components/tooltip/__tests__/tooltip.browser-test.jsx +214 -0
  58. package/components/tree/__tests__/tree.browser-test.jsx +303 -0
  59. package/components/vertical-navigation/__tests__/navigation.browser-test.jsx +117 -0
  60. package/components/visual-picker/__tests__/visual-picker.browser-test.jsx +288 -0
  61. package/components/welcome-mat/__tests__/welcome-mat.browser-test.jsx +358 -0
  62. package/design-system-react-components.js +1 -1
  63. package/design-system-react-components.min.js.LICENSE.txt +1 -1
  64. package/design-system-react.js +1 -1
  65. package/design-system-react.min.js.LICENSE.txt +1 -1
  66. package/lib/design-system-react-components.min.js.LICENSE.txt +1 -1
  67. package/lib/design-system-react.min.js.LICENSE.txt +1 -1
  68. package/lib/package.json +1 -1
  69. package/package.json +1 -1
@@ -0,0 +1,588 @@
1
+ /* eslint-disable max-lines */
2
+
3
+ // Import your external dependencies
4
+ import React from 'react';
5
+ import ReactDOM from 'react-dom';
6
+ import chai, { expect } from 'chai';
7
+ import chaiEnzyme from 'chai-enzyme';
8
+ import assign from 'lodash.assign';
9
+ import { Simulate } from 'react-dom/test-utils';
10
+
11
+ /* Enzyme Helpers that can mount and unmount React component instances to
12
+ * the DOM and set `this.wrapper` and `this.dom` within Mocha's `this`
13
+ * context [full source here](tests/enzyme-helpers.js). `this` can
14
+ * only be referenced if inside `function () {}`.
15
+ */
16
+ import {
17
+ mountComponent,
18
+ unmountComponent,
19
+ } from '../../../tests/enzyme-helpers';
20
+
21
+ // Import your internal dependencies (for example):
22
+ import Dropdown from '../../menu-dropdown';
23
+ import IconSettings from '../../icon-settings';
24
+ import Tooltip from '../../tooltip';
25
+ import List from '../../utilities/menu-list';
26
+ import { keyObjects } from '../../../utilities/key-code';
27
+ import EventUtil from '../../../utilities/event';
28
+
29
+ /* Set Chai to use chaiEnzyme for enzyme compatible assertions:
30
+ * https://github.com/producthunt/chai-enzyme
31
+ */
32
+ chai.use(chaiEnzyme());
33
+
34
+ const menuOptions = [
35
+ { label: 'A super short', value: 'A0' },
36
+ { label: 'B Option Super Super Long', value: 'B0' },
37
+ { label: 'C Option', value: 'C0' },
38
+ { disabled: true, label: 'D Option', value: 'D0' },
39
+ ];
40
+
41
+ const defaultProps = {
42
+ iconCategory: 'utility',
43
+ iconName: 'down',
44
+ id: 'sample-dropdown',
45
+ label: 'Test',
46
+ menuPosition: 'relative',
47
+ openOn: 'click',
48
+ options: menuOptions,
49
+ placeholder: 'Select a contact',
50
+ value: 'B0',
51
+ };
52
+
53
+ /* eslint-disable react/prop-types */
54
+ const DropdownCustomContent = (props) => (
55
+ <div id="custom-dropdown-menu-content">
56
+ <div className="slds-m-around_medium">
57
+ <div className="slds-tile slds-tile_board slds-m-horizontal_small">
58
+ <p className="tile__title slds-text-heading_small">Art Vandelay</p>
59
+ <div className="slds-tile__detail">
60
+ <p className="slds-truncate">
61
+ <a
62
+ id="custom-dropdown-menu-content-link"
63
+ className="slds-m-right_medium"
64
+ href="#"
65
+ onClick={EventUtil.trappedHandler(props.onClick)}
66
+ >
67
+ Settings
68
+ </a>
69
+ <a href="#" onClick={EventUtil.trappedHandler(props.onClick)}>
70
+ Log Out
71
+ </a>
72
+ </p>
73
+ </div>
74
+ </div>
75
+ </div>
76
+ </div>
77
+ );
78
+ DropdownCustomContent.displayName = 'DropdownCustomContent';
79
+
80
+ /* A re-usable demo component fixture outside of `describe` sections
81
+ * can accept props within each test and be unmounted after each tests.
82
+ * This wrapping component will be similar to your wrapping component
83
+ * you will create in the React Storybook for manual testing.
84
+ */
85
+ class DemoComponent extends React.Component {
86
+ render() {
87
+ return (
88
+ <IconSettings iconPath="/assets/icons">
89
+ <Dropdown {...defaultProps} {...this.props}>
90
+ {this.props.children}
91
+ </Dropdown>
92
+ </IconSettings>
93
+ );
94
+ }
95
+ }
96
+
97
+ DemoComponent.displayName = 'DropdownDemoComponent';
98
+ DemoComponent.defaultProps = defaultProps;
99
+
100
+ const getNodes = ({ wrapper }) => ({
101
+ trigger: wrapper.find('.slds-dropdown-trigger'),
102
+ button: wrapper.find('.slds-dropdown-trigger button'),
103
+ menu: wrapper.find('.slds-dropdown'),
104
+ customContent: wrapper.find('#custom-dropdown-menu-content'),
105
+ customContentLink: wrapper.find(
106
+ '#custom-dropdown-menu-content #custom-dropdown-menu-content-link'
107
+ ),
108
+ });
109
+
110
+ /* All tests for component being tested should be wrapped in a root `describe`,
111
+ * which should be named after the component being tested.
112
+ * When read aloud, the cumulative `describe` and `it` names should form a coherent
113
+ * sentence, eg "Date Picker default structure and css is present with expected
114
+ * attributes set". If you are having trouble constructing a cumulative short
115
+ * sentence, this may be an indicator that your test is poorly structured.
116
+ * String provided as first parameter names the `describe` section. Limit to nouns
117
+ * as much as possible/appropriate.`
118
+ */
119
+ describe('SLDSMenuDropdown', function () {
120
+ describe('Styling', () => {
121
+ beforeEach(
122
+ mountComponent(
123
+ <DemoComponent menuStyle={{ height: '500px' }} width="small" />
124
+ )
125
+ );
126
+
127
+ afterEach(unmountComponent);
128
+
129
+ it('has correct CSS classes and style', function () {
130
+ const nodes = getNodes({ wrapper: this.wrapper });
131
+ nodes.button.simulate('click', {});
132
+ const openNodes = getNodes({ wrapper: this.wrapper });
133
+ expect(openNodes.menu).to.exist;
134
+ expect(openNodes.menu).to.have.style('height', '500px');
135
+ expect(openNodes.menu.hasClass('slds-dropdown_small')).to.equal(true);
136
+ });
137
+ });
138
+
139
+ describe('Inverse', () => {
140
+ beforeEach(mountComponent(<DemoComponent inverse />));
141
+
142
+ afterEach(unmountComponent);
143
+
144
+ it('has correct CSS class for inverse', function () {
145
+ const nodes = getNodes({ wrapper: this.wrapper });
146
+ nodes.button.simulate('click', {});
147
+ const openNodes = getNodes({ wrapper: this.wrapper });
148
+ expect(openNodes.menu.hasClass('slds-dropdown_inverse')).to.equal(true);
149
+ });
150
+ });
151
+
152
+ describe('Custom Content Present', () => {
153
+ beforeEach(
154
+ mountComponent(
155
+ <DemoComponent nubbinPosition="top left" openOn="click">
156
+ <DropdownCustomContent />
157
+ <List
158
+ options={[{ label: 'Custom Content Option' }, ...menuOptions]}
159
+ />
160
+ </DemoComponent>
161
+ )
162
+ );
163
+
164
+ afterEach(unmountComponent);
165
+
166
+ it('has content with custom ID is present', function () {
167
+ const nodes = getNodes({ wrapper: this.wrapper });
168
+ nodes.button.simulate('click', {});
169
+ const openNodes = getNodes({ wrapper: this.wrapper });
170
+ expect(openNodes.customContent.length).to.equal(1);
171
+ });
172
+
173
+ it('closes when custom content is clicked', function () {
174
+ const nodes = getNodes({ wrapper: this.wrapper });
175
+ nodes.button.simulate('click', {});
176
+ const openNodes = getNodes({ wrapper: this.wrapper });
177
+ openNodes.customContentLink.simulate('click', {});
178
+ const closedNodes = getNodes({ wrapper: this.wrapper });
179
+ expect(closedNodes.customContent.length).to.equal(0);
180
+ });
181
+
182
+ it("has additional ListItem from list child's options prop", function () {
183
+ const nodes = getNodes({ wrapper: this.wrapper });
184
+ const buttonId = nodes.trigger.prop('id');
185
+ nodes.button.simulate('click', {});
186
+ const openNodes = getNodes({ wrapper: this.wrapper });
187
+ expect(openNodes.menu.find(`li#${buttonId}-item-0`).text()).to.equal(
188
+ 'Custom Content Option'
189
+ );
190
+ });
191
+ });
192
+
193
+ describe('Clickable', () => {
194
+ const onClick = sinon.spy();
195
+
196
+ beforeEach(mountComponent(<DemoComponent onClick={onClick} />));
197
+
198
+ afterEach(unmountComponent);
199
+
200
+ it('does not expand on hover', function () {
201
+ const nodes = getNodes({ wrapper: this.wrapper });
202
+ expect(nodes.menu.length).to.equal(0);
203
+ nodes.trigger.simulate('mouseEnter', {});
204
+ const hoverNodes = getNodes({ wrapper: this.wrapper });
205
+ expect(hoverNodes.menu.length).to.equal(0);
206
+ });
207
+
208
+ it('expands/contracts on click', function () {
209
+ const nodes = getNodes({ wrapper: this.wrapper });
210
+ expect(nodes.menu.length).to.equal(0);
211
+ nodes.trigger.simulate('click', {});
212
+ const openNodes = getNodes({ wrapper: this.wrapper });
213
+ expect(openNodes.menu.length).to.equal(1);
214
+ openNodes.trigger.simulate('click', {});
215
+ const closedNodes = getNodes({ wrapper: this.wrapper });
216
+ expect(closedNodes.menu.length).to.equal(0);
217
+ });
218
+
219
+ it('preserves click behavior', function () {
220
+ onClick.resetHistory();
221
+ const nodes = getNodes({ wrapper: this.wrapper });
222
+ nodes.trigger.simulate('click', {});
223
+ expect(onClick.calledOnce);
224
+ });
225
+ });
226
+
227
+ describe('Expanded', () => {
228
+ let selected;
229
+
230
+ beforeEach(
231
+ mountComponent(
232
+ <DemoComponent
233
+ onSelect={(selectedOption) => {
234
+ selected = selectedOption;
235
+ }}
236
+ />
237
+ )
238
+ );
239
+
240
+ afterEach(unmountComponent);
241
+
242
+ it('selects an item on click', function () {
243
+ const nodes = getNodes({ wrapper: this.wrapper });
244
+ expect(nodes.menu.length).to.equal(0);
245
+ nodes.trigger.simulate('click', {});
246
+ const openNodes = getNodes({ wrapper: this.wrapper });
247
+ openNodes.menu.find('li a').first().simulate('click', {});
248
+ expect(selected.value).to.equal('A0');
249
+ });
250
+ });
251
+
252
+ describe('accessible markup for label Dropdowns', () => {
253
+ beforeEach(mountComponent(<DemoComponent />));
254
+
255
+ afterEach(unmountComponent);
256
+
257
+ it('<ul> has role menu & aria-labelledby', function () {
258
+ const nodes = getNodes({ wrapper: this.wrapper });
259
+ nodes.trigger.simulate('click', {});
260
+ const openNodes = getNodes({ wrapper: this.wrapper });
261
+ expect(openNodes.menu.find('ul')).to.have.attr('role', 'menu');
262
+ const nodeId = openNodes.trigger.prop('id');
263
+ expect(openNodes.menu.find('ul')).attr('aria-labelledby', nodeId);
264
+ });
265
+
266
+ it('<a> inside <li> has role menuitem', function () {
267
+ const nodes = getNodes({ wrapper: this.wrapper });
268
+ nodes.trigger.simulate('click', {});
269
+ const openNodes = getNodes({ wrapper: this.wrapper });
270
+ const anchorRole = openNodes.menu.find('li a').first().prop('role');
271
+ const match =
272
+ anchorRole === 'menuitem' ||
273
+ anchorRole === 'menuitemradio' ||
274
+ anchorRole === 'menuitemcheckbox';
275
+ expect(match).to.be.true;
276
+ });
277
+
278
+ it('if option.disabled, add aria-disabled to <a> that has role menuitem', function () {
279
+ const nodes = getNodes({ wrapper: this.wrapper });
280
+ nodes.trigger.simulate('click', {});
281
+ const openNodes = getNodes({ wrapper: this.wrapper });
282
+ const lastItemAriaDisabledRole = openNodes.menu
283
+ .find('li a')
284
+ .at(3)
285
+ .prop('aria-disabled');
286
+ expect(lastItemAriaDisabledRole).to.be.true;
287
+ });
288
+ });
289
+
290
+ describe('accessible markup for Icon Only Dropdowns', () => {
291
+ beforeEach(
292
+ mountComponent(
293
+ <DemoComponent
294
+ assistiveText={{ icon: 'more options' }}
295
+ buttonVariant="icon"
296
+ checkmark
297
+ iconCategory="utility"
298
+ iconName="down"
299
+ iconVariant="border-filled"
300
+ />
301
+ )
302
+ );
303
+
304
+ afterEach(unmountComponent);
305
+
306
+ it('<button> has assistiveText', function () {
307
+ const nodes = getNodes({ wrapper: this.wrapper });
308
+ expect(nodes.button.find('.slds-assistive-text').text()).to.equal(
309
+ 'more options'
310
+ );
311
+ });
312
+ });
313
+
314
+ describe('Keyboard behavior', () => {
315
+ let selected;
316
+
317
+ beforeEach(
318
+ mountComponent(
319
+ <DemoComponent
320
+ onSelect={(selectedOption) => {
321
+ selected = selectedOption;
322
+ }}
323
+ />
324
+ )
325
+ );
326
+
327
+ afterEach(unmountComponent);
328
+
329
+ it('opens menu with enter', function () {
330
+ const nodes = getNodes({ wrapper: this.wrapper });
331
+ expect(nodes.menu.length).to.equal(0);
332
+ nodes.button.simulate('keyDown', keyObjects.ENTER);
333
+ const openNodes = getNodes({ wrapper: this.wrapper });
334
+ expect(openNodes.menu.length).to.equal(1);
335
+ });
336
+
337
+ it('opens menu with down arrow key', function () {
338
+ const nodes = getNodes({ wrapper: this.wrapper });
339
+ expect(nodes.menu.length).to.equal(0);
340
+ nodes.button.simulate('keyDown', keyObjects.DOWN);
341
+ const openNodes = getNodes({ wrapper: this.wrapper });
342
+ expect(openNodes.menu.length).to.equal(1);
343
+ });
344
+
345
+ it('selects an item with keyboard', function () {
346
+ const nodes = getNodes({ wrapper: this.wrapper });
347
+ nodes.trigger.simulate('click', {});
348
+ const openNodes = getNodes({ wrapper: this.wrapper });
349
+ openNodes.menu.simulate('keyDown', keyObjects.DOWN);
350
+ openNodes.menu.simulate('keyDown', keyObjects.DOWN);
351
+ openNodes.menu.simulate('keyDown', keyObjects.ENTER);
352
+ expect(selected.value).to.equal('B0');
353
+ });
354
+
355
+ it('closes Menu on esc', function () {
356
+ const nodes = getNodes({ wrapper: this.wrapper });
357
+ expect(nodes.menu.length).to.equal(0);
358
+ nodes.trigger.simulate('click', {});
359
+ const openNodes = getNodes({ wrapper: this.wrapper });
360
+ expect(openNodes.menu.length).to.equal(1);
361
+ openNodes.menu
362
+ .find('.slds-dropdown__item a')
363
+ .first()
364
+ .simulate('keyDown', keyObjects.ESCAPE);
365
+ const closedNodes = getNodes({ wrapper: this.wrapper });
366
+ expect(closedNodes.menu.length).to.equal(0);
367
+ });
368
+ });
369
+
370
+ describe('multiple selection', function () {
371
+ beforeEach(mountComponent(<DemoComponent multiple checkmark />));
372
+
373
+ afterEach(unmountComponent);
374
+
375
+ it('selects multiple items and renders checkmarks', function () {
376
+ const nodes = getNodes({ wrapper: this.wrapper });
377
+ nodes.trigger.simulate('click', {});
378
+ let openNodes = getNodes({ wrapper: this.wrapper });
379
+ const firstNode = openNodes.menu.find('.slds-dropdown__item a').at(0);
380
+ firstNode.simulate('click');
381
+ const secondNode = openNodes.menu.find('.slds-dropdown__item a').at(2);
382
+ secondNode.simulate('click');
383
+ const thirdNode = openNodes.menu.find('.slds-dropdown__item a').at(3);
384
+ openNodes = getNodes({ wrapper: this.wrapper });
385
+ // item with checkmark has proper aria markup
386
+ expect(firstNode.getDOMNode().getAttribute('aria-checked')).to.equal(
387
+ 'true'
388
+ );
389
+ expect(secondNode.getDOMNode().getAttribute('aria-checked')).to.equal(
390
+ 'true'
391
+ );
392
+ expect(thirdNode.getDOMNode().getAttribute('aria-checked')).to.equal(
393
+ null
394
+ );
395
+ expect(firstNode).attr('role', 'menuitemcheckbox');
396
+ });
397
+ });
398
+
399
+ // Hover and hybrid hover UX patterns are not approved UX patterns due to accessibility concerns
400
+
401
+ describe('Hoverable', () => {
402
+ let body;
403
+
404
+ const renderDropdown = (inst) => {
405
+ body = document.createElement('div');
406
+ document.body.appendChild(body);
407
+ /* deepscan-disable REACT_ASYNC_RENDER_RETURN_VALUE */
408
+ // eslint-disable-next-line react/no-render-return-value
409
+ return ReactDOM.render(
410
+ <div>
411
+ <IconSettings iconPath="/assets/icons">{inst}</IconSettings>
412
+ </div>,
413
+ body
414
+ );
415
+ /* deepscan-enable REACT_ASYNC_RENDER_RETURN_VALUE */
416
+ };
417
+
418
+ function removeDropdownTrigger() {
419
+ ReactDOM.unmountComponentAtNode(body);
420
+ document.body.removeChild(body);
421
+ }
422
+
423
+ const createDropdown = (props) =>
424
+ React.createElement(Dropdown, assign({}, defaultProps, props));
425
+ createDropdown.displayName = 'createDropdown';
426
+
427
+ const dropItDown = (props) => renderDropdown(createDropdown(props));
428
+
429
+ const getMenu = (dom) => dom.querySelector('.slds-dropdown');
430
+
431
+ let cmp;
432
+ let btn;
433
+
434
+ beforeEach(() => {
435
+ cmp = dropItDown({
436
+ buttonClassName: 'dijkstrafied',
437
+ openOn: 'hover',
438
+ hoverCloseDelay: 2,
439
+ });
440
+ [btn] = cmp.getElementsByClassName('slds-dropdown-trigger');
441
+ });
442
+
443
+ afterEach((done) => {
444
+ // due to hover-close delay, removal from DOM must be delayed
445
+ setTimeout(() => {
446
+ removeDropdownTrigger();
447
+ done();
448
+ }, 100);
449
+ });
450
+
451
+ it('gives the button correct aria properties', () => {
452
+ expect(btn.firstChild.getAttribute('aria-haspopup')).to.equal('true');
453
+ });
454
+
455
+ it('sets the label', () => {
456
+ expect(btn.textContent).to.equal('Test');
457
+ });
458
+
459
+ it('expands the dropdown on hover', () => {
460
+ expect(getMenu(body)).to.equal(null);
461
+ Simulate.mouseEnter(btn, {});
462
+ expect(getMenu(body).className).to.include('slds-dropdown');
463
+ Simulate.mouseLeave(btn, {});
464
+ });
465
+
466
+ it('closes on blur based on timeout delay', (done) => {
467
+ expect(getMenu(body)).to.equal(null);
468
+ Simulate.mouseEnter(btn, {});
469
+ Simulate.mouseLeave(btn);
470
+ expect(getMenu(body)).to.not.equal(null);
471
+ setTimeout(() => {
472
+ expect(getMenu(body)).to.equal(null);
473
+ done();
474
+ }, 3);
475
+ });
476
+
477
+ it("doesn't close on quick hover outside", (done) => {
478
+ expect(getMenu(body)).to.equal(null);
479
+ Simulate.mouseEnter(btn, {});
480
+ Simulate.mouseLeave(btn);
481
+ setTimeout(() => {
482
+ Simulate.mouseEnter(btn, {});
483
+ expect(getMenu(body)).to.not.equal(null);
484
+ setTimeout(() => {
485
+ expect(getMenu(body)).to.not.equal(null);
486
+ done();
487
+ }, 3);
488
+ }, 1);
489
+ });
490
+ });
491
+
492
+ describe('Hybrid-able', () => {
493
+ let body;
494
+
495
+ const renderDropdown = (inst) => {
496
+ body = document.createElement('div');
497
+ document.body.appendChild(body);
498
+ /* deepscan-disable REACT_ASYNC_RENDER_RETURN_VALUE */
499
+ // eslint-disable-next-line react/no-render-return-value
500
+ return ReactDOM.render(
501
+ <div>
502
+ <IconSettings iconPath="/assets/icons">{inst}</IconSettings>
503
+ </div>,
504
+ body
505
+ );
506
+ /* deepscan-enable REACT_ASYNC_RENDER_RETURN_VALUE */
507
+ };
508
+
509
+ function removeDropdownTrigger() {
510
+ ReactDOM.unmountComponentAtNode(body);
511
+ document.body.removeChild(body);
512
+ }
513
+
514
+ const createDropdown = (props) =>
515
+ React.createElement(Dropdown, assign({}, defaultProps, props));
516
+ createDropdown.displayName = 'createDropdown';
517
+
518
+ const dropItDown = (props) => renderDropdown(createDropdown(props));
519
+
520
+ const getMenu = (dom) => dom.querySelector('.slds-dropdown');
521
+
522
+ let cmp;
523
+ let btn;
524
+ const onClick = sinon.spy();
525
+
526
+ beforeEach(() => {
527
+ cmp = dropItDown({ openOn: 'hybrid', onClick, hoverCloseDelay: 1 });
528
+ [btn] = cmp.getElementsByClassName('slds-dropdown-trigger');
529
+ });
530
+
531
+ afterEach(() => {
532
+ removeDropdownTrigger();
533
+ });
534
+
535
+ it('doesnt expand on hover', () => {
536
+ expect(getMenu(body)).to.equal(null);
537
+ Simulate.mouseEnter(btn, {});
538
+ expect(getMenu(body)).to.equal(null);
539
+ });
540
+
541
+ it('opens on click, closes on mouseLeave', (done) => {
542
+ // open
543
+ expect(getMenu(body)).to.equal(null);
544
+ Simulate.click(btn, {});
545
+ expect(getMenu(body).className).to.include('slds-dropdown');
546
+
547
+ // close
548
+ Simulate.mouseEnter(btn, {});
549
+ Simulate.mouseLeave(btn);
550
+ expect(getMenu(body)).to.not.equal(null);
551
+ setTimeout(() => {
552
+ expect(getMenu(body)).to.equal(null);
553
+ done();
554
+ }, 2);
555
+ });
556
+ });
557
+
558
+ describe('Tooltips function as expected', () => {
559
+ beforeEach(
560
+ mountComponent(
561
+ <DemoComponent
562
+ options={[
563
+ { label: 'Test item A', value: 'A0' },
564
+ {
565
+ label: 'Test item B',
566
+ value: 'B0',
567
+ tooltipContent: 'Testing tooltip content',
568
+ },
569
+ { label: 'Test item C', value: 'C0' },
570
+ ]}
571
+ tooltipMenuItem={<Tooltip />}
572
+ />
573
+ )
574
+ );
575
+
576
+ afterEach(unmountComponent);
577
+
578
+ it('Tooltip component shows when focused on menu item.', function () {
579
+ const nodes = getNodes({ wrapper: this.wrapper });
580
+ nodes.trigger.simulate('focus');
581
+ nodes.trigger.simulate('keyDown', keyObjects.ENTER);
582
+ nodes.trigger.simulate('keyDown', keyObjects.DOWN);
583
+
584
+ const tooltip = this.wrapper.find('#sample-dropdown-item-1-tooltip');
585
+ expect(tooltip.length).to.equal(1);
586
+ });
587
+ });
588
+ });
@@ -0,0 +1,41 @@
1
+ /* eslint-env jest */
2
+ import React from 'react';
3
+ import ReactDOMServer from 'react-dom/server';
4
+ import renderer from 'react-test-renderer';
5
+ import jsBeautify from 'js-beautify';
6
+
7
+ import SnapshotDefault from '../__examples__/snapshot-default';
8
+
9
+ test('MenuPicklist Default DOM Snapshot', () => {
10
+ const domTree = renderer
11
+ .create(<SnapshotDefault silenceDeprecationWarning />)
12
+ .toJSON();
13
+ expect(domTree).toMatchSnapshot();
14
+ });
15
+
16
+ test('MenuPicklist Default HTML Snapshot', () => {
17
+ const domTree = String(
18
+ jsBeautify.html(
19
+ ReactDOMServer.renderToStaticMarkup(
20
+ <SnapshotDefault silenceDeprecationWarning />
21
+ ),
22
+ {}
23
+ )
24
+ );
25
+ expect(domTree).toMatchSnapshot();
26
+ });
27
+
28
+ test(`MenuPicklist
29
+ errorText
30
+ DOM Snapshot`, () => {
31
+ const domTree = renderer
32
+ .create(
33
+ <SnapshotDefault
34
+ errorText="This field is required."
35
+ required
36
+ silenceDeprecationWarning
37
+ />
38
+ )
39
+ .toJSON();
40
+ expect(domTree).toMatchSnapshot();
41
+ });