|
| 1 | +import { getOptionLabel, createValue } from '../files/select'; |
| 2 | + |
| 3 | +describe('<Select />', () => { |
| 4 | + describe('helpers', () => { |
| 5 | + describe('#getOptionLabel', () => { |
| 6 | + it('undefined', () => { |
| 7 | + expect(getOptionLabel(undefined)).toEqual(''); |
| 8 | + }); |
| 9 | + |
| 10 | + it('empty string', () => { |
| 11 | + expect(getOptionLabel('')).toEqual(''); |
| 12 | + }); |
| 13 | + |
| 14 | + it('empty array', () => { |
| 15 | + expect(getOptionLabel([])).toEqual(''); |
| 16 | + }); |
| 17 | + |
| 18 | + it('object', () => { |
| 19 | + expect(getOptionLabel({ label: 'some label' })).toEqual('some label'); |
| 20 | + }); |
| 21 | + |
| 22 | + it('find in options', () => { |
| 23 | + const options = [ |
| 24 | + { value: '1', label: 'one' }, |
| 25 | + { value: 'key', label: 'this label' }, |
| 26 | + { value: '2', label: 'two' } |
| 27 | + ]; |
| 28 | + |
| 29 | + expect(getOptionLabel('key', options)).toEqual('this label'); |
| 30 | + }); |
| 31 | + }); |
| 32 | + |
| 33 | + describe('#createOptions', () => { |
| 34 | + it('is multi - single', () => { |
| 35 | + const option = { label: 'label', value: '123' }; |
| 36 | + |
| 37 | + expect(createValue(option, true)).toEqual(option); |
| 38 | + }); |
| 39 | + |
| 40 | + it('is multi - array with objects', () => { |
| 41 | + const option = [ |
| 42 | + { label: 'label', value: '123' }, |
| 43 | + { label: 'label 2', value: '456' } |
| 44 | + ]; |
| 45 | + |
| 46 | + expect(createValue(option, true)).toEqual(option); |
| 47 | + }); |
| 48 | + |
| 49 | + it('is multi - array with values', () => { |
| 50 | + const option = ['123', '456']; |
| 51 | + |
| 52 | + expect(createValue(option, true)).toEqual([{ value: '123' }, { value: '456' }]); |
| 53 | + }); |
| 54 | + |
| 55 | + it('is multi - array with values and object', () => { |
| 56 | + const option = ['123', '456', { value: '789', label: 'some label' }]; |
| 57 | + |
| 58 | + expect(createValue(option, true)).toEqual([{ value: '123' }, { value: '456' }, { value: '789', label: 'some label' }]); |
| 59 | + }); |
| 60 | + |
| 61 | + it('createValue', () => { |
| 62 | + const option = { label: 'label', value: '123' }; |
| 63 | + |
| 64 | + expect(createValue(option, false)).toEqual(option); |
| 65 | + }); |
| 66 | + }); |
| 67 | + }); |
| 68 | +}); |
0 commit comments