@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,654 @@
1
+ /* eslint-disable max-lines */
2
+ import React from 'react';
3
+ import PropTypes from 'prop-types';
4
+ import chai, { expect } from 'chai';
5
+ import chaiEnzyme from 'chai-enzyme';
6
+ import { mount } from 'enzyme';
7
+ import assign from 'lodash.assign';
8
+
9
+ /* Enzyme Helpers that can mount and unmount React component instances to
10
+ * the DOM and set `this.wrapper` and `this.dom` within Mocha's `this`
11
+ * context [full source here](tests/enzyme-helpers.js). `this` can
12
+ * only be referenced if inside `function () {}`.
13
+ */
14
+ import {
15
+ createMountNode,
16
+ destroyMountNode,
17
+ } from '../../../tests/enzyme-helpers';
18
+
19
+ // Import your internal dependencies (for example):
20
+ import Combobox from '../../../components/combobox';
21
+ import Tooltip from '../../../components/tooltip';
22
+ import Icon from '../../../components/icon';
23
+ import filter from '../../../components/combobox/filter';
24
+ import Popover from '../../../components/popover';
25
+ import { keyObjects } from '../../../utilities/key-code';
26
+ import { keyObjects as letterKeyObjects } from '../../../utilities/letter-key-code';
27
+ import IconSettings from '../../../components/icon-settings';
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 callbacks = require('../../../utilities/key-callbacks');
35
+
36
+ const accounts = [
37
+ {
38
+ id: '1',
39
+ label: 'Acme',
40
+ subTitle: 'Account • San Francisco',
41
+ type: 'account',
42
+ },
43
+ {
44
+ id: '2',
45
+ label: 'Salesforce.com, Inc.',
46
+ subTitle: 'Account • San Francisco',
47
+ type: 'account',
48
+ },
49
+ {
50
+ id: '3',
51
+ label: "Paddy's Pub",
52
+ subTitle: 'Account • Boston, MA',
53
+ type: 'account',
54
+ },
55
+ {
56
+ id: '4',
57
+ label: 'Tyrell Corp',
58
+ subTitle: 'Account • San Francisco, CA',
59
+ type: 'account',
60
+ disabled: true,
61
+ },
62
+ {
63
+ id: '5',
64
+ label: 'Paper St. Soap Company',
65
+ subTitle: 'Account • Beloit, WI',
66
+ type: 'account',
67
+ },
68
+ {
69
+ id: '6',
70
+ label: 'Nakatomi Investments',
71
+ subTitle: 'Account • Chicago, IL',
72
+ type: 'account',
73
+ },
74
+ { id: '7', label: 'Acme Landscaping', type: 'account' },
75
+ {
76
+ id: '8',
77
+ label: 'Acme Construction',
78
+ subTitle: 'Account • Grand Marais, MN',
79
+ type: 'account',
80
+ },
81
+ ];
82
+
83
+ const accountsWithIcon = accounts.map((elem) =>
84
+ assign(elem, {
85
+ icon: (
86
+ <Icon
87
+ assistiveText={{ label: 'Account' }}
88
+ category="standard"
89
+ name={elem.type}
90
+ />
91
+ ),
92
+ })
93
+ );
94
+
95
+ const defaultProps = {
96
+ id: 'combobox-unique-id',
97
+ labels: {
98
+ label: 'Search',
99
+ placeholder: 'Search Salesforce',
100
+ },
101
+ menuPosition: 'relative',
102
+ onOpen: () => {},
103
+ };
104
+
105
+ const propTypes = {
106
+ componentDidUpdate: PropTypes.func,
107
+ initialSelection: PropTypes.array,
108
+ };
109
+
110
+ /* A re-usable demo component fixture outside of `describe` sections
111
+ * can accept props within each test and be unmounted after each tests.
112
+ * This wrapping component will be similar to your wrapping component
113
+ * you will create in the React Storybook for manual testing.
114
+ */
115
+ class DemoComponent extends React.Component {
116
+ constructor(props) {
117
+ super(props);
118
+
119
+ this.state = {
120
+ inputValue: '',
121
+ selection: this.props.initialSelection || [],
122
+ };
123
+ }
124
+
125
+ componentDidUpdate() {
126
+ if (this.props.componentDidUpdate) {
127
+ this.props.componentDidUpdate(this.state);
128
+ }
129
+ }
130
+
131
+ render() {
132
+ return (
133
+ <IconSettings iconPath="/assets/icons">
134
+ <Combobox
135
+ events={{
136
+ onChange: (event, { value }) => {
137
+ this.setState({ inputValue: value });
138
+ },
139
+ onRequestRemoveSelectedOption: (event, data) => {
140
+ this.setState({
141
+ inputValue: '',
142
+ selection: data.selection,
143
+ });
144
+ },
145
+ onSubmit: (event, { value }) => {
146
+ this.setState({
147
+ inputValue: '',
148
+ selection: [
149
+ ...this.state.selection,
150
+ {
151
+ label: value,
152
+ id: 'another-account',
153
+ icon: (
154
+ <Icon
155
+ assistiveText={{
156
+ label: 'Account',
157
+ }}
158
+ category="standard"
159
+ name="account"
160
+ />
161
+ ),
162
+ },
163
+ ],
164
+ });
165
+ },
166
+ onSelect: (event, data) => {
167
+ this.setState({
168
+ inputValue: '',
169
+ selection: data.selection,
170
+ });
171
+ },
172
+ onOpen: () => {
173
+ this.props.onOpen();
174
+ },
175
+ }}
176
+ options={filter({
177
+ inputValue: this.state.inputValue,
178
+ options: accountsWithIcon,
179
+ selection: this.state.selection,
180
+ })}
181
+ selection={this.state.selection}
182
+ value={this.state.inputValue}
183
+ {...this.props}
184
+ />
185
+ </IconSettings>
186
+ );
187
+ }
188
+ }
189
+
190
+ DemoComponent.displayName = 'ComboboxDemoComponent';
191
+ DemoComponent.propTypes = propTypes;
192
+ DemoComponent.defaultProps = defaultProps;
193
+
194
+ const getNodes = ({ wrapper }) => ({
195
+ combobox: wrapper.find('.slds-combobox'),
196
+ input: wrapper.find('.slds-combobox input'),
197
+ menuListbox: wrapper.find('.slds-combobox .slds-listbox.slds-dropdown'),
198
+ removeSingleItem: wrapper.find('.slds-combobox button.slds-input__icon'),
199
+ selectedListbox: wrapper.find(
200
+ `#${defaultProps.id}-selected-listbox .slds-listbox`
201
+ ),
202
+ popover: wrapper.find('.slds-popover'),
203
+ });
204
+
205
+ /* All tests for component being tested should be wrapped in a root `describe`,
206
+ * which should be named after the component being tested.
207
+ * When read aloud, the cumulative `describe` and `it` names should form a coherent
208
+ * sentence, eg "Date Picker default structure and css is present with expected
209
+ * attributes set". If you are having trouble constructing a cumulative short
210
+ * sentence, this may be an indicator that your test is poorly structured.
211
+ * String provided as first parameter names the `describe` section. Limit to nouns
212
+ * as much as possible/appropriate.`
213
+ */
214
+ describe('SLDSCombobox', function describeFunction() {
215
+ let mountNode;
216
+ let wrapper;
217
+
218
+ describe('Assistive technology and keyboard interactions', () => {
219
+ /* Detect if presence of accessibility features such as ARIA
220
+ * roles and screen reader text is present in the DOM.
221
+ */
222
+ beforeEach(() => {
223
+ mountNode = createMountNode({ context: this });
224
+ });
225
+
226
+ afterEach(() => {
227
+ destroyMountNode({ wrapper, mountNode });
228
+ });
229
+
230
+ it('has aria-haspopup, aria-expanded is false when closed, aria-expanded is true when open', function () {
231
+ wrapper = mount(<DemoComponent multiple />, { attachTo: mountNode });
232
+ const nodes = getNodes({ wrapper });
233
+ expect(nodes.combobox).attr('aria-haspopup', 'listbox');
234
+ expect(nodes.combobox).attr('role', 'combobox');
235
+ // closed
236
+ expect(nodes.combobox).attr('aria-expanded', 'false');
237
+ // open
238
+ nodes.input.simulate('click', {});
239
+ expect(nodes.combobox).attr('aria-expanded', 'true');
240
+ });
241
+
242
+ it('menu filters to second item, menu listbox menu item 2 aria-selected is true, input activedescendent has item 2 id, after pressing down arrow, enter selects item 2', function () {
243
+ wrapper = mount(
244
+ <DemoComponent
245
+ multiple
246
+ isOpen
247
+ optionsSearchEntity={[
248
+ {
249
+ id: 'options-search-id-1',
250
+ icon: (
251
+ <Icon
252
+ assistiveText={{ label: 'add' }}
253
+ size="x-small"
254
+ category="utility"
255
+ name="search"
256
+ />
257
+ ),
258
+ label: 'Search in Salesforce',
259
+ },
260
+ {
261
+ id: 'search-in-account-id',
262
+ icon: (
263
+ <Icon
264
+ assistiveText={{ label: 'add in Accounts' }}
265
+ size="x-small"
266
+ category="utility"
267
+ name="search"
268
+ />
269
+ ),
270
+ label: (searchTerm) => (
271
+ <React.Fragment>
272
+ {searchTerm && searchTerm.length > 0 ? (
273
+ <span className="slds-text-title_bold">{`"${searchTerm}" `}</span>
274
+ ) : (
275
+ 'Search '
276
+ )}
277
+ in Accounts
278
+ </React.Fragment>
279
+ ),
280
+ },
281
+ ]}
282
+ optionsAddItem={[
283
+ {
284
+ id: 'options-add-id-1',
285
+ icon: (
286
+ <Icon
287
+ assistiveText={{ label: 'add' }}
288
+ category="utility"
289
+ size="x-small"
290
+ name="add"
291
+ />
292
+ ),
293
+ label: 'New Entity',
294
+ },
295
+ ]}
296
+ />,
297
+ {
298
+ attachTo: mountNode,
299
+ }
300
+ );
301
+ let nodes = getNodes({ wrapper });
302
+ nodes.input.simulate('focus');
303
+ nodes.input.simulate('change', { target: { value: accounts[1].label } });
304
+ // pass over header item 1
305
+ nodes.input.simulate('keyDown', keyObjects.DOWN);
306
+ // pass over header item 2
307
+ nodes.input.simulate('keyDown', keyObjects.DOWN);
308
+ nodes.input.simulate('keyDown', keyObjects.DOWN);
309
+ expect(
310
+ nodes.menuListbox.find('#combobox-unique-id-listbox-option-2')
311
+ ).to.have.attr('aria-selected', 'true');
312
+ expect(nodes.input).attr(
313
+ 'aria-activedescendant',
314
+ `${defaultProps.id}-listbox-option-2`
315
+ );
316
+ // select
317
+ nodes.input.simulate('keyDown', keyObjects.ENTER);
318
+ nodes = getNodes({ wrapper });
319
+ expect(nodes.input).attr('value', '');
320
+ expect(nodes.selectedListbox.find('.slds-pill__label').text()).to.equal(
321
+ accounts[1].label
322
+ );
323
+ });
324
+
325
+ it('Selected Listbox: remove initial first pill, remove third initial item, cycles focus (first to last), removes last and initial fifth pill, cycles focus (last to first), remove inital second and fourth pill', function (done) {
326
+ const getSelectedListboxPills = ({ nodes, index }) =>
327
+ nodes.selectedListbox.children().at(index).childAt(0);
328
+ const getFocusedPillLabel = () =>
329
+ document.activeElement.querySelector('.slds-pill__label').innerText;
330
+ const selectionKeyedStates = {
331
+ removeInitialFirstPill: [
332
+ accountsWithIcon[1],
333
+ accountsWithIcon[2],
334
+ accountsWithIcon[3],
335
+ accountsWithIcon[4],
336
+ ],
337
+ removeThirdInitialItem: [
338
+ accountsWithIcon[1],
339
+ accountsWithIcon[3],
340
+ accountsWithIcon[4],
341
+ ],
342
+ removesLastAndInitialFifthPill: [
343
+ accountsWithIcon[1],
344
+ accountsWithIcon[3],
345
+ ],
346
+ removeInitalSecondAndFourthPill: [accountsWithIcon[3]],
347
+ allPillsRemoved: [],
348
+ };
349
+ const selectionIndexedStates = Object.keys(selectionKeyedStates).map(
350
+ (key) => selectionKeyedStates[key]
351
+ );
352
+
353
+ let counter = 0;
354
+ wrapper = mount(
355
+ <DemoComponent
356
+ componentDidUpdate={(prevState) => {
357
+ expect(prevState.selection).to.have.members(
358
+ selectionIndexedStates[counter]
359
+ );
360
+ if (counter === 4) {
361
+ done();
362
+ }
363
+ counter += 1;
364
+ }}
365
+ initialSelection={[
366
+ accounts[0],
367
+ accounts[1],
368
+ accounts[2],
369
+ accounts[3],
370
+ accounts[4],
371
+ ]}
372
+ multiple
373
+ />,
374
+ { attachTo: mountNode }
375
+ );
376
+ const nodes = getNodes({ wrapper });
377
+ nodes.input.simulate('focus');
378
+ nodes.input.simulate('keyDown', keyObjects.TAB);
379
+ getSelectedListboxPills({ nodes, index: 0 }).simulate(
380
+ 'keyDown',
381
+ keyObjects.DELETE
382
+ );
383
+ expect(getFocusedPillLabel()).to.equal(accountsWithIcon[1].label);
384
+ getSelectedListboxPills({
385
+ nodes: getNodes({ wrapper }),
386
+ index: 0,
387
+ }).simulate('keyDown', keyObjects.RIGHT);
388
+ expect(getFocusedPillLabel()).to.equal(accountsWithIcon[2].label);
389
+ getSelectedListboxPills({
390
+ nodes: getNodes({ wrapper }),
391
+ index: 1,
392
+ }).simulate('keyDown', keyObjects.DELETE);
393
+ expect(getFocusedPillLabel()).to.equal(accountsWithIcon[3].label);
394
+ getSelectedListboxPills({
395
+ nodes: getNodes({ wrapper }),
396
+ index: 1,
397
+ }).simulate('keyDown', keyObjects.LEFT);
398
+ getSelectedListboxPills({
399
+ nodes: getNodes({ wrapper }),
400
+ index: 0,
401
+ }).simulate('keyDown', keyObjects.LEFT);
402
+ expect(getFocusedPillLabel()).to.equal(accountsWithIcon[4].label);
403
+ getSelectedListboxPills({
404
+ nodes: getNodes({ wrapper }),
405
+ index: 2,
406
+ }).simulate('keyDown', keyObjects.DELETE);
407
+ expect(getFocusedPillLabel()).to.equal(accountsWithIcon[3].label);
408
+ getSelectedListboxPills({
409
+ nodes: getNodes({ wrapper }),
410
+ index: 1,
411
+ }).simulate('keyDown', keyObjects.RIGHT);
412
+ expect(getFocusedPillLabel()).to.equal(accountsWithIcon[1].label);
413
+ getSelectedListboxPills({
414
+ nodes: getNodes({ wrapper }),
415
+ index: 0,
416
+ }).simulate('keyDown', keyObjects.DELETE);
417
+ getSelectedListboxPills({
418
+ nodes: getNodes({ wrapper }),
419
+ index: 0,
420
+ }).simulate('keydown', keyObjects.DELETE);
421
+ });
422
+
423
+ it('selects a menu item and scrolls when a letter key is pressed in read-only mode', () => {
424
+ wrapper = mount(<DemoComponent variant="readonly" />, {
425
+ attachTo: mountNode,
426
+ });
427
+ let nodes = getNodes({ wrapper });
428
+
429
+ nodes.input.simulate('keyDown', keyObjects.DOWN);
430
+ nodes = getNodes({ wrapper });
431
+ for (let i = 0; i < 3; i += 1) {
432
+ nodes.input.simulate('keyDown', letterKeyObjects.A);
433
+ }
434
+
435
+ const menuListItem = nodes.menuListbox.find(
436
+ '#combobox-unique-id-listbox-option-8'
437
+ );
438
+ expect(
439
+ menuListItem.instance().className.search('slds-has-focus') > -1
440
+ ).to.eql(true);
441
+
442
+ const { scrollTop } = nodes.menuListbox.instance();
443
+ expect(scrollTop === 98 || scrollTop === 0).to.eql(true); // done because menu and menu item size in phantomjs is weird
444
+ });
445
+
446
+ it('selects menu items and scrolls when the down/up keys are pressed', () => {
447
+ wrapper = mount(<DemoComponent variant="readonly" />, {
448
+ attachTo: mountNode,
449
+ });
450
+ let nodes = getNodes({ wrapper });
451
+ let i;
452
+ let menuListItem;
453
+
454
+ nodes.input.simulate('keyDown', keyObjects.DOWN);
455
+ nodes = getNodes({ wrapper });
456
+
457
+ for (i = 0; i < 8; i += 1) {
458
+ nodes.input.simulate('keyDown', keyObjects.DOWN);
459
+ }
460
+
461
+ menuListItem = nodes.menuListbox.find(
462
+ '#combobox-unique-id-listbox-option-8'
463
+ );
464
+ expect(
465
+ menuListItem.instance().className.search('slds-has-focus') > -1
466
+ ).to.eql(true);
467
+
468
+ const { scrollTop: scrollTop1 } = nodes.menuListbox.instance();
469
+ expect(scrollTop1 === 98 || scrollTop1 === 0).to.eql(true); // done because menu and menu item size in phantomjs is weird
470
+
471
+ for (i = 0; i < 8; i += 1) {
472
+ nodes.input.simulate('keyDown', keyObjects.UP);
473
+ }
474
+
475
+ menuListItem = nodes.menuListbox.find(
476
+ '#combobox-unique-id-listbox-option-1'
477
+ );
478
+ expect(
479
+ menuListItem.instance().className.search('slds-has-focus') > -1
480
+ ).to.eql(true);
481
+
482
+ const { scrollTop: scrollTop2 } = nodes.menuListbox.instance();
483
+ expect(scrollTop2 === 4 || scrollTop2 === 0).to.eql(true); // done because menu and menu item size in phantomjs is weird
484
+ });
485
+
486
+ it('propagates keyboard events when menu is closed', function () {
487
+ const spiedCallbacks = sinon.spy(callbacks, 'default');
488
+ wrapper = mount(<DemoComponent variant="inline-listbox" />, {
489
+ attachTo: mountNode,
490
+ });
491
+ const nodes = getNodes({ wrapper });
492
+ // click in the input to open up menu
493
+ nodes.input.simulate('click', {});
494
+ // esc to close the menu and stop event propagation
495
+ nodes.input.simulate('keyDown', keyObjects.ESCAPE);
496
+ expect(spiedCallbacks.getCall(0).lastArg.stopPropagation).to.equal(true);
497
+ // esc to propagate the events further up
498
+ nodes.input.simulate('keyDown', keyObjects.ESCAPE);
499
+ expect(spiedCallbacks.getCall(1).lastArg.stopPropagation).to.equal(false);
500
+ });
501
+ });
502
+
503
+ describe('Variant-specific', () => {
504
+ beforeEach(() => {
505
+ mountNode = createMountNode({ context: this });
506
+ });
507
+
508
+ afterEach(() => {
509
+ destroyMountNode({ wrapper, mountNode });
510
+ });
511
+
512
+ it('Limit to pre-defined choices', function () {
513
+ wrapper = mount(<DemoComponent multiple predefinedOptionsOnly />, {
514
+ attachTo: mountNode,
515
+ });
516
+ let nodes = getNodes({ wrapper });
517
+ nodes.input.simulate('focus');
518
+ nodes.input.simulate('keyDown', letterKeyObjects.A);
519
+ nodes.input.simulate('keyDown', keyObjects.ENTER);
520
+ nodes = getNodes({ wrapper });
521
+ expect(nodes.selectedListbox).not.to.be.present;
522
+ });
523
+
524
+ it('Inline Single Selection Remove selection', function () {
525
+ wrapper = mount(<DemoComponent variant="inline-listbox" />, {
526
+ attachTo: mountNode,
527
+ });
528
+ let nodes = getNodes({ wrapper });
529
+
530
+ // add selection
531
+ nodes.input.simulate('focus');
532
+ nodes.input.simulate('change', { target: { value: accounts[1].label } });
533
+ nodes.input.simulate('keyDown', keyObjects.ENTER);
534
+ expect(nodes.input).to.have.value('Salesforce.com, Inc.');
535
+ nodes = getNodes({ wrapper });
536
+
537
+ // remove selection
538
+ nodes.removeSingleItem.simulate('click');
539
+ nodes = getNodes({ wrapper });
540
+ expect(nodes.input).to.have.value('');
541
+ });
542
+ });
543
+
544
+ describe('Dialog variant', () => {
545
+ beforeEach(() => {
546
+ mountNode = createMountNode({ context: this });
547
+ });
548
+
549
+ afterEach(() => {
550
+ destroyMountNode({ wrapper, mountNode });
551
+ });
552
+
553
+ it('popover opens when down arrow is pressed', () => {
554
+ wrapper = mount(
555
+ <DemoComponent variant="popover" popover={<Popover />} isOpen />
556
+ );
557
+
558
+ let nodes = getNodes({ wrapper });
559
+ nodes.input.simulate('keyDown', keyObjects.DOWN);
560
+ nodes = getNodes({ wrapper });
561
+ expect(nodes.popover).to.be.present;
562
+ });
563
+
564
+ it('onOpen callback is called when dialog variant', () => {
565
+ wrapper = mount(
566
+ <DemoComponent variant="popover" popover={<Popover />} isOpen />
567
+ );
568
+
569
+ let nodes = getNodes({ wrapper });
570
+ nodes.input.simulate('click', {});
571
+ nodes = getNodes({ wrapper });
572
+ expect(nodes.popover).to.be.present;
573
+ });
574
+ });
575
+
576
+ describe('Optional Props', () => {
577
+ beforeEach(() => {
578
+ mountNode = createMountNode({ context: this });
579
+ });
580
+
581
+ afterEach(() => {
582
+ destroyMountNode({ wrapper, mountNode });
583
+ });
584
+
585
+ it('Displays No match found', function () {
586
+ wrapper = mount(<DemoComponent isOpen />, { attachTo: mountNode });
587
+ let nodes = getNodes({ wrapper });
588
+ nodes.input.simulate('focus');
589
+ nodes.input.simulate('change', { target: { value: 'Random text' } });
590
+ // nodes.input.simulate('keyDown', keyObjects.ENTER);
591
+ nodes = getNodes({ wrapper });
592
+ expect(
593
+ nodes.menuListbox
594
+ .find('.slds-listbox__item.slds-listbox__status')
595
+ .text()
596
+ ).to.equal('No matches found.');
597
+ });
598
+ });
599
+
600
+ describe('Input Onclick', () => {
601
+ const onOpenCallback = sinon.spy();
602
+ beforeEach(() => {
603
+ mountNode = createMountNode({ context: this });
604
+ });
605
+
606
+ afterEach(() => {
607
+ destroyMountNode({ wrapper, mountNode });
608
+ });
609
+
610
+ it('onOpen callback is called', function () {
611
+ wrapper = mount(<DemoComponent onOpen={onOpenCallback} />, {
612
+ attachTo: mountNode,
613
+ });
614
+ const nodes = getNodes({ wrapper });
615
+ nodes.input.simulate('click', {});
616
+ expect(onOpenCallback.callCount).to.equal(1);
617
+ });
618
+ });
619
+
620
+ describe('Combobox with items disabled', () => {
621
+ beforeEach(() => {
622
+ mountNode = createMountNode({ context: this });
623
+ });
624
+
625
+ afterEach(() => {
626
+ destroyMountNode({ wrapper, mountNode });
627
+ });
628
+ it('Tooltip component shows when focused on menu item.', function () {
629
+ wrapper = mount(
630
+ <DemoComponent multiple isOpen tooltipMenuItemDisabled={<Tooltip />} />,
631
+ {
632
+ attachTo: mountNode,
633
+ }
634
+ );
635
+ const nodes = getNodes({ wrapper });
636
+ nodes.input.simulate('focus');
637
+ nodes.input.simulate('change', { target: { value: accounts[3].label } });
638
+ nodes.input.simulate('keyDown', keyObjects.DOWN);
639
+
640
+ const nodeInFocus = nodes.menuListbox.find('.slds-tooltip-trigger');
641
+ const span = nodeInFocus.find('#combobox-unique-id-listbox-option-4');
642
+
643
+ // verify span is aria-selected and aria-disabled
644
+ expect(span).to.have.attr('aria-selected', 'true');
645
+ expect(span).to.have.attr('aria-disabled', 'true');
646
+
647
+ // verify tooltip is rendered
648
+ expect(
649
+ nodes.menuListbox.find('#combobox-unique-id-listbox-option-help-4')
650
+ .length
651
+ ).to.equal(1);
652
+ });
653
+ });
654
+ });