@@ -15,7 +15,7 @@ import { DateRangeType } from '../core/dates';
15
15
import { IgxDateRangePickerComponent , IgxDateRangeEndComponent } from './public_api' ;
16
16
import { AutoPositionStrategy , IgxOverlayService } from '../services/public_api' ;
17
17
import { AnimationMetadata , AnimationOptions } from '@angular/animations' ;
18
- import { IgxCalendarComponent , WEEKDAYS } from '../calendar/public_api' ;
18
+ import { IgxCalendarComponent , IgxCalendarHeaderTemplateDirective , IgxCalendarHeaderTitleTemplateDirective , IgxCalendarSubheaderTemplateDirective , WEEKDAYS } from '../calendar/public_api' ;
19
19
import { Subject } from 'rxjs' ;
20
20
import { AsyncPipe } from '@angular/common' ;
21
21
import { AnimationService } from '../services/animation/animation' ;
@@ -44,6 +44,9 @@ const CSS_CLASS_OVERLAY_CONTENT = 'igx-overlay__content';
44
44
const CSS_CLASS_DATE_RANGE = 'igx-date-range-picker' ;
45
45
const CSS_CLASS_CALENDAR_DATE = 'igx-days-view__date' ;
46
46
const CSS_CLASS_INACTIVE_DATE = 'igx-days-view__date--inactive' ;
47
+ const CSS_CLASS_CALENDAR_HEADER = '.igx-calendar__header-date' ;
48
+ const CSS_CLASS_CALENDAR_HEADER_TITLE = '.igx-calendar__header-year' ;
49
+ const CSS_CLASS_CALENDAR_SUBHEADER = '.igx-calendar-picker__dates' ;
47
50
48
51
describe ( 'IgxDateRangePicker' , ( ) => {
49
52
describe ( 'Unit tests: ' , ( ) => {
@@ -1562,6 +1565,62 @@ describe('IgxDateRangePicker', () => {
1562
1565
expect ( dateRange . locale ) . toEqual ( 'en-US' ) ;
1563
1566
expect ( dateRange . weekStart ) . toEqual ( WEEKDAYS . FRIDAY ) ;
1564
1567
} ) ) ;
1568
+
1569
+ it ( 'Should render calendar with header in dialog mode by default' , fakeAsync ( ( ) => {
1570
+ fixture = TestBed . createComponent ( DateRangeDefaultComponent ) ;
1571
+ fixture . detectChanges ( ) ;
1572
+ dateRange = fixture . componentInstance . dateRange ;
1573
+ dateRange . mode = 'dialog' ;
1574
+ dateRange . open ( ) ;
1575
+ tick ( ) ;
1576
+ fixture . detectChanges ( ) ;
1577
+
1578
+ expect ( dateRange [ '_calendar' ] . hasHeader ) . toBeTrue ( ) ;
1579
+ const calendarHeader = fixture . debugElement . query ( By . css ( CSS_CLASS_CALENDAR_HEADER ) ) ;
1580
+ expect ( calendarHeader ) . toBeTruthy ( 'Calendar header should be present' ) ;
1581
+ } ) ) ;
1582
+
1583
+ describe ( 'Templated Calendar Header' , ( ) => {
1584
+ let dateRangeDebugEl : DebugElement ;
1585
+ beforeEach ( fakeAsync ( ( ) => {
1586
+ TestBed . configureTestingModule ( {
1587
+ imports : [ DateRangeTemplatesComponent ]
1588
+ } ) . compileComponents ( ) ;
1589
+
1590
+ fixture = TestBed . createComponent ( DateRangeTemplatesComponent ) ;
1591
+ fixture . detectChanges ( ) ;
1592
+ dateRangeDebugEl = fixture . debugElement . queryAll ( By . directive ( IgxDateRangePickerComponent ) ) [ 0 ] ;
1593
+ dateRange = dateRangeDebugEl . componentInstance ;
1594
+ dateRange . mode = 'dialog' ;
1595
+ dateRange . open ( ) ;
1596
+ tick ( ) ;
1597
+ fixture . detectChanges ( ) ;
1598
+ } ) ) ;
1599
+
1600
+ it ( 'Should use the custom template for header title' , fakeAsync ( ( ) => {
1601
+ const headerTitleElement = dateRangeDebugEl . query ( By . css ( CSS_CLASS_CALENDAR_HEADER_TITLE ) ) ;
1602
+ expect ( headerTitleElement ) . toBeTruthy ( 'Header title element should be present' ) ;
1603
+ if ( headerTitleElement ) {
1604
+ expect ( headerTitleElement . nativeElement . textContent . trim ( ) ) . toBe ( 'Test header title' ) ;
1605
+ }
1606
+ } ) ) ;
1607
+
1608
+ it ( 'Should use the custom template for header' , fakeAsync ( ( ) => {
1609
+ const headerElement = dateRangeDebugEl . query ( By . css ( CSS_CLASS_CALENDAR_HEADER ) ) ;
1610
+ expect ( headerElement ) . toBeTruthy ( 'Header element should be present' ) ;
1611
+ if ( headerElement ) {
1612
+ expect ( headerElement . nativeElement . textContent . trim ( ) ) . toBe ( 'Test header' ) ;
1613
+ }
1614
+ } ) ) ;
1615
+
1616
+ it ( 'Should use the custom template for subheader' , fakeAsync ( ( ) => {
1617
+ const headerElement = dateRangeDebugEl . query ( By . css ( CSS_CLASS_CALENDAR_SUBHEADER ) ) ;
1618
+ expect ( headerElement ) . toBeTruthy ( 'Subheader element should be present' ) ;
1619
+ if ( headerElement ) {
1620
+ expect ( headerElement . nativeElement . textContent . trim ( ) ) . toBe ( 'Test subheader' ) ;
1621
+ }
1622
+ } ) ) ;
1623
+ } ) ;
1565
1624
} ) ;
1566
1625
} ) ;
1567
1626
} ) ;
@@ -1684,6 +1743,9 @@ export class DateRangeCustomComponent extends DateRangeTestComponent {
1684
1743
<igx-picker-toggle igxPrefix>
1685
1744
<igx-icon>flight_takeoff</igx-icon>
1686
1745
</igx-picker-toggle>
1746
+ <ng-template igxCalendarHeader let-formatCalendar>Test header</ng-template>
1747
+ <ng-template igxCalendarHeaderTitle let-formatCalendar>Test header title</ng-template>
1748
+ <ng-template igxCalendarSubheader let-formatCalendar>Test subheader</ng-template>
1687
1749
</igx-date-range-picker>
1688
1750
<igx-date-range-picker #suffixSingleRange>
1689
1751
<igx-picker-toggle igxSuffix>
@@ -1727,7 +1789,10 @@ export class DateRangeCustomComponent extends DateRangeTestComponent {
1727
1789
IgxInputDirective ,
1728
1790
IgxDateTimeEditorDirective ,
1729
1791
IgxPrefixDirective ,
1730
- IgxSuffixDirective
1792
+ IgxSuffixDirective ,
1793
+ IgxCalendarHeaderTemplateDirective ,
1794
+ IgxCalendarHeaderTitleTemplateDirective ,
1795
+ IgxCalendarSubheaderTemplateDirective
1731
1796
]
1732
1797
} )
1733
1798
export class DateRangeTemplatesComponent extends DateRangeTestComponent {
0 commit comments