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

atinc / ngx-tethys / #96

12 Aug 2025 06:20AM UTC coverage: 90.341% (+0.02%) from 90.324%
#96

push

web-flow
refactor(date-picker): migrate to signal for date-picker #TINFR-1463 (#3513)

* refactor(date-picker): migrate to signal for calendar header

* refactor(date-picker): migrate to signal for calendar footer

* refactor(date-picker): migrate to signal for calendar table

* refactor(date-picker): migrate to signal for date table cell

* refactor(date-picker): migrate to signal for date carousel

* refactor(date-picker): migrate to signal for inner-popup and date-popup

* refactor(date-picker): migrate to signal for pickers

5531 of 6813 branches covered (81.18%)

Branch coverage included in aggregate %.

342 of 367 new or added lines in 20 files covered. (93.19%)

66 existing lines in 11 files now uncovered.

13969 of 14772 relevant lines covered (94.56%)

904.1 hits per line

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

86.11
/src/date-picker/lib/calendar/calendar-table.component.ts
1
import { Directive, input, OnInit, Signal, SimpleChange, SimpleChanges, TemplateRef, model, output, effect } from '@angular/core';
2
import { injectLocale, ThyDatePickerLocale } from 'ngx-tethys/i18n';
3
import { SafeAny } from 'ngx-tethys/types';
4
import { coerceBooleanProperty, FunctionProp, isTemplateRef, TinyDate } from 'ngx-tethys/util';
5
import { DateBodyRow, DateCell } from '../date/types';
6
import { DisabledDateFn } from 'ngx-tethys/date-picker';
7

8
/**
9
 * @private
1✔
10
 */
11
@Directive()
244✔
12
export abstract class CalendarTable implements OnInit {
244✔
13
    protected locale: Signal<ThyDatePickerLocale> = injectLocale('datePicker');
244✔
14

244✔
15
    isTemplateRef = isTemplateRef;
244✔
16

244✔
17
    headRow: DateCell[] = [];
244✔
18

244✔
19
    bodyRows: DateBodyRow[] = [];
244✔
20

244✔
21
    MAX_ROW = 6;
244✔
22

244✔
23
    MAX_COL = 7;
244✔
24

244✔
25
    readonly prefixCls = input<string>('thy-calendar');
244✔
26

244✔
27
    readonly value = model<TinyDate>();
244✔
28

29
    readonly activeDate = model<TinyDate>(new TinyDate());
30

697!
31
    readonly showWeek = input(false, { transform: coerceBooleanProperty });
697✔
32

697✔
33
    readonly selectedValue = input<TinyDate[]>([]);
34

35
    readonly hoverValue = input<TinyDate[]>([]);
36

590✔
37
    readonly timeZone = input<string>();
38

39
    readonly disabledDate = input<DisabledDateFn>();
1,820✔
40

41
    readonly cellRender = input<FunctionProp<TemplateRef<Date> | string>>();
NEW
42

×
43
    readonly valueChange = output<TinyDate>();
44

45
    readonly cellHover = output<TinyDate>(); // Emitted when hover on a day by mouse enter
243✔
46

47
    protected render(): void {
48
        if (this.activeDate()) {
500!
49
            this.headRow = this.makeHeadRow();
×
50
            this.bodyRows = this.makeBodyRows();
51
        }
500✔
52
    }
53

54
    trackByBodyRow(_index: number, item: DateBodyRow): SafeAny {
55
        return item.trackByIndex;
56
    }
57

58
    trackByBodyColumn(_index: number, item: DateCell): SafeAny {
442✔
59
        return item.trackByIndex;
60
    }
61

62
    hasRangeValue(): boolean {
488✔
63
        return this.selectedValue()?.length > 0 || this.hoverValue()?.length > 0;
365✔
64
    }
365✔
65

365✔
66
    abstract makeHeadRow(): DateCell[];
88✔
67

68
    abstract makeBodyRows(): DateBodyRow[];
UNCOV
69

×
UNCOV
70
    ngOnInit(): void {
×
71
        this.render();
72
    }
73

74
    ngOnChanges(changes: SimpleChanges): void {
277✔
75
        if (changes.activeDate && !changes.activeDate.currentValue) {
76
            this.activeDate.set(new TinyDate(undefined, this.timeZone()));
77
        }
123✔
78

79
        if (
80
            changes.disabledDate ||
277✔
81
            changes.locale ||
82
            changes.showWeek ||
1✔
83
            this.isDateRealChange(changes.activeDate) ||
84
            this.isDateRealChange(changes.value) ||
85
            this.isDateRealChange(changes.selectedValue) ||
86
            this.isDateRealChange(changes.hoverValue)
87
        ) {
88
            this.render();
89
        }
90
    }
91

92
    private isDateRealChange(change: SimpleChange): boolean {
93
        if (change) {
94
            const previousValue: TinyDate | TinyDate[] = change.previousValue;
95
            const currentValue: TinyDate | TinyDate[] = change.currentValue;
96
            if (Array.isArray(currentValue)) {
1✔
97
                return (
98
                    !Array.isArray(previousValue) ||
99
                    currentValue.length !== previousValue.length ||
100
                    currentValue.some((value, index) => {
101
                        const previousCandyDate = previousValue[index];
102
                        return previousCandyDate instanceof TinyDate ? previousCandyDate.isSameDay(value) : previousCandyDate !== value;
103
                    })
104
                );
105
            } else {
106
                return !this.isSameDate(previousValue as TinyDate, currentValue);
107
            }
108
        }
109
        return false;
110
    }
111

112
    private isSameDate(left: TinyDate, right: TinyDate): boolean {
113
        return (!left && !right) || (left && right && right.isSameDay(left));
114
    }
115
}
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