|
6 | 6 | IgxHintDirective, IgxInputGroupComponent, IgxInputState, IgxLabelDirective, IgxPrefixDirective, IgxSuffixDirective |
7 | 7 | } from '../input-group/public_api'; |
8 | 8 | import { configureTestSuite } from '../test-utils/configure-suite'; |
9 | | -import { IFormattingViews, IgxCalendarComponent, WEEKDAYS } from '../calendar/public_api'; |
| 9 | +import { IFormattingViews, IgxCalendarComponent, IgxCalendarHeaderTemplateDirective, IgxCalendarHeaderTitleTemplateDirective, WEEKDAYS } from '../calendar/public_api'; |
10 | 10 | import { IgxCalendarContainerComponent } from '../date-common/calendar-container/calendar-container.component'; |
11 | 11 | import { IgxDatePickerComponent } from './date-picker.component'; |
12 | 12 | import { |
@@ -46,6 +46,7 @@ describe('IgxDatePicker', () => { |
46 | 46 | IgxDatePickerTestComponent, |
47 | 47 | IgxDatePickerNgModelComponent, |
48 | 48 | IgxDatePickerWithProjectionsComponent, |
| 49 | + IgxDatePickerWithTemplatesComponent, |
49 | 50 | IgxDatePickerInFormComponent, |
50 | 51 | IgxDatePickerReactiveFormComponent |
51 | 52 | ] |
@@ -492,6 +493,47 @@ describe('IgxDatePicker', () => { |
492 | 493 | }); |
493 | 494 | }); |
494 | 495 |
|
| 496 | + describe('Templated Header', () => { |
| 497 | + let fixture: ComponentFixture<IgxDatePickerWithTemplatesComponent>; |
| 498 | + |
| 499 | + beforeEach(fakeAsync(() => { |
| 500 | + TestBed.configureTestingModule({ |
| 501 | + imports: [IgxDatePickerWithTemplatesComponent] |
| 502 | + }).compileComponents(); |
| 503 | + |
| 504 | + fixture = TestBed.createComponent(IgxDatePickerWithTemplatesComponent); |
| 505 | + fixture.detectChanges(); |
| 506 | + })); |
| 507 | + |
| 508 | + it('Should use the custom template for header title', fakeAsync(() => { |
| 509 | + const testDate = new Date(2024, 10, 11); |
| 510 | + fixture.componentInstance.datePicker.value = testDate; |
| 511 | + fixture.componentInstance.datePicker.open(); |
| 512 | + tick(); |
| 513 | + fixture.detectChanges(); |
| 514 | + |
| 515 | + const headerTitleElement = fixture.debugElement.query(By.css('.igx-calendar__header-year')); |
| 516 | + expect(headerTitleElement).toBeTruthy('Header title element should be present'); |
| 517 | + if (headerTitleElement) { |
| 518 | + expect(headerTitleElement.nativeElement.textContent.trim()).toBe('2024'); |
| 519 | + } |
| 520 | + })); |
| 521 | + |
| 522 | + it('Should use the custom template for header', fakeAsync(() => { |
| 523 | + const testDate = new Date(2024, 10, 11); |
| 524 | + fixture.componentInstance.datePicker.value = testDate; |
| 525 | + fixture.componentInstance.datePicker.open(); |
| 526 | + tick(); |
| 527 | + fixture.detectChanges(); |
| 528 | + |
| 529 | + const headerElement = fixture.debugElement.query(By.css('.igx-calendar__header-date')); |
| 530 | + expect(headerElement).toBeTruthy('Header element should be present'); |
| 531 | + if (headerElement) { |
| 532 | + expect(headerElement.nativeElement.textContent.trim()).toBe('Nov'); |
| 533 | + } |
| 534 | + })); |
| 535 | + }); |
| 536 | + |
495 | 537 | describe('UI Interaction', () => { |
496 | 538 | let fixture: ComponentFixture<any>; |
497 | 539 | let datePicker: IgxDatePickerComponent; |
@@ -1531,6 +1573,20 @@ export class IgxDatePickerWithProjectionsComponent { |
1531 | 1573 | public showCustomClear = false; |
1532 | 1574 | } |
1533 | 1575 |
|
| 1576 | +@Component({ |
| 1577 | + template: ` |
| 1578 | + <igx-date-picker [mode]="mode"> |
| 1579 | + <ng-template igxCalendarHeaderTitle let-formatCalendar>{{ formatCalendar.year.value }}</ng-template> |
| 1580 | + <ng-template igxCalendarHeader let-formatCalendar>{{ formatCalendar.month.value }}</ng-template> |
| 1581 | + </igx-date-picker>`, |
| 1582 | + standalone: true, |
| 1583 | + imports: [IgxDatePickerComponent, IgxCalendarHeaderTemplateDirective, IgxCalendarHeaderTitleTemplateDirective] |
| 1584 | +}) |
| 1585 | +export class IgxDatePickerWithTemplatesComponent { |
| 1586 | + @ViewChild(IgxDatePickerComponent) public datePicker: IgxDatePickerComponent; |
| 1587 | + public mode: PickerInteractionMode = PickerInteractionMode.Dialog; |
| 1588 | +} |
| 1589 | + |
1534 | 1590 | @Component({ |
1535 | 1591 | template: ` |
1536 | 1592 | <form #form="ngForm"> |
|
0 commit comments