Skip to content

Commit 1c9733c

Browse files
committed
chore(calendar): fix sample update changelog #7039
1 parent 8a04499 commit 1c9733c

File tree

3 files changed

+63
-12
lines changed

3 files changed

+63
-12
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ All notable changes for each version of this project will be documented in this
1919
- Removed `onDataPreLoad` event as it is specific for remote virtualization implementation, which is not supported for the `igxTreeGrid`. A more generic `onScroll` event is exposed and can be used instead.
2020

2121
### New Features
22+
- `IgxCalendar` and `IgxMonthPicker`
23+
- `onViewDateChanged` emitted after the month/year presented in the view is changed after user interaction.
24+
- `onActiveViewChanged` event emitted after the active view (DEFAULT, YEAR, DECADE) is changed after user interaction.
25+
- `viewDate` day value is always 1.
26+
- `activeView` setter is now available as an input property.
2227
- `IgxGridState` directive
2328
- Added support for expansion states, column selection and row pinning.
2429
- Added support for `IgxTreeGrid` and `IgxHierarchicalGrid` (including child grids)

projects/igniteui-angular/src/lib/calendar/calendar.component.spec.ts

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ 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';
1111
import { DateRangeDescriptor, DateRangeType } from '../core/dates/dateRange';
1212

1313
import { configureTestSuite } from '../test-utils/configure-suite';
1414
import { IgxDayItemComponent } from './days-view/day-item.component';
1515
import { HelperTestFunctions } from './calendar-helper-utils';
16+
import { CalendarView } from './month-picker-base';
17+
import { IViewDateChangeEventArgs } from './calendar-base';
1618

