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

atinc / ngx-tethys / c0ef8457-a839-451f-8b72-80fd73106231

02 Apr 2024 02:27PM UTC coverage: 90.524% (-0.06%) from 90.585%
c0ef8457-a839-451f-8b72-80fd73106231

Pull #3062

circleci

minlovehua
refactor(all): use the transform attribute of @Input() instead of @InputBoolean() and @InputNumber()
Pull Request #3062: refactor(all): use the transform attribute of @input() instead of @InputBoolean() and @InputNumber()

4987 of 6108 branches covered (81.65%)

Branch coverage included in aggregate %.

217 of 223 new or added lines in 82 files covered. (97.31%)

202 existing lines in 53 files now uncovered.

12246 of 12929 relevant lines covered (94.72%)

1055.59 hits per line

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

85.29
/src/shared/option/group/option-group.component.ts
1
import {
2
    Component,
3
    HostBinding,
4
    Input,
5
    ContentChildren,
6
    QueryList,
7
    NgZone,
8
    OnDestroy,
9
    AfterContentInit,
10
    ChangeDetectorRef,
11
    booleanAttribute
1✔
12
} from '@angular/core';
13
import { Observable, defer, Subject, merge } from 'rxjs';
43✔
14
import { ThyOptionVisibleChangeEvent, ThyOption } from '../option.component';
15
import { take, switchMap, startWith, takeUntil, debounceTime, map } from 'rxjs/operators';
16
import { THY_OPTION_GROUP_COMPONENT } from '../option.token';
8✔
17

8✔
18
/**
8✔
19
 * @private
8✔
20
 */
8✔
21
@Component({
8✔
UNCOV
22
    selector: 'thy-option-group',
×
23
    templateUrl: './option-group.component.html',
×
24
    providers: [
UNCOV
25
        {
×
26
            provide: THY_OPTION_GROUP_COMPONENT,
27
            useExisting: ThySelectOptionGroup
28
        }
29
    ],
8✔
30
    standalone: true
8✔
31
})
32
export class ThySelectOptionGroup implements OnDestroy, AfterContentInit {
33
    _hidden = false;
34
    @Input({ transform: booleanAttribute })
8✔
35
    @HostBinding(`class.disabled`)
11✔
36
    thyDisabled: boolean;
37

5✔
38
    @HostBinding('class.thy-option-item-group') _isOptionGroup = true;
10✔
39

1✔
40
    @HostBinding('class.thy-select-option-group-hidden')
41
    get hidden(): boolean {
42
        return this._hidden;
5✔
43
    }
1✔
44

45
    @Input() thyGroupLabel: string;
46

4✔
47
    @ContentChildren(ThyOption) options: QueryList<ThyOption>;
48

49
    _destroy$: Subject<void> = new Subject<void>();
50

5✔
51
    optionVisibleChanges: Observable<ThyOptionVisibleChangeEvent> = defer(() => {
5✔
52
        if (this.options) {
53
            return merge(...this.options.map(option => option.visibleChange));
54
        }
55
        return this._ngZone.onStable.asObservable().pipe(
8✔
56
            take(1),
8✔
57
            switchMap(() => this.optionVisibleChanges)
58
        );
1✔
59
    }) as Observable<ThyOptionVisibleChangeEvent>;
60

61
    constructor(private _ngZone: NgZone, private cdr: ChangeDetectorRef) {}
62

1✔
63
    ngAfterContentInit() {
64
        this.options.changes.pipe(startWith(null), takeUntil(this._destroy$)).subscribe(() => {
65
            this._resetOptions();
66
        });
67
    }
68

69
    _resetOptions() {
70
        const changedOrDestroyed$ = merge(this.options.changes, this._destroy$);
1✔
71
        merge(...this.options.map(option => option.visibleChange))
72
            .pipe(
73
                takeUntil(changedOrDestroyed$),
74
                debounceTime(10),
75
                map((event: ThyOptionVisibleChangeEvent) => {
76
                    const hasOption = this.options.find(option => {
77
                        if (!option.hidden) {
78
                            return true;
79
                        }
80
                    });
81
                    if (hasOption) {
82
                        return false;
83
                    } else {
84
                        return true;
85
                    }
86
                })
87
            )
88
            .subscribe((data: boolean) => {
89
                this._hidden = data;
90
                this.cdr.markForCheck();
91
            });
92
    }
93

94
    ngOnDestroy() {
95
        this._destroy$.next();
96
        this._destroy$.complete();
97
    }
98
}
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