|
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', |
| 15 | + }, |
| 16 | +}; |
| 17 | + |
| 18 | +const bad = { |
| 19 | + target: { |
| 20 | + name: 'bad', |
| 21 | + value: '1972-08-foo', |
8 | 22 | }, |
9 | | - all: { |
10 | | - datetime: 'foo bar baz', |
| 23 | +}; |
| 24 | + |
| 25 | +const time = { |
| 26 | + target: { |
| 27 | + name: 'with time', |
| 28 | + value: '1972-08-21T13:00', |
11 | 29 | }, |
12 | 30 | }; |
13 | 31 |
|
14 | | -const settings = { |
| 32 | +const timeSpace = { |
15 | 33 | target: { |
16 | | - empty: false, |
| 34 | + name: 'space in time', |
| 35 | + value: '1972-08-21 13:00', |
17 | 36 | }, |
18 | | - all: { |
19 | | - datetime: { |
20 | | - empty: false, |
21 | | - }, |
| 37 | +}; |
| 38 | + |
| 39 | +const reverse = { |
| 40 | + target: { |
| 41 | + name: 'reverse time to date', |
| 42 | + value: '13:00 1972-08-21', |
22 | 43 | }, |
23 | 44 | }; |
24 | 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'); |
29 | 54 | }); |
30 | 55 |
|
31 | | -// Invalid input |
32 | | -test('validate correct input', t => { |
33 | | - const ip = input; |
34 | | - ip.target.value = ''; |
| 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 | +}); |
35 | 70 |
|
36 | | - t.is(validation(ip, settings), 'datetime cannot be left blank!', 'Return string if not valid'); |
| 71 | +// Revers date/time input |
| 72 | +test('reverse input', t => { |
| 73 | + t.true(validation(reverse), 'Reverse time/date input returns true'); |
37 | 74 | }); |
0 commit comments