@salesforce/design-system-react 0.10.50-alpha.1 → 0.10.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,497 @@
|
|
|
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 moment from 'moment';
|
|
8
|
+
import { mount } from 'enzyme';
|
|
9
|
+
import IconSettings from '../../icon-settings';
|
|
10
|
+
|
|
11
|
+
// Import your internal dependencies (for example):
|
|
12
|
+
import Datepicker from '../../date-picker';
|
|
13
|
+
import Input from '../../input';
|
|
14
|
+
import KEYS from '../../../utilities/key-code';
|
|
15
|
+
|
|
16
|
+
// eslint-disable-next-line camelcase
|
|
17
|
+
import UNSAFE_DirectionSettings from '../../utilities/UNSAFE_direction';
|
|
18
|
+
|
|
19
|
+
const makeRtl = (component) => (
|
|
20
|
+
// eslint-disable-next-line
|
|
21
|
+
<UNSAFE_DirectionSettings.Provider value="rtl">
|
|
22
|
+
<div dir="rtl">{component}</div>
|
|
23
|
+
</UNSAFE_DirectionSettings.Provider>
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
/* Set Chai to use chaiEnzyme for enzyme compatible assertions:
|
|
27
|
+
* https://github.com/producthunt/chai-enzyme
|
|
28
|
+
*/
|
|
29
|
+
chai.use(chaiEnzyme());
|
|
30
|
+
|
|
31
|
+
const defaultProps = {
|
|
32
|
+
id: 'sample-datepicker',
|
|
33
|
+
value: new Date(2007, 0, 6),
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/* A re-usable demo component fixture outside of `describe` sections
|
|
37
|
+
* can accept props within each test and be unmounted after each tests.
|
|
38
|
+
* This wrapping component will be similar to your wrapping component
|
|
39
|
+
* you will create in the React Storybook for manual testing.
|
|
40
|
+
*/
|
|
41
|
+
class DemoComponent extends React.Component {
|
|
42
|
+
static displayName = 'DatepickerDemoComponent';
|
|
43
|
+
|
|
44
|
+
static propTypes = {
|
|
45
|
+
isOpen: PropTypes.bool,
|
|
46
|
+
isRtl: PropTypes.bool,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
static defaultProps = defaultProps;
|
|
50
|
+
|
|
51
|
+
state = {};
|
|
52
|
+
|
|
53
|
+
// event handlers
|
|
54
|
+
|
|
55
|
+
render() {
|
|
56
|
+
const component = (
|
|
57
|
+
<IconSettings iconPath="/assets/icons">
|
|
58
|
+
<Datepicker
|
|
59
|
+
formatter={(date) => {
|
|
60
|
+
return date ? moment(date).format('M/D/YYYY') : '';
|
|
61
|
+
}}
|
|
62
|
+
parser={(dateString) => {
|
|
63
|
+
return moment(dateString, 'MM-DD-YYYY').toDate();
|
|
64
|
+
}}
|
|
65
|
+
{...this.props}
|
|
66
|
+
/>
|
|
67
|
+
</IconSettings>
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
return this.props.isRtl ? makeRtl(component) : component;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/* All tests for component being tested should be wrapped in a root `describe`,
|
|
75
|
+
* which should be named after the component being tested.
|
|
76
|
+
* When read aloud, the cumulative `describe` and `it` names should form a coherent
|
|
77
|
+
* sentence, eg "Date Picker default structure and css is present with expected
|
|
78
|
+
* attributes set". If you are having trouble constructing a cumulative short
|
|
79
|
+
* sentence, this may be an indicator that your test is poorly structured.
|
|
80
|
+
* String provided as first parameter names the `describe` section. Limit to nouns
|
|
81
|
+
* as much as possible/appropriate.`
|
|
82
|
+
*/
|
|
83
|
+
describe('SLDSDatepicker', function describeFunction() {
|
|
84
|
+
let wrapper;
|
|
85
|
+
|
|
86
|
+
const triggerClassSelector = 'button.slds-input__icon';
|
|
87
|
+
|
|
88
|
+
describe('Assistive technology', () => {
|
|
89
|
+
afterEach(() => wrapper.unmount());
|
|
90
|
+
|
|
91
|
+
it('has aria-haspopup, correct aria-expanded on input trigger.', function () {
|
|
92
|
+
wrapper = mount(<DemoComponent isOpen />);
|
|
93
|
+
|
|
94
|
+
const inputTrigger = wrapper.find(triggerClassSelector);
|
|
95
|
+
expect(inputTrigger).to.have.attr('aria-haspopup', 'true');
|
|
96
|
+
|
|
97
|
+
const ariaExpanded = inputTrigger.find('button');
|
|
98
|
+
expect(ariaExpanded).to.have.attr('aria-expanded', 'true');
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// PROPS AND CHILDREN
|
|
103
|
+
|
|
104
|
+
describe('Optional props', () => {
|
|
105
|
+
const customPlaceholder = 'With custom Input';
|
|
106
|
+
const optionalProps = {
|
|
107
|
+
input: <Input placeholder={customPlaceholder} />,
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
afterEach(() => wrapper.unmount());
|
|
111
|
+
|
|
112
|
+
it('has custom input with custom placeholder', function () {
|
|
113
|
+
wrapper = mount(<DemoComponent {...optionalProps} />);
|
|
114
|
+
|
|
115
|
+
expect(wrapper.find('input')).to.have.attr(
|
|
116
|
+
'placeholder',
|
|
117
|
+
customPlaceholder
|
|
118
|
+
);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// EVENTS
|
|
123
|
+
|
|
124
|
+
describe('onClose, onRequestClose, onOpen callbacks are set', function describeFunction2() {
|
|
125
|
+
afterEach(() => wrapper.unmount());
|
|
126
|
+
|
|
127
|
+
it('onOpen is executed when trigger is clicked, onClose is executed when date is selected', function (done) {
|
|
128
|
+
wrapper = mount(
|
|
129
|
+
<DemoComponent
|
|
130
|
+
menuPosition="relative"
|
|
131
|
+
onClose={() => {
|
|
132
|
+
setTimeout(() => {
|
|
133
|
+
const month = wrapper.find('.datepicker__month');
|
|
134
|
+
expect(month).to.not.be.present;
|
|
135
|
+
done();
|
|
136
|
+
}, 0);
|
|
137
|
+
}}
|
|
138
|
+
onRequestClose={() => {
|
|
139
|
+
const month = wrapper.find('.datepicker__month');
|
|
140
|
+
expect(month).to.be.present;
|
|
141
|
+
}}
|
|
142
|
+
onOpen={() => {
|
|
143
|
+
setTimeout(() => {
|
|
144
|
+
const firstDayOfMonth = wrapper
|
|
145
|
+
.find('.datepicker__month [aria-disabled=false]')
|
|
146
|
+
.first();
|
|
147
|
+
expect(firstDayOfMonth).to.be.present;
|
|
148
|
+
firstDayOfMonth.simulate('click', {});
|
|
149
|
+
}, 0);
|
|
150
|
+
}}
|
|
151
|
+
/>
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
const trigger = wrapper.find(triggerClassSelector);
|
|
155
|
+
trigger.simulate('click', {});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('onChange is triggered when date is selected', function (done) {
|
|
159
|
+
wrapper = mount(
|
|
160
|
+
<DemoComponent
|
|
161
|
+
menuPosition="relative"
|
|
162
|
+
onChange={(event, data) => {
|
|
163
|
+
setTimeout(() => {
|
|
164
|
+
// test callback parameters
|
|
165
|
+
expect(data.date.getTime()).to.equal(
|
|
166
|
+
new Date('1/1/2007').getTime()
|
|
167
|
+
);
|
|
168
|
+
expect(data.formattedDate).to.equal('1/1/2007');
|
|
169
|
+
|
|
170
|
+
done();
|
|
171
|
+
}, 0);
|
|
172
|
+
}}
|
|
173
|
+
onOpen={() => {
|
|
174
|
+
setTimeout(() => {
|
|
175
|
+
const firstDayOfMonth = wrapper
|
|
176
|
+
.find('.datepicker__month [aria-disabled=false]')
|
|
177
|
+
.first();
|
|
178
|
+
expect(firstDayOfMonth).to.exist;
|
|
179
|
+
firstDayOfMonth.simulate('click', {});
|
|
180
|
+
});
|
|
181
|
+
}}
|
|
182
|
+
/>
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
const trigger = wrapper.find(triggerClassSelector);
|
|
186
|
+
trigger.simulate('click', {});
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
describe('keyboard interactions', () => {
|
|
191
|
+
/* Test event callback functions using Simulate. For more information, view
|
|
192
|
+
* https://github.com/airbnb/enzyme/blob/master/docs/api/ReactWrapper/simulate.md
|
|
193
|
+
*/
|
|
194
|
+
describe('Esc when menu is open', function () {
|
|
195
|
+
afterEach(() => wrapper.unmount());
|
|
196
|
+
|
|
197
|
+
it('opens on trigger click, closes on ESC', function (done) {
|
|
198
|
+
wrapper = mount(
|
|
199
|
+
<DemoComponent
|
|
200
|
+
menuPosition="relative"
|
|
201
|
+
onClose={() => {
|
|
202
|
+
setTimeout(() => {
|
|
203
|
+
const month = wrapper.find('.datepicker__month');
|
|
204
|
+
expect(month).to.not.be.present;
|
|
205
|
+
done();
|
|
206
|
+
}, 0);
|
|
207
|
+
}}
|
|
208
|
+
onOpen={() => {
|
|
209
|
+
setTimeout(() => {
|
|
210
|
+
const firstDayOfMonth = wrapper
|
|
211
|
+
.find('.datepicker__month [aria-disabled=false]')
|
|
212
|
+
.first();
|
|
213
|
+
firstDayOfMonth.simulate('keyDown', {
|
|
214
|
+
key: 'Esc',
|
|
215
|
+
keyCode: KEYS.ESCAPE,
|
|
216
|
+
which: KEYS.ESCAPE,
|
|
217
|
+
});
|
|
218
|
+
}, 0);
|
|
219
|
+
}}
|
|
220
|
+
/>
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
const trigger = wrapper.find(triggerClassSelector);
|
|
224
|
+
trigger.simulate('click', {});
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it('navigates to next week', function (done) {
|
|
228
|
+
wrapper = mount(
|
|
229
|
+
<DemoComponent
|
|
230
|
+
isOpen
|
|
231
|
+
menuPosition="relative"
|
|
232
|
+
onCalendarFocus={(event, data) => {
|
|
233
|
+
expect(data.date.getTime()).to.equal(
|
|
234
|
+
new Date(2007, 0, 13).getTime()
|
|
235
|
+
);
|
|
236
|
+
done();
|
|
237
|
+
}}
|
|
238
|
+
/>
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
const selectedDay = wrapper.find(
|
|
242
|
+
'.datepicker__month [aria-selected=true]'
|
|
243
|
+
);
|
|
244
|
+
selectedDay.simulate('keyDown', {
|
|
245
|
+
key: 'Down',
|
|
246
|
+
keyCode: KEYS.DOWN,
|
|
247
|
+
which: KEYS.DOWN,
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
it('navigates to next day', function (done) {
|
|
252
|
+
wrapper = mount(
|
|
253
|
+
<DemoComponent
|
|
254
|
+
isOpen
|
|
255
|
+
menuPosition="relative"
|
|
256
|
+
onCalendarFocus={(event, data) => {
|
|
257
|
+
expect(data.date.getTime()).to.equal(
|
|
258
|
+
new Date(2007, 0, 7).getTime()
|
|
259
|
+
);
|
|
260
|
+
done();
|
|
261
|
+
}}
|
|
262
|
+
/>
|
|
263
|
+
);
|
|
264
|
+
|
|
265
|
+
const selectedDay = wrapper.find(
|
|
266
|
+
'.datepicker__month [aria-selected=true]'
|
|
267
|
+
);
|
|
268
|
+
selectedDay.simulate('keyDown', {
|
|
269
|
+
key: 'Right',
|
|
270
|
+
keyCode: KEYS.RIGHT,
|
|
271
|
+
which: KEYS.RIGHT,
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it('navigates to next day with the opposite button for RTL', function (done) {
|
|
276
|
+
wrapper = mount(
|
|
277
|
+
<DemoComponent
|
|
278
|
+
isRtl
|
|
279
|
+
isOpen
|
|
280
|
+
menuPosition="relative"
|
|
281
|
+
onCalendarFocus={(event, data) => {
|
|
282
|
+
expect(data.date.getTime()).to.equal(
|
|
283
|
+
new Date(2007, 0, 7).getTime()
|
|
284
|
+
);
|
|
285
|
+
done();
|
|
286
|
+
}}
|
|
287
|
+
/>
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
const selectedDay = wrapper.find(
|
|
291
|
+
'.datepicker__month [aria-selected=true]'
|
|
292
|
+
);
|
|
293
|
+
selectedDay.simulate('keyDown', {
|
|
294
|
+
key: 'Left',
|
|
295
|
+
keyCode: KEYS.LEFT,
|
|
296
|
+
which: KEYS.LEFT,
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
it('navigates to previous week (that is of a previous month)', function (done) {
|
|
301
|
+
wrapper = mount(
|
|
302
|
+
<DemoComponent
|
|
303
|
+
isOpen
|
|
304
|
+
menuPosition="relative"
|
|
305
|
+
onCalendarFocus={(event, data) => {
|
|
306
|
+
expect(data.date.getTime()).to.equal(
|
|
307
|
+
new Date(2006, 11, 30).getTime()
|
|
308
|
+
);
|
|
309
|
+
done();
|
|
310
|
+
}}
|
|
311
|
+
/>
|
|
312
|
+
);
|
|
313
|
+
|
|
314
|
+
const selectedDay = wrapper.find(
|
|
315
|
+
'.datepicker__month [aria-selected=true]'
|
|
316
|
+
);
|
|
317
|
+
selectedDay.simulate('keyDown', {
|
|
318
|
+
key: 'Up',
|
|
319
|
+
keyCode: KEYS.UP,
|
|
320
|
+
which: KEYS.UP,
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
it('navigates to previous day', function (done) {
|
|
325
|
+
wrapper = mount(
|
|
326
|
+
<DemoComponent
|
|
327
|
+
isOpen
|
|
328
|
+
menuPosition="relative"
|
|
329
|
+
onCalendarFocus={(event, data) => {
|
|
330
|
+
expect(data.date.getTime()).to.equal(
|
|
331
|
+
new Date(2007, 0, 5).getTime()
|
|
332
|
+
);
|
|
333
|
+
done();
|
|
334
|
+
}}
|
|
335
|
+
/>
|
|
336
|
+
);
|
|
337
|
+
|
|
338
|
+
const selectedDay = wrapper.find(
|
|
339
|
+
'.datepicker__month [aria-selected=true]'
|
|
340
|
+
);
|
|
341
|
+
selectedDay.simulate('keyDown', {
|
|
342
|
+
key: 'Left',
|
|
343
|
+
keyCode: KEYS.LEFT,
|
|
344
|
+
which: KEYS.LEFT,
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
it('navigates to previous day with the opposite button for RTL', function (done) {
|
|
349
|
+
wrapper = mount(
|
|
350
|
+
<DemoComponent
|
|
351
|
+
isRtl
|
|
352
|
+
isOpen
|
|
353
|
+
menuPosition="relative"
|
|
354
|
+
onCalendarFocus={(event, data) => {
|
|
355
|
+
expect(data.date.getTime()).to.equal(
|
|
356
|
+
new Date(2007, 0, 5).getTime()
|
|
357
|
+
);
|
|
358
|
+
done();
|
|
359
|
+
}}
|
|
360
|
+
/>
|
|
361
|
+
);
|
|
362
|
+
|
|
363
|
+
const selectedDay = wrapper.find(
|
|
364
|
+
'.datepicker__month [aria-selected=true]'
|
|
365
|
+
);
|
|
366
|
+
selectedDay.simulate('keyDown', {
|
|
367
|
+
key: 'Right',
|
|
368
|
+
keyCode: KEYS.RIGHT,
|
|
369
|
+
which: KEYS.RIGHT,
|
|
370
|
+
});
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
it('calendar blur, focus on previous month button', function (done) {
|
|
374
|
+
wrapper = mount(
|
|
375
|
+
<DemoComponent
|
|
376
|
+
isOpen
|
|
377
|
+
menuPosition="relative"
|
|
378
|
+
onCalendarFocus={(event, data) => {
|
|
379
|
+
expect(data.ref.textContent).to.equal('Previous month');
|
|
380
|
+
done();
|
|
381
|
+
}}
|
|
382
|
+
/>
|
|
383
|
+
);
|
|
384
|
+
|
|
385
|
+
const selectedDay = wrapper.find(
|
|
386
|
+
'.datepicker__month [aria-selected=true]'
|
|
387
|
+
);
|
|
388
|
+
selectedDay.simulate('keyDown', {
|
|
389
|
+
key: 'Tab',
|
|
390
|
+
keyCode: KEYS.TAB,
|
|
391
|
+
which: KEYS.TAB,
|
|
392
|
+
});
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
it('calendar blur, focus on today', function (done) {
|
|
396
|
+
wrapper = mount(
|
|
397
|
+
<DemoComponent
|
|
398
|
+
isOpen
|
|
399
|
+
menuPosition="relative"
|
|
400
|
+
onCalendarFocus={(event, data) => {
|
|
401
|
+
expect(data.ref.textContent).to.equal('Today');
|
|
402
|
+
done();
|
|
403
|
+
}}
|
|
404
|
+
/>
|
|
405
|
+
);
|
|
406
|
+
|
|
407
|
+
const selectedDay = wrapper.find(
|
|
408
|
+
'.datepicker__month [aria-selected=true]'
|
|
409
|
+
);
|
|
410
|
+
selectedDay.simulate('keyDown', {
|
|
411
|
+
key: 'Tab',
|
|
412
|
+
keyCode: KEYS.TAB,
|
|
413
|
+
shiftKey: true,
|
|
414
|
+
which: KEYS.TAB,
|
|
415
|
+
});
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
it('typing in input closes calendar', function () {
|
|
419
|
+
wrapper = mount(<DemoComponent menuPosition="relative" />);
|
|
420
|
+
|
|
421
|
+
// Calendar is closed
|
|
422
|
+
expect(wrapper.find('.slds-datepicker').length).to.equal(0);
|
|
423
|
+
|
|
424
|
+
// Click on input to open the calendar
|
|
425
|
+
const trigger = wrapper.find(triggerClassSelector);
|
|
426
|
+
trigger.simulate('click', {});
|
|
427
|
+
expect(wrapper.find('.slds-datepicker').length).to.equal(1);
|
|
428
|
+
|
|
429
|
+
// Changing input value closes the calendar
|
|
430
|
+
const input = wrapper.find('input#sample-datepicker');
|
|
431
|
+
input.simulate('change', { target: { value: '1/1/2020' } });
|
|
432
|
+
expect(wrapper.find('.slds-datepicker').length).to.equal(0);
|
|
433
|
+
});
|
|
434
|
+
});
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
describe('Disabled', function describeFunction2() {
|
|
438
|
+
const triggerClicked = sinon.spy();
|
|
439
|
+
const dialogOpened = sinon.spy();
|
|
440
|
+
|
|
441
|
+
afterEach(() => wrapper.unmount());
|
|
442
|
+
|
|
443
|
+
it('onOpen is not called when disabled', function () {
|
|
444
|
+
wrapper = mount(
|
|
445
|
+
<DemoComponent
|
|
446
|
+
disabled
|
|
447
|
+
menuPosition="relative"
|
|
448
|
+
onClick={triggerClicked}
|
|
449
|
+
onOpen={dialogOpened}
|
|
450
|
+
/>
|
|
451
|
+
);
|
|
452
|
+
|
|
453
|
+
wrapper.simulate('click', {});
|
|
454
|
+
|
|
455
|
+
expect(dialogOpened.callCount).to.equal(0);
|
|
456
|
+
});
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
describe('Disable dates', () => {
|
|
460
|
+
afterEach(() => wrapper.unmount());
|
|
461
|
+
|
|
462
|
+
it('disable weekends', (done) => {
|
|
463
|
+
// this only tests if onChange fires
|
|
464
|
+
const handleChangeSpy = sinon.spy();
|
|
465
|
+
wrapper = mount(
|
|
466
|
+
<DemoComponent
|
|
467
|
+
isOpen
|
|
468
|
+
menuPosition="relative"
|
|
469
|
+
value={new Date(2007, 0, 5)}
|
|
470
|
+
dateDisabled={({ date }) => date.getDay() > 5 || date.getDay() < 1}
|
|
471
|
+
onChange={handleChangeSpy}
|
|
472
|
+
/>
|
|
473
|
+
);
|
|
474
|
+
|
|
475
|
+
const input = wrapper.find('input').first();
|
|
476
|
+
expect(input).to.have.value('1/5/2007');
|
|
477
|
+
|
|
478
|
+
const disabledDay = wrapper
|
|
479
|
+
.find('.datepicker__month [aria-disabled=true]')
|
|
480
|
+
.first();
|
|
481
|
+
disabledDay.simulate('click', {});
|
|
482
|
+
|
|
483
|
+
expect(handleChangeSpy.calledOnce).to.equal(false);
|
|
484
|
+
|
|
485
|
+
const day = wrapper
|
|
486
|
+
.find('.datepicker__month [aria-disabled=false]')
|
|
487
|
+
.first();
|
|
488
|
+
day.simulate('click', {});
|
|
489
|
+
|
|
490
|
+
expect(handleChangeSpy.calledOnce).to.equal(true);
|
|
491
|
+
done();
|
|
492
|
+
|
|
493
|
+
const trigger = wrapper.find(triggerClassSelector);
|
|
494
|
+
trigger.simulate('click', {});
|
|
495
|
+
});
|
|
496
|
+
});
|
|
497
|
+
});
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/* eslint-env jest */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import moment from 'moment';
|
|
4
|
+
import renderer from 'react-test-renderer';
|
|
5
|
+
import { renderMarkup } from '../../../tests/snapshot-helpers';
|
|
6
|
+
|
|
7
|
+
import SnapshotDefault from '../__examples__/snapshot-default';
|
|
8
|
+
|
|
9
|
+
// eslint-disable-next-line camelcase
|
|
10
|
+
import UNSAFE_DirectionSettings from '../../utilities/UNSAFE_direction';
|
|
11
|
+
|
|
12
|
+
const makeRtl = (component) => (
|
|
13
|
+
// eslint-disable-next-line
|
|
14
|
+
<UNSAFE_DirectionSettings.Provider value="rtl">
|
|
15
|
+
<div dir="rtl">{component}</div>
|
|
16
|
+
</UNSAFE_DirectionSettings.Provider>
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
test('Datepicker Default DOM Snapshot', () => {
|
|
20
|
+
const domTree = renderer.create(<SnapshotDefault />).toJSON();
|
|
21
|
+
expect(domTree).toMatchSnapshot();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('Datepicker Default HTML Snapshot', () => {
|
|
25
|
+
expect(renderMarkup(SnapshotDefault)).toMatchSnapshot();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const customProps = {
|
|
29
|
+
align: 'right',
|
|
30
|
+
assistiveText: {
|
|
31
|
+
openCalendar: 'CUSTOM open Calendar',
|
|
32
|
+
nextMonth: 'CUSTOM next month',
|
|
33
|
+
previousMonth: 'CUSTOM previous month',
|
|
34
|
+
},
|
|
35
|
+
className: 'CUSTOM-CLASSNAME',
|
|
36
|
+
formatter() {
|
|
37
|
+
return "Llama and Lamb's epiphany of love";
|
|
38
|
+
},
|
|
39
|
+
id: 'CUSTOM-ID',
|
|
40
|
+
labels: {
|
|
41
|
+
abbreviatedWeekDays: ['ONE', 'TWO', 'THR', 'FOU', 'FIV', 'SIX', 'SEV'],
|
|
42
|
+
label: 'Date',
|
|
43
|
+
months: [
|
|
44
|
+
'MONTH 1',
|
|
45
|
+
'MONTH 2',
|
|
46
|
+
'MONTH 3',
|
|
47
|
+
'MONTH 4',
|
|
48
|
+
'MONTH 5',
|
|
49
|
+
'MONTH 6',
|
|
50
|
+
'MONTH 7',
|
|
51
|
+
'MONTH 8',
|
|
52
|
+
'MONTH 9',
|
|
53
|
+
'MONTH 10',
|
|
54
|
+
'MONTH 11',
|
|
55
|
+
'MONTH 12',
|
|
56
|
+
],
|
|
57
|
+
placeholder: 'SWIPE RIGHT :-)',
|
|
58
|
+
today: 'TODAY YOU ARE YOU!',
|
|
59
|
+
weekDays: ['Day 1', 'Day 2', 'Day 3', 'Day 4', 'Day 5', 'Day 6', 'Day 7'],
|
|
60
|
+
},
|
|
61
|
+
parser() {
|
|
62
|
+
return moment('1/6/2007', 'MM-DD-YYYY').toDate();
|
|
63
|
+
},
|
|
64
|
+
relativeYearFrom: -20,
|
|
65
|
+
relativeYearTo: 20,
|
|
66
|
+
triggerClassName: 'CUSTOM-TRIGGER-CLASSNAME',
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
test(`Datepicker
|
|
70
|
+
abbreviatedWeekDayLabels,
|
|
71
|
+
assistiveTextNextMonth,
|
|
72
|
+
assistiveTextOpenCalendar,
|
|
73
|
+
assistiveTextPreviousMonth,
|
|
74
|
+
align,
|
|
75
|
+
className,
|
|
76
|
+
formatter,
|
|
77
|
+
monthLabels,
|
|
78
|
+
placeholder,
|
|
79
|
+
relativeYearFrom,
|
|
80
|
+
relativeYearTo,
|
|
81
|
+
todayLabel,
|
|
82
|
+
triggerClassName,
|
|
83
|
+
weekDayLabels
|
|
84
|
+
DOM Snapshot`, () => {
|
|
85
|
+
const domTree = renderer
|
|
86
|
+
.create(<SnapshotDefault {...customProps} />)
|
|
87
|
+
.toJSON();
|
|
88
|
+
expect(domTree).toMatchSnapshot();
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test(`Datepicker
|
|
92
|
+
Right-to-Left (RTL)`, () => {
|
|
93
|
+
const domTree = renderer
|
|
94
|
+
.create(makeRtl(<SnapshotDefault {...customProps} />))
|
|
95
|
+
.toJSON();
|
|
96
|
+
expect(domTree).toMatchSnapshot();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test(`Datepicker
|
|
100
|
+
isIsoWeekday
|
|
101
|
+
DOM Snapshot`, () => {
|
|
102
|
+
const domTree = renderer.create(<SnapshotDefault isIsoWeekday />).toJSON();
|
|
103
|
+
expect(domTree).toMatchSnapshot();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test('ErrorPicker', () => {
|
|
107
|
+
const domTree = renderer.create(<SnapshotDefault hasError />).toJSON();
|
|
108
|
+
expect(domTree).toMatchSnapshot();
|
|
109
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import chai, { expect } from 'chai';
|
|
4
|
+
import chaiEnzyme from 'chai-enzyme';
|
|
5
|
+
import { mount } from 'enzyme';
|
|
6
|
+
import IconSettings from '../../icon-settings';
|
|
7
|
+
import DockedComposer from '../../docked-composer';
|
|
8
|
+
|
|
9
|
+
chai.use(chaiEnzyme());
|
|
10
|
+
class DemoComponent extends React.Component {
|
|
11
|
+
static displayName = 'DockedComposerDemoComponent';
|
|
12
|
+
|
|
13
|
+
state = {
|
|
14
|
+
isOpen: true,
|
|
15
|
+
isClosed: false,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
handleMinimize = () => {
|
|
19
|
+
this.setState({ isOpen: false });
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
handleExpand = () => {
|
|
23
|
+
this.setState({ isOpen: true });
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
handleClose = () => {
|
|
27
|
+
this.setState({ isClosed: true });
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
render() {
|
|
31
|
+
const component = (
|
|
32
|
+
<IconSettings iconPath="/assets/icons">
|
|
33
|
+
<DockedComposer
|
|
34
|
+
header="What's New this Release?"
|
|
35
|
+
body={<div id="composer-body">Hello</div>}
|
|
36
|
+
id="docked-composer-demo"
|
|
37
|
+
events={{
|
|
38
|
+
onRequestMinimize: this.handleMinimize,
|
|
39
|
+
onRequestExpand: this.handleExpand,
|
|
40
|
+
onRequestClose: this.handleClose,
|
|
41
|
+
}}
|
|
42
|
+
isOpen={this.state.isOpen}
|
|
43
|
+
/>
|
|
44
|
+
<div id={this.state.isOpen ? 'open' : 'collapsed'} />
|
|
45
|
+
<div id={this.state.isClosed ? 'closed' : 'notClosed'} />
|
|
46
|
+
</IconSettings>
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
return component;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
describe('SLDSDockedComposer', function describeFunction() {
|
|
54
|
+
let wrapper;
|
|
55
|
+
|
|
56
|
+
it('onRequestMinimize, onRequestExpand, onRequestClose callbacks', () => {
|
|
57
|
+
wrapper = mount(<DemoComponent />);
|
|
58
|
+
|
|
59
|
+
// Composer should be initially open
|
|
60
|
+
expect(wrapper.find('#open')).to.have.length(1);
|
|
61
|
+
expect(wrapper.find('#closed')).to.have.length(0);
|
|
62
|
+
|
|
63
|
+
// Click the minimize button
|
|
64
|
+
wrapper
|
|
65
|
+
.find('button#docked-composer-demo-minimize-button')
|
|
66
|
+
.simulate('click');
|
|
67
|
+
|
|
68
|
+
expect(wrapper.find('#collapsed')).to.have.length(1);
|
|
69
|
+
expect(wrapper.find('#closed')).to.have.length(0);
|
|
70
|
+
|
|
71
|
+
// Click the expand button now
|
|
72
|
+
wrapper.find('button#docked-composer-demo-expand-button').simulate('click');
|
|
73
|
+
|
|
74
|
+
expect(wrapper.find('#open')).to.have.length(1);
|
|
75
|
+
expect(wrapper.find('#closed')).to.have.length(0);
|
|
76
|
+
|
|
77
|
+
// Clicking the close button sets the close state
|
|
78
|
+
wrapper.find('button#docked-composer-demo-close-button').simulate('click');
|
|
79
|
+
|
|
80
|
+
expect(wrapper.find('#open')).to.have.length(1);
|
|
81
|
+
expect(wrapper.find('#closed')).to.have.length(1);
|
|
82
|
+
});
|
|
83
|
+
});
|