• 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

79.59
/projects/igniteui-angular/src/lib/directives/for-of/base.helper.component.ts
1
import {
2
    HostListener,
3
    ElementRef,
4
    ChangeDetectorRef,
5
    OnDestroy,
6
    Directive,
7
    AfterViewInit,
8
    Inject,
9
    NgZone
10
} from '@angular/core';
11
import { DOCUMENT } from '@angular/common';
12
import { Subject } from 'rxjs';
13
import { takeUntil, throttleTime } from 'rxjs/operators';
14
import { resizeObservable, PlatformUtil } from '../../core/utils';
15

16
@Directive({
17
    selector: '[igxVirtualHelperBase]',
18
    standalone: true
19
})
20
export class VirtualHelperBaseDirective implements OnDestroy, AfterViewInit {
2✔
21
    public scrollAmount = 0;
114✔
22
    public _size = 0;
114✔
23
    public destroyed;
24

25
    protected destroy$ = new Subject<any>();
114✔
26

27
    private _afterViewInit = false;
114✔
28
    private _scrollNativeSize: number;
29
    private _detached = false;
114✔
30

31
    constructor(
32
        public elementRef: ElementRef<HTMLElement>,
114✔
33
        public cdr: ChangeDetectorRef,
114✔
34
        protected _zone: NgZone,
114✔
35
        @Inject(DOCUMENT) public document: any,
114✔
36
        protected platformUtil: PlatformUtil,
114✔
37
    ) {
38
        this._scrollNativeSize = this.calculateScrollNativeSize();
114✔
39
    }
40

41
    @HostListener('scroll', ['$event'])
42
    public onScroll(event) {
UNCOV
43
        this.scrollAmount = event.target.scrollTop || event.target.scrollLeft;
×
44
    }
45

46

47
    public ngAfterViewInit() {
48
        this._afterViewInit = true;
114✔
49
        if (!this.platformUtil.isBrowser) {
114!
50
            return;
×
51
        }
52
        const delayTime = 0;
114✔
53
        this._zone.runOutsideAngular(() => {
114✔
54
            resizeObservable(this.nativeElement).pipe(
114✔
55
                throttleTime(delayTime),
UNCOV
56
                takeUntil(this.destroy$)).subscribe((event) => this.handleMutations(event));
×
57
        });
58
    }
59

60
    public get nativeElement() {
61
        return this.elementRef.nativeElement;
3,830✔
62
    }
63

64
    public ngOnDestroy() {
65
        this.destroyed = true;
114✔
66
        this.destroy$.next(true);
114✔
67
        this.destroy$.complete();
114✔
68
    }
69

70
    public calculateScrollNativeSize() {
71
        const div = this.document.createElement('div');
114✔
72
        const style = div.style;
114✔
73
        style.width = '100px';
114✔
74
        style.height = '100px';
114✔
75
        style.position = 'absolute';
114✔
76
        style.top = '-10000px';
114✔
77
        style.top = '-10000px';
114✔
78
        style.overflow = 'scroll';
114✔
79
        this.document.body.appendChild(div);
114✔
80
        const scrollWidth = div.offsetWidth - div.clientWidth;
114✔
81
        this.document.body.removeChild(div);
114✔
82
        return scrollWidth ? scrollWidth + 1 : 1;
114!
83
    }
84

85
    public set size(value) {
86
        if (this.destroyed) {
984!
UNCOV
87
            return;
×
88
        }
89
        this._size = value;
984✔
90
        if (this._afterViewInit) {
984✔
91
            this.cdr.detectChanges();
682✔
92
        }
93
    }
94

95
    public get size() {
96
        return this._size;
5,360✔
97
    }
98

99
    public get scrollNativeSize() {
100
        return this._scrollNativeSize;
1,708✔
101
    }
102

103
    protected get isAttachedToDom(): boolean {
UNCOV
104
        return this.document.body.contains(this.nativeElement);
×
105
    }
106

107
    protected handleMutations(event) {
UNCOV
108
        const hasSize = !(event[0].contentRect.height === 0 && event[0].contentRect.width === 0);
×
UNCOV
109
        if (!hasSize && !this.isAttachedToDom) {
×
110
            // scroll bar detached from DOM
UNCOV
111
            this._detached = true;
×
UNCOV
112
        } else if (this._detached && hasSize && this.isAttachedToDom) {
×
113
            // attached back now.
UNCOV
114
            this.restoreScroll();
×
115
        }
116
    }
117

118
    protected restoreScroll() {}
119
}
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