@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,122 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import chai, { expect } from 'chai';
|
|
4
|
+
import chaiEnzyme from 'chai-enzyme';
|
|
5
|
+
import { mount } from 'enzyme';
|
|
6
|
+
|
|
7
|
+
/* Enzyme Helpers that can mount and unmount React component instances to
|
|
8
|
+
* the DOM and set `this.wrapper` and `this.dom` within Mocha's `this`
|
|
9
|
+
* context [full source here](tests/enzyme-helpers.js). `this` can
|
|
10
|
+
* only be referenced if inside `function () {}`.
|
|
11
|
+
*/
|
|
12
|
+
import {
|
|
13
|
+
createMountNode,
|
|
14
|
+
destroyMountNode,
|
|
15
|
+
} from '../../../tests/enzyme-helpers';
|
|
16
|
+
|
|
17
|
+
import RadioButtonGroup from '../../radio-button-group';
|
|
18
|
+
import Radio from '../../radio-button-group/radio';
|
|
19
|
+
|
|
20
|
+
chai.use(chaiEnzyme());
|
|
21
|
+
|
|
22
|
+
/* Re-usable demo component.
|
|
23
|
+
*/
|
|
24
|
+
class RadioButtonGroupExample extends React.Component {
|
|
25
|
+
constructor(props) {
|
|
26
|
+
super(props);
|
|
27
|
+
this.state = { checked: 'Tue' };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
render() {
|
|
31
|
+
const days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'];
|
|
32
|
+
return (
|
|
33
|
+
<RadioButtonGroup
|
|
34
|
+
labels={this.props.labels}
|
|
35
|
+
onChange={(event) => this.setState({ checked: event.target.value })}
|
|
36
|
+
disabled={this.props.disabled}
|
|
37
|
+
required={this.props.required}
|
|
38
|
+
>
|
|
39
|
+
{days.map((day) => (
|
|
40
|
+
<Radio
|
|
41
|
+
key={day}
|
|
42
|
+
labels={{ label: day }}
|
|
43
|
+
value={day}
|
|
44
|
+
checked={this.state.checked === day}
|
|
45
|
+
variant="button-group"
|
|
46
|
+
/>
|
|
47
|
+
))}
|
|
48
|
+
</RadioButtonGroup>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
RadioButtonGroupExample.propTypes = {
|
|
54
|
+
labels: PropTypes.shape({
|
|
55
|
+
error: PropTypes.string,
|
|
56
|
+
label: PropTypes.string,
|
|
57
|
+
}),
|
|
58
|
+
disabled: PropTypes.bool,
|
|
59
|
+
required: PropTypes.bool,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
RadioButtonGroupExample.defaultProps = {
|
|
63
|
+
labels: { label: 'Day of week' },
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/* RadioButtonGroup rendering tests
|
|
67
|
+
*/
|
|
68
|
+
describe('RadioButtonGroup', function () {
|
|
69
|
+
let mountNode;
|
|
70
|
+
let wrapper;
|
|
71
|
+
|
|
72
|
+
beforeEach(() => {
|
|
73
|
+
mountNode = createMountNode({ context: this });
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
afterEach(() => {
|
|
77
|
+
destroyMountNode({ wrapper, mountNode });
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('renders a radio button group', () => {
|
|
81
|
+
wrapper = mount(<RadioButtonGroupExample />, { attachTo: mountNode });
|
|
82
|
+
const radios = wrapper.find(Radio);
|
|
83
|
+
expect(radios).to.have.lengthOf(5, 'there are five radio inputs');
|
|
84
|
+
radios.forEach((radioWrapper, index) => {
|
|
85
|
+
const radio = radios.get(index);
|
|
86
|
+
expect(radio.props.checked).to.equal(
|
|
87
|
+
radio.props.labels.label === 'Tue',
|
|
88
|
+
'the second radio input is checked'
|
|
89
|
+
);
|
|
90
|
+
});
|
|
91
|
+
const legend = wrapper.find('legend');
|
|
92
|
+
expect(legend.text()).to.equal('Day of week', 'there is a label');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('renders a disabled state', () => {
|
|
96
|
+
wrapper = mount(<RadioButtonGroupExample disabled />, {
|
|
97
|
+
attachTo: mountNode,
|
|
98
|
+
});
|
|
99
|
+
const radios = wrapper.find(Radio);
|
|
100
|
+
radios.forEach((radioWrapper, index) => {
|
|
101
|
+
const radio = radios.get(index);
|
|
102
|
+
expect(radio.props.disabled, 'all radio inputs are disabled').to.be.true;
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('renders a required indicator', () => {
|
|
107
|
+
wrapper = mount(<RadioButtonGroupExample required />, {
|
|
108
|
+
attachTo: mountNode,
|
|
109
|
+
});
|
|
110
|
+
const abbr = wrapper.find('abbr');
|
|
111
|
+
expect(abbr.text()).to.equal('*Required ', 'there is a required indicator');
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('triggers a change callback', () => {
|
|
115
|
+
wrapper = mount(<RadioButtonGroupExample />, { attachTo: mountNode });
|
|
116
|
+
let radio = wrapper.find({ value: 'Mon' }).find('input');
|
|
117
|
+
expect(radio.props().checked).to.be.false;
|
|
118
|
+
radio.simulate('change', { event: { target: 'Mon' } });
|
|
119
|
+
radio = wrapper.find({ value: 'Mon' }).find('input');
|
|
120
|
+
expect(radio).to.have.prop('checked', true);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import chai, { expect } from 'chai';
|
|
4
|
+
import chaiEnzyme from 'chai-enzyme';
|
|
5
|
+
import { mount } from 'enzyme';
|
|
6
|
+
|
|
7
|
+
/* Enzyme Helpers that can mount and unmount React component instances to
|
|
8
|
+
* the DOM and set `this.wrapper` and `this.dom` within Mocha's `this`
|
|
9
|
+
* context [full source here](tests/enzyme-helpers.js). `this` can
|
|
10
|
+
* only be referenced if inside `function () {}`.
|
|
11
|
+
*/
|
|
12
|
+
import {
|
|
13
|
+
createMountNode,
|
|
14
|
+
destroyMountNode,
|
|
15
|
+
} from '../../../tests/enzyme-helpers';
|
|
16
|
+
|
|
17
|
+
import RadioGroup from '../../radio-group';
|
|
18
|
+
import Radio from '../../radio-group/radio';
|
|
19
|
+
|
|
20
|
+
chai.use(chaiEnzyme());
|
|
21
|
+
|
|
22
|
+
/* Re-usable demo component.
|
|
23
|
+
*/
|
|
24
|
+
class RadioGroupExample extends React.Component {
|
|
25
|
+
constructor(props) {
|
|
26
|
+
super(props);
|
|
27
|
+
this.state = { checked: 'Radio Label One' };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
render() {
|
|
31
|
+
const values = ['Radio Label One', 'Radio Label Two'];
|
|
32
|
+
return (
|
|
33
|
+
<RadioGroup
|
|
34
|
+
labels={this.props.labels}
|
|
35
|
+
onChange={(event) => this.setState({ checked: event.target.value })}
|
|
36
|
+
disabled={this.props.disabled}
|
|
37
|
+
required={this.props.required}
|
|
38
|
+
>
|
|
39
|
+
{values.map((value) => (
|
|
40
|
+
<Radio
|
|
41
|
+
key={value}
|
|
42
|
+
labels={{ label: value }}
|
|
43
|
+
value={value}
|
|
44
|
+
checked={this.state.checked === value}
|
|
45
|
+
variant="base"
|
|
46
|
+
/>
|
|
47
|
+
))}
|
|
48
|
+
</RadioGroup>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
RadioGroupExample.propTypes = {
|
|
54
|
+
labels: PropTypes.shape({
|
|
55
|
+
error: PropTypes.string,
|
|
56
|
+
label: PropTypes.string,
|
|
57
|
+
}),
|
|
58
|
+
disabled: PropTypes.bool,
|
|
59
|
+
required: PropTypes.bool,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
RadioGroupExample.defaultProps = {
|
|
63
|
+
labels: { label: 'Radio Group Label' },
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/* RadioGroup rendering tests
|
|
67
|
+
*/
|
|
68
|
+
describe('RadioGroup', function () {
|
|
69
|
+
let mountNode;
|
|
70
|
+
let wrapper;
|
|
71
|
+
|
|
72
|
+
beforeEach(() => {
|
|
73
|
+
mountNode = createMountNode({ context: this });
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
afterEach(() => {
|
|
77
|
+
destroyMountNode({ wrapper, mountNode });
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('renders a radio group', () => {
|
|
81
|
+
wrapper = mount(<RadioGroupExample />, { attachTo: mountNode });
|
|
82
|
+
const radios = wrapper.find(Radio);
|
|
83
|
+
expect(radios).to.have.lengthOf(2, 'there are 2 radio inputs');
|
|
84
|
+
radios.forEach((radioWrapper, index) => {
|
|
85
|
+
const radio = radios.get(index);
|
|
86
|
+
expect(radio.props.checked).to.equal(
|
|
87
|
+
radio.props.labels.label === 'Radio Label One',
|
|
88
|
+
'the second radio input is checked'
|
|
89
|
+
);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const legend = wrapper.find('legend');
|
|
93
|
+
expect(legend.text()).to.equal('Radio Group Label', 'there is a label');
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('renders a disabled state', () => {
|
|
97
|
+
wrapper = mount(<RadioGroupExample disabled />, { attachTo: mountNode });
|
|
98
|
+
const radios = wrapper.find(Radio);
|
|
99
|
+
radios.forEach((radioWrapper, index) => {
|
|
100
|
+
const radio = radios.get(index);
|
|
101
|
+
expect(radio.props.disabled, 'all radio inputs are disabled').to.be.true;
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('renders a required indicator', () => {
|
|
106
|
+
wrapper = mount(<RadioGroupExample required />, { attachTo: mountNode });
|
|
107
|
+
const abbr = wrapper.find('abbr');
|
|
108
|
+
expect(abbr.text()).to.equal('*Required ', 'there is a required indicator');
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('triggers a change callback', () => {
|
|
112
|
+
wrapper = mount(<RadioGroupExample />, { attachTo: mountNode });
|
|
113
|
+
let radio = wrapper.find({ value: 'Radio Label Two' }).find('input');
|
|
114
|
+
expect(radio).to.have.prop('checked', false);
|
|
115
|
+
radio.simulate('change', { event: { target: 'Radio Label Two' } });
|
|
116
|
+
radio = wrapper.find({ value: 'Radio Label Two' }).find('input');
|
|
117
|
+
expect(radio).to.have.prop('checked', true);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { expect } from 'chai';
|
|
3
|
+
import { mount } from 'enzyme';
|
|
4
|
+
|
|
5
|
+
import IconSettings from '../../icon-settings';
|
|
6
|
+
import SetupAssistant from '../../setup-assistant';
|
|
7
|
+
import SetupAssistantStep from '../../setup-assistant/step';
|
|
8
|
+
|
|
9
|
+
/* eslint-disable react/no-find-dom-node */
|
|
10
|
+
|
|
11
|
+
describe('SLDS Setup Assistant', () => {
|
|
12
|
+
const handles = {
|
|
13
|
+
setupAssistant: null,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
describe('Setup Assistant & Setup Assistant Step events', () => {
|
|
17
|
+
let onStepToggleIsOpenObject;
|
|
18
|
+
let onToggleIsOpenObject;
|
|
19
|
+
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
handles.setupAssistant = mount(
|
|
22
|
+
<IconSettings iconPath="/assets/icons">
|
|
23
|
+
<SetupAssistant
|
|
24
|
+
id="setup-assistant-event-test-1"
|
|
25
|
+
onStepToggleIsOpen={(event, data) => {
|
|
26
|
+
onStepToggleIsOpenObject = { event, data };
|
|
27
|
+
}}
|
|
28
|
+
>
|
|
29
|
+
<SetupAssistantStep
|
|
30
|
+
heading="Setup Assistant Step Heading"
|
|
31
|
+
id="setup-assistant-event-test-1-step-1"
|
|
32
|
+
isExpandable
|
|
33
|
+
isOpen
|
|
34
|
+
/>
|
|
35
|
+
<SetupAssistantStep
|
|
36
|
+
heading="Setup Assistant Step Heading"
|
|
37
|
+
id="setup-assistant-event-test-1-step-2"
|
|
38
|
+
isExpandable
|
|
39
|
+
isOpen
|
|
40
|
+
onToggleIsOpen={(event, data) => {
|
|
41
|
+
onToggleIsOpenObject = { event, data };
|
|
42
|
+
}}
|
|
43
|
+
/>
|
|
44
|
+
</SetupAssistant>
|
|
45
|
+
</IconSettings>
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('renders setup assistant', () => {
|
|
50
|
+
expect(handles.setupAssistant.length).to.equal(1);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('handles onStepToggleIsOpen correctly', () => {
|
|
54
|
+
const expandButton = handles.setupAssistant.find(
|
|
55
|
+
'#setup-assistant-event-test-1-step-1 .slds-setup-assistant__step-summary-title button'
|
|
56
|
+
);
|
|
57
|
+
expandButton.simulate('click');
|
|
58
|
+
expect(typeof onStepToggleIsOpenObject.event).to.eql('object');
|
|
59
|
+
expect(typeof onStepToggleIsOpenObject.data).to.eql('object');
|
|
60
|
+
expect(onStepToggleIsOpenObject.data.index).to.eql(0);
|
|
61
|
+
expect(onStepToggleIsOpenObject.data.isOpen).to.eql(true);
|
|
62
|
+
expect(typeof onStepToggleIsOpenObject.data.step).to.eql('object');
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('handles onToggleIsOpen correctly', () => {
|
|
66
|
+
const expandButton = handles.setupAssistant.find(
|
|
67
|
+
'#setup-assistant-event-test-1-step-2 .slds-setup-assistant__step-summary-title button'
|
|
68
|
+
);
|
|
69
|
+
expandButton.simulate('click');
|
|
70
|
+
expect(typeof onToggleIsOpenObject.event).to.eql('object');
|
|
71
|
+
expect(typeof onToggleIsOpenObject.data).to.eql('object');
|
|
72
|
+
expect(onToggleIsOpenObject.data.index).to.eql(1);
|
|
73
|
+
expect(onToggleIsOpenObject.data.isOpen).to.eql(true);
|
|
74
|
+
expect(typeof onToggleIsOpenObject.data.step).to.eql('object');
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
});
|
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
/* eslint-disable react/no-render-return-value */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import ReactDOM from 'react-dom';
|
|
4
|
+
import chai, { expect } from 'chai';
|
|
5
|
+
import chaiEnzyme from 'chai-enzyme';
|
|
6
|
+
import assign from 'lodash.assign';
|
|
7
|
+
import TestUtils from 'react-dom/test-utils';
|
|
8
|
+
import { mount } from 'enzyme';
|
|
9
|
+
|
|
10
|
+
/* Enzyme Helpers that can mount and unmount React component instances to
|
|
11
|
+
* the DOM and set `this.wrapper` and `this.dom` within Mocha's `this`
|
|
12
|
+
* context [full source here](tests/enzyme-helpers.js). `this` can
|
|
13
|
+
* only be referenced if inside `function () {}`.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import {
|
|
17
|
+
createMountNode,
|
|
18
|
+
destroyMountNode,
|
|
19
|
+
} from '../../../tests/enzyme-helpers';
|
|
20
|
+
|
|
21
|
+
import Slider from '../../slider';
|
|
22
|
+
|
|
23
|
+
/* Set Chai to use chaiEnzyme for enzyme compatible assertions:
|
|
24
|
+
* https://github.com/producthunt/chai-enzyme
|
|
25
|
+
*/
|
|
26
|
+
chai.use(chaiEnzyme());
|
|
27
|
+
|
|
28
|
+
const {
|
|
29
|
+
findRenderedDOMComponentWithTag,
|
|
30
|
+
findRenderedDOMComponentWithClass,
|
|
31
|
+
} = TestUtils;
|
|
32
|
+
|
|
33
|
+
describe('SLDSSlider', () => {
|
|
34
|
+
const defaultProps = {};
|
|
35
|
+
|
|
36
|
+
let body;
|
|
37
|
+
let body2;
|
|
38
|
+
|
|
39
|
+
const renderSlider = (instance) => {
|
|
40
|
+
body = document.createElement('div');
|
|
41
|
+
document.body.appendChild(body);
|
|
42
|
+
return ReactDOM.render(instance, body); // deepscan-disable-line REACT_ASYNC_RENDER_RETURN_VALUE
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const renderSecondSlider = (instance) => {
|
|
46
|
+
body2 = document.createElement('div');
|
|
47
|
+
document.body.appendChild(body2);
|
|
48
|
+
return ReactDOM.render(instance, body2); // deepscan-disable-line REACT_ASYNC_RENDER_RETURN_VALUE
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
function removeSlider() {
|
|
52
|
+
ReactDOM.unmountComponentAtNode(body);
|
|
53
|
+
document.body.removeChild(body);
|
|
54
|
+
if (body2 && body2.firstChild) {
|
|
55
|
+
ReactDOM.unmountComponentAtNode(body2);
|
|
56
|
+
document.body.removeChild(body2);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const createSlider = (props) =>
|
|
61
|
+
React.createElement(Slider, assign({}, defaultProps, props));
|
|
62
|
+
const getSlider = (props) => renderSlider(createSlider(props));
|
|
63
|
+
const getSecondSlider = (props) => renderSecondSlider(createSlider(props));
|
|
64
|
+
|
|
65
|
+
describe('Standard Slider with Label', () => {
|
|
66
|
+
let component;
|
|
67
|
+
let wrapper;
|
|
68
|
+
let slider;
|
|
69
|
+
let label;
|
|
70
|
+
let labelText;
|
|
71
|
+
|
|
72
|
+
beforeEach(() => {
|
|
73
|
+
component = getSlider({ label: 'Slider Label', id: 'custom-id' });
|
|
74
|
+
wrapper = findRenderedDOMComponentWithClass(
|
|
75
|
+
component,
|
|
76
|
+
'slds-form-element'
|
|
77
|
+
);
|
|
78
|
+
slider = findRenderedDOMComponentWithTag(component, 'input');
|
|
79
|
+
label = findRenderedDOMComponentWithClass(
|
|
80
|
+
component,
|
|
81
|
+
'slds-form-element__label'
|
|
82
|
+
);
|
|
83
|
+
labelText = findRenderedDOMComponentWithClass(
|
|
84
|
+
component,
|
|
85
|
+
'slds-slider-label__label'
|
|
86
|
+
);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
afterEach(() => {
|
|
90
|
+
removeSlider();
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('has type of "range"', () => {
|
|
94
|
+
expect(slider.getAttribute('type')).to.equal('range');
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('is wrapped in div with class "slds-form-element"', () => {
|
|
98
|
+
expect(wrapper.className).to.include('slds-form-element');
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('renders label', () => {
|
|
102
|
+
expect(labelText.textContent).to.equal('Slider Label');
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('renders slider element with class "slds-slider"', () => {
|
|
106
|
+
expect(slider.className).to.include('slds-slider');
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('has an id', () => {
|
|
110
|
+
expect(slider.getAttribute('id')).to.be.ok;
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('can pass custom id', () => {
|
|
114
|
+
expect(slider.getAttribute('id')).to.equal('custom-id');
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('has associated label for tag pointing to id of slider', () => {
|
|
118
|
+
const labelForTag = label.getAttribute('for');
|
|
119
|
+
const sliderId = slider.getAttribute('id');
|
|
120
|
+
expect(labelForTag).to.equal(sliderId);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
describe('Component basic props', () => {
|
|
125
|
+
let component;
|
|
126
|
+
let slider;
|
|
127
|
+
let labelRange;
|
|
128
|
+
let sliderValue;
|
|
129
|
+
|
|
130
|
+
beforeEach(() => {
|
|
131
|
+
component = getSlider({
|
|
132
|
+
label: 'Slider Label',
|
|
133
|
+
id: 'custom-id',
|
|
134
|
+
value: 200,
|
|
135
|
+
min: 0,
|
|
136
|
+
max: 400,
|
|
137
|
+
step: 100,
|
|
138
|
+
});
|
|
139
|
+
slider = findRenderedDOMComponentWithTag(component, 'input');
|
|
140
|
+
labelRange = findRenderedDOMComponentWithClass(
|
|
141
|
+
component,
|
|
142
|
+
'slds-slider-label__range'
|
|
143
|
+
);
|
|
144
|
+
sliderValue = findRenderedDOMComponentWithClass(
|
|
145
|
+
component,
|
|
146
|
+
'slds-slider__value'
|
|
147
|
+
);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
afterEach(() => {
|
|
151
|
+
removeSlider();
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('has min', () => {
|
|
155
|
+
expect(slider.getAttribute('min')).to.equal('0');
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('has max', () => {
|
|
159
|
+
expect(slider.getAttribute('max')).to.equal('400');
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('min/max matches label range', () => {
|
|
163
|
+
expect(labelRange.textContent).to.equal('0 - 400');
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('has step', () => {
|
|
167
|
+
expect(slider.getAttribute('step')).to.equal('100');
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('has value', () => {
|
|
171
|
+
expect(slider.getAttribute('value')).to.equal('200');
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it('value matches slider value label', () => {
|
|
175
|
+
expect(slider.value).to.equal(sliderValue.textContent);
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
describe('onInput, onChange callbacks are set', function () {
|
|
180
|
+
let mountNode;
|
|
181
|
+
let wrapper;
|
|
182
|
+
|
|
183
|
+
beforeEach(() => {
|
|
184
|
+
mountNode = createMountNode({ context: this });
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
afterEach(() => {
|
|
188
|
+
destroyMountNode({ wrapper, mountNode });
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it('onChange trigged callback', function (done) {
|
|
192
|
+
wrapper = mount(
|
|
193
|
+
<Slider
|
|
194
|
+
value={200}
|
|
195
|
+
min={0}
|
|
196
|
+
max={400}
|
|
197
|
+
step={100}
|
|
198
|
+
onChange={(e, { value }) => {
|
|
199
|
+
expect(value).to.equal(300);
|
|
200
|
+
done();
|
|
201
|
+
}}
|
|
202
|
+
/>,
|
|
203
|
+
{ attachTo: mountNode }
|
|
204
|
+
);
|
|
205
|
+
const trigger = wrapper.find('input');
|
|
206
|
+
trigger.simulate('change', { target: { value: 300 } });
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('onInput trigged callback', function (done) {
|
|
210
|
+
wrapper = mount(
|
|
211
|
+
<Slider
|
|
212
|
+
value={200}
|
|
213
|
+
min={0}
|
|
214
|
+
max={400}
|
|
215
|
+
step={100}
|
|
216
|
+
onInput={(e, { value }) => {
|
|
217
|
+
expect(value).to.equal(300);
|
|
218
|
+
done();
|
|
219
|
+
}}
|
|
220
|
+
/>,
|
|
221
|
+
{ attachTo: mountNode }
|
|
222
|
+
);
|
|
223
|
+
const trigger = wrapper.find('input');
|
|
224
|
+
trigger.simulate('input', { target: { value: '300' } });
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
describe('Slider with Assistive Text Label', () => {
|
|
229
|
+
let component;
|
|
230
|
+
let slider;
|
|
231
|
+
let label;
|
|
232
|
+
let labelText;
|
|
233
|
+
|
|
234
|
+
beforeEach(() => {
|
|
235
|
+
component = getSlider({ assistiveText: { label: 'Assistive Label' } });
|
|
236
|
+
slider = findRenderedDOMComponentWithTag(component, 'input');
|
|
237
|
+
label = findRenderedDOMComponentWithClass(
|
|
238
|
+
component,
|
|
239
|
+
'slds-form-element__label'
|
|
240
|
+
);
|
|
241
|
+
labelText = findRenderedDOMComponentWithClass(
|
|
242
|
+
component,
|
|
243
|
+
'slds-slider-label__label'
|
|
244
|
+
);
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
afterEach(() => {
|
|
248
|
+
removeSlider();
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
it('renders label (assitive)', () => {
|
|
252
|
+
expect(labelText.textContent).to.equal('Assistive Label');
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it('label has class "slds-assistive-text"', () => {
|
|
256
|
+
expect(label.className).to.include('slds-assistive-text');
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it('has associated label for tag pointing to id of slider', () => {
|
|
260
|
+
const labelForTag = label.getAttribute('for');
|
|
261
|
+
const sliderId = slider.getAttribute('id');
|
|
262
|
+
expect(labelForTag).to.equal(sliderId);
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
describe('Disabled slider', () => {
|
|
267
|
+
let component;
|
|
268
|
+
let slider;
|
|
269
|
+
|
|
270
|
+
beforeEach(() => {
|
|
271
|
+
component = getSlider({ label: 'Slider Label', disabled: true });
|
|
272
|
+
slider = findRenderedDOMComponentWithTag(component, 'input');
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
afterEach(() => {
|
|
276
|
+
removeSlider();
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it('slider has attribute "disabled"', () => {
|
|
280
|
+
expect(slider.getAttribute('disabled')).to.exist;
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
describe('Slider size', () => {
|
|
285
|
+
let component;
|
|
286
|
+
let container;
|
|
287
|
+
|
|
288
|
+
beforeEach(() => {
|
|
289
|
+
component = getSlider({
|
|
290
|
+
id: 'custom-id',
|
|
291
|
+
label: 'Slider Label',
|
|
292
|
+
size: 'medium',
|
|
293
|
+
});
|
|
294
|
+
container = findRenderedDOMComponentWithClass(component, 'slds-slider');
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
afterEach(() => {
|
|
298
|
+
removeSlider();
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
it('renders size class', () => {
|
|
302
|
+
expect(container.className).to.include('slds-size_medium');
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
describe('Multiple sliders', () => {
|
|
307
|
+
let component1;
|
|
308
|
+
let component2;
|
|
309
|
+
let slider1;
|
|
310
|
+
let slider2;
|
|
311
|
+
|
|
312
|
+
beforeEach(() => {
|
|
313
|
+
component1 = getSlider({ label: 'Slider One' });
|
|
314
|
+
component2 = getSecondSlider({ label: 'Slider Two' });
|
|
315
|
+
slider1 = findRenderedDOMComponentWithTag(component1, 'input');
|
|
316
|
+
slider2 = findRenderedDOMComponentWithTag(component2, 'input');
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
afterEach(() => {
|
|
320
|
+
removeSlider();
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
it('each slider has unique generated id', () => {
|
|
324
|
+
expect(slider1.getAttribute('id')).to.not.equal(
|
|
325
|
+
slider2.getAttribute('id')
|
|
326
|
+
);
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
describe('Required slider in Error State', () => {
|
|
331
|
+
let component;
|
|
332
|
+
let wrapper;
|
|
333
|
+
let error;
|
|
334
|
+
let slider;
|
|
335
|
+
|
|
336
|
+
beforeEach(() => {
|
|
337
|
+
component = getSlider({
|
|
338
|
+
label: 'Slider Label',
|
|
339
|
+
required: true,
|
|
340
|
+
errorText: 'Error Message',
|
|
341
|
+
});
|
|
342
|
+
wrapper = findRenderedDOMComponentWithClass(
|
|
343
|
+
component,
|
|
344
|
+
'slds-form-element'
|
|
345
|
+
);
|
|
346
|
+
error = findRenderedDOMComponentWithClass(
|
|
347
|
+
component,
|
|
348
|
+
'slds-form-element__help'
|
|
349
|
+
);
|
|
350
|
+
slider = findRenderedDOMComponentWithTag(component, 'input');
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
afterEach(() => {
|
|
354
|
+
removeSlider();
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
it('slider wrapper has class "slds-has-error"', () => {
|
|
358
|
+
expect(wrapper.className).to.include('slds-has-error');
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
it('renders error message', () => {
|
|
362
|
+
expect(error.textContent).to.equal('Error Message');
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
it('has associated aria-describedby pointing to id of error message', () => {
|
|
366
|
+
const sliderDescribedBy = slider.getAttribute('aria-describedby');
|
|
367
|
+
const errorId = error.getAttribute('id');
|
|
368
|
+
expect(sliderDescribedBy).to.equal(errorId);
|
|
369
|
+
});
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
describe('Vertical slider', () => {
|
|
373
|
+
let component;
|
|
374
|
+
let container;
|
|
375
|
+
|
|
376
|
+
beforeEach(() => {
|
|
377
|
+
component = getSlider({ label: 'Slider Label', vertical: true });
|
|
378
|
+
container = findRenderedDOMComponentWithClass(component, 'slds-slider');
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
afterEach(() => {
|
|
382
|
+
removeSlider();
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
it('slider has class "slds-slider_vertical"', () => {
|
|
386
|
+
expect(container.className).to.include('slds-slider_vertical');
|
|
387
|
+
});
|
|
388
|
+
});
|
|
389
|
+
});
|