-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add unit tests to datepickerformatter * Update wording for comment regarding date --------- Co-authored-by: Jason Qiu <[email protected]>
- Loading branch information
1 parent
8bc5ed6
commit 70be153
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
src/web/app/components/datepicker/datepicker-formatter.spec.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,43 @@ | ||
import { NgbDateStruct } from '@ng-bootstrap/ng-bootstrap'; | ||
import { DatePickerFormatter } from './datepicker-formatter'; | ||
|
||
describe('DatepickerFormatter', () => { | ||
let formatter : DatePickerFormatter; | ||
|
||
beforeEach(() => { | ||
formatter = new DatePickerFormatter(); | ||
}); | ||
|
||
it('should create an instance', () => { | ||
expect(formatter).toBeTruthy(); | ||
}); | ||
|
||
it('should return an empty string if date is null', () => { | ||
// Any is used as the type for date here as it is the only way to pass in null to NgbDateStruct | ||
const date: any = null; | ||
const formattedDate: String = formatter.format(date); | ||
expect(formattedDate).toEqual(''); | ||
}); | ||
|
||
it('should return a properly formatted date string', () => { | ||
const date: NgbDateStruct = { year: 2023, month: 12, day: 12 }; | ||
const formattedDate = formatter.format(date); | ||
expect(formattedDate).toEqual('Tue, 12 Dec, 2023'); | ||
}); | ||
|
||
it('should parse the valid date string correctly', () => { | ||
const date : string = 'Tue, 12 Dec, 2023'; | ||
const parsedDate : NgbDateStruct = formatter.parse(date); | ||
expect(parsedDate.day).toEqual(12); | ||
expect(parsedDate.month).toEqual(12); | ||
expect(parsedDate.year).toEqual(2023); | ||
}); | ||
|
||
it('should return NaN for all the fields if invalid date string format is parsed', () => { | ||
const date : string = '12th December 2023'; | ||
const parsedDate : NgbDateStruct = formatter.parse(date); | ||
expect(parsedDate.day).toEqual(NaN); | ||
expect(parsedDate.month).toEqual(NaN); | ||
expect(parsedDate.year).toEqual(NaN); | ||
}); | ||
}); |