@@ -7,12 +7,14 @@ import {
77 Calendar , IgxCalendarComponent , IgxCalendarModule , isLeap ,
88 monthRange , weekDay , WEEKDAYS
99} from './public_api' ;
10- import { UIInteractions } from '../test-utils/ui-interactions.spec' ;
10+ import { UIInteractions , wait } from '../test-utils/ui-interactions.spec' ;
1111import { DateRangeDescriptor , DateRangeType } from '../core/dates/dateRange' ;
1212
1313import { configureTestSuite } from '../test-utils/configure-suite' ;
1414import { IgxDayItemComponent } from './days-view/day-item.component' ;
1515import { HelperTestFunctions } from './calendar-helper-utils' ;
16+ import { CalendarView } from './month-picker-base' ;
17+ import { IViewDateChangeEventArgs } from './calendar-base' ;
1618
1719describe ( 'IgxCalendar - ' , ( ) => {
1820
@@ -252,8 +254,8 @@ describe('IgxCalendar - ', () => {
252254 expect ( calendar . formatOptions ) . toEqual ( jasmine . objectContaining ( defaultOptions ) ) ;
253255 expect ( calendar . formatViews ) . toEqual ( jasmine . objectContaining ( defaultViews ) ) ;
254256 expect ( headerYear . nativeElement . textContent . trim ( ) ) . toMatch ( '2018' ) ;
255- expect ( headerWeekday . nativeElement . textContent . trim ( ) ) . toMatch ( 'Mon ' ) ;
256- expect ( headerDate . nativeElement . textContent . trim ( ) ) . toMatch ( 'Sep 17 ' ) ;
257+ expect ( headerWeekday . nativeElement . textContent . trim ( ) ) . toMatch ( 'Sat ' ) ;
258+ expect ( headerDate . nativeElement . textContent . trim ( ) ) . toMatch ( 'Sep 1 ' ) ;
257259 expect ( bodyYear . nativeElement . textContent . trim ( ) ) . toMatch ( '2018' ) ;
258260 expect ( bodyMonth . nativeElement . textContent . trim ( ) ) . toMatch ( 'Sep' ) ;
259261
@@ -267,8 +269,8 @@ describe('IgxCalendar - ', () => {
267269 expect ( calendar . formatOptions ) . toEqual ( jasmine . objectContaining ( Object . assign ( defaultOptions , formatOptions ) ) ) ;
268270 expect ( calendar . formatViews ) . toEqual ( jasmine . objectContaining ( Object . assign ( defaultViews , formatViews ) ) ) ;
269271 expect ( headerYear . nativeElement . textContent . trim ( ) ) . toMatch ( '18' ) ;
270- expect ( headerWeekday . nativeElement . textContent . trim ( ) ) . toMatch ( 'Mon ' ) ;
271- expect ( headerDate . nativeElement . textContent . trim ( ) ) . toMatch ( 'September 17 ' ) ;
272+ expect ( headerWeekday . nativeElement . textContent . trim ( ) ) . toMatch ( 'Sat ' ) ;
273+ expect ( headerDate . nativeElement . textContent . trim ( ) ) . toMatch ( 'September 1 ' ) ;
272274 expect ( bodyYear . nativeElement . textContent . trim ( ) ) . toMatch ( '18' ) ;
273275 expect ( bodyMonth . nativeElement . textContent . trim ( ) ) . toMatch ( 'September' ) ;
274276
@@ -283,8 +285,8 @@ describe('IgxCalendar - ', () => {
283285 expect ( calendar . formatOptions ) . toEqual ( jasmine . objectContaining ( Object . assign ( defaultOptions , formatOptions ) ) ) ;
284286 expect ( calendar . formatViews ) . toEqual ( jasmine . objectContaining ( Object . assign ( defaultViews , formatViews ) ) ) ;
285287 expect ( headerYear . nativeElement . textContent . trim ( ) ) . toMatch ( '2018' ) ;
286- expect ( headerWeekday . nativeElement . textContent . trim ( ) ) . toMatch ( 'Mon ' ) ;
287- expect ( headerDate . nativeElement . textContent . trim ( ) ) . toMatch ( 'September 17 ' ) ;
288+ expect ( headerWeekday . nativeElement . textContent . trim ( ) ) . toMatch ( 'Sat ' ) ;
289+ expect ( headerDate . nativeElement . textContent . trim ( ) ) . toMatch ( 'September 1 ' ) ;
288290 expect ( bodyYear . nativeElement . textContent . trim ( ) ) . toMatch ( '2018' ) ;
289291 expect ( bodyMonth . nativeElement . textContent . trim ( ) ) . toMatch ( '8' ) ;
290292 } ) ;
@@ -305,8 +307,8 @@ describe('IgxCalendar - ', () => {
305307 fixture . detectChanges ( ) ;
306308
307309 expect ( headerYear . nativeElement . textContent . trim ( ) ) . toMatch ( '2018' ) ;
308- expect ( headerWeekday . nativeElement . textContent . trim ( ) ) . toMatch ( 'Mon ' ) ;
309- expect ( headerDate . nativeElement . textContent . trim ( ) ) . toMatch ( 'Sep 17 ' ) ;
310+ expect ( headerWeekday . nativeElement . textContent . trim ( ) ) . toMatch ( 'Sat ' ) ;
311+ expect ( headerDate . nativeElement . textContent . trim ( ) ) . toMatch ( 'Sep 1 ' ) ;
310312 expect ( bodyYear . nativeElement . textContent . trim ( ) ) . toMatch ( '2018' ) ;
311313 expect ( bodyMonth . nativeElement . textContent . trim ( ) ) . toMatch ( 'Sep' ) ;
312314 expect ( bodyWeekday . nativeElement . textContent . trim ( ) ) . toMatch ( 'Sun' ) ;
@@ -319,8 +321,8 @@ describe('IgxCalendar - ', () => {
319321 bodyWeekday = dom . query ( By . css ( HelperTestFunctions . WEEKSTART_LABEL_CSSCLASS ) ) ;
320322 expect ( calendar . locale ) . toEqual ( locale ) ;
321323 expect ( headerYear . nativeElement . textContent . trim ( ) ) . toMatch ( '18' ) ;
322- expect ( headerWeekday . nativeElement . textContent . trim ( ) ) . toMatch ( 'lun .,' ) ;
323- expect ( headerDate . nativeElement . textContent . trim ( ) ) . toMatch ( '17 sept.' ) ;
324+ expect ( headerWeekday . nativeElement . textContent . trim ( ) ) . toMatch ( 'sam .,' ) ;
325+ expect ( headerDate . nativeElement . textContent . trim ( ) ) . toMatch ( '1 sept.' ) ;
324326 expect ( bodyYear . nativeElement . textContent . trim ( ) ) . toMatch ( '18' ) ;
325327 expect ( bodyMonth . nativeElement . textContent . trim ( ) ) . toMatch ( 'sept.' ) ;
326328 expect ( bodyWeekday . nativeElement . textContent . trim ( ) ) . toMatch ( 'Dim.' ) ;
@@ -1559,36 +1561,41 @@ describe('IgxCalendar - ', () => {
15591561 prev . nativeElement . focus ( ) ;
15601562
15611563 expect ( prev . nativeElement ) . toBe ( document . activeElement ) ;
1562-
15631564 UIInteractions . triggerKeyDownEvtUponElem ( 'Enter' , prev . nativeElement ) ;
15641565 tick ( 100 ) ;
15651566 fixture . detectChanges ( ) ;
15661567
15671568 expect ( calendar . viewDate . getMonth ( ) ) . toEqual ( 4 ) ;
1568-
15691569 const next = dom . queryAll ( By . css ( HelperTestFunctions . CALENDAR_NEXT_BUTTON_CSSCLASS ) ) [ 0 ] ;
15701570 next . nativeElement . focus ( ) ;
15711571 expect ( next . nativeElement ) . toBe ( document . activeElement ) ;
15721572
15731573 UIInteractions . triggerKeyDownEvtUponElem ( 'Enter' , next . nativeElement ) ;
1574- tick ( 100 ) ;
1575- fixture . detectChanges ( ) ;
15761574
1575+ fixture . detectChanges ( ) ;
1576+ tick ( 100 ) ;
15771577 UIInteractions . triggerKeyDownEvtUponElem ( 'Enter' , next . nativeElement ) ;
15781578 tick ( 100 ) ;
15791579 fixture . detectChanges ( ) ;
15801580
1581+
15811582 expect ( calendar . viewDate . getMonth ( ) ) . toEqual ( 6 ) ;
15821583 } ) ) ;
15831584
1584- it ( 'Should open years view, navigate through and select an year via KB.' , ( ) => {
1585+ it ( 'Should open years view, navigate through and select an year via KB.' , fakeAsync ( ( ) => {
15851586 const year = dom . queryAll ( By . css ( HelperTestFunctions . CALENDAR_DATE_CSSCLASS ) ) [ 1 ] ;
15861587 year . nativeElement . focus ( ) ;
15871588
15881589 expect ( year . nativeElement ) . toBe ( document . activeElement ) ;
15891590
1591+ spyOn ( calendar . onActiveViewChanged , 'emit' ) . and . callThrough ( ) ;
1592+
15901593 UIInteractions . triggerKeyDownEvtUponElem ( 'Enter' , document . activeElement ) ;
15911594 fixture . detectChanges ( ) ;
1595+ tick ( ) ;
1596+
1597+ expect ( calendar . onActiveViewChanged . emit ) . toHaveBeenCalledTimes ( 1 ) ;
1598+ expect ( calendar . onActiveViewChanged . emit ) . toHaveBeenCalledWith ( CalendarView . DECADE ) ;
15921599
15931600 const years = dom . queryAll ( By . css ( HelperTestFunctions . YEAR_CSSCLASS ) ) ;
15941601 let currentYear = dom . query ( By . css ( HelperTestFunctions . CURRENT_YEAR_CSSCLASS ) ) ;
@@ -1609,20 +1616,33 @@ describe('IgxCalendar - ', () => {
16091616 currentYear = dom . query ( By . css ( HelperTestFunctions . CURRENT_YEAR_CSSCLASS ) ) ;
16101617 expect ( currentYear . nativeElement . textContent . trim ( ) ) . toMatch ( '2016' ) ;
16111618
1619+ const previousValue = fixture . componentInstance . calendar . viewDate ;
1620+ spyOn ( calendar . onViewDateChanged , 'emit' ) . and . callThrough ( ) ;
1621+
16121622 UIInteractions . triggerKeyDownEvtUponElem ( 'Enter' , currentYear . nativeElement ) ;
1623+
16131624 fixture . detectChanges ( ) ;
1625+ tick ( ) ;
16141626
1627+ const eventArgs : IViewDateChangeEventArgs = { previousValue, currentValue : fixture . componentInstance . calendar . viewDate } ;
1628+ expect ( calendar . onViewDateChanged . emit ) . toHaveBeenCalledTimes ( 1 ) ;
1629+ expect ( calendar . onViewDateChanged . emit ) . toHaveBeenCalledWith ( eventArgs ) ;
16151630 expect ( calendar . viewDate . getFullYear ( ) ) . toEqual ( 2016 ) ;
1616- } ) ;
1631+ } ) ) ;
16171632
1618- it ( 'Should open months view, navigate through and select a month via KB.' , ( ) => {
1633+ it ( 'Should open months view, navigate through and select a month via KB.' , fakeAsync ( ( ) => {
16191634 const month = dom . queryAll ( By . css ( HelperTestFunctions . CALENDAR_DATE_CSSCLASS ) ) [ 0 ] ;
16201635 month . nativeElement . focus ( ) ;
1636+ spyOn ( calendar . onActiveViewChanged , 'emit' ) . and . callThrough ( ) ;
16211637
16221638 expect ( month . nativeElement ) . toBe ( document . activeElement ) ;
16231639
16241640 UIInteractions . triggerKeyDownEvtUponElem ( 'Enter' , document . activeElement ) ;
16251641 fixture . detectChanges ( ) ;
1642+ tick ( ) ;
1643+
1644+ expect ( calendar . onActiveViewChanged . emit ) . toHaveBeenCalledTimes ( 1 ) ;
1645+ expect ( calendar . onActiveViewChanged . emit ) . toHaveBeenCalledWith ( CalendarView . YEAR ) ;
16261646
16271647 const months = dom . queryAll ( By . css ( HelperTestFunctions . MONTH_CSSCLASS ) ) ;
16281648 const currentMonth = dom . query ( By . css ( HelperTestFunctions . CURRENT_MONTH_CSSCLASS ) ) ;
@@ -1651,11 +1671,18 @@ describe('IgxCalendar - ', () => {
16511671
16521672 expect ( document . activeElement . textContent . trim ( ) ) . toMatch ( 'Sep' ) ;
16531673
1674+ const previousValue = fixture . componentInstance . calendar . viewDate ;
1675+ spyOn ( calendar . onViewDateChanged , 'emit' ) . and . callThrough ( ) ;
1676+
16541677 UIInteractions . triggerKeyDownEvtUponElem ( 'Enter' , document . activeElement ) ;
16551678 fixture . detectChanges ( ) ;
1679+ tick ( ) ;
16561680
1681+ const eventArgs : IViewDateChangeEventArgs = { previousValue, currentValue : fixture . componentInstance . calendar . viewDate } ;
1682+ expect ( calendar . onViewDateChanged . emit ) . toHaveBeenCalledTimes ( 1 ) ;
1683+ expect ( calendar . onViewDateChanged . emit ) . toHaveBeenCalledWith ( eventArgs ) ;
16571684 expect ( calendar . viewDate . getMonth ( ) ) . toEqual ( 8 ) ;
1658- } ) ;
1685+ } ) ) ;
16591686
16601687 it ( 'Should navigate to the first enabled date from the previous month when using "arrow up" key.' , fakeAsync ( ( ) => {
16611688 const dateRangeDescriptors : DateRangeDescriptor [ ] = [ ] ;
0 commit comments