Skip to content

Commit

Permalink
filled in getErrorState tests
Browse files Browse the repository at this point in the history
  • Loading branch information
FireLemons committed Nov 7, 2023
1 parent 0c0c6f4 commit 4c08187
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions app/javascript/__tests__/validated_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe('RangedDatePicker', () => {
beforeEach(() => {
$(() => {
datePickerElement = $('input')
datePickerElement.attr('data-min-date', new Date(new Date().getTime() - 2 * MILLISECONDS_IN_A_DAY))
datePickerElement.attr('data-min-date', new Date(new Date().getTime() - (2 * MILLISECONDS_IN_A_DAY)))
rangedDatePicker = new RangedDatePicker($('input'), notifier)
})
})
Expand All @@ -118,16 +118,27 @@ describe('RangedDatePicker', () => {
test('returns an error message if the user input date is before min', (done) => {
$(() => {
try {
datePickerElement.val(new Date(new Date().getTime() - (3 * MILLISECONDS_IN_A_DAY)))

const errorState = rangedDatePicker.getErrorState()

expect(typeof errorState).toBe('string')
expect(errorState.length).toBeGreaterThan(0)
done()
} catch (error) {
done(error)
}
})
})

test('returns empty string if the user input string is between min and max', (done) => {
test('returns a falsy value if the user input string is between min and max', (done) => {
$(() => {
try {
datePickerElement.val(new Date(new Date().getTime() - MILLISECONDS_IN_A_DAY))

const errorState = rangedDatePicker.getErrorState()

expect(errorState).toBeFalsy()
done()
} catch (error) {
done(error)
Expand Down

0 comments on commit 4c08187

Please sign in to comment.