Add tests for updated functionality in date-selector and formatting

This commit is contained in:
leigh-mil 2019-09-24 13:08:29 -04:00
parent 32583feb99
commit e26edcd1bb
2 changed files with 41 additions and 9 deletions

View File

@ -163,6 +163,20 @@ describe('DateSelector', () => {
component.year = new Date().getFullYear()
expect(component.isYearValid).toEqual(true)
})
it('returns true when year is between min and max years', () => {
component.year = new Date('2019-01-01').getFullYear()
component.mindate = new Date('2018-01-01')
component.maxdate = new Date('2019-12-31')
expect(component.isYearValid).toEqual(true)
})
it('returns false when year is outside of min and max years', () => {
component.year = new Date('2020-01-01').getFullYear()
component.mindate = new Date('2018-01-01')
component.maxdate = new Date('2019-01-01')
expect(component.isYearValid).toEqual(false)
})
})
describe('formattedDate', () => {
@ -184,4 +198,20 @@ describe('DateSelector', () => {
expect(component.formattedDate).toEqual('01/22/1988')
})
})
describe('isDateComplete', () => {
it('returns true if all fields are completed', () => {
component.day = 22
component.month = 1
component.year = 1988
expect(component.isDateComplete).toEqual(true)
})
it('returns false if all fields are not completed', () => {
component.day = 22
component.month = 1
component.year = 19
expect(component.isDateComplete).toEqual(false)
})
})
})

View File

@ -102,9 +102,16 @@ export default {
isYearValid: function() {
// Emit a change event
var minYear = new Date(this.mindate).getFullYear()
var maxYear = new Date(this.maxdate).getFullYear()
var valid = this.year >= minYear && this.year <= maxYear
var valid
var minYear = this.mindate ? new Date(this.mindate).getFullYear() : null
var maxYear = this.maxdate ? new Date(this.maxdate).getFullYear() : null
if (minYear && maxYear) {
valid = this.year >= minYear && this.year <= maxYear
} else {
valid = parseInt(this.year) >= 1
}
this._emitChange('year', this.year, valid)
return valid
},
@ -138,12 +145,7 @@ export default {
},
isDateComplete: function() {
return (
!!this.day &&
!!this.month &&
!!this.year &&
this.year > 999
)
return !!this.day && !!this.month && !!this.year && this.year > 999
},
daysMaxCalculation: function() {