• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IgniteUI / igniteui-angular / 13331632524

14 Feb 2025 02:51PM CUT coverage: 22.015% (-69.6%) from 91.622%
13331632524

Pull #15372

github

web-flow
Merge d52d57714 into bcb78ae0a
Pull Request #15372: chore(*): test ci passing

1990 of 15592 branches covered (12.76%)

431 of 964 new or added lines in 18 files covered. (44.71%)

19956 existing lines in 307 files now uncovered.

6452 of 29307 relevant lines covered (22.02%)

249.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

37.5
/projects/igniteui-angular/src/lib/test-utils/calendar-helper-utils.ts
1
import { ComponentFixture } from '@angular/core/testing';
2
import { By } from '@angular/platform-browser';
3

4
export class HelperTestFunctions {
5
    public static DAYS_VIEW = 'igx-days-view';
2✔
6
    public static CALENDAR = 'igx-calendar';
2✔
7
    public static SELECTED_DATE = 'igx-days-view__date--selected';
2✔
8
    public static ICON_CSSCLASS = '.igx-icon';
2✔
9
    public static OVERLAY_CSSCLASS = '.igx-overlay';
2✔
10
    public static MODAL_OVERLAY_CSSCLASS = 'igx-overlay__wrapper--modal';
2✔
11

12
    public static CALENDAR_CSSCLASS = '.igx-calendar';
2✔
13
    public static CALENDAR_WRAPPER_CLASS = '.igx-calendar__wrapper';
2✔
14
    public static CALENDAR_WEEK_NUMBER_CLASS = '.igx-days-view__date--week-number';
2✔
15
    public static CALENDAR_WEEK_NUMBER_ITEM_CLASS = '.igx-days-view__date-inner--week-number';
2✔
16
    public static CALENDAR_WEEK_NUMBER_LABEL_CLASS = '.igx-days-view__label--week-number';
2✔
17
    public static CALENDAR_HEADER_CSSCLASS = '.igx-calendar__header';
2✔
18
    public static CALENDAR_HEADER_YEAR_CSSCLASS = '.igx-calendar__header-year';
2✔
19
    public static CALENDAR_HEADER_DATE_CSSCLASS = '.igx-calendar__header-date';
2✔
20
    public static WEEKSTART_LABEL_CSSCLASS = '.igx-days-view__label';
2✔
21
    public static VERTICAL_CALENDAR_CSSCLASS = '.igx-calendar__wrapper--vertical';
2✔
22
    public static DAY_CSSCLASS = '.igx-days-view__date';
2✔
23
    public static CURRENT_MONTH_DATES = '.igx-days-view__date:not(.igx-days-view__date--inactive)';
2✔
24
    public static CURRENT_DATE_CSSCLASS = '.igx-days-view__date--current';
2✔
25
    public static INACTIVE_DAYS_CSSCLASS = '.igx-days-view__date--inactive';
2✔
26
    public static HIDDEN_DAYS_CSSCLASS = '.igx-days-view__date--hidden';
2✔
27
    public static SELECTED_DATE_CSSCLASS = '.igx-days-view__date--selected';
2✔
28
    public static RANGE_CSSCLASS = 'igx-days-view__date--range';
2✔
29
    public static CALENDAR_ROW_CSSCLASS = '.igx-days-view__row';
2✔
30
    public static CALENDAR_ROW_WRAP_CSSCLASS = '.igx-days-view__row--wrap';
2✔
31
    public static MONTH_CSSCLASS = '.igx-calendar-view__item';
2✔
32
    public static CURRENT_MONTH_CSSCLASS = '.igx-calendar-view__item--selected';
2✔
33
    public static YEAR_CSSCLASS = '.igx-calendar-view__item';
2✔
34
    public static CURRENT_YEAR_CSSCLASS = '.igx-calendar-view__item--selected';
2✔
35

36
    public static CALENDAR_PREV_BUTTON_CSSCLASS = '.igx-calendar-picker__prev';
2✔
37
    public static CALENDAR_NEXT_BUTTON_CSSCLASS = '.igx-calendar-picker__next';
2✔
38
    public static CALENDAR_DATE_CSSCLASS = '.igx-calendar-picker__date';
2✔
39

40
    public static CALENDAR_SUBHEADERS_SELECTOR =
2✔
41
        'div:not(' + HelperTestFunctions.CALENDAR_PREV_BUTTON_CSSCLASS + '):not(' + HelperTestFunctions.CALENDAR_NEXT_BUTTON_CSSCLASS + ')';
42

43
    public static verifyMonthsViewNumber(fixture, monthsView: number, checkCurrentDate = false) {
×
UNCOV
44
        const el = fixture.nativeElement ? fixture.nativeElement : fixture;
×
UNCOV
45
        const daysView = el.querySelectorAll(HelperTestFunctions.DAYS_VIEW);
×
UNCOV
46
        expect(daysView).toBeDefined();
×
UNCOV
47
        expect(daysView.length).toBe(monthsView);
×
UNCOV
48
        const monthPickers = HelperTestFunctions.getCalendarSubHeader(el).querySelectorAll('.igx-calendar-picker__dates');
×
UNCOV
49
        expect(monthPickers.length).toBe(monthsView);
×
UNCOV
50
        if (checkCurrentDate) {
×
UNCOV
51
            const currentDate = el.querySelector(HelperTestFunctions.CURRENT_DATE_CSSCLASS);
×
UNCOV
52
            expect(currentDate).not.toBeNull();
×
53
        }
54
    }
55

56
    public static verifyCalendarHeader(fixture: ComponentFixture<any>, selectedDate: Date) {
UNCOV
57
        const daysView = fixture.nativeElement.querySelector(HelperTestFunctions.CALENDAR_HEADER_CSSCLASS);
×
UNCOV
58
        expect(daysView).not.toBeNull();
×
59

UNCOV
60
        const year = fixture.nativeElement.querySelector(HelperTestFunctions.CALENDAR_HEADER_YEAR_CSSCLASS);
×
UNCOV
61
        expect(year).not.toBeNull();
×
UNCOV
62
        expect(year.innerText).toEqual("Select Date");
×
63

UNCOV
64
        const date = fixture.nativeElement.querySelector(HelperTestFunctions.CALENDAR_HEADER_DATE_CSSCLASS);
×
UNCOV
65
        expect(date).not.toBeNull();
×
66

UNCOV
67
        const dateParts = selectedDate.toUTCString().split(' '); // (weekday, date month year)
×
UNCOV
68
        expect(date.children[0].innerText.trim()).toEqual(dateParts[0]);
×
UNCOV
69
        expect(date.children[1].innerText.trim()).toEqual(dateParts[2] + ' ' + Number(dateParts[1]));
×
70
    }
71

72
    public static verifyNoRangeSelectionCreated(fixture, monthNumber: number) {
UNCOV
73
        expect(HelperTestFunctions.getMonthView(fixture, monthNumber).querySelector('.igx-days-view__date--range')).toBeNull();
×
UNCOV
74
        expect(HelperTestFunctions.getMonthView(fixture, monthNumber).querySelector('.igx-days-view__date--first')).toBeNull();
×
UNCOV
75
        expect(HelperTestFunctions.getMonthView(fixture, monthNumber).querySelector('.igx-days-view__date--last')).toBeNull();
×
76
    }
77

78
    public static verifyCalendarSubHeader(fixture, monthNumber: number, viewDate: Date) {
79
        const monthPickers = HelperTestFunctions.getCalendarSubHeader(fixture).querySelectorAll('div');
×
80
        const dateParts = viewDate.toString().split(' '); // weekday month day year
×
81
        expect(monthPickers[monthNumber].children[0].innerHTML.trim()).toEqual(dateParts[1]);
×
82
        expect(monthPickers[monthNumber].children[1].innerHTML.trim()).toEqual(dateParts[3]);
×
83
    }
84

85
    public static verifyCalendarSubHeaders(fixture, viewDates: Date[]) {
UNCOV
86
        const dom = fixture.nativeElement ? fixture.nativeElement : fixture;
×
UNCOV
87
        const monthPickers = HelperTestFunctions.getCalendarSubHeader(dom).querySelectorAll('.igx-calendar-picker__dates');
×
88

UNCOV
89
        expect(monthPickers.length).toEqual(viewDates.length);
×
90

UNCOV
91
        for (let index = 0; index < viewDates.length; index++) {
×
UNCOV
92
            const dateParts = viewDates[index].toString().split(' '); // weekday month day year
×
UNCOV
93
            const monthPickerDates = monthPickers[index].querySelectorAll('.igx-calendar-picker__date');
×
UNCOV
94
            expect(monthPickerDates[0].innerHTML.trim()).toContain(dateParts[1]);
×
UNCOV
95
            expect(monthPickerDates[1].innerHTML.trim()).toContain(dateParts[3]);
×
96
        }
97
    }
98

99
    public static getHiddenDays(fixture, monthNumber: number) {
UNCOV
100
        const monthView = HelperTestFunctions.getMonthView(fixture, monthNumber);
×
UNCOV
101
        return monthView.querySelectorAll(HelperTestFunctions.HIDDEN_DAYS_CSSCLASS);
×
102
    }
103

104
    public static getInactiveDays(fixture, monthNumber: number) {
UNCOV
105
        const monthView = HelperTestFunctions.getMonthView(fixture, monthNumber);
×
UNCOV
106
        return monthView.querySelectorAll(HelperTestFunctions.INACTIVE_DAYS_CSSCLASS);
×
107
    }
108

109
    public static getCalendarSubHeader(fixture): HTMLElement {
UNCOV
110
        const element = fixture.nativeElement ? fixture.nativeElement : fixture;
×
UNCOV
111
        return element.querySelector('.igx-calendar__pickers');
×
112
    }
113

114
    public static getMonthView(fixture, monthsViewNumber: number) {
UNCOV
115
        const domEL = fixture.nativeElement ? fixture.nativeElement : fixture;
×
UNCOV
116
        return domEL.querySelectorAll('igx-days-view')[monthsViewNumber];
×
117
    }
118

119
    public static getMonthViewDates(fixture, monthsViewNumber: number) {
UNCOV
120
        const month = HelperTestFunctions.getMonthView(fixture, monthsViewNumber);
×
UNCOV
121
        return month.querySelectorAll(HelperTestFunctions.CURRENT_MONTH_DATES);
×
122
    }
123

124
    public static getMonthViewInactiveDates(fixture, monthsViewNumber: number) {
125
        const month = HelperTestFunctions.getMonthView(fixture, monthsViewNumber);
×
126
        return month.querySelectorAll(HelperTestFunctions.INACTIVE_DAYS_CSSCLASS);
×
127
    }
128

129
    public static getMonthViewSelectedDates(fixture, monthsViewNumber: number) {
UNCOV
130
        const month = HelperTestFunctions.getMonthView(fixture, monthsViewNumber);
×
UNCOV
131
        return month.querySelectorAll(HelperTestFunctions.SELECTED_DATE_CSSCLASS +
×
132
            `:not(${HelperTestFunctions.HIDDEN_DAYS_CSSCLASS})`);
133
    }
134

135
    public static getMonthsFromMonthView(fixture) {
UNCOV
136
        return fixture.nativeElement.querySelector('igx-months-view')
×
137
            .querySelectorAll('.igx-calendar-view__item, .igx-calendar-view__item--current');
138
    }
139

140
    public static getYearsFromYearView(fixture) {
UNCOV
141
        return fixture.nativeElement.querySelector('igx-years-view')
×
142
            .querySelectorAll('.igx-calendar-view__item, .igx-calendar-view__item--selected');
143
    }
144

145
    public static getCurrentYearsFromYearView(fixture) {
146
        return fixture.nativeElement.querySelector('igx-years-view')
×
147
            .querySelector('.igx-calendar-view__item--current');
148
    }
149

150
    public static getNexArrowElement(fixture) {
UNCOV
151
        return fixture.debugElement.query(By.css(HelperTestFunctions.CALENDAR_NEXT_BUTTON_CSSCLASS)).nativeElement;
×
152
    }
153

154
    public static getPreviousArrowElement(fixture) {
UNCOV
155
        return fixture.debugElement.query(By.css(HelperTestFunctions.CALENDAR_PREV_BUTTON_CSSCLASS)).nativeElement;
×
156
    }
157

158
    public static verifyDateSelected(el) {
UNCOV
159
        expect(
×
160
            el.nativeElement.classList.contains(
161
                HelperTestFunctions.SELECTED_DATE
162
            )
163
        ).toBe(true);
164
    }
165

166
    public static verifyDateNotSelected(el) {
UNCOV
167
        expect(
×
168
            el.nativeElement.classList.contains(
169
                HelperTestFunctions.SELECTED_DATE
170
            )
171
        ).toBe(false);
172
    }
173
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc