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

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,118 @@
1
+ /* eslint-disable react/no-render-return-value */
2
+ /* eslint-disable react/no-find-dom-node */
3
+
4
+ import React from 'react';
5
+ import chai, { expect } from 'chai';
6
+ import chaiEnzyme from 'chai-enzyme';
7
+ import {
8
+ mountComponent,
9
+ unmountComponent,
10
+ } from '../../../tests/enzyme-helpers';
11
+
12
+ import Toast from '../../toast'; // `~` is replaced with design-system-react at runtime
13
+ import ToastContainer from '../../toast/container'; // `~` is replaced with design-system-react at runtime
14
+ import Icon from '../../icon'; // `~` is replaced with design-system-react at runtime
15
+ import IconSettings from '../../icon-settings';
16
+
17
+ chai.use(chaiEnzyme());
18
+
19
+ class DemoComponent extends React.Component {
20
+ constructor(props) {
21
+ super(props);
22
+
23
+ this.state = {
24
+ isOpen: true,
25
+ };
26
+ }
27
+
28
+ render() {
29
+ return (
30
+ <IconSettings iconPath="/assets/icons">
31
+ <div>
32
+ <ToastContainer>
33
+ {this.state.isOpen ? (
34
+ <Toast
35
+ dismissible
36
+ icon={<Icon category="utility" name="user" />}
37
+ labels={{
38
+ heading: 'Logged in as John Smith (johnsmith@acme.com).',
39
+ headingLink: 'Log out',
40
+ }}
41
+ onRequestClose={() => {
42
+ this.setState({ isOpen: false });
43
+ }}
44
+ {...this.props}
45
+ />
46
+ ) : null}
47
+ </ToastContainer>
48
+ </div>
49
+ </IconSettings>
50
+ );
51
+ }
52
+ }
53
+
54
+ DemoComponent.displayName = 'ToastExample';
55
+
56
+ describe('SLDSToast: ', function () {
57
+ const onClickHeadingLink = sinon.spy();
58
+
59
+ describe('Dismiss Toast', () => {
60
+ beforeEach(
61
+ mountComponent(<DemoComponent onClickHeadingLink={onClickHeadingLink} />)
62
+ );
63
+
64
+ afterEach(unmountComponent);
65
+
66
+ /* Please notice the of `function () {}` and not () => {}.
67
+ * It allows access to the Mocha test context via `this`.
68
+ */
69
+ it('calls onRequestClose handler', function () {
70
+ const button = this.wrapper.find('button.slds-notify__close');
71
+ // If applicable, use second parameter to pass the data object
72
+ expect(this.wrapper.find('.slds-notify').length).to.equal(1);
73
+ button.simulate('click', {});
74
+ expect(this.wrapper.find('.slds-notify').length).to.equal(0);
75
+ });
76
+
77
+ it('calls onClickHeadingLink handler', function () {
78
+ const link = this.wrapper.find('a');
79
+ // If applicable, use second parameter to pass the data object
80
+ link.simulate('click', {});
81
+ expect(onClickHeadingLink.calledOnce).to.be.true;
82
+ });
83
+ });
84
+
85
+ describe('Toast with duration auto-closes itself', () => {
86
+ beforeEach(mountComponent(<DemoComponent duration={1} />));
87
+
88
+ // afterEach(unmountComponent);
89
+
90
+ /* Please notice the of `function () {}` and not () => {}.
91
+ * It allows access to the Mocha test context via `this`.
92
+ */
93
+ it('it calls onRequestClose after 1ms', function (done) {
94
+ expect(this.wrapper).to.have.state('isOpen', true);
95
+
96
+ setTimeout(() => {
97
+ expect(this.wrapper).to.have.state('isOpen', false);
98
+ done();
99
+ }, 2);
100
+ });
101
+ });
102
+
103
+ describe('Basic Toast Props Render', function () {
104
+ beforeEach(
105
+ mountComponent(
106
+ <DemoComponent style={{ backgroundColor: 'rgb(18, 49, 35)' }} />
107
+ )
108
+ );
109
+
110
+ afterEach(unmountComponent);
111
+
112
+ it('renders custom styles', function () {
113
+ expect(
114
+ this.wrapper.find('.slds-notify').prop('style').backgroundColor
115
+ ).to.equal('rgb(18, 49, 35)');
116
+ });
117
+ });
118
+ });
@@ -0,0 +1,214 @@
1
+ /* eslint-disable react/no-render-return-value */
2
+
3
+ import React from 'react';
4
+ import ReactDOM from 'react-dom';
5
+ import { expect } from 'chai';
6
+ import TestUtils from 'react-dom/test-utils';
7
+
8
+ import SLDSTooltip from '../../tooltip';
9
+ import SLDSButton from '../../button';
10
+
11
+ const { Simulate, findRenderedDOMComponentWithTag } = TestUtils;
12
+
13
+ describe('SLDSTooltip: ', function () {
14
+ let body;
15
+
16
+ const defaultTrigger = <SLDSButton label="Hover me for tooltip" />;
17
+ const defaultTextContent = 'This is more info. blah blah.';
18
+ const defaultProps = {
19
+ content: (
20
+ <span className="tooltip-content" style={{ width: 30 }}>
21
+ {defaultTextContent}
22
+ </span>
23
+ ),
24
+ hasStaticAlignment: true,
25
+ id: 'myTooltip123',
26
+ };
27
+
28
+ afterEach(() => {
29
+ try {
30
+ Array.prototype.forEach.call(
31
+ document.body.querySelectorAll('.drop'),
32
+ (component) => document.body.removeChild(component)
33
+ );
34
+ if (body) {
35
+ document.body.removeChild(body);
36
+ }
37
+ } catch (e) {
38
+ /* empty */
39
+ }
40
+ });
41
+
42
+ const createBody = () => {
43
+ const target = document.createElement('h1');
44
+ target.textContent = 'Tooltip Tip Target';
45
+ body = document.createElement('div');
46
+ body.style.height = '300px';
47
+ body.style.width = '300px';
48
+ body.appendChild(target);
49
+ document.body.appendChild(body);
50
+ };
51
+
52
+ const renderTooltip = (inst) => ReactDOM.render(inst, body); // deepscan-disable-line REACT_ASYNC_RENDER_RETURN_VALUE
53
+
54
+ const createTooltip = (props, kids) =>
55
+ React.createElement(SLDSTooltip, props, kids);
56
+
57
+ const generateTooltip = (props, kids) =>
58
+ renderTooltip(createTooltip(props, kids));
59
+
60
+ const getTip = (dom) => dom.querySelector('.slds-popover_tooltip');
61
+
62
+ describe('component basic props render', () => {
63
+ let rootNode;
64
+
65
+ beforeEach(() => {
66
+ createBody();
67
+ rootNode = generateTooltip(
68
+ {
69
+ ...defaultProps,
70
+ align: 'top',
71
+ },
72
+ defaultTrigger
73
+ );
74
+ });
75
+
76
+ it('is not open', () => {
77
+ expect(getTip(document.body)).to.equal(null);
78
+ });
79
+
80
+ describe('expanded', () => {
81
+ let tip;
82
+ let trigger;
83
+
84
+ beforeEach((done) => {
85
+ trigger = findRenderedDOMComponentWithTag(rootNode, 'button');
86
+ Simulate.mouseEnter(trigger, {});
87
+ setTimeout(() => {
88
+ tip = getTip(document.body);
89
+ done();
90
+ }, 0);
91
+ });
92
+
93
+ it('places bottom aligned tooltip at the trigger if no target', (done) => {
94
+ // "Magic Number" in pixels, based on size of trigger, CSS, and DropJS offset
95
+ const tooltipOffset = 46;
96
+ const tipBounds = tip.getBoundingClientRect();
97
+ const triggerBounds = trigger.getBoundingClientRect();
98
+ expect(tipBounds.top).to.be.within(
99
+ triggerBounds.top - tooltipOffset,
100
+ triggerBounds.top
101
+ );
102
+ done();
103
+ });
104
+
105
+ it('adds nubbin', () => {
106
+ expect(tip.className).to.include('slds-nubbin_bottom');
107
+ });
108
+
109
+ it('closes', (done) => {
110
+ Simulate.mouseLeave(trigger, {});
111
+ setTimeout(() => {
112
+ expect(getTip(document.body)).to.be.null;
113
+ done();
114
+ }, 60);
115
+ });
116
+ });
117
+ });
118
+
119
+ describe('Custom props work as expected', () => {
120
+ it('isOpen is false', (done) => {
121
+ const rootNode = generateTooltip(
122
+ {
123
+ ...defaultProps,
124
+ isOpen: false,
125
+ },
126
+ defaultTrigger
127
+ );
128
+
129
+ setTimeout(() => {
130
+ const trigger = findRenderedDOMComponentWithTag(rootNode, 'button');
131
+ Simulate.mouseEnter(trigger, {});
132
+ setTimeout(() => {
133
+ expect(getTip(document.body)).to.be.null;
134
+ done();
135
+ }, 0);
136
+ }, 0);
137
+ });
138
+
139
+ it('isOpen is true', (done) => {
140
+ let contentRendered;
141
+
142
+ const tooltipContentRendered = (component) => {
143
+ this.tip = getTip(document.body);
144
+ if (!contentRendered) {
145
+ expect(component).to.not.be.null;
146
+ contentRendered = true;
147
+ done();
148
+ }
149
+ };
150
+
151
+ generateTooltip(
152
+ {
153
+ ...defaultProps,
154
+ // overwrite default content
155
+ content: (
156
+ <span
157
+ ref={tooltipContentRendered}
158
+ className="tooltip-content"
159
+ style={{ width: 30 }}
160
+ >
161
+ {defaultTextContent}
162
+ </span>
163
+ ),
164
+ isOpen: true,
165
+ },
166
+ defaultTrigger
167
+ );
168
+ });
169
+ });
170
+
171
+ /*
172
+ // Commented out until fully understood.
173
+ describe('using target', () => {
174
+ let rootNode, trigger;
175
+
176
+ beforeEach(() => {
177
+ const content = (<span style={{width: 30}}>This is more info. blah blah.</span>);
178
+ createBody();
179
+ rootNode = generateTooltip({
180
+ align: 'bottom',
181
+ content: content,
182
+ target: body.firstChild
183
+ }, React.createElement(SLDSButton, {}), ['Hover me for tooltip']);
184
+ trigger = document.body.querySelector('[role=tooltip]').firstChild;
185
+ })
186
+
187
+ describe('expanded', () => {
188
+ let tip;
189
+
190
+ beforeEach((done) => {
191
+ expect(getTip(document.body)).to.equal(null);
192
+
193
+ setTimeout(() => {
194
+ Simulate.mouseEnter(trigger, {})
195
+ setTimeout(() => {
196
+ tip = getTip(document.body);
197
+ done();
198
+ }, 200);
199
+ }, 200);
200
+ });
201
+
202
+ it('sets the tooltip close to the target, not the trigger', () => {
203
+ // "Magic Number" in pixels, based on size of trigger and CSS
204
+ const tooltipOffset = 40;
205
+ const tipBounds = tip.getBoundingClientRect();
206
+ const targetBounds = body.firstChild.getBoundingClientRect();
207
+ console.log(tipBounds);
208
+ console.log(targetBounds);
209
+ expect(tipBounds.bottom).to.be.within(targetBounds.bottom, targetBounds.bottom + tooltipOffset);
210
+ })
211
+ })
212
+ })
213
+ */
214
+ });
@@ -0,0 +1,303 @@
1
+ /* eslint-env mocha */
2
+ /* global sinon */
3
+ /* eslint-disable prefer-arrow-callback */
4
+ /* eslint-disable no-unused-expressions */
5
+
6
+ import React from 'react';
7
+
8
+ import chai, { expect } from 'chai';
9
+ import chaiEnzyme from 'chai-enzyme';
10
+ // `this.wrapper` and `this.dom` is set in the helpers file
11
+ import {
12
+ mountComponent,
13
+ unmountComponent,
14
+ } from '../../../tests/enzyme-helpers';
15
+
16
+ import { keyObjects } from '../../../utilities/key-code';
17
+ import sampleNodesDynamicHashMap from '../__docs__/dynamic-hashmap';
18
+
19
+ import DefaultExample from '../__examples__/default';
20
+
21
+ chai.use(chaiEnzyme());
22
+
23
+ const COMPONENT_CSS_CLASSES = {
24
+ base: 'slds-tree',
25
+ };
26
+
27
+ describe('Tree: ', () => {
28
+ /*
29
+ Tests
30
+ */
31
+ describe('Tree can be navigated up/down using the keyboard', () => {
32
+ beforeEach(mountComponent(<DefaultExample log={() => {}} />));
33
+
34
+ afterEach(unmountComponent);
35
+
36
+ it('moves selection up/down with wrapping when using keyboard up/down keys', function () {
37
+ // Initial focus selects the item
38
+ this.wrapper.find('#example-tree-1').simulate('focus');
39
+ let itemDiv = this.wrapper
40
+ .find('#example-tree-1')
41
+ .find('.slds-is-selected');
42
+ expect(itemDiv).to.have.length(1);
43
+
44
+ // Go to next node
45
+ this.wrapper.find('#example-tree-1').simulate('keyDown', keyObjects.DOWN);
46
+ itemDiv = this.wrapper.find('#example-tree-2').find('.slds-is-selected');
47
+ expect(itemDiv).to.have.length(1);
48
+
49
+ // Go to next node
50
+ this.wrapper.find('#example-tree-2').simulate('keyDown', keyObjects.DOWN);
51
+ itemDiv = this.wrapper.find('#example-tree-3').find('.slds-is-selected');
52
+ expect(itemDiv).to.have.length(1);
53
+
54
+ // Go to next node
55
+ this.wrapper.find('#example-tree-3').simulate('keyDown', keyObjects.DOWN);
56
+ itemDiv = this.wrapper.find('#example-tree-7').find('.slds-is-selected');
57
+ expect(itemDiv).to.have.length(1);
58
+
59
+ // Wrap to first node
60
+ this.wrapper.find('#example-tree-7').simulate('keyDown', keyObjects.DOWN);
61
+ itemDiv = this.wrapper.find('#example-tree-1').find('.slds-is-selected');
62
+ expect(itemDiv).to.have.length(1);
63
+
64
+ // Wrap to last node
65
+ this.wrapper.find('#example-tree-1').simulate('keyDown', keyObjects.UP);
66
+ itemDiv = this.wrapper.find('#example-tree-7').find('.slds-is-selected');
67
+ expect(itemDiv).to.have.length(1);
68
+
69
+ // Go to previous node
70
+ this.wrapper.find('#example-tree-7').simulate('keyDown', keyObjects.UP);
71
+ itemDiv = this.wrapper.find('#example-tree-3').find('.slds-is-selected');
72
+ expect(itemDiv).to.have.length(1);
73
+
74
+ // Go to previous node
75
+ this.wrapper.find('#example-tree-3').simulate('keyDown', keyObjects.UP);
76
+ itemDiv = this.wrapper.find('#example-tree-2').find('.slds-is-selected');
77
+ expect(itemDiv).to.have.length(1);
78
+
79
+ // Go to previous node
80
+ this.wrapper.find('#example-tree-2').simulate('keyDown', keyObjects.UP);
81
+ itemDiv = this.wrapper.find('#example-tree-1').find('.slds-is-selected');
82
+ expect(itemDiv).to.have.length(1);
83
+ });
84
+ });
85
+
86
+ describe('Tree can be navigated right/left using the keyboard', () => {
87
+ beforeEach(mountComponent(<DefaultExample log={() => {}} />));
88
+
89
+ afterEach(unmountComponent);
90
+
91
+ it('expands/collapses branches when using right/left keys', function () {
92
+ // Initial focus selects the item
93
+ const item = this.wrapper.find('#example-tree-1');
94
+ item.simulate('focus');
95
+ const itemDiv = this.wrapper
96
+ .find('#example-tree-1')
97
+ .find('.slds-is-selected');
98
+ expect(itemDiv).to.have.length(1);
99
+
100
+ // Expand branch
101
+ this.wrapper
102
+ .find('#example-tree-3')
103
+ .simulate('keyDown', keyObjects.RIGHT);
104
+ let items = this.wrapper.find('li[aria-level=2]');
105
+ expect(items).to.have.length(4);
106
+
107
+ // Collapse branch
108
+ this.wrapper.find('#example-tree-3').simulate('keyDown', keyObjects.LEFT);
109
+ items = this.wrapper.find('li[aria-level=2]');
110
+ expect(items).to.have.length(0);
111
+
112
+ // Expand branch and select an item
113
+ this.wrapper
114
+ .find('#example-tree-3')
115
+ .simulate('keyDown', keyObjects.RIGHT);
116
+ items = this.wrapper.find('li[aria-level=2]');
117
+ expect(items).to.have.length(4);
118
+
119
+ // Collapse branch from an item
120
+ this.wrapper.find('#example-tree-3').simulate('keyDown', keyObjects.DOWN);
121
+ this.wrapper.find('#example-tree-8').simulate('keyDown', keyObjects.LEFT);
122
+ items = this.wrapper.find('li[aria-level=2]');
123
+ expect(items).to.have.length(0);
124
+ });
125
+ });
126
+
127
+ describe('Default Structure and CSS', () => {
128
+ const id = 'this-is-a-container-test';
129
+ beforeEach(
130
+ mountComponent(
131
+ <DefaultExample
132
+ className="this-is-a-container-test"
133
+ heading="Foods"
134
+ id={id}
135
+ listClassName="this-is-an-unordered-list-test"
136
+ listStyle={{ height: '500px' }}
137
+ log={() => {}}
138
+ />
139
+ )
140
+ );
141
+
142
+ afterEach(unmountComponent);
143
+
144
+ it('has tree container class, list class, and heading', function () {
145
+ const container = this.wrapper.find('.slds-tree_container');
146
+ expect(container.hasClass('this-is-a-container-test')).to.be.true;
147
+
148
+ const list = this.wrapper.find(`.${COMPONENT_CSS_CLASSES.base}`);
149
+ expect(list).to.have.length(1);
150
+ expect(list.hasClass('this-is-an-unordered-list-test')).to.be.true;
151
+ expect(list.get(0).props.style).to.have.property(
152
+ 'height',
153
+ '500px',
154
+ 'height of list'
155
+ );
156
+
157
+ const heading = this.wrapper.find(`#${id}__heading`);
158
+ expect(heading).to.have.length(1);
159
+ });
160
+ });
161
+
162
+ describe('Assistive Technology', () => {
163
+ beforeEach(
164
+ mountComponent(
165
+ <DefaultExample log={() => {}} assistiveText={{ label: 'Foods' }} />
166
+ )
167
+ );
168
+
169
+ afterEach(unmountComponent);
170
+
171
+ it('has heading via assistiveText', function () {
172
+ const heading = this.wrapper.find(
173
+ '#example-tree__heading.slds-assistive-text'
174
+ );
175
+ expect(heading).to.have.length(1);
176
+ const ariaLabelledbyId = this.wrapper.find(
177
+ '.slds-tree[aria-labelledby="example-tree__heading"]'
178
+ );
179
+ expect(ariaLabelledbyId).to.have.length(1);
180
+ });
181
+ });
182
+
183
+ describe('Initial Expanded and Selection based on nodes', () => {
184
+ beforeEach(
185
+ mountComponent(
186
+ <DefaultExample
187
+ log={() => {}}
188
+ nodes={sampleNodesDynamicHashMap.initialExpandedSelected}
189
+ />
190
+ )
191
+ );
192
+
193
+ afterEach(unmountComponent);
194
+
195
+ it('has initial selection', function () {
196
+ let selectedNode = this.wrapper
197
+ .find('#example-tree-2')
198
+ .find('.slds-is-selected');
199
+ // Fruits, Watermelon, Tree Fruits
200
+ expect(selectedNode).to.have.length(3);
201
+ selectedNode = this.wrapper
202
+ .find('#example-tree-5')
203
+ .find('.slds-is-selected');
204
+ expect(selectedNode).to.have.length(1);
205
+ });
206
+
207
+ it('has initial expanded branches', function () {
208
+ const expandedBranchList = this.wrapper
209
+ .find('#example-tree-2')
210
+ .find('.slds-is-expanded');
211
+ expect(expandedBranchList).to.have.length(2);
212
+ });
213
+ });
214
+
215
+ describe('Branch expands and selects on click', () => {
216
+ const itemClicked = sinon.spy();
217
+ const expandClicked = sinon.spy();
218
+
219
+ beforeEach(
220
+ mountComponent(
221
+ <DefaultExample
222
+ log={() => {}}
223
+ onExpandClick={expandClicked}
224
+ onClick={itemClicked}
225
+ />
226
+ )
227
+ );
228
+
229
+ afterEach(unmountComponent);
230
+
231
+ it('branch calls onExpandClicked and onClick', function () {
232
+ const branch = this.wrapper
233
+ .find('#example-tree-2')
234
+ .find('.slds-tree__item');
235
+ branch.simulate('click');
236
+ expect(itemClicked.callCount).to.equal(1);
237
+
238
+ const expandButton = this.wrapper
239
+ .find('#example-tree-2')
240
+ .find('.slds-button');
241
+ expandButton.simulate('click');
242
+ expect(expandClicked.callCount).to.equal(1);
243
+ });
244
+ });
245
+
246
+ describe('Item calls onClick', () => {
247
+ const itemClicked = sinon.spy();
248
+
249
+ beforeEach(
250
+ mountComponent(<DefaultExample log={() => {}} onClick={itemClicked} />)
251
+ );
252
+
253
+ afterEach(unmountComponent);
254
+
255
+ it('item calls itemClicked', function () {
256
+ const item = this.wrapper
257
+ .find('#example-tree-1')
258
+ .find('.slds-tree__item');
259
+ item.simulate('click');
260
+ expect(itemClicked.callCount).to.equal(1);
261
+ });
262
+ });
263
+
264
+ describe('Search term is highlighted', () => {
265
+ beforeEach(
266
+ mountComponent(<DefaultExample log={() => {}} searchTerm="fruit" />)
267
+ );
268
+
269
+ afterEach(unmountComponent);
270
+
271
+ it('item calls itemClicked', function () {
272
+ const markedItem = this.wrapper.find('mark');
273
+ expect(markedItem).to.have.length(1);
274
+ });
275
+ });
276
+
277
+ describe('Scrolling calls onScroll', () => {
278
+ const onScroll = sinon.spy();
279
+
280
+ beforeEach(
281
+ mountComponent(
282
+ <DefaultExample
283
+ heading="Foods"
284
+ listStyle={{
285
+ height: '300px',
286
+ overflowY: 'auto',
287
+ }}
288
+ log={() => {}}
289
+ nodes={sampleNodesDynamicHashMap.large}
290
+ onScroll={onScroll}
291
+ />
292
+ )
293
+ );
294
+
295
+ afterEach(unmountComponent);
296
+
297
+ it('scrolling calls onScroll', function () {
298
+ const list = this.wrapper.find(`.${COMPONENT_CSS_CLASSES.base}`);
299
+ list.simulate('scroll');
300
+ expect(onScroll.callCount).to.equal(1);
301
+ });
302
+ });
303
+ });