-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(datepicker): removed dependency on moment.js (#2465)
* chore(datepicker): covering with tests * WIP * WIP * feat(datepicker): removed dependency on moment.js
- Loading branch information
Showing
15 changed files
with
256 additions
and
73 deletions.
There are no files selected for viewing
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
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
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
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,46 @@ | ||
import { async, TestBed } from '@angular/core/testing'; | ||
import { AlertModule } from './alert/alert.module'; | ||
import { AccordionModule } from './accordion/accordion.module'; | ||
import { ButtonsModule } from './buttons/buttons.module'; | ||
import { CarouselModule } from './carousel/carousel.module'; | ||
import { CollapseModule } from './collapse/collapse.module'; | ||
import { DatepickerModule } from './datepicker/datepicker.module'; | ||
import { BsDropdownModule } from './dropdown/bs-dropdown.module'; | ||
import { ModalModule } from './modal/modal.module'; | ||
import { PaginationModule } from './pagination/pagination.module'; | ||
import { ProgressbarModule } from './progressbar/progressbar.module'; | ||
import { PopoverModule } from './popover/popover.module'; | ||
import { RatingModule } from './rating/rating.module'; | ||
import { TabsModule } from './tabs/tabs.module'; | ||
import { TimepickerModule } from './timepicker/timepicker.module'; | ||
import { TooltipModule } from './tooltip/tooltip.module'; | ||
import { TypeaheadModule } from './typeahead/typeahead.module'; | ||
|
||
describe('datepicker: [bsDatepickerDayDecorator]', () => { | ||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
AccordionModule.forRoot(), | ||
AlertModule.forRoot(), | ||
ButtonsModule.forRoot(), | ||
CarouselModule.forRoot(), | ||
CollapseModule.forRoot(), | ||
DatepickerModule.forRoot(), | ||
BsDropdownModule.forRoot(), | ||
ModalModule.forRoot(), | ||
PaginationModule.forRoot(), | ||
ProgressbarModule.forRoot(), | ||
PopoverModule.forRoot(), | ||
RatingModule.forRoot(), | ||
TabsModule.forRoot(), | ||
TimepickerModule.forRoot(), | ||
TooltipModule.forRoot(), | ||
TypeaheadModule.forRoot() | ||
] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
// beforeEach(() => { | ||
// }); | ||
}); |
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
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import moment from 'moment'; | ||
import { formatDate } from '../bs-moment/format'; | ||
|
||
export class DateFormatter { | ||
public format(date:Date, format:string):string { | ||
return moment(date.getTime()).format(format); | ||
public format(date: Date, format: string): string { | ||
return formatDate(date, format); | ||
} | ||
} |
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
76 changes: 76 additions & 0 deletions
76
src/datepicker/themes/bs/bs-datepicker-day-decorator.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,76 @@ | ||
import { Component } from '@angular/core'; | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { DayViewModel } from '../../models/index'; | ||
import { BsDatepickerDayDecoratorComponent } from './bs-datepicker-day-decorator.directive'; | ||
|
||
function getDayElement(fixture: ComponentFixture<TestComponent>): HTMLElement { | ||
return fixture.nativeElement.querySelector('[bsDatepickerDayDecorator]') as HTMLElement; | ||
} | ||
|
||
function setDay(fixture: ComponentFixture<TestComponent>, day: Partial<DayViewModel>): void { | ||
fixture.componentInstance.day = day as DayViewModel; | ||
fixture.detectChanges(); | ||
} | ||
|
||
describe('datepicker: [bsDatepickerDayDecorator]', () => { | ||
let fixture: ComponentFixture<TestComponent>; | ||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [TestComponent, BsDatepickerDayDecoratorComponent] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(TestComponent); | ||
}); | ||
|
||
it('should display date', () => { | ||
// arrange | ||
const label = 'some label'; | ||
setDay(fixture, {label}); | ||
const el = getDayElement(fixture); | ||
// assert | ||
expect(el.innerText).toBe(label); | ||
}); | ||
|
||
it('should not add any special classes by default', () => { | ||
fixture.detectChanges(); | ||
const el = getDayElement(fixture); | ||
expect(el).not.toHaveCssClass('disabled'); | ||
expect(el).not.toHaveCssClass('is-highlighted'); | ||
expect(el).not.toHaveCssClass('is-other-month'); | ||
expect(el).not.toHaveCssClass('in-range'); | ||
expect(el).not.toHaveCssClass('select-start'); | ||
expect(el).not.toHaveCssClass('select-end'); | ||
expect(el).not.toHaveCssClass('selected'); | ||
}); | ||
|
||
it('should add classes corresponding to day state', () => { | ||
setDay(fixture, { | ||
isDisabled: true, | ||
isHovered: true, | ||
isOtherMonth: true, | ||
isInRange: true, | ||
isSelectionStart: true, | ||
isSelectionEnd: true, | ||
isSelected: true | ||
}); | ||
const el = getDayElement(fixture); | ||
expect(el).toHaveCssClass('disabled'); | ||
expect(el).toHaveCssClass('is-highlighted'); | ||
expect(el).toHaveCssClass('is-other-month'); | ||
expect(el).toHaveCssClass('in-range'); | ||
expect(el).toHaveCssClass('select-start'); | ||
expect(el).toHaveCssClass('select-end'); | ||
expect(el).toHaveCssClass('selected'); | ||
}); | ||
}); | ||
|
||
@Component({ | ||
selector: 'test-cmp', | ||
template: `<span bsDatepickerDayDecorator [day]="day">{{ day.label }}</span>` | ||
}) | ||
class TestComponent { | ||
day: DayViewModel = { } as DayViewModel; | ||
} |
35 changes: 0 additions & 35 deletions
35
src/datepicker/themes/bs/bs-datepicker-day-view.component.ts
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.