|
| 1 | +import { offsetMin, offsetMax } from 'utils/propValidation'; |
| 2 | + |
| 3 | +describe('offsetMin prop validation', () => { |
| 4 | + |
| 5 | + it('returns null when provided a valid value', () => { |
| 6 | + expect(offsetMin({ offsetXMin: -100 }, 'offsetXMin', 'foo')).toBe(null); |
| 7 | + expect(offsetMin({ offsetXMin: '-10321px' }, 'offsetXMin', 'foo')).toBe(null); |
| 8 | + expect(offsetMin({ offsetXMin: '-10%' }, 'offsetXMin', 'foo')).toBe(null); |
| 9 | + }); |
| 10 | + |
| 11 | + it('throws when provided a invalid value type', () => { |
| 12 | + const error = new Error('[offsetXMin] in foo must be a string with with "%"" or "px" units or number.'); |
| 13 | + expect(offsetMin({ offsetXMin: false }, 'offsetXMin', 'foo')).toEqual(error); |
| 14 | + expect(offsetMin({ offsetXMin: {} }, 'offsetXMin', 'foo')).toEqual(error); |
| 15 | + expect(offsetMin({ offsetXMin: null }, 'offsetXMin', 'foo')).toEqual(error); |
| 16 | + expect(offsetMin({ offsetXMin: undefined }, 'offsetXMin', 'foo')).toEqual(error); |
| 17 | + expect(offsetMin({ offsetXMin: [] }, 'offsetXMin', 'foo')).toEqual(error); |
| 18 | + }); |
| 19 | + |
| 20 | + it('throws when provided a invalid value', () => { |
| 21 | + const error = new Error('[offsetXMin] in foo is greater than zero. [offsetXMin] must be less than or equal to zero.') |
| 22 | + expect(offsetMin({ offsetXMin: 100 }, 'offsetXMin', 'foo')).toEqual(error); |
| 23 | + expect(offsetMin({ offsetXMin: 1 }, 'offsetXMin', 'foo')).toEqual(error); |
| 24 | + expect(offsetMin({ offsetXMin: 0.0009 }, 'offsetXMin', 'foo')).toEqual(error); |
| 25 | + expect(offsetMin({ offsetXMin: '100px' }, 'offsetXMin', 'foo')).toEqual(error); |
| 26 | + expect(offsetMin({ offsetXMin: '99%' }, 'offsetXMin', 'foo')).toEqual(error); |
| 27 | + }); |
| 28 | + |
| 29 | +}); |
| 30 | + |
| 31 | +describe('offsetMax prop validation', () => { |
| 32 | + |
| 33 | + it('returns null when provided a valid value', () => { |
| 34 | + expect(offsetMax({ offsetXMax: 100 }, 'offsetXMax', 'foo')).toBe(null); |
| 35 | + expect(offsetMax({ offsetXMax: '10321px' }, 'offsetXMax', 'foo')).toBe(null); |
| 36 | + expect(offsetMax({ offsetXMax: '10%' }, 'offsetXMax', 'foo')).toBe(null); |
| 37 | + }); |
| 38 | + |
| 39 | + it('throws when provided a invalid value type', () => { |
| 40 | + const error = new Error('[offsetXMax] in foo must be a string with with "%"" or "px" units or number.'); |
| 41 | + expect(offsetMax({ offsetXMax: false }, 'offsetXMax', 'foo')).toEqual(error); |
| 42 | + expect(offsetMax({ offsetXMax: {} }, 'offsetXMax', 'foo')).toEqual(error); |
| 43 | + expect(offsetMax({ offsetXMax: null }, 'offsetXMax', 'foo')).toEqual(error); |
| 44 | + expect(offsetMax({ offsetXMax: undefined }, 'offsetXMax', 'foo')).toEqual(error); |
| 45 | + expect(offsetMax({ offsetXMax: [] }, 'offsetXMax', 'foo')).toEqual(error); |
| 46 | + }); |
| 47 | + |
| 48 | + it('throws when provided a invalid value', () => { |
| 49 | + const error = new Error('[offsetXMax] in foo is less than zero. [offsetXMax] must be greater than or equal to zero.') |
| 50 | + expect(offsetMax({ offsetXMax: -100 }, 'offsetXMax', 'foo')).toEqual(error); |
| 51 | + expect(offsetMax({ offsetXMax: -1 }, 'offsetXMax', 'foo')).toEqual(error); |
| 52 | + expect(offsetMax({ offsetXMax: -0.0009 }, 'offsetXMax', 'foo')).toEqual(error); |
| 53 | + expect(offsetMax({ offsetXMax: '-100px' }, 'offsetXMax', 'foo')).toEqual(error); |
| 54 | + expect(offsetMax({ offsetXMax: '-99%' }, 'offsetXMax', 'foo')).toEqual(error); |
| 55 | + }); |
| 56 | + |
| 57 | +}); |
0 commit comments