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

atinc / ngx-tethys / cd64db52-e563-41a3-85f3-a0adb87ce135

30 Oct 2024 08:03AM UTC coverage: 90.402% (-0.04%) from 90.438%
cd64db52-e563-41a3-85f3-a0adb87ce135

push

circleci

web-flow
refactor: refactor constructor to the inject function (#3222)

5503 of 6730 branches covered (81.77%)

Branch coverage included in aggregate %.

422 of 429 new or added lines in 170 files covered. (98.37%)

344 existing lines in 81 files now uncovered.

13184 of 13941 relevant lines covered (94.57%)

997.19 hits per line

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

93.1
/src/tooltip/tooltip.component.ts
1
import {
2
    Component,
3
    ViewEncapsulation,
4
    ChangeDetectionStrategy,
5
    ChangeDetectorRef,
6
    HostBinding,
7
    TemplateRef,
8
    OnInit,
9
    inject
10
} from '@angular/core';
11
import { Observable, Subject } from 'rxjs';
12
import { AnimationEvent } from '@angular/animations';
1✔
13
import { useHostRenderer } from '@tethys/cdk/dom';
14
import { ThyTooltipVisibility } from './interface';
24✔
15
import { thyTooltipAnimations } from './tooltip-animations';
24✔
16
import { coerceArray } from 'ngx-tethys/util';
24✔
17
import { NgTemplateOutlet } from '@angular/common';
24✔
18

24✔
19
/**
24✔
20
 * @internal
24✔
21
 */
24✔
22
@Component({
23
    selector: 'thy-tooltip',
24
    templateUrl: './tooltip.component.html',
39✔
25
    encapsulation: ViewEncapsulation.None,
26
    changeDetection: ChangeDetectionStrategy.OnPush,
27
    animations: [thyTooltipAnimations.tooltipState],
25✔
28
    host: {
25✔
29
        '[@state]': 'visibility',
30
        '(@state.start)': 'animationStart()',
31
        '(@state.done)': 'animationDone($event)'
24✔
32
    },
24!
33
    standalone: true,
24✔
34
    imports: [NgTemplateOutlet]
35
})
24✔
36
export class ThyTooltip implements OnInit {
37
    private changeDetectorRef = inject(ChangeDetectorRef);
38

39
    @HostBinding(`class.thy-tooltip`) addTooltipContainerClass = true;
77✔
40

41
    _content: string | TemplateRef<HTMLElement>;
42

64✔
43
    data: any;
44

45
    private readonly onHide: Subject<void> = new Subject();
46

24!
UNCOV
47
    private closeOnInteraction = false;
×
UNCOV
48

×
49
    private hostRenderer = useHostRenderer();
50

51
    visibility: ThyTooltipVisibility = 'initial';
24✔
52

24✔
53
    showTimeoutId: number | null | any;
22✔
54

22✔
55
    hideTimeoutId: number | null | any;
22✔
56

57
    tooltipClasses: string[] = [];
58

59
    isTemplateRef = false;
60

30✔
61
    get content() {
2✔
62
        return this._content;
2✔
63
    }
64

30✔
65
    set content(value: string | TemplateRef<HTMLElement>) {
30✔
66
        this._content = value;
30✔
67
        this.isTemplateRef = value instanceof TemplateRef;
30✔
68
    }
69

70
    private updateClasses() {
71
        let classes: string[] = [];
52✔
72

73
        if (this.tooltipClasses) {
74
            classes = classes.concat(this.tooltipClasses);
52✔
75
        }
52✔
76

9✔
77
        this.hostRenderer.updateClass(classes);
78
    }
52✔
79

26✔
80
    ngOnInit() {}
81

82
    markForCheck(): void {
83
        this.changeDetectorRef.markForCheck();
24✔
84
    }
85

86
    isVisible() {
24✔
87
        return this.visibility === 'visible';
24✔
88
    }
89

90
    show(delay: number): void {
1✔
91
        // Cancel the delayed hide if it is scheduled
92
        if (this.hideTimeoutId) {
93
            clearTimeout(this.hideTimeoutId);
94
            this.hideTimeoutId = null;
1✔
95
        }
96

97
        // Body interactions should cancel the tooltip if there is a delay in showing.
98
        this.closeOnInteraction = true;
99
        this.showTimeoutId = setTimeout(() => {
100
            this.visibility = 'visible';
101
            this.showTimeoutId = null;
102
            this.markForCheck();
103
        }, delay);
104
    }
105

106
    hide(delay: number): void {
107
        // Cancel the delayed show if it is scheduled
108
        if (this.showTimeoutId) {
109
            clearTimeout(this.showTimeoutId);
110
            this.showTimeoutId = null;
111
        }
112

113
        this.hideTimeoutId = setTimeout(() => {
114
            this.visibility = 'hidden';
115
            this.hideTimeoutId = null;
116
            this.markForCheck();
117
        }, delay);
118
    }
119

120
    animationStart() {
121
        this.closeOnInteraction = false;
122
    }
123

124
    animationDone(event: AnimationEvent): void {
125
        const toState = event.toState as ThyTooltipVisibility;
126
        if (toState === 'hidden' && !this.isVisible()) {
127
            this.onHide.next();
128
        }
129
        if (toState === 'visible' || toState === 'hidden') {
130
            this.closeOnInteraction = true;
131
        }
132
    }
133

134
    afterHidden(): Observable<void> {
135
        return this.onHide.asObservable();
136
    }
137

138
    setTooltipClass(classes: string | string[]) {
139
        this.tooltipClasses = coerceArray(classes);
140
        this.updateClasses();
141
        // this.markForCheck();
142
    }
143
}
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

© 2026 Coveralls, Inc