17-
describe('IgxCalendar - ', () => {
19+
fdescribe('IgxCalendar - ', () => {
1820

1921
it('Should create proper calendar model', () => {
2022
const calendar = new Calendar();
@@ -1554,41 +1556,66 @@ describe('IgxCalendar - ', () => {
15541556
dom = fixture.debugElement;
15551557
}));
15561558

1557-
it('Should navigate to the previous/next month via KB.', fakeAsync(() => {
1559+
fit('Should navigate to the previous/next month via KB.', fakeAsync(() => {
1560+
fixture.detectChanges();
1561+
const next = dom.queryAll(By.css(HelperTestFunctions.CALENDAR_NEXT_BUTTON_CSSCLASS))[0];
15581562
const prev = dom.queryAll(By.css(HelperTestFunctions.CALENDAR_PREV_BUTTON_CSSCLASS))[0];
1563+
1564+
let previousValue = fixture.componentInstance.calendar.viewDate;
15591565
prev.nativeElement.focus();
1566+
spyOn(calendar.onViewDateChanged, 'emit').and.callThrough();
15601567

15611568
expect(prev.nativeElement).toBe(document.activeElement);
15621569

15631570
UIInteractions.triggerKeyDownEvtUponElem('Enter', prev.nativeElement);
1564-
tick(100);
15651571
fixture.detectChanges();
1572+
const tt = flush();
1573+
tick(100);
15661574

1575+
let eventArgs: IViewDateChangeEventArgs = { previousValue, currentValue: fixture.componentInstance.calendar.viewDate };
1576+
expect(calendar.onViewDateChanged.emit).toHaveBeenCalledTimes(1);
1577+
expect(calendar.onViewDateChanged.emit).toHaveBeenCalledWith(eventArgs);
15671578
expect(calendar.viewDate.getMonth()).toEqual(4);
15681579

1569-
const next = dom.queryAll(By.css(HelperTestFunctions.CALENDAR_NEXT_BUTTON_CSSCLASS))[0];
15701580
next.nativeElement.focus();
1581+
previousValue = fixture.componentInstance.calendar.viewDate;
15711582
expect(next.nativeElement).toBe(document.activeElement);
15721583

15731584
UIInteractions.triggerKeyDownEvtUponElem('Enter', next.nativeElement);
1574-
tick(100);
1585+
15751586
fixture.detectChanges();
1587+
tick(100);
15761588

1589+
eventArgs = { previousValue, currentValue: fixture.componentInstance.calendar.viewDate };
1590+
expect(calendar.onViewDateChanged.emit).toHaveBeenCalledTimes(1);
1591+
expect(calendar.onViewDateChanged.emit).toHaveBeenCalledWith(eventArgs);
1592+
1593+
previousValue = fixture.componentInstance.calendar.viewDate;
15771594
UIInteractions.triggerKeyDownEvtUponElem('Enter', next.nativeElement);
1578-
tick(100);
1595+
15791596
fixture.detectChanges();
1597+
tick(100);
15801598

1599+
eventArgs = { previousValue, currentValue: fixture.componentInstance.calendar.viewDate };
1600+
expect(calendar.onViewDateChanged.emit).toHaveBeenCalledTimes(1);
1601+
expect(calendar.onViewDateChanged.emit).toHaveBeenCalledWith(eventArgs);
15811602
expect(calendar.viewDate.getMonth()).toEqual(6);
15821603
}));
15831604

1584-
it('Should open years view, navigate through and select an year via KB.', () => {
1605+
it('Should open years view, navigate through and select an year via KB.', fakeAsync(() => {
15851606
const year = dom.queryAll(By.css(HelperTestFunctions.CALENDAR_DATE_CSSCLASS))[1];
15861607
year.nativeElement.focus();
15871608

15881609
expect(year.nativeElement).toBe(document.activeElement);
15891610

1611+
spyOn(calendar.onActiveViewChanged, 'emit').and.callThrough();
1612+
15901613
UIInteractions.triggerKeyDownEvtUponElem('Enter', document.activeElement);
15911614
fixture.detectChanges();
1615+
tick();
1616+
1617+
expect(calendar.onActiveViewChanged.emit).toHaveBeenCalledTimes(1);
1618+
expect(calendar.onActiveViewChanged.emit).toHaveBeenCalledWith(CalendarView.DECADE);
15921619

15931620
const years = dom.queryAll(By.css(HelperTestFunctions.YEAR_CSSCLASS));
15941621
let currentYear = dom.query(By.css(HelperTestFunctions.CURRENT_YEAR_CSSCLASS));
@@ -1609,20 +1636,33 @@ describe('IgxCalendar - ', () => {
16091636
currentYear = dom.query(By.css(HelperTestFunctions.CURRENT_YEAR_CSSCLASS));
16101637
expect(currentYear.nativeElement.textContent.trim()).toMatch('2016');
16111638

1639+
const previousValue = fixture.componentInstance.calendar.viewDate;
1640+
spyOn(calendar.onViewDateChanged, 'emit').and.callThrough();
1641+
16121642
UIInteractions.triggerKeyDownEvtUponElem('Enter', currentYear.nativeElement);
1643+
16131644
fixture.detectChanges();
1645+
tick();
16141646

1647+
const eventArgs: IViewDateChangeEventArgs = { previousValue, currentValue: fixture.componentInstance.calendar.viewDate };
1648+
expect(calendar.onViewDateChanged.emit).toHaveBeenCalledTimes(1);
1649+
expect(calendar.onViewDateChanged.emit).toHaveBeenCalledWith(eventArgs);
16151650
expect(calendar.viewDate.getFullYear()).toEqual(2016);
1616-
});
1651+
}));
16171652

1618-
it('Should open months view, navigate through and select a month via KB.', () => {
1653+
it('Should open months view, navigate through and select a month via KB.', fakeAsync(() => {
16191654
const month = dom.queryAll(By.css(HelperTestFunctions.CALENDAR_DATE_CSSCLASS))[0];
16201655
month.nativeElement.focus();
1656+
spyOn(calendar.onActiveViewChanged, 'emit').and.callThrough();
16211657

16221658
expect(month.nativeElement).toBe(document.activeElement);
16231659

16241660
UIInteractions.triggerKeyDownEvtUponElem('Enter', document.activeElement);
16251661
fixture.detectChanges();
1662+
tick();
1663+
1664+
expect(calendar.onActiveViewChanged.emit).toHaveBeenCalledTimes(1);
1665+
expect(calendar.onActiveViewChanged.emit).toHaveBeenCalledWith(CalendarView.YEAR);
16261666

16271667
const months = dom.queryAll(By.css(HelperTestFunctions.MONTH_CSSCLASS));
16281668
const currentMonth = dom.query(By.css(HelperTestFunctions.CURRENT_MONTH_CSSCLASS));
@@ -1651,11 +1691,18 @@ describe('IgxCalendar - ', () => {
16511691

16521692
expect(document.activeElement.textContent.trim()).toMatch('Sep');
16531693

1694+
const previousValue = fixture.componentInstance.calendar.viewDate;
1695+
spyOn(calendar.onViewDateChanged, 'emit').and.callThrough();
1696+
16541697
UIInteractions.triggerKeyDownEvtUponElem('Enter', document.activeElement);
16551698
fixture.detectChanges();
1699+
tick();
16561700

1701+
const eventArgs: IViewDateChangeEventArgs = { previousValue, currentValue: fixture.componentInstance.calendar.viewDate };
1702+
expect(calendar.onViewDateChanged.emit).toHaveBeenCalledTimes(1);
1703+
expect(calendar.onViewDateChanged.emit).toHaveBeenCalledWith(eventArgs);
16571704
expect(calendar.viewDate.getMonth()).toEqual(8);
1658-
});
1705+
}));
16591706

16601707
it('Should navigate to the first enabled date from the previous month when using "arrow up" key.', fakeAsync(() => {
16611708
const dateRangeDescriptors: DateRangeDescriptor[] = [];

src/app/calendar/calendar.sample.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Component, OnInit, ViewChild } from '@angular/core';
22
import { IgxCalendarComponent, DateRangeType, CalendarView } from 'igniteui-angular';
33
import { IViewDateChangeEventArgs } from '../../../projects/igniteui-angular/src/lib/calendar/calendar-base';
4-
import { CalendarView } from '../../../projects/igniteui-angular/src/lib/calendar/public_api';
54

65
@Component({
76
selector: 'app-calendar-sample',

0 commit comments

Comments
 (0)