-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f5b48ef
commit 73131cc
Showing
2 changed files
with
46 additions
and
2 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
plugins/ui/src/js/src/elements/hooks/useDatepickerProps.test.ts
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,41 @@ | ||
import { parseDateValue } from './useDatepickerProps'; | ||
|
||
describe('parseDateValue', () => { | ||
const isoDate = '2021-02-03'; | ||
const isoDateTime = '2021-03-03T04:05:06'; | ||
const isoZonedDateTime = '2021-04-04T05:06:07-04:00[America/New_York]'; | ||
const nonIsoZonedDateTime = '2021-04-04T05:06:07 America/New_York'; | ||
const invalidDate = 'invalid-date'; | ||
|
||
it('should return null if the value is null', () => { | ||
expect(parseDateValue(null)).toBeNull(); | ||
}); | ||
|
||
it('should return undefined if the value is undefined', () => { | ||
expect(parseDateValue(undefined)).toBeUndefined(); | ||
}); | ||
|
||
it('should parse an ISO 8601 date string', () => { | ||
expect(parseDateValue(isoDate)?.toString()).toEqual(isoDate); | ||
}); | ||
|
||
it('should parse an ISO 8601 date time string', () => { | ||
expect(parseDateValue(isoDateTime)?.toString()).toEqual(isoDateTime); | ||
}); | ||
|
||
it('should parse an ISO 8601 zoned date time string', () => { | ||
expect(parseDateValue(isoZonedDateTime)?.toString()).toEqual( | ||
isoZonedDateTime | ||
); | ||
}); | ||
|
||
it('should parse a non-ISO 8601 zoned date time string', () => { | ||
expect(parseDateValue(nonIsoZonedDateTime)?.toString()).toEqual( | ||
isoZonedDateTime | ||
); | ||
}); | ||
|
||
it('should throw an error if the value is invalid', () => { | ||
expect(() => parseDateValue(invalidDate)).toThrow(); | ||
}); | ||
}); |
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