@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.
- package/components/accordion/__tests__/accordion.browser-test.jsx +302 -0
- package/components/alert/__tests__/alert.browser-test.jsx +100 -0
- package/components/app-launcher/__tests__/app-launcher.browser-test.jsx +228 -0
- package/components/app-launcher/__tests__/expandable-section.browser-test.jsx +144 -0
- package/components/app-launcher/__tests__/link.browser-test.jsx +107 -0
- package/components/app-launcher/__tests__/tile.browser-test.jsx +267 -0
- package/components/avatar/__tests__/avatar.browser-test.jsx +207 -0
- package/components/builder-header/__tests__/builder-header.browser-test.jsx +53 -0
- package/components/button/__tests__/button.browser-test.jsx +226 -0
- package/components/button-group/__tests__/button-group.browser-test.jsx +144 -0
- package/components/button-stateful/__tests__/button-stateful.browser-test.jsx +125 -0
- package/components/card/__tests__/card.browser-test.jsx +255 -0
- package/components/carousel/__tests__/carousel.browser-test.jsx +527 -0
- package/components/color-picker/__tests__/color-picker.browser-test.jsx +767 -0
- package/components/combobox/__tests__/combobox.browser-test.jsx +654 -0
- package/components/data-table/__tests__/data-table.browser-test.jsx +1051 -0
- package/components/date-picker/__tests__/__snapshots__/datepicker.dom-snapshot-test.jsx.snap +4429 -0
- package/components/date-picker/__tests__/date-picker.browser-test.jsx +497 -0
- package/components/date-picker/__tests__/datepicker.dom-snapshot-test.jsx +109 -0
- package/components/docked-composer/__tests__/docked-composer.browser-test.jsx +83 -0
- package/components/expandable-section/__tests__/expandable-section.browser-test.jsx +133 -0
- package/components/expression/__tests__/expression.browser-test.jsx +255 -0
- package/components/filter/__tests__/filter.browser-test.jsx +147 -0
- package/components/forms/input/__tests__/inline.browser-test.jsx +164 -0
- package/components/global-header/__tests__/global-header.browser-test.jsx +177 -0
- package/components/global-navigation-bar/__tests__/global-navigation-bar.browser-test.jsx +464 -0
- package/components/icon/__tests__/icon.browser-test.jsx +214 -0
- package/components/illustration/__tests__/illustration.browser-test.jsx +177 -0
- package/components/input/__tests__/input.browser-test.jsx +612 -0
- package/components/location-map/__tests__/location-map.browser-test.jsx +158 -0
- package/components/lookup/__tests__/lookup.browser-test.jsx +353 -0
- package/components/media-object/__tests__/media-object.browser-test.jsx +87 -0
- package/components/menu-dropdown/__tests__/dropdown.browser-test.jsx +588 -0
- package/components/menu-picklist/__tests__/menupicklist.snapshot-old-test.jsx +41 -0
- package/components/menu-picklist/__tests__/picklist-base.browser-test.jsx +275 -0
- package/components/modal/__tests__/modal.browser-test.jsx +333 -0
- package/components/notification/__tests__/notification.browser-test.jsx +113 -0
- package/components/page-header/__tests__/page-header.browser-test.jsx +161 -0
- package/components/panel/__tests__/__snapshots__/filtering.dom-snapshot-test.jsx.snap +298 -0
- package/components/panel/__tests__/filtering.dom-snapshot-test.jsx +9 -0
- package/components/pill/__tests__/pill.browser-test.jsx +308 -0
- package/components/pill-container/__tests__/pill-container.browser-test.jsx +186 -0
- package/components/popover/__tests__/popover.browser-test.jsx +327 -0
- package/components/progress-indicator/__tests__/progress-indicator.browser-test.jsx +335 -0
- package/components/radio-button-group/__tests__/radio-button-group.browser-test.jsx +122 -0
- package/components/radio-group/__tests__/radio-group.browser-test.jsx +119 -0
- package/components/setup-assistant/__tests__/setup-assistant.browser-test.jsx +77 -0
- package/components/slider/__tests__/slider.browser-test.jsx +389 -0
- package/components/spinner/__tests__/spinner.browser-test.jsx +57 -0
- package/components/split-view/__tests__/split-view.listbox.browser-test.jsx +225 -0
- package/components/split-view/__tests__/split-view.listbox.header.browser-test.jsx +158 -0
- package/components/split-view/__tests__/split-view.listbox.unread.browser-test.jsx +114 -0
- package/components/tabs/__tests__/tabs.browser-test.jsx +458 -0
- package/components/textarea/__tests__/textarea.browser-test.jsx +175 -0
- package/components/time-picker/__tests__/time-picker.browser-test.jsx +46 -0
- package/components/toast/__tests__/toast.browser-test.jsx +118 -0
- package/components/tooltip/__tests__/tooltip.browser-test.jsx +214 -0
- package/components/tree/__tests__/tree.browser-test.jsx +303 -0
- package/components/vertical-navigation/__tests__/navigation.browser-test.jsx +117 -0
- package/components/visual-picker/__tests__/visual-picker.browser-test.jsx +288 -0
- package/components/welcome-mat/__tests__/welcome-mat.browser-test.jsx +358 -0
- package/design-system-react-components.js +1 -1
- package/design-system-react-components.min.js.LICENSE.txt +1 -1
- package/design-system-react.js +1 -1
- package/design-system-react.min.js.LICENSE.txt +1 -1
- package/lib/design-system-react-components.min.js.LICENSE.txt +1 -1
- package/lib/design-system-react.min.js.LICENSE.txt +1 -1
- package/lib/package.json +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import chai, { expect } from 'chai';
|
|
3
|
+
import chaiEnzyme from 'chai-enzyme';
|
|
4
|
+
import { mount } from 'enzyme';
|
|
5
|
+
|
|
6
|
+
/* Enzyme Helpers that can mount and unmount React component instances to
|
|
7
|
+
* the DOM and set `this.wrapper` and `this.dom` within Mocha's `this`
|
|
8
|
+
* context [full source here](tests/enzyme-helpers.js). `this` can
|
|
9
|
+
* only be referenced if inside `function () {}`.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
createMountNode,
|
|
14
|
+
destroyMountNode,
|
|
15
|
+
} from '../../../tests/enzyme-helpers';
|
|
16
|
+
|
|
17
|
+
import Accordion from '../../accordion';
|
|
18
|
+
import IconSettings from '../../icon-settings';
|
|
19
|
+
import Panel from '../../accordion/panel';
|
|
20
|
+
import Dropdown from '../../menu-dropdown';
|
|
21
|
+
|
|
22
|
+
/* Set Chai to use chaiEnzyme for enzyme compatible assertions:
|
|
23
|
+
* https://github.com/producthunt/chai-enzyme
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
chai.use(chaiEnzyme());
|
|
27
|
+
|
|
28
|
+
/* Re-usable demo component.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
const propTypes = {};
|
|
32
|
+
|
|
33
|
+
const defaultProps = {};
|
|
34
|
+
|
|
35
|
+
class AccordionExample extends React.Component {
|
|
36
|
+
constructor(props) {
|
|
37
|
+
super(props);
|
|
38
|
+
this.state = {
|
|
39
|
+
expandedPanels: {},
|
|
40
|
+
items: [
|
|
41
|
+
{
|
|
42
|
+
id: '1',
|
|
43
|
+
summary: 'Accordion Summary',
|
|
44
|
+
details: 'Accordion details - A',
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
id: '2',
|
|
48
|
+
summary: 'Accordion Summary',
|
|
49
|
+
details: 'Accordion details - B',
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
id: '3',
|
|
53
|
+
summary: 'Accordion Summary',
|
|
54
|
+
details: 'Accordion details - C',
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
menuDropdown(selectedItem) {
|
|
61
|
+
return (
|
|
62
|
+
<Dropdown
|
|
63
|
+
align="right"
|
|
64
|
+
id="ButtonGroupExampleDropdown"
|
|
65
|
+
assistiveText={{ icon: 'More Options' }}
|
|
66
|
+
buttonVariant="icon"
|
|
67
|
+
buttonClassName="slds-shrink-none"
|
|
68
|
+
iconCategory="utility"
|
|
69
|
+
iconName="down"
|
|
70
|
+
iconVariant="border-filled"
|
|
71
|
+
onSelect={(option) => {
|
|
72
|
+
if (option.label === 'delete') {
|
|
73
|
+
this.setState((state) => ({
|
|
74
|
+
...state,
|
|
75
|
+
items: state.items.filter((item) => item.id !== selectedItem.id),
|
|
76
|
+
}));
|
|
77
|
+
} else if (console) {
|
|
78
|
+
console.log('onSelect', event, option);
|
|
79
|
+
}
|
|
80
|
+
}}
|
|
81
|
+
options={[
|
|
82
|
+
{
|
|
83
|
+
label: 'delete',
|
|
84
|
+
value: 'A0',
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
label: 'redo',
|
|
88
|
+
value: 'B0',
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
label: 'activate',
|
|
92
|
+
value: 'C0',
|
|
93
|
+
},
|
|
94
|
+
]}
|
|
95
|
+
iconSize="x-small"
|
|
96
|
+
/>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
togglePanel(id) {
|
|
101
|
+
this.setState((state) => ({
|
|
102
|
+
...state,
|
|
103
|
+
expandedPanels: {
|
|
104
|
+
...state.expandedPanels,
|
|
105
|
+
[id]: !state.expandedPanels[id],
|
|
106
|
+
},
|
|
107
|
+
}));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
render() {
|
|
111
|
+
return (
|
|
112
|
+
<IconSettings iconPath="/assets/icons">
|
|
113
|
+
<Accordion id="base-example-accordion">
|
|
114
|
+
{this.state.items.map((item) => (
|
|
115
|
+
<Panel
|
|
116
|
+
expanded={!!this.state.expandedPanels[item.id]}
|
|
117
|
+
id={item.id}
|
|
118
|
+
panelContentActions={this.menuDropdown(item)}
|
|
119
|
+
key={item.id}
|
|
120
|
+
onTogglePanel={() => this.togglePanel(item.id)}
|
|
121
|
+
summary={item.summary}
|
|
122
|
+
>
|
|
123
|
+
{item.details}
|
|
124
|
+
</Panel>
|
|
125
|
+
))}
|
|
126
|
+
</Accordion>
|
|
127
|
+
</IconSettings>
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
AccordionExample.displayName = 'AccordionExampleComponent';
|
|
133
|
+
AccordionExample.propTypes = propTypes;
|
|
134
|
+
AccordionExample.defaultProps = defaultProps;
|
|
135
|
+
|
|
136
|
+
class AccordionWithOnePanelExample extends React.Component {
|
|
137
|
+
constructor(props) {
|
|
138
|
+
super(props);
|
|
139
|
+
this.state = {
|
|
140
|
+
expandedPanels: {},
|
|
141
|
+
item: {
|
|
142
|
+
id: '1',
|
|
143
|
+
summary: 'Accordion Summary',
|
|
144
|
+
details: 'Accordion Details',
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
togglePanel(id) {
|
|
150
|
+
this.setState((state) => ({
|
|
151
|
+
...state,
|
|
152
|
+
expandedPanels: {
|
|
153
|
+
...state.expandedPanels,
|
|
154
|
+
[id]: !state.expandedPanels[id],
|
|
155
|
+
},
|
|
156
|
+
}));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
render() {
|
|
160
|
+
const { item } = this.state;
|
|
161
|
+
|
|
162
|
+
return (
|
|
163
|
+
<IconSettings iconPath="/assets/icons">
|
|
164
|
+
<Accordion id="base-example-accordion">
|
|
165
|
+
<Panel
|
|
166
|
+
expanded={!!this.state.expandedPanels[item.id]}
|
|
167
|
+
id={item.id}
|
|
168
|
+
key={item.id}
|
|
169
|
+
onTogglePanel={() => this.togglePanel(item.id)}
|
|
170
|
+
summary={item.summary}
|
|
171
|
+
>
|
|
172
|
+
{item.details}
|
|
173
|
+
</Panel>
|
|
174
|
+
</Accordion>
|
|
175
|
+
</IconSettings>
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
AccordionWithOnePanelExample.displayName =
|
|
181
|
+
'AccordionWithOnePanelExampleComponent';
|
|
182
|
+
AccordionWithOnePanelExample.propTypes = propTypes;
|
|
183
|
+
AccordionWithOnePanelExample.defaultProps = defaultProps;
|
|
184
|
+
|
|
185
|
+
/* Accordion rendering tests
|
|
186
|
+
*/
|
|
187
|
+
|
|
188
|
+
describe('Accordion', function describeFunction() {
|
|
189
|
+
describe('Renders Accordion', () => {
|
|
190
|
+
let mountNode;
|
|
191
|
+
let wrapper;
|
|
192
|
+
|
|
193
|
+
beforeEach(() => {
|
|
194
|
+
mountNode = createMountNode({ context: this });
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
afterEach(() => {
|
|
198
|
+
destroyMountNode({ wrapper, mountNode });
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it('renders an accordion', () => {
|
|
202
|
+
wrapper = mount(<AccordionExample />, { attachTo: mountNode });
|
|
203
|
+
const accordion = wrapper.find(Accordion);
|
|
204
|
+
expect(accordion).to.be.present;
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it('renders `panelContentActions` component, if passed', () => {
|
|
208
|
+
wrapper = mount(<AccordionExample />, {
|
|
209
|
+
attachTo: mountNode,
|
|
210
|
+
});
|
|
211
|
+
const panelContentActions = wrapper.find('div .slds-dropdown-trigger');
|
|
212
|
+
expect(panelContentActions, 'panel dropdown component exists').to.exist;
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('renders accordion with only one panel', () => {
|
|
216
|
+
wrapper = mount(<AccordionWithOnePanelExample />, {
|
|
217
|
+
attachTo: mountNode,
|
|
218
|
+
});
|
|
219
|
+
const accordion = wrapper.find(Accordion);
|
|
220
|
+
expect(accordion).to.be.present;
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
describe('Interactions keyboard', () => {
|
|
225
|
+
let mountNode;
|
|
226
|
+
let wrapper;
|
|
227
|
+
|
|
228
|
+
beforeEach(() => {
|
|
229
|
+
mountNode = createMountNode({ context: this });
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
afterEach(() => {
|
|
233
|
+
destroyMountNode({ wrapper, mountNode });
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it('focuses the next accordion button on arrow down', () => {
|
|
237
|
+
wrapper = mount(<AccordionExample />, { attachTo: mountNode });
|
|
238
|
+
const accordionButtons = wrapper.find(
|
|
239
|
+
'button.slds-accordion__summary-action'
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
accordionButtons.at(0).simulate('keyDown', {
|
|
243
|
+
key: 'ArrowDown',
|
|
244
|
+
keyCode: 40,
|
|
245
|
+
which: 40,
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
expect(
|
|
249
|
+
accordionButtons.at(1).getDOMNode() === document.activeElement
|
|
250
|
+
).to.equal(true);
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it('focuses the previous accordion button on arrow up', () => {
|
|
254
|
+
wrapper = mount(<AccordionExample />, { attachTo: mountNode });
|
|
255
|
+
const accordionButtons = wrapper.find(
|
|
256
|
+
'button.slds-accordion__summary-action'
|
|
257
|
+
);
|
|
258
|
+
|
|
259
|
+
accordionButtons.at(0).simulate('keyDown', {
|
|
260
|
+
key: 'ArrowUp',
|
|
261
|
+
keyCode: 38,
|
|
262
|
+
which: 38,
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
const lastAccordionButton = accordionButtons.at(
|
|
266
|
+
accordionButtons.length - 1
|
|
267
|
+
);
|
|
268
|
+
expect(
|
|
269
|
+
lastAccordionButton.getDOMNode() === document.activeElement
|
|
270
|
+
).to.equal(true);
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
describe('Open panel', () => {
|
|
275
|
+
let mountNode;
|
|
276
|
+
let wrapper;
|
|
277
|
+
beforeEach(() => {
|
|
278
|
+
mountNode = createMountNode({ context: this });
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
afterEach(() => {
|
|
282
|
+
destroyMountNode({ wrapper, mountNode });
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it('triggers a change callback on panel select', () => {
|
|
286
|
+
wrapper = mount(<AccordionExample />, { attachTo: mountNode });
|
|
287
|
+
const panel = () => wrapper.find('SLDSAccordionPanel').first();
|
|
288
|
+
expect(panel()).to.have.prop('expanded', false);
|
|
289
|
+
panel().find('button.slds-accordion__summary-action').simulate('click');
|
|
290
|
+
expect(panel()).to.have.prop('expanded', true);
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
it('`aria-expanded` set to true on panel select', () => {
|
|
294
|
+
wrapper = mount(<AccordionExample />, { attachTo: mountNode });
|
|
295
|
+
const panel = () => wrapper.find('SLDSAccordionPanel').first();
|
|
296
|
+
panel().find('button.slds-accordion__summary-action').simulate('click');
|
|
297
|
+
expect(
|
|
298
|
+
panel().find('button.slds-accordion__summary-action')
|
|
299
|
+
).to.have.prop('aria-expanded', true);
|
|
300
|
+
});
|
|
301
|
+
});
|
|
302
|
+
});
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/* eslint-disable react/no-render-return-value */
|
|
2
|
+
/* eslint-disable react/no-find-dom-node */
|
|
3
|
+
|
|
4
|
+
import React, { Component } 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 Alert from '../';
|
|
13
|
+
import AlertContainer from '../container';
|
|
14
|
+
import Icon from '../../icon';
|
|
15
|
+
import IconSettings from '../../icon-settings';
|
|
16
|
+
|
|
17
|
+
chai.use(chaiEnzyme());
|
|
18
|
+
|
|
19
|
+
class DemoComponent extends 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
|
+
<AlertContainer>
|
|
33
|
+
{this.state.isOpen ? (
|
|
34
|
+
<Alert
|
|
35
|
+
style={this.props.style}
|
|
36
|
+
dismissible
|
|
37
|
+
icon={<Icon category="utility" name="user" />}
|
|
38
|
+
labels={{
|
|
39
|
+
heading: 'Logged in as John Smith (johnsmith@acme.com).',
|
|
40
|
+
headingLink: 'Log out',
|
|
41
|
+
}}
|
|
42
|
+
onClickHeadingLink={this.props.onClickHeadingLink}
|
|
43
|
+
onRequestClose={() => {
|
|
44
|
+
this.setState({ isOpen: false });
|
|
45
|
+
}}
|
|
46
|
+
/>
|
|
47
|
+
) : null}
|
|
48
|
+
</AlertContainer>
|
|
49
|
+
</div>
|
|
50
|
+
</IconSettings>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
DemoComponent.displayName = 'AlertExample';
|
|
56
|
+
|
|
57
|
+
describe('SLDSAlert: ', function describeFunction() {
|
|
58
|
+
const onClickHeadingLink = sinon.spy();
|
|
59
|
+
|
|
60
|
+
describe('Dismiss alert', () => {
|
|
61
|
+
beforeEach(
|
|
62
|
+
mountComponent(<DemoComponent onClickHeadingLink={onClickHeadingLink} />)
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
afterEach(unmountComponent);
|
|
66
|
+
|
|
67
|
+
/* Please notice the of `function () {}` and not () => {}.
|
|
68
|
+
* It allows access to the Mocha test context via `this`.
|
|
69
|
+
*/
|
|
70
|
+
it('calls onRequestClose handler', function () {
|
|
71
|
+
const button = this.wrapper.find('button.slds-notify__close');
|
|
72
|
+
// If applicable, use second parameter to pass the data object
|
|
73
|
+
expect(this.wrapper).to.have.state('isOpen', true);
|
|
74
|
+
button.simulate('click', {});
|
|
75
|
+
expect(this.wrapper).to.have.state('isOpen', false);
|
|
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('Basic Alert Props Render', function describeFunction2() {
|
|
86
|
+
beforeEach(
|
|
87
|
+
mountComponent(
|
|
88
|
+
<DemoComponent style={{ backgroundColor: 'rgb(18, 49, 35)' }} />
|
|
89
|
+
)
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
afterEach(unmountComponent);
|
|
93
|
+
|
|
94
|
+
it('render custom styles', function () {
|
|
95
|
+
expect(
|
|
96
|
+
this.wrapper.find('.slds-notify').prop('style').backgroundColor
|
|
97
|
+
).to.equal('rgb(18, 49, 35)');
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
});
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import ReactModal from 'react-modal';
|
|
3
|
+
import { expect } from 'chai';
|
|
4
|
+
import { mount, ReactWrapper } from 'enzyme';
|
|
5
|
+
import assign from 'lodash.assign';
|
|
6
|
+
|
|
7
|
+
import IconSettings from '../../icon-settings';
|
|
8
|
+
import AppLauncher from '../../app-launcher';
|
|
9
|
+
import AppLauncherTile from '../../app-launcher/tile';
|
|
10
|
+
import AppLauncherExpandableSection from '../../app-launcher/expandable-section';
|
|
11
|
+
import Search from '../../input/search';
|
|
12
|
+
import Button from '../../button';
|
|
13
|
+
|
|
14
|
+
/* eslint-disable react/no-find-dom-node */
|
|
15
|
+
|
|
16
|
+
const should = chai.should();
|
|
17
|
+
|
|
18
|
+
describe('SLDS APP LAUNCHER *******************************************', () => {
|
|
19
|
+
const handles = {
|
|
20
|
+
appLauncher: null,
|
|
21
|
+
appLauncherIcon: null,
|
|
22
|
+
modal: null,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const defaultAppLauncherProps = {
|
|
26
|
+
isOpen: true,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const createAppLauncher = (props) =>
|
|
30
|
+
React.createElement(
|
|
31
|
+
AppLauncher,
|
|
32
|
+
assign({}, defaultAppLauncherProps, props),
|
|
33
|
+
<AppLauncherExpandableSection title="All Items">
|
|
34
|
+
<AppLauncherTile title="Marketing Cloud" />
|
|
35
|
+
<AppLauncherTile title="Support Cloud" />
|
|
36
|
+
</AppLauncherExpandableSection>
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
function mountAppLauncher(props) {
|
|
40
|
+
handles.appLauncher = mount(
|
|
41
|
+
<IconSettings iconPath="/assets/icons">
|
|
42
|
+
{createAppLauncher(props)}
|
|
43
|
+
</IconSettings>
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
handles.appLauncherIcon = handles.appLauncher.find(
|
|
47
|
+
'.slds-context-bar__icon-action'
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
// Wrap the modal portal in an Enzyme wrapper
|
|
51
|
+
handles.modal = new ReactWrapper(
|
|
52
|
+
handles.appLauncher.find(ReactModal).getElement().portal,
|
|
53
|
+
true
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function cleanDom() {
|
|
58
|
+
// Removes the modal container element from the bottom of the DOM, this will prevent the 'setState' errors
|
|
59
|
+
// gotta be a better way to do this..
|
|
60
|
+
const modalWrapper = document.documentElement.querySelectorAll(
|
|
61
|
+
'.ReactModalPortal'
|
|
62
|
+
)[0];
|
|
63
|
+
|
|
64
|
+
if (modalWrapper) {
|
|
65
|
+
modalWrapper.parentNode.removeChild(modalWrapper);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// ///////////////////////
|
|
70
|
+
// ////// T O D O ////////
|
|
71
|
+
// ///////////////////////
|
|
72
|
+
// APP LAUNCHER -----
|
|
73
|
+
// tabs?
|
|
74
|
+
// if you pass a isOpen prop, you must control the component with it (this.state.isOpen will now work)
|
|
75
|
+
// (#591, waiting on #590) modal content has classes: slds-modal__content slds-app-launcher__content slds-p-around_medium
|
|
76
|
+
|
|
77
|
+
describe('App Launcher', () => {
|
|
78
|
+
let onClose;
|
|
79
|
+
|
|
80
|
+
beforeEach(() => {
|
|
81
|
+
onClose = sinon.spy();
|
|
82
|
+
|
|
83
|
+
mountAppLauncher({
|
|
84
|
+
modalClassName: 'custom-modal-class',
|
|
85
|
+
modalHeaderButton: <Button label="App Exchange" />,
|
|
86
|
+
onClose,
|
|
87
|
+
search: <Search assistiveText={{ icon: 'Find an app' }} />,
|
|
88
|
+
title: 'App Launcher!',
|
|
89
|
+
triggerName: 'App Name',
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
afterEach(() => {
|
|
94
|
+
cleanDom();
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('renders modal', () => {
|
|
98
|
+
expect(handles.appLauncher.find('.slds-modal').length).to.eql(1);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('renders custom modal class', () => {
|
|
102
|
+
should.exist(handles.appLauncher.find('.custom-modal-class'));
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('renders modal header', () => {
|
|
106
|
+
should.exist(handles.appLauncher.find('.slds-app-launcher__header'));
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('app launcher title can be set', () => {
|
|
110
|
+
const appLauncherTitle = handles.appLauncher.find(
|
|
111
|
+
'h2.slds-text-heading_medium'
|
|
112
|
+
);
|
|
113
|
+
expect(appLauncherTitle.length).to.eql(1);
|
|
114
|
+
expect(appLauncherTitle.text()).to.eql('App Launcher!');
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('app launcher triggerName can be set', () => {
|
|
118
|
+
const appLauncherTriggerName = handles.appLauncher.find(
|
|
119
|
+
'.slds-context-bar__app-name'
|
|
120
|
+
);
|
|
121
|
+
expect(appLauncherTriggerName.length).to.eql(1);
|
|
122
|
+
expect(appLauncherTriggerName.text()).to.eql('App Name');
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('renders search bar', () => {
|
|
126
|
+
should.exist(handles.modal.find(Search));
|
|
127
|
+
expect(
|
|
128
|
+
handles.appLauncher.find('.slds-app-launcher__header-search').length
|
|
129
|
+
).to.eql(1);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('renders `modalHeaderButton`', () => {
|
|
133
|
+
const headerButton = handles.appLauncher.find(
|
|
134
|
+
'header.slds-modal__header button.slds-button.slds-button_neutral'
|
|
135
|
+
);
|
|
136
|
+
expect(headerButton.length).to.eql(1);
|
|
137
|
+
expect(headerButton.text()).to.eql('App Exchange');
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('closing modal fires callback', () => {
|
|
141
|
+
handles.appLauncher.find('button.slds-modal__close').simulate('click');
|
|
142
|
+
expect(onClose.calledOnce).to.be.true; // eslint-disable-line no-unused-expressions
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('close modal callback receives original event as arg', () => {
|
|
146
|
+
handles.appLauncher.find('button.slds-modal__close').simulate('click');
|
|
147
|
+
expect(onClose.args.length).to.equal(1);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('renders modal content', () => {
|
|
151
|
+
expect(
|
|
152
|
+
handles.appLauncher.find(
|
|
153
|
+
'.slds-modal__content.slds-app-launcher__content.slds-p-around_medium'
|
|
154
|
+
).length
|
|
155
|
+
).to.equal(1);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('app launcher can be passed children', () => {
|
|
159
|
+
should.exist(
|
|
160
|
+
handles.appLauncher.find('SLDSAppLauncherExpandableSection')
|
|
161
|
+
);
|
|
162
|
+
expect(handles.appLauncher.find('SLDSAppLauncherTile').length).to.equal(
|
|
163
|
+
2
|
|
164
|
+
);
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
describe('App Launcher Icon', () => {
|
|
169
|
+
let triggerOnClick;
|
|
170
|
+
|
|
171
|
+
beforeEach(() => {
|
|
172
|
+
triggerOnClick = sinon.spy();
|
|
173
|
+
|
|
174
|
+
mountAppLauncher({
|
|
175
|
+
assistiveText: { trigger: 'Custom Icon Assistive Text' },
|
|
176
|
+
triggerOnClick,
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
afterEach(() => {
|
|
181
|
+
cleanDom();
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('renders App Launcer icon', () => {
|
|
185
|
+
should.exist(handles.appLauncherIcon);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('renders all App Launcher dots', () => {
|
|
189
|
+
expect(
|
|
190
|
+
handles.appLauncherIcon
|
|
191
|
+
.find('.slds-icon-waffle')
|
|
192
|
+
.containsAllMatchingElements([
|
|
193
|
+
<span className="slds-r1" />,
|
|
194
|
+
<span className="slds-r2" />,
|
|
195
|
+
<span className="slds-r3" />,
|
|
196
|
+
<span className="slds-r4" />,
|
|
197
|
+
<span className="slds-r5" />,
|
|
198
|
+
<span className="slds-r6" />,
|
|
199
|
+
<span className="slds-r7" />,
|
|
200
|
+
<span className="slds-r8" />,
|
|
201
|
+
<span className="slds-r9" />,
|
|
202
|
+
])
|
|
203
|
+
).to.equal(true);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it('App Launcher Icon link has proper classes', () => {
|
|
207
|
+
const button = handles.appLauncherIcon.find('button');
|
|
208
|
+
expect(button).to.have.className('slds-icon-waffle_container');
|
|
209
|
+
expect(button).to.have.className('slds-context-bar__button');
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('clicking App Launcher Icon fires callback', () => {
|
|
213
|
+
handles.appLauncherIcon.find('button').simulate('click');
|
|
214
|
+
expect(triggerOnClick.calledOnce).to.be.true; // eslint-disable-line no-unused-expressions
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it('App Launcher Icon callback receives original event as arg', () => {
|
|
218
|
+
handles.appLauncherIcon.find('button').simulate('click');
|
|
219
|
+
expect(triggerOnClick.args.length).to.equal(1);
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it('renders assistive text from prop', () => {
|
|
223
|
+
expect(
|
|
224
|
+
handles.appLauncherIcon.find('.slds-assistive-text').text()
|
|
225
|
+
).to.equal('Custom Icon Assistive Text');
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
});
|