@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.
Files changed (69) hide show
  1. package/components/accordion/__tests__/accordion.browser-test.jsx +302 -0
  2. package/components/alert/__tests__/alert.browser-test.jsx +100 -0
  3. package/components/app-launcher/__tests__/app-launcher.browser-test.jsx +228 -0
  4. package/components/app-launcher/__tests__/expandable-section.browser-test.jsx +144 -0
  5. package/components/app-launcher/__tests__/link.browser-test.jsx +107 -0
  6. package/components/app-launcher/__tests__/tile.browser-test.jsx +267 -0
  7. package/components/avatar/__tests__/avatar.browser-test.jsx +207 -0
  8. package/components/builder-header/__tests__/builder-header.browser-test.jsx +53 -0
  9. package/components/button/__tests__/button.browser-test.jsx +226 -0
  10. package/components/button-group/__tests__/button-group.browser-test.jsx +144 -0
  11. package/components/button-stateful/__tests__/button-stateful.browser-test.jsx +125 -0
  12. package/components/card/__tests__/card.browser-test.jsx +255 -0
  13. package/components/carousel/__tests__/carousel.browser-test.jsx +527 -0
  14. package/components/color-picker/__tests__/color-picker.browser-test.jsx +767 -0
  15. package/components/combobox/__tests__/combobox.browser-test.jsx +654 -0
  16. package/components/data-table/__tests__/data-table.browser-test.jsx +1051 -0
  17. package/components/date-picker/__tests__/__snapshots__/datepicker.dom-snapshot-test.jsx.snap +4429 -0
  18. package/components/date-picker/__tests__/date-picker.browser-test.jsx +497 -0
  19. package/components/date-picker/__tests__/datepicker.dom-snapshot-test.jsx +109 -0
  20. package/components/docked-composer/__tests__/docked-composer.browser-test.jsx +83 -0
  21. package/components/expandable-section/__tests__/expandable-section.browser-test.jsx +133 -0
  22. package/components/expression/__tests__/expression.browser-test.jsx +255 -0
  23. package/components/filter/__tests__/filter.browser-test.jsx +147 -0
  24. package/components/forms/input/__tests__/inline.browser-test.jsx +164 -0
  25. package/components/global-header/__tests__/global-header.browser-test.jsx +177 -0
  26. package/components/global-navigation-bar/__tests__/global-navigation-bar.browser-test.jsx +464 -0
  27. package/components/icon/__tests__/icon.browser-test.jsx +214 -0
  28. package/components/illustration/__tests__/illustration.browser-test.jsx +177 -0
  29. package/components/input/__tests__/input.browser-test.jsx +612 -0
  30. package/components/location-map/__tests__/location-map.browser-test.jsx +158 -0
  31. package/components/lookup/__tests__/lookup.browser-test.jsx +353 -0
  32. package/components/media-object/__tests__/media-object.browser-test.jsx +87 -0
  33. package/components/menu-dropdown/__tests__/dropdown.browser-test.jsx +588 -0
  34. package/components/menu-picklist/__tests__/menupicklist.snapshot-old-test.jsx +41 -0
  35. package/components/menu-picklist/__tests__/picklist-base.browser-test.jsx +275 -0
  36. package/components/modal/__tests__/modal.browser-test.jsx +333 -0
  37. package/components/notification/__tests__/notification.browser-test.jsx +113 -0
  38. package/components/page-header/__tests__/page-header.browser-test.jsx +161 -0
  39. package/components/panel/__tests__/__snapshots__/filtering.dom-snapshot-test.jsx.snap +298 -0
  40. package/components/panel/__tests__/filtering.dom-snapshot-test.jsx +9 -0
  41. package/components/pill/__tests__/pill.browser-test.jsx +308 -0
  42. package/components/pill-container/__tests__/pill-container.browser-test.jsx +186 -0
  43. package/components/popover/__tests__/popover.browser-test.jsx +327 -0
  44. package/components/progress-indicator/__tests__/progress-indicator.browser-test.jsx +335 -0
  45. package/components/radio-button-group/__tests__/radio-button-group.browser-test.jsx +122 -0
  46. package/components/radio-group/__tests__/radio-group.browser-test.jsx +119 -0
  47. package/components/setup-assistant/__tests__/setup-assistant.browser-test.jsx +77 -0
  48. package/components/slider/__tests__/slider.browser-test.jsx +389 -0
  49. package/components/spinner/__tests__/spinner.browser-test.jsx +57 -0
  50. package/components/split-view/__tests__/split-view.listbox.browser-test.jsx +225 -0
  51. package/components/split-view/__tests__/split-view.listbox.header.browser-test.jsx +158 -0
  52. package/components/split-view/__tests__/split-view.listbox.unread.browser-test.jsx +114 -0
  53. package/components/tabs/__tests__/tabs.browser-test.jsx +458 -0
  54. package/components/textarea/__tests__/textarea.browser-test.jsx +175 -0
  55. package/components/time-picker/__tests__/time-picker.browser-test.jsx +46 -0
  56. package/components/toast/__tests__/toast.browser-test.jsx +118 -0
  57. package/components/tooltip/__tests__/tooltip.browser-test.jsx +214 -0
  58. package/components/tree/__tests__/tree.browser-test.jsx +303 -0
  59. package/components/vertical-navigation/__tests__/navigation.browser-test.jsx +117 -0
  60. package/components/visual-picker/__tests__/visual-picker.browser-test.jsx +288 -0
  61. package/components/welcome-mat/__tests__/welcome-mat.browser-test.jsx +358 -0
  62. package/design-system-react-components.js +1 -1
  63. package/design-system-react-components.min.js.LICENSE.txt +1 -1
  64. package/design-system-react.js +1 -1
  65. package/design-system-react.min.js.LICENSE.txt +1 -1
  66. package/lib/design-system-react-components.min.js.LICENSE.txt +1 -1
  67. package/lib/design-system-react.min.js.LICENSE.txt +1 -1
  68. package/lib/package.json +1 -1
  69. package/package.json +1 -1
