@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,458 @@
|
|
|
1
|
+
// Import your external dependencies
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
import PropTypes from 'prop-types';
|
|
5
|
+
import chai, { expect } from 'chai';
|
|
6
|
+
import chaiEnzyme from 'chai-enzyme';
|
|
7
|
+
import classNames from 'classnames';
|
|
8
|
+
|
|
9
|
+
// Import your internal dependencies (for example):
|
|
10
|
+
import Tabs from '../../tabs';
|
|
11
|
+
import Panel from '../../tabs/panel';
|
|
12
|
+
|
|
13
|
+
/* Enzyme Helpers can mount and unmount React component instances to
|
|
14
|
+
* the DOM and set `this.wrapper` and `this.dom` within Mocha's `this`
|
|
15
|
+
* context [full source here](tests/enzyme-helpers.js).
|
|
16
|
+
*/
|
|
17
|
+
import {
|
|
18
|
+
mountComponent,
|
|
19
|
+
unmountComponent,
|
|
20
|
+
} from '../../../tests/enzyme-helpers';
|
|
21
|
+
|
|
22
|
+
/* Set Chai to use chaiEnzyme for enzyme compatible assertions:
|
|
23
|
+
* https://github.com/producthunt/chai-enzyme
|
|
24
|
+
*/
|
|
25
|
+
chai.use(chaiEnzyme());
|
|
26
|
+
|
|
27
|
+
const COMPONENT_CSS_CLASSES = {
|
|
28
|
+
wrapper: 'slds-tabs_default_wrapper',
|
|
29
|
+
base: 'slds-tabs_default',
|
|
30
|
+
nav: 'slds-tabs_default__nav',
|
|
31
|
+
item: 'slds-tabs_default__item',
|
|
32
|
+
link: 'slds-tabs_default__link',
|
|
33
|
+
content: 'slds-tabs_default__content',
|
|
34
|
+
testClass: 'this-is-a-css-class-name',
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/* A re-usable demo component fixture outside of `describe` sections
|
|
38
|
+
* can accept props within each test and be unmounted after each tests.
|
|
39
|
+
* This wrapping component will be similar to your wrapping component
|
|
40
|
+
* you will create in the React Storybook for manual testing.
|
|
41
|
+
*/
|
|
42
|
+
class TabsDemoComponent extends React.Component {
|
|
43
|
+
static displayName = 'TabsDemoComponent';
|
|
44
|
+
|
|
45
|
+
// ### Prop Types
|
|
46
|
+
static propTypes = {
|
|
47
|
+
/**
|
|
48
|
+
* Class names to be added to the container element and is passed along to its children.
|
|
49
|
+
*/
|
|
50
|
+
className: PropTypes.oneOfType([
|
|
51
|
+
PropTypes.array,
|
|
52
|
+
PropTypes.object,
|
|
53
|
+
PropTypes.string,
|
|
54
|
+
]),
|
|
55
|
+
/**
|
|
56
|
+
* HTML `id` attribute of primary element that has `.slds-tabs_default` on it. Optional: If one is not supplied, a `shortid` will be created.
|
|
57
|
+
*/
|
|
58
|
+
id: PropTypes.string,
|
|
59
|
+
/**
|
|
60
|
+
* Function that triggers when a tab is selected.
|
|
61
|
+
*/
|
|
62
|
+
onSelect: PropTypes.func,
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
render() {
|
|
66
|
+
const { className, id, ...attributes } = this.props;
|
|
67
|
+
|
|
68
|
+
// Delete all known props, so they don't get added to DOM
|
|
69
|
+
delete attributes.selectedIndex;
|
|
70
|
+
delete attributes.onSelect;
|
|
71
|
+
delete attributes.children;
|
|
72
|
+
delete attributes.id;
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
<div
|
|
76
|
+
className={classNames(
|
|
77
|
+
'slds-m-top_large',
|
|
78
|
+
`${COMPONENT_CSS_CLASSES.wrapper}`
|
|
79
|
+
)}
|
|
80
|
+
>
|
|
81
|
+
<Tabs className={classNames(className)} id={id} {...attributes}>
|
|
82
|
+
<Panel label="Tab A">
|
|
83
|
+
<p>This is tab A</p>
|
|
84
|
+
</Panel>
|
|
85
|
+
<Panel label="Tab B" disabled>
|
|
86
|
+
<p>This is tab B.</p>
|
|
87
|
+
<p>It is disabled.</p>
|
|
88
|
+
</Panel>
|
|
89
|
+
<Panel label="Tab C" hasError>
|
|
90
|
+
<p>This is tab C</p>
|
|
91
|
+
<p>It has an error icon next to the tab label.</p>
|
|
92
|
+
</Panel>
|
|
93
|
+
<Panel label="Always No">
|
|
94
|
+
<p>
|
|
95
|
+
This one can not be selected from the tabs list because this
|
|
96
|
+
example provides a custom <code>onSelct</code> function that
|
|
97
|
+
retuns false when it is run, preventing the component’s
|
|
98
|
+
built-in handler from running, and thus the tab is never selected.
|
|
99
|
+
</p>
|
|
100
|
+
<p>
|
|
101
|
+
Note that you <em>can</em> still see the panel if you hide the
|
|
102
|
+
other tabs, because the tab/panel are not <em>disabled</em>.
|
|
103
|
+
</p>
|
|
104
|
+
<p>
|
|
105
|
+
In other words, this should not be taken as an example of how to
|
|
106
|
+
be sneaky about disabling tab selection, but rather that you can{' '}
|
|
107
|
+
<strong>do stuff</strong> when a tab is selected by sending it a
|
|
108
|
+
custom <code>onSelect</code> function.
|
|
109
|
+
</p>
|
|
110
|
+
</Panel>
|
|
111
|
+
</Tabs>
|
|
112
|
+
</div>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
describe('Tabs', () => {
|
|
118
|
+
// BASIC STRUCTURE
|
|
119
|
+
|
|
120
|
+
describe('Default structure and CSS', () => {
|
|
121
|
+
const id = 'this-is-an-id-for-testing';
|
|
122
|
+
|
|
123
|
+
before(
|
|
124
|
+
mountComponent(
|
|
125
|
+
<TabsDemoComponent
|
|
126
|
+
className={`${COMPONENT_CSS_CLASSES.testClass}`}
|
|
127
|
+
id={id}
|
|
128
|
+
bar="baz"
|
|
129
|
+
/>
|
|
130
|
+
)
|
|
131
|
+
);
|
|
132
|
+
after(unmountComponent);
|
|
133
|
+
|
|
134
|
+
it('Has a main wrapper with the proper class name.', function () {
|
|
135
|
+
const myTabsWrapper = this.wrapper.find(
|
|
136
|
+
`.${COMPONENT_CSS_CLASSES.wrapper}`
|
|
137
|
+
);
|
|
138
|
+
expect(myTabsWrapper.hasClass(COMPONENT_CSS_CLASSES.wrapper)).to.be.true;
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('Has exactly one (1) tabs component, and has with the proper class name.', function () {
|
|
142
|
+
const myTabs = this.wrapper.find(`.${COMPONENT_CSS_CLASSES.base}`);
|
|
143
|
+
expect(myTabs.hasClass(COMPONENT_CSS_CLASSES.base)).to.be.true;
|
|
144
|
+
expect(myTabs).to.have.length(1);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('Has the custom id (this-is-an-id-for-testing) we supplied.', function () {
|
|
148
|
+
const myTabs = this.wrapper.find(`.${COMPONENT_CSS_CLASSES.base}`);
|
|
149
|
+
expect(myTabs).attr('id').to.equal(id);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('Has exactly one (1) nav component, and has with the proper class name.', function () {
|
|
153
|
+
const myTabsNav = this.wrapper.find(`.${COMPONENT_CSS_CLASSES.nav}`);
|
|
154
|
+
expect(myTabsNav.hasClass(COMPONENT_CSS_CLASSES.nav)).to.be.true;
|
|
155
|
+
expect(myTabsNav).to.have.length(1);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it(`Nav component builds proper ID (${id}-tabs__nav) because it inherits Tabs id property and appends "-slds-tabs__nav" to it.`, function () {
|
|
159
|
+
const myTabsNav = this.wrapper.find(`.${COMPONENT_CSS_CLASSES.nav}`);
|
|
160
|
+
expect(myTabsNav).attr('id').to.equal(`${id}-slds-tabs__nav`);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it(`Has exactly four (4) <Tab /> components, each with the proper class name (${COMPONENT_CSS_CLASSES.item}).`, function () {
|
|
164
|
+
const myTabsListItems = this.wrapper.find(
|
|
165
|
+
`.${COMPONENT_CSS_CLASSES.item}`
|
|
166
|
+
);
|
|
167
|
+
this.wrapper
|
|
168
|
+
.find(`.${COMPONENT_CSS_CLASSES.item}`)
|
|
169
|
+
.forEach(function (node) {
|
|
170
|
+
expect(node.hasClass(COMPONENT_CSS_CLASSES.item)).to.equal(true);
|
|
171
|
+
});
|
|
172
|
+
expect(myTabsListItems).to.have.length(4);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('Has only one (1) tab with ".slds-disabled" class on it.', function () {
|
|
176
|
+
const myTabsListItem = this.wrapper.find(
|
|
177
|
+
`.${COMPONENT_CSS_CLASSES.item}.slds-disabled`
|
|
178
|
+
);
|
|
179
|
+
expect(myTabsListItem).to.have.length(1);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it('Tab components have proper ID attributes because they inherit the Tabs "id" property and append "-slds-tabs_tab-<index>" to it.', function () {
|
|
183
|
+
this.wrapper
|
|
184
|
+
.find(`.${COMPONENT_CSS_CLASSES.item}`)
|
|
185
|
+
.forEach(function (node, index) {
|
|
186
|
+
expect(node).to.have.attr('id', `${id}-slds-tabs_tab-${index}`);
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it('TabPanel components have proper ID attributes because they inherit the Tabs "id" property and append "-slds-tabs_panel-<index>" to it.', function () {
|
|
191
|
+
this.wrapper
|
|
192
|
+
.find(`.${COMPONENT_CSS_CLASSES.panel}`)
|
|
193
|
+
.forEach(function (node, index) {
|
|
194
|
+
expect(node).to.have.attr('id', `${id}-slds-tabs_panel-${index}`);
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('Has the proper disabled class on the second tab.', function () {
|
|
199
|
+
const myTabsListItem = this.wrapper.find(
|
|
200
|
+
`.${COMPONENT_CSS_CLASSES.item}.slds-disabled`
|
|
201
|
+
);
|
|
202
|
+
expect(myTabsListItem.hasClass('slds-disabled')).to.equal(true);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it('Has the same number of tabs as panels.', function () {
|
|
206
|
+
const myTabsListItems = this.wrapper.find(
|
|
207
|
+
`.${COMPONENT_CSS_CLASSES.item}`
|
|
208
|
+
);
|
|
209
|
+
const myTabsPanels = this.wrapper.find(
|
|
210
|
+
`.${COMPONENT_CSS_CLASSES.content}`
|
|
211
|
+
);
|
|
212
|
+
expect(myTabsListItems).to.have.length(4);
|
|
213
|
+
expect(myTabsPanels).to.have.length(4);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it('Tab 2 should have an error icon', function () {
|
|
217
|
+
this.wrapper
|
|
218
|
+
.find(`.${COMPONENT_CSS_CLASSES.link}`)
|
|
219
|
+
.forEach(function (node, index) {
|
|
220
|
+
if (index === 2) {
|
|
221
|
+
expect(node).to.have.descendants('.slds-icon-utility-error');
|
|
222
|
+
} else {
|
|
223
|
+
expect(node).to.not.have.descendants('.slds-icon-utility-error');
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
describe('Assistive technology', () => {
|
|
230
|
+
/* Detect if presence of accessibility features such as ARIA
|
|
231
|
+
* roles and screen reader text is present in the DOM.
|
|
232
|
+
*/
|
|
233
|
+
const id = 'this-is-an-id-for-testing';
|
|
234
|
+
|
|
235
|
+
before(
|
|
236
|
+
mountComponent(
|
|
237
|
+
<TabsDemoComponent
|
|
238
|
+
className={`${COMPONENT_CSS_CLASSES.testClass}`}
|
|
239
|
+
id={id}
|
|
240
|
+
/>
|
|
241
|
+
)
|
|
242
|
+
);
|
|
243
|
+
after(unmountComponent);
|
|
244
|
+
|
|
245
|
+
it('Tab components have proper "aria-controls" attribute because they inherit Tabs ID property and append "-slds-tabs_panel-<index>" to it.', function () {
|
|
246
|
+
this.wrapper
|
|
247
|
+
.find(`.${COMPONENT_CSS_CLASSES.link}`)
|
|
248
|
+
.forEach(function (node, index) {
|
|
249
|
+
expect(node).to.have.attr(
|
|
250
|
+
'aria-controls',
|
|
251
|
+
`${id}-slds-tabs_panel-${index}`
|
|
252
|
+
);
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it('TabPanel components have proper "aria-labelledby" attribute because they inherit Tabs ID property and append "-slds-tabs_tab-<index>" to it.', function () {
|
|
257
|
+
this.wrapper
|
|
258
|
+
.find(`.${COMPONENT_CSS_CLASSES.panel}`)
|
|
259
|
+
.forEach(function (node, index) {
|
|
260
|
+
expect(node).to.have.attr(
|
|
261
|
+
'aria-labelledby',
|
|
262
|
+
`${id}-slds-tabs_tab-${index}`
|
|
263
|
+
);
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
it('Has the aria-disabled attribute on the second tab.', function () {
|
|
268
|
+
const myTabsListItem = this.wrapper.find(
|
|
269
|
+
`.${COMPONENT_CSS_CLASSES.link}.slds-disabled`
|
|
270
|
+
);
|
|
271
|
+
expect(myTabsListItem).to.have.attr('aria-disabled').equal('true');
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it('Has a tabindex of -1 on the second tab.', function () {
|
|
275
|
+
const myTabsListItem = this.wrapper.find(
|
|
276
|
+
`.${COMPONENT_CSS_CLASSES.item}.slds-disabled a`
|
|
277
|
+
);
|
|
278
|
+
expect(myTabsListItem).to.have.attr('tabindex').equal('-1');
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
describe('Interactions click', () => {
|
|
283
|
+
const id = 'this-is-an-id-for-testing--click';
|
|
284
|
+
|
|
285
|
+
before(mountComponent(<TabsDemoComponent id={id} />));
|
|
286
|
+
after(unmountComponent);
|
|
287
|
+
|
|
288
|
+
it('New panel renders when a tab is clicked ', function () {
|
|
289
|
+
const myTabsListItems = this.wrapper.find(
|
|
290
|
+
`.${COMPONENT_CSS_CLASSES.item}`
|
|
291
|
+
);
|
|
292
|
+
let myFirstPanel = this.wrapper.find(`div#${id}-slds-tabs_panel-0`);
|
|
293
|
+
let myThirdPanel = this.wrapper.find(`div#${id}-slds-tabs_panel-2`);
|
|
294
|
+
|
|
295
|
+
expect(myFirstPanel.hasClass('slds-show')).to.equal(true);
|
|
296
|
+
expect(myFirstPanel.hasClass('slds-hide')).to.equal(false);
|
|
297
|
+
|
|
298
|
+
expect(myThirdPanel.hasClass('slds-show')).to.equal(false);
|
|
299
|
+
expect(myThirdPanel.hasClass('slds-hide')).to.equal(true);
|
|
300
|
+
|
|
301
|
+
myTabsListItems.at(2).simulate('click');
|
|
302
|
+
myFirstPanel = this.wrapper.find(`div#${id}-slds-tabs_panel-0`);
|
|
303
|
+
myThirdPanel = this.wrapper.find(`div#${id}-slds-tabs_panel-2`);
|
|
304
|
+
|
|
305
|
+
expect(myFirstPanel.hasClass('slds-show')).to.equal(false);
|
|
306
|
+
expect(myFirstPanel.hasClass('slds-hide')).to.equal(true);
|
|
307
|
+
|
|
308
|
+
expect(myThirdPanel.hasClass('slds-show')).to.equal(true);
|
|
309
|
+
expect(myThirdPanel.hasClass('slds-hide')).to.equal(false);
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
describe('Interactions disabled', () => {
|
|
314
|
+
const id = 'this-is-an-id-for-testing--disabled';
|
|
315
|
+
|
|
316
|
+
before(mountComponent(<TabsDemoComponent id={id} />));
|
|
317
|
+
after(unmountComponent);
|
|
318
|
+
|
|
319
|
+
it('Disabled tab does not reveal new content ', function () {
|
|
320
|
+
const myTabsListItems = this.wrapper.find(
|
|
321
|
+
`.${COMPONENT_CSS_CLASSES.item}`
|
|
322
|
+
);
|
|
323
|
+
const myFirstPanel = this.wrapper.find(`div#${id}-slds-tabs_panel-0`);
|
|
324
|
+
const mySecondPanel = this.wrapper.find(`div#${id}-slds-tabs_panel-1`);
|
|
325
|
+
|
|
326
|
+
expect(myFirstPanel.hasClass('slds-show')).to.equal(true);
|
|
327
|
+
expect(myFirstPanel.hasClass('slds-hide')).to.equal(false);
|
|
328
|
+
|
|
329
|
+
expect(mySecondPanel.hasClass('slds-show')).to.equal(false);
|
|
330
|
+
expect(mySecondPanel.hasClass('slds-hide')).to.equal(true);
|
|
331
|
+
|
|
332
|
+
myTabsListItems.at(1).simulate('click');
|
|
333
|
+
|
|
334
|
+
expect(myFirstPanel.hasClass('slds-show')).to.equal(true);
|
|
335
|
+
expect(myFirstPanel.hasClass('slds-hide')).to.equal(false);
|
|
336
|
+
|
|
337
|
+
expect(mySecondPanel.hasClass('slds-show')).to.equal(false);
|
|
338
|
+
expect(mySecondPanel.hasClass('slds-hide')).to.equal(true);
|
|
339
|
+
});
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
describe('Interactions tabby', () => {
|
|
343
|
+
const id = 'this-is-an-id-for-testing--tabby';
|
|
344
|
+
|
|
345
|
+
before(mountComponent(<TabsDemoComponent id={id} />));
|
|
346
|
+
after(unmountComponent);
|
|
347
|
+
|
|
348
|
+
it('Can be tabbed into', function () {
|
|
349
|
+
const myTabsListItems = this.wrapper.find(
|
|
350
|
+
`.${COMPONENT_CSS_CLASSES.item}`
|
|
351
|
+
);
|
|
352
|
+
let myFirstPanel = this.wrapper.find(`div#${id}-slds-tabs_panel-0`);
|
|
353
|
+
let myThirdPanel = this.wrapper.find(`div#${id}-slds-tabs_panel-2`);
|
|
354
|
+
|
|
355
|
+
expect(myFirstPanel.hasClass('slds-show')).to.equal(true);
|
|
356
|
+
expect(myFirstPanel.hasClass('slds-hide')).to.equal(false);
|
|
357
|
+
|
|
358
|
+
expect(myThirdPanel.hasClass('slds-show')).to.equal(false);
|
|
359
|
+
expect(myThirdPanel.hasClass('slds-hide')).to.equal(true);
|
|
360
|
+
|
|
361
|
+
myTabsListItems.at(0).simulate('keyDown', {
|
|
362
|
+
key: 'Tab',
|
|
363
|
+
keyCode: 9,
|
|
364
|
+
which: 9,
|
|
365
|
+
});
|
|
366
|
+
myTabsListItems.at(0).simulate('keyDown', {
|
|
367
|
+
key: 'Right',
|
|
368
|
+
keyCode: 39,
|
|
369
|
+
which: 39,
|
|
370
|
+
});
|
|
371
|
+
myFirstPanel = this.wrapper.find(`div#${id}-slds-tabs_panel-0`);
|
|
372
|
+
myThirdPanel = this.wrapper.find(`div#${id}-slds-tabs_panel-2`);
|
|
373
|
+
|
|
374
|
+
expect(myFirstPanel.hasClass('slds-show')).to.equal(false);
|
|
375
|
+
expect(myFirstPanel.hasClass('slds-hide')).to.equal(true);
|
|
376
|
+
|
|
377
|
+
expect(myThirdPanel.hasClass('slds-show')).to.equal(true);
|
|
378
|
+
expect(myThirdPanel.hasClass('slds-hide')).to.equal(false);
|
|
379
|
+
});
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
describe('Interactions tabby disabled', () => {
|
|
383
|
+
const id = 'this-is-an-id-for-testing--tabby-disabled';
|
|
384
|
+
|
|
385
|
+
before(mountComponent(<TabsDemoComponent id={id} />));
|
|
386
|
+
after(unmountComponent);
|
|
387
|
+
|
|
388
|
+
it('Disabled tab can NOT be tabbed into', function () {
|
|
389
|
+
const myTabsListItems = this.wrapper.find(
|
|
390
|
+
`.${COMPONENT_CSS_CLASSES.item}`
|
|
391
|
+
);
|
|
392
|
+
let myFirstPanel = this.wrapper.find(`div#${id}-slds-tabs_panel-0`);
|
|
393
|
+
let mySecondPanel = this.wrapper.find(`div#${id}-slds-tabs_panel-1`);
|
|
394
|
+
|
|
395
|
+
expect(myFirstPanel.hasClass('slds-show')).to.equal(true);
|
|
396
|
+
expect(myFirstPanel.hasClass('slds-hide')).to.equal(false);
|
|
397
|
+
|
|
398
|
+
expect(mySecondPanel.hasClass('slds-show')).to.equal(false);
|
|
399
|
+
expect(mySecondPanel.hasClass('slds-hide')).to.equal(true);
|
|
400
|
+
|
|
401
|
+
myTabsListItems.at(0).simulate('keyDown', {
|
|
402
|
+
key: 'Tab',
|
|
403
|
+
keyCode: 9,
|
|
404
|
+
which: 9,
|
|
405
|
+
});
|
|
406
|
+
myTabsListItems.at(0).simulate('keyDown', {
|
|
407
|
+
key: 'Right',
|
|
408
|
+
keyCode: 39,
|
|
409
|
+
which: 39,
|
|
410
|
+
});
|
|
411
|
+
myFirstPanel = this.wrapper.find(`div#${id}-slds-tabs_panel-0`);
|
|
412
|
+
mySecondPanel = this.wrapper.find(`div#${id}-slds-tabs_panel-1`);
|
|
413
|
+
|
|
414
|
+
expect(myFirstPanel.hasClass('slds-show')).to.equal(false);
|
|
415
|
+
expect(myFirstPanel.hasClass('slds-hide')).to.equal(true);
|
|
416
|
+
|
|
417
|
+
expect(mySecondPanel.hasClass('slds-show')).to.equal(false);
|
|
418
|
+
expect(mySecondPanel.hasClass('slds-hide')).to.equal(true);
|
|
419
|
+
});
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
describe('Interactions intercept tab selection', () => {
|
|
423
|
+
const id = 'this-is-an-id-for-testing--tab-intercept';
|
|
424
|
+
|
|
425
|
+
function interceptTabSelect() {
|
|
426
|
+
return false;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
before(
|
|
430
|
+
mountComponent(
|
|
431
|
+
<TabsDemoComponent id={id} onSelect={interceptTabSelect} />
|
|
432
|
+
)
|
|
433
|
+
);
|
|
434
|
+
after(unmountComponent);
|
|
435
|
+
|
|
436
|
+
it('Maintains the same tab selection when onSelect function returns false', function () {
|
|
437
|
+
const myTabsListItems = this.wrapper.find(
|
|
438
|
+
`.${COMPONENT_CSS_CLASSES.item}`
|
|
439
|
+
);
|
|
440
|
+
const myFirstPanel = this.wrapper.find(`div#${id}-slds-tabs_panel-0`);
|
|
441
|
+
const mySecondPanel = this.wrapper.find(`div#${id}-slds-tabs_panel-1`);
|
|
442
|
+
|
|
443
|
+
expect(myFirstPanel.hasClass('slds-show')).to.equal(true);
|
|
444
|
+
expect(myFirstPanel.hasClass('slds-hide')).to.equal(false);
|
|
445
|
+
|
|
446
|
+
expect(mySecondPanel.hasClass('slds-show')).to.equal(false);
|
|
447
|
+
expect(mySecondPanel.hasClass('slds-hide')).to.equal(true);
|
|
448
|
+
|
|
449
|
+
myTabsListItems.at(1).simulate('click');
|
|
450
|
+
|
|
451
|
+
expect(myFirstPanel.hasClass('slds-show')).to.equal(true);
|
|
452
|
+
expect(myFirstPanel.hasClass('slds-hide')).to.equal(false);
|
|
453
|
+
|
|
454
|
+
expect(mySecondPanel.hasClass('slds-show')).to.equal(false);
|
|
455
|
+
expect(mySecondPanel.hasClass('slds-hide')).to.equal(true);
|
|
456
|
+
});
|
|
457
|
+
});
|
|
458
|
+
});
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/* eslint-disable react/no-render-return-value */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import ReactDOM from 'react-dom';
|
|
4
|
+
import { expect } from 'chai';
|
|
5
|
+
import assign from 'lodash.assign';
|
|
6
|
+
import TestUtils from 'react-dom/test-utils';
|
|
7
|
+
|
|
8
|
+
import Textarea from '../';
|
|
9
|
+
|
|
10
|
+
const {
|
|
11
|
+
findRenderedDOMComponentWithTag,
|
|
12
|
+
findRenderedDOMComponentWithClass,
|
|
13
|
+
} = TestUtils;
|
|
14
|
+
|
|
15
|
+
describe('SLDS TEXTAREA **************************************************', () => {
|
|
16
|
+
const defaultProps = {
|
|
17
|
+
placeholder: 'Placeholder Text',
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
let body;
|
|
21
|
+
|
|
22
|
+
const renderTextarea = (instance) => {
|
|
23
|
+
body = document.createElement('div');
|
|
24
|
+
document.body.appendChild(body);
|
|
25
|
+
return ReactDOM.render(instance, body); // deepscan-disable-line REACT_ASYNC_RENDER_RETURN_VALUE
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
function removeTextarea() {
|
|
29
|
+
ReactDOM.unmountComponentAtNode(body);
|
|
30
|
+
document.body.removeChild(body);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const createTextarea = (props) =>
|
|
34
|
+
React.createElement(Textarea, assign({}, defaultProps, props));
|
|
35
|
+
const getTextarea = (props) => renderTextarea(createTextarea(props));
|
|
36
|
+
|
|
37
|
+
describe('Standard Textarea with Label', () => {
|
|
38
|
+
let component;
|
|
39
|
+
let wrapper;
|
|
40
|
+
let textarea;
|
|
41
|
+
let label;
|
|
42
|
+
|
|
43
|
+
beforeEach(() => {
|
|
44
|
+
component = getTextarea({ label: 'Textarea Label', id: 'custom-id' });
|
|
45
|
+
wrapper = findRenderedDOMComponentWithClass(
|
|
46
|
+
component,
|
|
47
|
+
'slds-form-element'
|
|
48
|
+
);
|
|
49
|
+
textarea = findRenderedDOMComponentWithTag(component, 'textarea');
|
|
50
|
+
label = findRenderedDOMComponentWithClass(
|
|
51
|
+
component,
|
|
52
|
+
'slds-form-element__label'
|
|
53
|
+
);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
afterEach(() => {
|
|
57
|
+
removeTextarea();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('is wrapped in div with class "slds-form-element"', () => {
|
|
61
|
+
expect(wrapper.className).to.include('slds-form-element');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('renders label', () => {
|
|
65
|
+
expect(label.textContent).to.equal('Textarea Label');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('renders textarea element with class "slds-textarea"', () => {
|
|
69
|
+
expect(textarea.className).to.include('slds-textarea');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('has an id', () => {
|
|
73
|
+
expect(textarea.getAttribute('id')).to.be.ok;
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('can pass custom id', () => {
|
|
77
|
+
expect(textarea.getAttribute('id')).to.equal('custom-id');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('renders placeholder text', () => {
|
|
81
|
+
expect(textarea.getAttribute('placeholder')).to.equal('Placeholder Text');
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe('Textarea without Label', () => {
|
|
86
|
+
let component;
|
|
87
|
+
let label;
|
|
88
|
+
|
|
89
|
+
beforeEach(() => {
|
|
90
|
+
component = getTextarea({ assistiveText: { label: 'Assistive Label' } });
|
|
91
|
+
label = findRenderedDOMComponentWithClass(
|
|
92
|
+
component,
|
|
93
|
+
'slds-form-element__label'
|
|
94
|
+
);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
afterEach(() => {
|
|
98
|
+
removeTextarea();
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('renders label (assitive)', () => {
|
|
102
|
+
expect(label.textContent).to.equal('Assistive Label');
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('label has class "slds-assistive-text"', () => {
|
|
106
|
+
expect(label.className).to.include('slds-assistive-text');
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
describe('Multiple Textareas', () => {
|
|
111
|
+
let component1;
|
|
112
|
+
let component2;
|
|
113
|
+
let textarea1;
|
|
114
|
+
let textarea2;
|
|
115
|
+
|
|
116
|
+
beforeEach(() => {
|
|
117
|
+
component1 = getTextarea({ label: 'Textarea One' });
|
|
118
|
+
component2 = getTextarea({ label: 'Textarea Two' });
|
|
119
|
+
textarea1 = findRenderedDOMComponentWithTag(component1, 'textarea');
|
|
120
|
+
textarea2 = findRenderedDOMComponentWithTag(component2, 'textarea');
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
afterEach(() => {
|
|
124
|
+
const inputNodes = document.querySelectorAll('.slds-form-element');
|
|
125
|
+
inputNodes[0].parentNode.remove(inputNodes[0]);
|
|
126
|
+
inputNodes[1].parentNode.remove(inputNodes[1]);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('each textarea has unique generated id', () => {
|
|
130
|
+
expect(textarea1.getAttribute('id')).to.not.equal(
|
|
131
|
+
textarea2.getAttribute('id')
|
|
132
|
+
);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
describe('Required Textarea in Error State', () => {
|
|
137
|
+
let component;
|
|
138
|
+
let wrapper;
|
|
139
|
+
let error;
|
|
140
|
+
|
|
141
|
+
beforeEach(() => {
|
|
142
|
+
component = getTextarea({
|
|
143
|
+
label: 'Textarea Label',
|
|
144
|
+
required: true,
|
|
145
|
+
errorText: 'Error Message',
|
|
146
|
+
});
|
|
147
|
+
wrapper = findRenderedDOMComponentWithClass(
|
|
148
|
+
component,
|
|
149
|
+
'slds-form-element'
|
|
150
|
+
);
|
|
151
|
+
error = findRenderedDOMComponentWithClass(
|
|
152
|
+
component,
|
|
153
|
+
'slds-form-element__help'
|
|
154
|
+
);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
afterEach(() => {
|
|
158
|
+
removeTextarea();
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('textarea wrapper contains an <abbr> that has class "slds-required"', () => {
|
|
162
|
+
expect(
|
|
163
|
+
findRenderedDOMComponentWithTag(component, 'abbr').className
|
|
164
|
+
).to.include('slds-required');
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('textarea wrapper has class "slds-has-error"', () => {
|
|
168
|
+
expect(wrapper.className).to.include('slds-has-error');
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('renders error message', () => {
|
|
172
|
+
expect(error.textContent).to.equal('Error Message');
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/* eslint-disable react/no-string-refs */
|
|
2
|
+
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import TestUtils from 'react-dom/test-utils';
|
|
5
|
+
|
|
6
|
+
import SLDSTimepicker from '../../time-picker';
|
|
7
|
+
import IconSettings from '../../icon-settings';
|
|
8
|
+
|
|
9
|
+
const formatter = (date) =>
|
|
10
|
+
date.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' });
|
|
11
|
+
const dateTimeNow = new Date();
|
|
12
|
+
const defaultStrValue = formatter(dateTimeNow);
|
|
13
|
+
|
|
14
|
+
const defaultProps = {
|
|
15
|
+
onDateChange: () => {},
|
|
16
|
+
value: dateTimeNow,
|
|
17
|
+
strValue: defaultStrValue,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
describe('SLDSTimepicker: ', () => {
|
|
21
|
+
describe('Timepicker Value Prop Change', () => {
|
|
22
|
+
it('displays a modified state upon changing props', () => {
|
|
23
|
+
const futureDateTime = new Date(
|
|
24
|
+
new Date().getTime() + 24 * 60 * 60 * 1000
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
const TestTimepicker = class extends React.Component {
|
|
28
|
+
state = {
|
|
29
|
+
isOpen: false,
|
|
30
|
+
value: futureDateTime,
|
|
31
|
+
strValue: formatter(futureDateTime),
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
render() {
|
|
35
|
+
return (
|
|
36
|
+
<IconSettings iconPath="/assets/icons">
|
|
37
|
+
<SLDSTimepicker ref="timePicker" {...defaultProps} />
|
|
38
|
+
</IconSettings>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const parent = TestUtils.renderIntoDocument(<TestTimepicker />);
|
|
43
|
+
parent.refs.timePicker.state.strValue.should.eql(defaultStrValue);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
});
|