Skip to content

Commit

Permalink
Added some tests and fixed on isValidDate missed occurance
Browse files Browse the repository at this point in the history
-TravisCI was failing also b/c I missed a commit in my last push
  • Loading branch information
jacobbp25 committed Sep 11, 2018
1 parent 6a60e6f commit ef597cc
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 2 deletions.
2 changes: 1 addition & 1 deletion projects/uiowa/date-range-picker/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@uiowa/date-range-picker",
"version": "1.0.7",
"version": "1.0.8",
"author": "Changhui Xu <[email protected]>",
"contributors": [
"Jacob Feuerbach <[email protected]>"
Expand Down
58 changes: 58 additions & 0 deletions projects/uiowa/date-range-picker/src/lib/date-range.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { DateRange } from './date-range';

describe('isValidDate() tests', () => {
it('String as Date should be false', () => {
const actual = DateRange.isValidDate('aaaaa');
expect(actual).toBe(false);
});
it('null as Date should be false', () => {
const actual = DateRange.isValidDate(null);
expect(actual).toBe(false);
});
it('empty as Date should be false', () => {
const actual = DateRange.isValidDate(NaN);
expect(actual).toBe(false);
});
it('Some Date as Date should be true', () => {
const actual = DateRange.isValidDate(new Date());
expect(actual).toBe(true);
});
it('Some Defined Date as Date should be true', () => {
const actual = DateRange.isValidDate(new Date(2018, 0, 1));
expect(actual).toBe(true);
});
it('Some number as Date should be true', () => {
const actual = DateRange.isValidDate(123);
expect(actual).toBe(true);
});
});

describe('createDateRange() tests', () => {
const date1 = new Date(2018, 0, 1);
const date2 = new Date(2018, 0, 15);
it('Create Date Range with null and null should return null and null', () => {
const actual = DateRange.createDateRange(null, null);
expect(actual.start).toBe(null);
expect(actual.end).toBe(null);
});
it('Create Date Range with string and string should return null and null', () => {
const actual = DateRange.createDateRange('a', 'b');
expect(actual.start).toBe(null);
expect(actual.end).toBe(null);
});
it('Create Date Range with date and null should return date and null', () => {
const actual = DateRange.createDateRange(date1, null);
expect(actual.start).toEqual(date1);
expect(actual.end).toBe(null);
});
it('Create Date Range with null and date should return null and date', () => {
const actual = DateRange.createDateRange(null, date1);
expect(actual.start).toBe(null);
expect(actual.end).toEqual(date1);
});
it('Create Date Range with date and date should return date and date', () => {
const actual = DateRange.createDateRange(date1, date2);
expect(actual.start).toEqual(date1);
expect(actual.end).toEqual(date2);
});
});
4 changes: 4 additions & 0 deletions projects/uiowa/date-range-picker/src/lib/date-range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export class DateRange {
}

static isValidDate(value: any): boolean {
if (!value) {
return false;
}

switch (typeof value) {
case 'number':
return true;
Expand Down
1 change: 1 addition & 0 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class AppComponent implements OnInit {
dateRange4 = new DateRange(new Date(2018, 9, 1), new Date(2018, 9, 9));
dateRange5 = new DateRange(new Date(2018, 9, 1), null);
dateRange6 = new DateRange(null, new Date(2018, 9, 1));
dateRange7 = new DateRange(new Date('sssss'), new Date('aaaa'));
ngOnInit(): void {
this.maxDate.setDate(this.maxDate.getDate() + 20);
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { DateRangePickerModule } from '@uiowa/date-range-picker';

import { AppComponent } from './app.component';
//import { DateRangePickerModule } from 'projects/uiowa/date-range-picker/src/public_api';
// import { DateRangePickerModule } from 'projects/uiowa/date-range-picker/src/public_api';

@NgModule({
declarations: [AppComponent],
Expand Down

0 comments on commit ef597cc

Please sign in to comment.