@@ -7,12 +7,14 @@ import {
7
7
Calendar , IgxCalendarComponent , IgxCalendarModule , isLeap ,
8
8
monthRange , weekDay , WEEKDAYS
9
9
} from './public_api' ;
10
- import { UIInteractions } from '../test-utils/ui-interactions.spec' ;
10
+ import { UIInteractions , wait } from '../test-utils/ui-interactions.spec' ;
11
11
import { DateRangeDescriptor , DateRangeType } from '../core/dates/dateRange' ;
12
12
13
13
import { configureTestSuite } from '../test-utils/configure-suite' ;
14
14
import { IgxDayItemComponent } from './days-view/day-item.component' ;
15
15
import { HelperTestFunctions } from './calendar-helper-utils' ;
16
+ import { CalendarView } from './month-picker-base' ;
17
+ import { IViewDateChangeEventArgs } from './calendar-base' ;
16
18
17
19
describe ( 'IgxCalendar - ' , ( ) => {
18
20
@@ -252,8 +254,8 @@ describe('IgxCalendar - ', () => {
252
254
expect ( calendar . formatOptions ) . toEqual ( jasmine . objectContaining ( defaultOptions ) ) ;
253
255
expect ( calendar . formatViews ) . toEqual ( jasmine . objectContaining ( defaultViews ) ) ;
254
256
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 ' ) ;
257
259
expect ( bodyYear . nativeElement . textContent . trim ( ) ) . toMatch ( '2018' ) ;
258
260
expect ( bodyMonth . nativeElement . textContent . trim ( ) ) . toMatch ( 'Sep' ) ;
259
261
@@ -267,8 +269,8 @@ describe('IgxCalendar - ', () => {
267
269
expect ( calendar . formatOptions ) . toEqual ( jasmine . objectContaining ( Object . assign ( defaultOptions , formatOptions ) ) ) ;
268
270
expect ( calendar . formatViews ) . toEqual ( jasmine . objectContaining ( Object . assign ( defaultViews , formatViews ) ) ) ;
269
271
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 ' ) ;
272
274
expect ( bodyYear . nativeElement . textContent . trim ( ) ) . toMatch ( '18' ) ;
273
275
expect ( bodyMonth . nativeElement . textContent . trim ( ) ) . toMatch ( 'September' ) ;
274
276
@@ -283,8 +285,8 @@ describe('IgxCalendar - ', () => {
283
285
expect ( calendar . formatOptions ) . toEqual ( jasmine . objectContaining ( Object . assign ( defaultOptions , formatOptions ) ) ) ;
284
286
expect ( calendar . formatViews ) . toEqual ( jasmine . objectContaining ( Object . assign ( defaultViews , formatViews ) ) ) ;
285
287
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 ' ) ;
288
290
expect ( bodyYear . nativeElement . textContent . trim ( ) ) . toMatch ( '2018' ) ;
289
291
expect ( bodyMonth . nativeElement . textContent . trim ( ) ) . toMatch ( '8' ) ;
290
292
} ) ;
@@ -305,8 +307,8 @@ describe('IgxCalendar - ', () => {
305
307
fixture . detectChanges ( ) ;
306
308
307
309
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 ' ) ;
310
312
expect ( bodyYear . nativeElement . textContent . trim ( ) ) . toMatch ( '2018' ) ;
311
313
expect ( bodyMonth . nativeElement . textContent . trim ( ) ) . toMatch ( 'Sep' ) ;
312
314
expect ( bodyWeekday . nativeElement . textContent . trim ( ) ) . toMatch ( 'Sun' ) ;
@@ -319,8 +321,8 @@ describe('IgxCalendar - ', () => {
319
321
bodyWeekday = dom . query ( By . css ( HelperTestFunctions . WEEKSTART_LABEL_CSSCLASS ) ) ;
320
322
expect ( calendar . locale ) . toEqual ( locale ) ;
321
323
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.' ) ;
324
326
expect ( bodyYear . nativeElement . textContent . trim ( ) ) . toMatch ( '18' ) ;
325
327
expect ( bodyMonth . nativeElement . textContent . trim ( ) ) . toMatch ( 'sept.' ) ;
326
328
expect ( bodyWeekday . nativeElement . textContent . trim ( ) ) . toMatch ( 'Dim.' ) ;
@@ -1559,36 +1561,41 @@ describe('IgxCalendar - ', () => {
1559
1561
prev . nativeElement . focus ( ) ;
1560
1562
1561
1563
expect ( prev . nativeElement ) . toBe ( document . activeElement ) ;
1562
-
1563
1564
UIInteractions . triggerKeyDownEvtUponElem ( 'Enter' , prev . nativeElement ) ;
1564
1565
tick ( 100 ) ;
1565
1566
fixture . detectChanges ( ) ;
1566
1567
1567
1568
expect ( calendar . viewDate . getMonth ( ) ) . toEqual ( 4 ) ;
1568
-
1569
1569
const next = dom . queryAll ( By . css ( HelperTestFunctions . CALENDAR_NEXT_BUTTON_CSSCLASS ) ) [ 0 ] ;
1570
1570
next . nativeElement . focus ( ) ;
1571
1571
expect ( next . nativeElement ) . toBe ( document . activeElement ) ;
1572
1572
1573
1573
UIInteractions . triggerKeyDownEvtUponElem ( 'Enter' , next . nativeElement ) ;
1574
- tick ( 100 ) ;
1575
- fixture . detectChanges ( ) ;
1576
1574
1575
+ fixture . detectChanges ( ) ;
1576
+ tick ( 100 ) ;
1577
1577
UIInteractions . triggerKeyDownEvtUponElem ( 'Enter' , next . nativeElement ) ;
1578
1578
tick ( 100 ) ;
1579
1579
fixture . detectChanges ( ) ;
1580
1580
1581
+
1581
1582
expect ( calendar . viewDate . getMonth ( ) ) . toEqual ( 6 ) ;
1582
1583
} ) ) ;
1583
1584
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 ( ( ) => {
1585
1586
const year = dom . queryAll ( By . css ( HelperTestFunctions . CALENDAR_DATE_CSSCLASS ) ) [ 1 ] ;
1586
1587
year . nativeElement . focus ( ) ;
1587
1588
1588
1589
expect ( year . nativeElement ) . toBe ( document . activeElement ) ;
1589
1590
1591
+ spyOn ( calendar . onActiveViewChanged , 'emit' ) . and . callThrough ( ) ;
1592
+
1590
1593
UIInteractions . triggerKeyDownEvtUponElem ( 'Enter' , document . activeElement ) ;
1591
1594
fixture . detectChanges ( ) ;
1595
+ tick ( ) ;
1596
+
1597
+ expect ( calendar . onActiveViewChanged . emit ) . toHaveBeenCalledTimes ( 1 ) ;
1598
+ expect ( calendar . onActiveViewChanged . emit ) . toHaveBeenCalledWith ( CalendarView . DECADE ) ;
1592
1599
1593
1600
const years = dom . queryAll ( By . css ( HelperTestFunctions . YEAR_CSSCLASS ) ) ;
1594
1601
let currentYear = dom . query ( By . css ( HelperTestFunctions . CURRENT_YEAR_CSSCLASS ) ) ;
@@ -1609,20 +1616,33 @@ describe('IgxCalendar - ', () => {
1609
1616
currentYear = dom . query ( By . css ( HelperTestFunctions . CURRENT_YEAR_CSSCLASS ) ) ;
1610
1617
expect ( currentYear . nativeElement . textContent . trim ( ) ) . toMatch ( '2016' ) ;
1611
1618
1619
+ const previousValue = fixture . componentInstance . calendar . viewDate ;
1620
+ spyOn ( calendar . onViewDateChanged , 'emit' ) . and . callThrough ( ) ;
1621
+
1612
1622
UIInteractions . triggerKeyDownEvtUponElem ( 'Enter' , currentYear . nativeElement ) ;
1623
+
1613
1624
fixture . detectChanges ( ) ;
1625
+ tick ( ) ;
1614
1626
1627
+ const eventArgs : IViewDateChangeEventArgs = { previousValue, currentValue : fixture . componentInstance . calendar . viewDate } ;
1628
+ expect ( calendar . onViewDateChanged . emit ) . toHaveBeenCalledTimes ( 1 ) ;
1629
+ expect ( calendar . onViewDateChanged . emit ) . toHaveBeenCalledWith ( eventArgs ) ;
1615
1630
expect ( calendar . viewDate . getFullYear ( ) ) . toEqual ( 2016 ) ;
1616
- } ) ;
1631
+ } ) ) ;
1617
1632
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 ( ( ) => {
1619
1634
const month = dom . queryAll ( By . css ( HelperTestFunctions . CALENDAR_DATE_CSSCLASS ) ) [ 0 ] ;
1620
1635
month . nativeElement . focus ( ) ;
1636
+ spyOn ( calendar . onActiveViewChanged , 'emit' ) . and . callThrough ( ) ;
1621
1637
1622
1638
expect ( month . nativeElement ) . toBe ( document . activeElement ) ;
1623
1639
1624
1640
UIInteractions . triggerKeyDownEvtUponElem ( 'Enter' , document . activeElement ) ;
1625
1641
fixture . detectChanges ( ) ;
1642
+ tick ( ) ;
1643
+
1644
+ expect ( calendar . onActiveViewChanged . emit ) . toHaveBeenCalledTimes ( 1 ) ;
1645
+ expect ( calendar . onActiveViewChanged . emit ) . toHaveBeenCalledWith ( CalendarView . YEAR ) ;
1626
1646
1627
1647
const months = dom . queryAll ( By . css ( HelperTestFunctions . MONTH_CSSCLASS ) ) ;
1628
1648
const currentMonth = dom . query ( By . css ( HelperTestFunctions . CURRENT_MONTH_CSSCLASS ) ) ;
@@ -1651,11 +1671,18 @@ describe('IgxCalendar - ', () => {
1651
1671
1652
1672
expect ( document . activeElement . textContent . trim ( ) ) . toMatch ( 'Sep' ) ;
1653
1673
1674
+ const previousValue = fixture . componentInstance . calendar . viewDate ;
1675
+ spyOn ( calendar . onViewDateChanged , 'emit' ) . and . callThrough ( ) ;
1676
+
1654
1677
UIInteractions . triggerKeyDownEvtUponElem ( 'Enter' , document . activeElement ) ;
1655
1678
fixture . detectChanges ( ) ;
1679
+ tick ( ) ;
1656
1680
1681
+ const eventArgs : IViewDateChangeEventArgs = { previousValue, currentValue : fixture . componentInstance . calendar . viewDate } ;
1682
+ expect ( calendar . onViewDateChanged . emit ) . toHaveBeenCalledTimes ( 1 ) ;
1683
+ expect ( calendar . onViewDateChanged . emit ) . toHaveBeenCalledWith ( eventArgs ) ;
1657
1684
expect ( calendar . viewDate . getMonth ( ) ) . toEqual ( 8 ) ;
1658
- } ) ;
1685
+ } ) ) ;
1659
1686
1660
1687
it ( 'Should navigate to the first enabled date from the previous month when using "arrow up" key.' , fakeAsync ( ( ) => {
1661
1688
const dateRangeDescriptors : DateRangeDescriptor [ ] = [ ] ;
0 commit comments