-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(LastSeenFilter): Fixes Validators and adds test
- Loading branch information
1 parent
f53155a
commit 00fca84
Showing
6 changed files
with
120 additions
and
55 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import moment from 'moment'; | ||
|
||
export const oldestDate = new Date(1950, 1, 1); | ||
//validators control what date ranges can be selected in the component. | ||
//both validators need to keep in mind todays date, and the other components inputed date. | ||
|
||
//maxDate is the other date pickers currently selected Date | ||
//date is patternfly component date | ||
export const fromValidator = (maxDate) => (date) => { | ||
const todaysDate = moment().startOf('day'); | ||
const newMaxDate = moment(maxDate).startOf('day'); | ||
|
||
if (date < oldestDate) { | ||
return 'Date is before the allowable range.'; | ||
} else if (date > newMaxDate) { | ||
return `End date must be later than Start date.`; | ||
} else if (date > todaysDate) { | ||
return ' Start date must be earlier than End date.'; | ||
} else { | ||
return ''; | ||
} | ||
}; | ||
|
||
//minDate is the other components currently selected Date | ||
//dateToValidate is patternfly component date. | ||
export const toValidator = (minDate) => (dateToValidate) => { | ||
const todaysDate = moment().endOf('day'); | ||
const newDatetoValidate = new Date(dateToValidate); | ||
const newMinDate = moment(minDate).startOf('day'); | ||
|
||
if (newDatetoValidate < newMinDate) { | ||
return 'Start date must be earlier than End date.'; | ||
} else if (newDatetoValidate > todaysDate) { | ||
return `Date must be ${todaysDate.toISOString().split('T')[0]} or earlier`; | ||
} else { | ||
return ''; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { fromValidator, toValidator } from './helpers'; | ||
import moment from 'moment'; | ||
|
||
describe('Validates datepicker dates', () => { | ||
it('ToValidator', () => { | ||
const startOfToday = moment().startOf('day'); | ||
const endOfToday = moment().endOf('day'); | ||
expect(toValidator(startOfToday)(endOfToday)).toEqual(''); | ||
}); | ||
it('FromValidator', () => { | ||
const startOfToday = moment().startOf('day'); | ||
const endOfToday = moment().endOf('day'); | ||
expect(fromValidator(endOfToday)(startOfToday)).toEqual(''); | ||
|
||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters