Skip to content

Commit 2339866

Browse files
committed
test(date-picker): add test to cover custom template in calendar header
1 parent 6a7d3e8 commit 2339866

File tree

1 file changed

+58
-2
lines changed

1 file changed

+58
-2
lines changed

projects/igniteui-angular/src/lib/date-picker/date-picker.component.spec.ts

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
IgxHintDirective, IgxInputGroupComponent, IgxInputState, IgxLabelDirective, IgxPrefixDirective, IgxSuffixDirective
77
} from '../input-group/public_api';
88
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';
1010
import { IgxCalendarContainerComponent } from '../date-common/calendar-container/calendar-container.component';
1111
import { IgxDatePickerComponent } from './date-picker.component';
1212
import {
@@ -35,7 +35,7 @@ const DATE_PICKER_CLEAR_ICON = 'clear';
3535
const CSS_CLASS_INPUT_GROUP_REQUIRED = 'igx-input-group--required';
3636
const CSS_CLASS_INPUT_GROUP_INVALID = 'igx-input-group--invalid';
3737

38-
describe('IgxDatePicker', () => {
38+
fdescribe('IgxDatePicker', () => {
3939
describe('Integration tests', () => {
4040
configureTestSuite();
4141
beforeAll(waitForAsync(() => {
@@ -46,6 +46,7 @@ describe('IgxDatePicker', () => {
4646
IgxDatePickerTestComponent,
4747
IgxDatePickerNgModelComponent,
4848
IgxDatePickerWithProjectionsComponent,
49+
IgxDatePickerWithTemplatesComponent,
4950
IgxDatePickerInFormComponent,
5051
IgxDatePickerReactiveFormComponent
5152
]
@@ -492,6 +493,47 @@ describe('IgxDatePicker', () => {
492493
});
493494
});
494495

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+
495537
describe('UI Interaction', () => {
496538
let fixture: ComponentFixture<any>;
497539
let datePicker: IgxDatePickerComponent;
@@ -1531,6 +1573,20 @@ export class IgxDatePickerWithProjectionsComponent {
15311573
public showCustomClear = false;
15321574
}
15331575

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+
15341590
@Component({
15351591
template: `
15361592
<form #form="ngForm">

0 commit comments

Comments
 (0)