@@ -0,0 +1,767 @@
1
+ /* eslint-disable max-lines */
2
+ import React from 'react';
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 your internal dependencies (for example):
18
+ import ColorPicker from '../index';
19
+ import KEYS from '../../../utilities/key-code';
20
+
21
+ // eslint-disable-next-line camelcase
22
+ import UNSAFE_DirectionSettings from '../../utilities/UNSAFE_direction';
23
+
24
+ const makeRtl = (component) => (
25
+ // eslint-disable-next-line
26
+ <UNSAFE_DirectionSettings.Provider value="rtl">
27
+ <div dir="rtl">{component}</div>
28
+ </UNSAFE_DirectionSettings.Provider>
29
+ );
30
+
31
+ chai.use(chaiEnzyme());
32
+
33
+ const selectors = {
34
+ cancel: '.slds-color-picker__selector-cancel',
35
+ customError: '.slds-color-picker__input-custom-error',
36
+ customHex: '.slds-color-picker__input-custom-hex',
37
+ customRed: '.slds-color-picker__input-custom-r',
38
+ gridPoint: '.slds-color-picker__range-indicator',
39
+ hueSlider: '.slds-color-picker__hue-slider',
40
+ popover: '.slds-color-picker__selector',
41
+ summaryInput: '.slds-color-picker__summary-input input',
42
+ submit: '.slds-color-picker__selector-submit',
43
+ svGrid: '.slds-color-picker__custom-range',
44
+ swatch: '.slds-color-picker__swatch-trigger',
45
+ toggle: '.slds-color-picker__summary-button',
46
+ };
47
+
48
+ describe('SLDSColorPicker', function describeFunction() {
49
+ let mountNode;
50
+ let wrapper;
51
+
52
+ beforeEach(() => {
53
+ mountNode = createMountNode({ context: this });
54
+ });
55
+
56
+ afterEach(() => {
57
+ destroyMountNode({ wrapper, mountNode });
58
+ });
59
+
60
+ describe('Summary input', () => {
61
+ it('fires onChange with value and isValid set to true when valid', function () {
62
+ wrapper = mount(
63
+ <ColorPicker
64
+ events={{
65
+ onChange: (event, { color, isValid }) => {
66
+ expect(color).to.equal('#ff0000');
67
+ expect(isValid).to.be.true;
68
+ },
69
+ }}
70
+ />,
71
+ { attachTo: mountNode }
72
+ );
73
+
74
+ const input = wrapper.find(selectors.summaryInput).first();
75
+
76
+ input.simulate('change', {
77
+ target: {
78
+ value: '#ff0000',
79
+ },
80
+ });
81
+ });
82
+
83
+ it('fires onChange with named value and isValid set to true when valid', function () {
84
+ wrapper = mount(
85
+ <ColorPicker
86
+ events={{
87
+ onChange: (event, { color, isValid }) => {
88
+ expect(color).to.equal('red');
89
+ expect(isValid).to.be.true;
90
+ },
91
+ }}
92
+ />,
93
+ { attachTo: mountNode }
94
+ );
95
+
96
+ const input = wrapper.find(selectors.summaryInput).first();
97
+
98
+ input.simulate('change', {
99
+ target: {
100
+ value: 'red',
101
+ },
102
+ });
103
+ });
104
+
105
+ it('fires onChange with value and isValid set to false when invalid', function () {
106
+ wrapper = mount(
107
+ <ColorPicker
108
+ events={{
109
+ onChange: (event, { color, isValid }) => {
110
+ expect(color).to.equal('invalid');
111
+ expect(isValid).to.be.false;
112
+ },
113
+ }}
114
+ />,
115
+ { attachTo: mountNode }
116
+ );
117
+
118
+ const input = wrapper.find(selectors.summaryInput).first();
119
+
120
+ input.simulate('change', {
121
+ target: {
122
+ value: 'invalid',
123
+ },
124
+ });
125
+ });
126
+
127
+ it('fires onValidateColor when input changes', function () {
128
+ const customValidator = sinon.spy();
129
+
130
+ wrapper = mount(
131
+ <ColorPicker
132
+ events={{
133
+ onValidateColor: (hex) => {
134
+ customValidator(hex);
135
+ },
136
+ }}
137
+ />,
138
+ { attachTo: mountNode }
139
+ );
140
+
141
+ const input = wrapper.find(selectors.summaryInput).first();
142
+
143
+ input.simulate('change', {
144
+ target: {
145
+ value: '#FFFFFF',
146
+ },
147
+ });
148
+
149
+ expect(customValidator.calledWithExactly('#FFFFFF')).to.be.true;
150
+ });
151
+
152
+ it('value prop is set in input', () => {
153
+ wrapper = mount(<ColorPicker value="#FFFFFF" />, { attachTo: mountNode });
154
+
155
+ const input = wrapper.find(selectors.summaryInput).first();
156
+ expect(input.instance().value).to.equal('#FFFFFF');
157
+ });
158
+ });
159
+
160
+ describe('Swatch toggle button', () => {
161
+ it('opens popover when clicked and expects onRequestOpen and onOpen to be fired once', function describeFunction2() {
162
+ const onRequestOpenSpy = sinon.spy();
163
+ const onOpenSpy = sinon.spy();
164
+
165
+ wrapper = mount(
166
+ <ColorPicker onRequestOpen={onRequestOpenSpy} onOpen={onOpenSpy} />,
167
+ { attachTo: mountNode }
168
+ );
169
+
170
+ const button = wrapper.find(selectors.toggle).first();
171
+ button.simulate('click');
172
+
173
+ expect(wrapper.find(selectors.popover).exists()).to.be.true;
174
+ expect(onRequestOpenSpy.calledOnce).to.be.true;
175
+ expect(onOpenSpy.calledOnce).to.be.true;
176
+ });
177
+
178
+ it('closes popover when clicked and popover is open', function () {
179
+ const onCloseSpy = sinon.spy();
180
+ wrapper = mount(<ColorPicker isOpen onClose={onCloseSpy} />, {
181
+ attachTo: mountNode,
182
+ });
183
+
184
+ const button = wrapper.find(selectors.toggle).first();
185
+ button.simulate('click');
186
+ expect(onCloseSpy.calledOnce).to.be.true;
187
+ });
188
+ });
189
+
190
+ describe('Popover', function describeFunction2() {
191
+ const clickSubmit = (el) => {
192
+ el.find(selectors.submit).first().simulate('click');
193
+ };
194
+
195
+ describe('Swatch tab', function describeFunction3() {
196
+ it('clicking a swatch sets that working color', function (done) {
197
+ wrapper = mount(
198
+ <ColorPicker
199
+ isOpen
200
+ value="#000000"
201
+ swatchColors={['#ff0000']}
202
+ events={{
203
+ onWorkingColorChange: (event, { color }) => {
204
+ expect(color.hex).to.equal('#ff0000');
205
+ done();
206
+ },
207
+ }}
208
+ />,
209
+ { attachTo: mountNode }
210
+ );
211
+
212
+ const swatch = wrapper.find(selectors.swatch).first();
213
+ swatch.simulate('click');
214
+ });
215
+ });
216
+
217
+ describe('Swatch keyboard navigation', function describeFunction3() {
218
+ it('pressing right will move the color to the next one', function (done) {
219
+ wrapper = mount(
220
+ <ColorPicker
221
+ isOpen
222
+ value="#ff0000"
223
+ swatchColors={['#ff0000', '#0000ff']}
224
+ events={{
225
+ onWorkingColorChange: (event, { color }) => {
226
+ expect(color.hex).to.equal('#0000ff');
227
+ done();
228
+ },
229
+ }}
230
+ />,
231
+ { attachTo: mountNode }
232
+ );
233
+
234
+ const swatch = wrapper.find(selectors.swatch).first();
235
+ swatch.simulate('keyDown', {
236
+ keyCode: KEYS.RIGHT,
237
+ which: KEYS.RIGHT,
238
+ });
239
+ });
240
+
241
+ it('pressing left will move the color to the previous one', function (done) {
242
+ wrapper = mount(
243
+ <ColorPicker
244
+ isOpen
245
+ value="#0000ff"
246
+ swatchColors={['#ff0000', '#0000ff']}
247
+ events={{
248
+ onWorkingColorChange: (event, { color }) => {
249
+ expect(color.hex).to.equal('#ff0000');
250
+ done();
251
+ },
252
+ }}
253
+ />,
254
+ { attachTo: mountNode }
255
+ );
256
+
257
+ const swatch = wrapper.find(selectors.swatch).first();
258
+ swatch.simulate('keyDown', {
259
+ keyCode: KEYS.LEFT,
260
+ which: KEYS.LEFT,
261
+ });
262
+ });
263
+
264
+ it('pressing right in RTL will move the color to the previous one', function (done) {
265
+ wrapper = mount(
266
+ makeRtl(
267
+ <ColorPicker
268
+ isOpen
269
+ value="#0000ff"
270
+ swatchColors={['#ff0000', '#0000ff']}
271
+ events={{
272
+ onWorkingColorChange: (event, { color }) => {
273
+ expect(color.hex).to.equal('#ff0000');
274
+ done();
275
+ },
276
+ }}
277
+ />
278
+ ),
279
+ { attachTo: mountNode }
280
+ );
281
+
282
+ const swatch = wrapper.find(selectors.swatch).first();
283
+ swatch.simulate('keyDown', {
284
+ keyCode: KEYS.RIGHT,
285
+ which: KEYS.RIGHT,
286
+ });
287
+ });
288
+
289
+ it('pressing left in RTL will move the color to the next one', function (done) {
290
+ wrapper = mount(
291
+ makeRtl(
292
+ <ColorPicker
293
+ isOpen
294
+ value="#ff0000"
295
+ swatchColors={['#ff0000', '#0000ff']}
296
+ events={{
297
+ onWorkingColorChange: (event, { color }) => {
298
+ expect(color.hex).to.equal('#0000ff');
299
+ done();
300
+ },
301
+ }}
302
+ />
303
+ ),
304
+ { attachTo: mountNode }
305
+ );
306
+
307
+ const swatch = wrapper.find(selectors.swatch).first();
308
+ swatch.simulate('keyDown', {
309
+ keyCode: KEYS.LEFT,
310
+ which: KEYS.LEFT,
311
+ });
312
+ });
313
+ });
314
+
315
+ describe('Submit button', function describeFunction3() {
316
+ it('sets the input color', function () {
317
+ wrapper = mount(
318
+ <ColorPicker isOpen value="#000000" swatchColors={['#ff0000']} />,
319
+ { attachTo: mountNode }
320
+ );
321
+
322
+ const swatch = wrapper.find(selectors.swatch).first();
323
+ swatch.simulate('click');
324
+ clickSubmit(wrapper);
325
+
326
+ const input = wrapper.find(selectors.summaryInput).first();
327
+ expect(input.props().value).to.equal('#ff0000');
328
+ });
329
+
330
+ it('triggers onChange with value and isValid set to true', function (done) {
331
+ wrapper = mount(
332
+ <ColorPicker
333
+ isOpen
334
+ value="#000000"
335
+ swatchColors={['#ff0000']}
336
+ events={{
337
+ onChange: (event, { color, isValid }) => {
338
+ expect(color).to.equal('#ff0000');
339
+ expect(isValid).to.be.true;
340
+ done();
341
+ },
342
+ }}
343
+ />,
344
+ { attachTo: mountNode }
345
+ );
346
+
347
+ const swatch = wrapper.find(selectors.swatch).first();
348
+ swatch.simulate('click');
349
+ clickSubmit(wrapper);
350
+ });
351
+ });
352
+
353
+ describe('Cancel button', function describeFunction3() {
354
+ it('does not trigger onChange but triggers onRequestClose', function () {
355
+ const onRequestCloseSpy = sinon.spy();
356
+ wrapper = mount(
357
+ <ColorPicker
358
+ isOpen
359
+ value="#000000"
360
+ swatchColors={['#ff0000']}
361
+ events={{
362
+ onChange: () => {
363
+ expect().fail();
364
+ },
365
+ }}
366
+ onRequestClose={onRequestCloseSpy}
367
+ />,
368
+ { attachTo: mountNode }
369
+ );
370
+
371
+ const swatch = wrapper.find(selectors.swatch).first();
372
+ swatch.simulate('click');
373
+
374
+ const cancel = wrapper.find(selectors.cancel).first();
375
+ cancel.simulate('click');
376
+
377
+ expect(
378
+ onRequestCloseSpy.calledWithExactly(sinon.match.any, {
379
+ trigger: 'cancel',
380
+ })
381
+ ).to.be.true;
382
+ });
383
+ });
384
+
385
+ describe('Custom tab', function describeFunction3() {
386
+ describe('HSV', function describeFunction4() {
387
+ describe('hue slider', function describeFunction5() {
388
+ it('change causes color hue to update', function (done) {
389
+ wrapper = mount(
390
+ <ColorPicker
391
+ isOpen
392
+ events={{
393
+ onWorkingColorChange: (event, { color }) => {
394
+ expect(color.hsv.hue).to.equal(50);
395
+ done();
396
+ },
397
+ }}
398
+ />,
399
+ { attachTo: mountNode }
400
+ );
401
+
402
+ const hue = wrapper.find(selectors.hueSlider).first();
403
+ hue.simulate('change', {
404
+ target: {
405
+ value: 50,
406
+ },
407
+ });
408
+ });
409
+ });
410
+
411
+ describe('saturation-value grid', function describeFunction5() {
412
+ // it('click sets color using coordinates', function() {
413
+ // this.skip('too dependent on browser calculations');
414
+ // });
415
+
416
+ it('up key causes color value to go up', function (done) {
417
+ wrapper = mount(
418
+ <ColorPicker
419
+ value="#000000"
420
+ isOpen
421
+ events={{
422
+ onWorkingColorChange: (event, { color }) => {
423
+ expect(color.hsv.value).to.equal(1);
424
+ done();
425
+ },
426
+ }}
427
+ />,
428
+ { attachTo: mountNode }
429
+ );
430
+
431
+ const point = wrapper.find(selectors.gridPoint).first();
432
+ point.simulate('keyDown', {
433
+ keyCode: KEYS.UP,
434
+ which: KEYS.UP,
435
+ });
436
+ });
437
+
438
+ it('down key causes color value to go down', function (done) {
439
+ wrapper = mount(
440
+ <ColorPicker
441
+ value="#ffffff"
442
+ isOpen
443
+ events={{
444
+ onWorkingColorChange: (event, { color }) => {
445
+ expect(color.hsv.value).to.equal(99);
446
+ done();
447
+ },
448
+ }}
449
+ />,
450
+ { attachTo: mountNode }
451
+ );
452
+
453
+ const point = wrapper.find(selectors.gridPoint).first();
454
+ point.simulate('keyDown', {
455
+ keyCode: KEYS.DOWN,
456
+ which: KEYS.DOWN,
457
+ });
458
+ });
459
+
460
+ it('left key causes color sat. to go down 1', function (done) {
461
+ wrapper = mount(
462
+ <ColorPicker
463
+ value="#ff0000"
464
+ isOpen
465
+ events={{
466
+ onWorkingColorChange: (event, { color }) => {
467
+ expect(color.hsv.saturation).to.equal(99);
468
+ done();
469
+ },
470
+ }}
471
+ />,
472
+ { attachTo: mountNode }
473
+ );
474
+
475
+ const point = wrapper.find(selectors.gridPoint).first();
476
+ point.simulate('keyDown', {
477
+ keyCode: KEYS.LEFT,
478
+ which: KEYS.LEFT,
479
+ });
480
+ });
481
+
482
+ it('right key causes color sat. to go up 1', function (done) {
483
+ wrapper = mount(
484
+ <ColorPicker
485
+ value="#000000"
486
+ isOpen
487
+ events={{
488
+ onWorkingColorChange: (event, { color }) => {
489
+ expect(color.hsv.saturation).to.equal(1);
490
+ done();
491
+ },
492
+ }}
493
+ />,
494
+ { attachTo: mountNode }
495
+ );
496
+
497
+ const point = wrapper.find(selectors.gridPoint).first();
498
+ point.simulate('keyDown', {
499
+ keyCode: KEYS.RIGHT,
500
+ which: KEYS.RIGHT,
501
+ });
502
+ });
503
+
504
+ it('shift-up causes color value to go up 10', function (done) {
505
+ wrapper = mount(
506
+ <ColorPicker
507
+ value="#000000"
508
+ isOpen
509
+ events={{
510
+ onWorkingColorChange: (event, { color }) => {
511
+ expect(color.hsv.value).to.equal(10);
512
+ done();
513
+ },
514
+ }}
515
+ />,
516
+ { attachTo: mountNode }
517
+ );
518
+
519
+ const point = wrapper.find(selectors.gridPoint).first();
520
+ point.simulate('keyDown', {
521
+ shiftKey: true,
522
+ keyCode: KEYS.UP,
523
+ which: KEYS.UP,
524
+ });
525
+ });
526
+
527
+ it('up key at value 100 causes no change', function (done) {
528
+ wrapper = mount(
529
+ <ColorPicker
530
+ value="#ffffff"
531
+ isOpen
532
+ events={{
533
+ onWorkingColorChange: (event, { color }) => {
534
+ expect(color.hsv.value).to.equal(100);
535
+ done();
536
+ },
537
+ }}
538
+ />,
539
+ { attachTo: mountNode }
540
+ );
541
+
542
+ const point = wrapper.find(selectors.gridPoint).first();
543
+ point.simulate('keyDown', {
544
+ keyCode: KEYS.UP,
545
+ which: KEYS.UP,
546
+ });
547
+ });
548
+
549
+ it('shift-up at value > 90 causes value to be 100', function (done) {
550
+ wrapper = mount(
551
+ <ColorPicker
552
+ value="#EBEBEB"
553
+ isOpen
554
+ events={{
555
+ onWorkingColorChange: (event, { color }) => {
556
+ expect(color.hsv.value).to.equal(100);
557
+ done();
558
+ },
559
+ }}
560
+ />,
561
+ { attachTo: mountNode }
562
+ );
563
+
564
+ const point = wrapper.find(selectors.gridPoint).first();
565
+ point.simulate('keyDown', {
566
+ shiftKey: true,
567
+ keyCode: KEYS.UP,
568
+ which: KEYS.UP,
569
+ });
570
+ });
571
+ });
572
+ });
573
+
574
+ describe('Hex input', function describeFunction4() {
575
+ it('invalid value sets error message', function (done) {
576
+ wrapper = mount(
577
+ <ColorPicker
578
+ isOpen
579
+ events={{
580
+ onWorkingColorChange: (event, { color }) => {
581
+ expect(color.errors.hex).to.be.true;
582
+ done();
583
+ },
584
+ }}
585
+ />,
586
+ { attachTo: mountNode }
587
+ );
588
+
589
+ const hexInput = wrapper.find(selectors.customHex).first();
590
+ hexInput.find('input').simulate('change', {
591
+ target: {
592
+ value: 'invalid',
593
+ },
594
+ });
595
+ });
596
+
597
+ it('valid value updates color', function (done) {
598
+ wrapper = mount(
599
+ <ColorPicker
600
+ isOpen
601
+ events={{
602
+ onWorkingColorChange: (event, { color }) => {
603
+ expect(color.hex).to.equal('#00ff00');
604
+ done();
605
+ },
606
+ }}
607
+ />,
608
+ { attachTo: mountNode }
609
+ );
610
+
611
+ const hexInput = wrapper.find(selectors.customHex).first();
612
+ hexInput.find('input').simulate('change', {
613
+ target: {
614
+ value: '#00ff00',
615
+ },
616
+ });
617
+ });
618
+
619
+ it('fires onValidateWorkingColor when set', () => {
620
+ const spyCustomColorValidator = sinon.spy();
621
+ const customColorValidator = (hex) => {
622
+ spyCustomColorValidator(hex);
623
+ return true;
624
+ };
625
+
626
+ wrapper = mount(
627
+ <ColorPicker
628
+ isOpen
629
+ events={{ onValidateWorkingColor: customColorValidator }}
630
+ />,
631
+ { attachTo: mountNode }
632
+ );
633
+
634
+ const hexInput = wrapper.find(selectors.customHex).first();
635
+ hexInput.find('input').simulate('change', {
636
+ target: {
637
+ value: '#00ff00',
638
+ },
639
+ });
640
+
641
+ expect(spyCustomColorValidator.calledWith('#00ff00')).to.be.true;
642
+ });
643
+
644
+ it('valueWorking is set in custom tab inner input', () => {
645
+ wrapper = mount(<ColorPicker isOpen valueWorking="#00ff00" />, {
646
+ attachTo: mountNode,
647
+ });
648
+
649
+ const hexInput = wrapper.find(selectors.customHex).first();
650
+ expect(hexInput.find('input').instance().value).to.equal('#00ff00');
651
+ });
652
+ });
653
+
654
+ describe('RGB input', function describeFunction4() {
655
+ it('non-number causes error message', function (done) {
656
+ wrapper = mount(
657
+ <ColorPicker
658
+ isOpen
659
+ events={{
660
+ onWorkingColorChange: (event, { color }) => {
661
+ expect(color.errors.red).to.be.true;
662
+ done();
663
+ },
664
+ }}
665
+ />,
666
+ { attachTo: mountNode }
667
+ );
668
+
669
+ const redInput = wrapper.find(selectors.customRed).first();
670
+ redInput.find('input').simulate('change', {
671
+ target: {
672
+ value: 'abc',
673
+ },
674
+ });
675
+ });
676
+
677
+ it('non-integer number causes error message', function (done) {
678
+ wrapper = mount(
679
+ <ColorPicker
680
+ isOpen
681
+ events={{
682
+ onWorkingColorChange: (event, { color }) => {
683
+ expect(color.errors.red).to.be.true;
684
+ done();
685
+ },
686
+ }}
687
+ />,
688
+ { attachTo: mountNode }
689
+ );
690
+
691
+ const redInput = wrapper.find(selectors.customRed).first();
692
+ redInput.find('input').simulate('change', {
693
+ target: {
694
+ value: 123.45,
695
+ },
696
+ });
697
+ });
698
+
699
+ it('number greater than 255 causes error message', function (done) {
700
+ wrapper = mount(
701
+ <ColorPicker
702
+ isOpen
703
+ events={{
704
+ onWorkingColorChange: (event, { color }) => {
705
+ expect(color.errors.red).to.be.true;
706
+ done();
707
+ },
708
+ }}
709
+ />,
710
+ { attachTo: mountNode }
711
+ );
712
+
713
+ const redInput = wrapper.find(selectors.customRed).first();
714
+ redInput.find('input').simulate('change', {
715
+ target: {
716
+ value: 500,
717
+ },
718
+ });
719
+ });
720
+
721
+ it('negative number causes error message', function (done) {
722
+ wrapper = mount(
723
+ <ColorPicker
724
+ isOpen
725
+ events={{
726
+ onWorkingColorChange: (event, { color }) => {
727
+ expect(color.errors.red).to.be.true;
728
+ done();
729
+ },
730
+ }}
731
+ />,
732
+ { attachTo: mountNode }
733
+ );
734
+
735
+ const redInput = wrapper.find(selectors.customRed).first();
736
+ redInput.find('input').simulate('change', {
737
+ target: {
738
+ value: -123,
739
+ },
740
+ });
741
+ });
742
+
743
+ it('valid number updates color', function (done) {
744
+ wrapper = mount(
745
+ <ColorPicker
746
+ isOpen
747
+ events={{
748
+ onWorkingColorChange: (event, { color }) => {
749
+ expect(color.rgb.red).to.eql(123);
750
+ done();
751
+ },
752
+ }}
753
+ />,
754
+ { attachTo: mountNode }
755
+ );
756
+
757
+ const redInput = wrapper.find(selectors.customRed).first();
758
+ redInput.find('input').simulate('change', {
759
+ target: {
760
+ value: 123,
761
+ },
762
+ });
763
+ });
764
+ });
765
+ });
766
+ });
767
+ });