Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

refactor: replaced moment with dayjs #126

Merged
merged 3 commits into from
May 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion __test__/AvInput.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('AvInput', () => {

it('should have "is-untouched" class when untouched', () => {
const wrapper = shallow(<AvInput name="yo" />, options);
console.log(wrapper.html())

expect(wrapper.hasClass('is-untouched')).to.be.true;
expect(wrapper.hasClass('is-touched')).to.be.false;
});
Expand Down
29 changes: 19 additions & 10 deletions __test__/AvValidator.dateRange.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import moment from 'moment';
import dayjs from 'dayjs';
import customParseFormat from 'dayjs/plugin/customParseFormat'
import {AvValidator} from 'availity-reactstrap-validation';
import {inputTypeOverride} from 'availity-reactstrap-validation/AvValidator/utils';

dayjs.extend(customParseFormat);

const fn = AvValidator.dateRange;
const input = {props: {type: 'text'}};
const context = {};
Expand All @@ -11,9 +14,9 @@ let date2;

describe('Date Range Validation', () => {
beforeEach(() => {
date0 = moment(new Date());
date1 = moment(new Date());
date2 = moment(new Date());
date0 = dayjs(new Date());
date1 = dayjs(new Date());
date2 = dayjs(new Date());
});

it('should not require a value', () => {
Expand Down Expand Up @@ -104,19 +107,25 @@ describe('Date Range Validation', () => {
});

it('should return an error message when date is not within range of the current date', () => {
const dateOne = dayjs().add(-1,'day');
const dateTwo = dayjs().add(-5,'day');

expect(fn(date0.format('YYYY-MM-DD'), context, {
format: 'YYYY-MM-DD',
start: {value: date1.add(-5, 'day').format('YYYY-MM-DD')},
end: {value: date2.add(-1, 'day').format('YYYY-MM-DD')}
}, input)).to.equal(`Date must be between ${date1.format('MM/DD/YYYY')} and ${date2.format('MM/DD/YYYY')}`);
start: {value: dateOne.format('YYYY-MM-DD')},
end: {value: dateTwo.format('YYYY-MM-DD')}
}, input)).to.equal(`Date must be between ${dateOne.format('MM/DD/YYYY')} and ${dateTwo.format('MM/DD/YYYY')}`);
});

it('should allow the start and end formats to be different than the user format', () => {
const dateOne = dayjs().add(-1,'day');
const dateTwo = dayjs().add(-5,'day');

expect(fn(date0.format('YYYY-MM-DD'), context, {
format: 'YYYY-MM-DD',
start: {value: date1.add(-5, 'day').format('DD-MM-YYYY'), format: 'DD-MM-YYYY'},
end: {value: date2.add(-1, 'day').format('YYYY/MM/DD'), format: 'YYYY/MM/DD'}
}, input)).to.equal(`Date must be between ${date1.format('MM/DD/YYYY')} and ${date2.format('MM/DD/YYYY')}`);
start: {value: dateOne.format('DD-MM-YYYY'), format: 'DD-MM-YYYY'},
end: {value: dateTwo.format('YYYY/MM/DD'), format: 'YYYY/MM/DD'}
}, input)).to.equal(`Date must be between ${dateOne.format('MM/DD/YYYY')} and ${dateTwo.format('MM/DD/YYYY')}`);
});
});

Expand Down
Loading