|
1 | 1 | import test from 'ava'; |
2 | 2 | import validation from '../lib/validation'; |
3 | 3 |
|
| 4 | +const empty = { |
| 5 | + target: { |
| 6 | + name: 'empty', |
| 7 | + value: '', |
| 8 | + }, |
| 9 | +}; |
| 10 | + |
4 | 11 | const input = { |
5 | 12 | target: { |
6 | | - name: 'datetime', |
7 | | - value: 'foo bar baz', |
| 13 | + name: 'good', |
| 14 | + value: '1972-08-21', |
8 | 15 | }, |
9 | | - all: { |
10 | | - datetime: 'foo bar baz', |
| 16 | +}; |
| 17 | + |
| 18 | +const bad = { |
| 19 | + target: { |
| 20 | + name: 'bad', |
| 21 | + value: '1972-08-foo', |
11 | 22 | }, |
12 | 23 | }; |
13 | 24 |
|
14 | | -const settings = { |
| 25 | +const time = { |
15 | 26 | target: { |
16 | | - empty: false, |
| 27 | + name: 'with time', |
| 28 | + value: '1972-08-21T13:00', |
17 | 29 | }, |
18 | | - all: { |
19 | | - datetime: { |
20 | | - empty: false, |
21 | | - }, |
| 30 | +}; |
| 31 | + |
| 32 | +const timeSpace = { |
| 33 | + target: { |
| 34 | + name: 'space in time', |
| 35 | + value: '1972-08-21 13:00', |
22 | 36 | }, |
23 | 37 | }; |
24 | 38 |
|
| 39 | +const reverse = { |
| 40 | + target: { |
| 41 | + name: 'reverse time to date', |
| 42 | + value: '13:00 1972-08-21', |
| 43 | + }, |
| 44 | +}; |
| 45 | + |
| 46 | +// Empty input |
| 47 | +test('empty input', t => { |
| 48 | + t.true(validation(empty), 'Empty input returns true'); |
| 49 | +}); |
25 | 50 |
|
26 | | -// Valid input |
| 51 | +// Valid date-only input |
27 | 52 | test('valid input', t => { |
28 | | - t.true(validation(input, settings), 'Valid input returns true'); |
| 53 | + t.true(validation(input), 'Valid input returns true'); |
| 54 | +}); |
| 55 | + |
| 56 | +// Bad input |
| 57 | +test('bad input', t => { |
| 58 | + t.is(validation(bad), 'bad must be a date!', 'Bad input returns string'); |
| 59 | +}); |
| 60 | + |
| 61 | +// Valid date/time input |
| 62 | +test('valid with time input', t => { |
| 63 | + t.true(validation(time), 'Valid input returns true'); |
| 64 | +}); |
| 65 | + |
| 66 | +// Valid date/time input |
| 67 | +test('valid with time input', t => { |
| 68 | + t.true(validation(timeSpace), 'Valid input returns true'); |
| 69 | +}); |
| 70 | + |
| 71 | +// Revers date/time input |
| 72 | +test('reverse input', t => { |
| 73 | + t.true(validation(reverse), 'Reverse time/date input returns true'); |
29 | 74 | }); |
0 commit comments