This repository has been archived by the owner on Feb 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathAvValidator.date.spec.js
93 lines (73 loc) · 3.14 KB
/
AvValidator.date.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import {AvValidator} from 'availity-reactstrap-validation';
import {inputTypeOverride} from 'availity-reactstrap-validation/AvValidator/utils';
const fn = AvValidator.date;
const input = {props: {type: 'text'}};
const context = {};
describe('Date Validation', () => {
it('should not require a value', () => {
expect(fn('', context, undefined, input)).to.be.true;
});
describe('error message', () => {
it('should allow the error message to be overridden', () => {
expect(fn('abc 123', context, {errorMessage: 'Custom'}, input)).to.equal('Custom');
});
it('should use the custom format in the default message', () => {
expect(fn('abc 123', context, {format: 'YYYY-MM-DD'}, input)).to.equal('Format needs to be YYYY-MM-DD');
});
it('should use the default format in the default message', () => {
expect(fn('abc 123', context, undefined, input)).to.equal('Format needs to be MM/DD/YYYY');
});
});
describe('non-date input type', () => {
beforeEach(() => {
input.props.type = 'text';
});
it('should accept MM/DD/YYYY format by default', () => {
expect(fn('10/12/2014', context, undefined, input)).to.be.true;
});
it('should accept ISO (YYYY-MM-DD) format by default', () => {
expect(fn('2014-10-12', context, undefined, input)).to.be.true;
});
it('should allow format to be customized', () => {
expect(fn('2014-12-14', context, {format: 'YYYY-MM-DD'}, input)).to.be.true;
});
it('should ensure the format matches the customized format', () => {
expect(fn('10/12/2014', context, {format: 'YYYY-MM-DD'}, input)).to.equal('Format needs to be YYYY-MM-DD');
});
});
describe('date input type', () => {
describe('without browser date input type support', () => {
beforeEach(() => {
inputTypeOverride('date', false);
input.props.type = 'date';
});
it('should accept MM/DD/YYYY format by default', () => {
expect(fn('10/12/2014', context, undefined, input)).to.be.true;
});
it('should accept ISO (YYYY-MM-DD) format by default', () => {
expect(fn('2014-10-12', context, undefined, input)).to.be.true;
});
it('should allow format to be customized', () => {
expect(fn('2014-12-14', context, {format: 'YYYY-MM-DD'}, input)).to.be.true;
});
it('should ensure the format matches the customized format', () => {
expect(fn('10/12/2014', context, {format: 'YYYY-MM-DD'}, input)).to.equal('Format needs to be YYYY-MM-DD');
});
});
describe('with browser date input type support', () => {
beforeEach(() => {
inputTypeOverride('date', true);
input.props.type = 'date';
});
it('should accept ISO (YYYY-MM-DD) format by default', () => {
expect(fn('2014-10-12', context, undefined, input)).to.be.true;
});
it('should accept MM/DD/YYYY format by default', () => {
expect(fn('10/12/2014', context, undefined, input)).to.be.true;
});
it('should allow format to be customized', () => {
expect(fn('10-12-2014', context, {format: 'DD-MM-YYYY'}, input)).to.be.true;
});
});
});
});