• 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

89.47
/src/shared/option/option.component.ts
1
import {
2
    Component,
3
    Input,
4
    TemplateRef,
5
    ViewChild,
6
    ChangeDetectionStrategy,
7
    HostBinding,
8
    HostListener,
9
    ElementRef,
×
10
    ChangeDetectorRef,
117✔
11
    EventEmitter,
117✔
12
    OnDestroy,
13
    Output,
14
    inject
15
} from '@angular/core';
16
import { Highlightable } from '@angular/cdk/a11y';
17
import { SelectOptionBase } from './select-option-base';
18
import { ENTER, SPACE, coerceBooleanProperty, hasModifierKey } from 'ngx-tethys/util';
19
import {
20
    IThyOptionGroupComponent,
1✔
21
    IThyOptionParentComponent,
22
    THY_OPTION_GROUP_COMPONENT,
580✔
23
    THY_OPTION_PARENT_COMPONENT
24
} from './option.token';
25

4,730✔
26
import { ThyIcon } from 'ngx-tethys/icon';
27

28
export class ThyOptionSelectionChangeEvent {
4,979✔
29
    constructor(
30
        public option: ThyOption,
31
        public isUserInput = false
9,975✔
32
    ) {}
33
}
34

4,730✔
35
export class ThyOptionVisibleChangeEvent {
36
    option: ThyOption;
37
}
4,911✔
38

39
/**
40
 * @private
953✔
41
 * @order 20
953✔
42
 */
953✔
43
@Component({
953✔
44
    selector: 'thy-option',
953✔
45
    templateUrl: './option.component.html',
953✔
46
    changeDetection: ChangeDetectionStrategy.OnPush,
953✔
47
    standalone: true,
953✔
48
    imports: [ThyIcon]
953✔
49
})
953✔
50
export class ThyOption extends SelectOptionBase implements OnDestroy, Highlightable {
953✔
51
    element = inject<ElementRef<HTMLElement>>(ElementRef);
52
    parent = inject(THY_OPTION_PARENT_COMPONENT, { optional: true })!;
53
    group = inject(THY_OPTION_GROUP_COMPONENT, { optional: true })!;
166✔
54
    private cdr = inject(ChangeDetectorRef);
55

56
    private _selected = false;
28✔
57
    private _hidden = false;
58
    private _disabled = false;
UNCOV
59

×
UNCOV
60
    @Input() thyValue: any;
×
UNCOV
61

×
62
    @Input() thyRawValue: any;
63

64
    @Input() thyLabelText: string;
65

37✔
66
    @Input() thyShowOptionCustom: boolean;
36✔
67

36✔
68
    @Input() thySearchKey: string;
36✔
69

70
    @HostBinding('class.thy-option-item') _isOptionItem = true;
71

72
    @ViewChild(TemplateRef, { static: true }) template: TemplateRef<any>;
92✔
73

90✔
74
    @Input({ transform: coerceBooleanProperty })
48✔
75
    @HostBinding(`class.disabled`)
48✔
76
    set thyDisabled(value: boolean) {
48✔
77
        this._disabled = value;
78
    }
79

80
    get thyDisabled(): boolean {
81
        return this._disabled;
35✔
82
    }
30✔
83

30✔
84
    get disabled(): boolean {
30✔
85
        return this.hidden || this._disabled;
86
    }
87

88
    @HostBinding('class.hidden')
40✔
89
    get hidden(): boolean {
34✔
90
        return this._hidden;
34✔
91
    }
34✔
92

93
    @HostBinding('attr.tabindex')
94
    get tabIndex(): string {
95
        return this.disabled ? '-1' : '0';
12✔
96
    }
7✔
97

7✔
98
    @HostBinding(`class.active`)
7✔
99
    get selected(): boolean {
100
        return this._selected;
101
    }
102

52✔
103
    @Output() readonly selectionChange: EventEmitter<ThyOptionSelectionChangeEvent> = new EventEmitter();
8✔
104
    @Output() readonly visibleChange: EventEmitter<ThyOptionVisibleChangeEvent> = new EventEmitter();
1✔
105

106
    constructor() {
107
        super();
7✔
108
    }
109

110
    getHostElement(): HTMLElement {
111
        return this.element.nativeElement;
44✔
112
    }
11✔
113

114
    @HostListener('click', ['$event'])
115
    onClick(event: Event) {
33✔
116
        this.selectViaInteraction();
117
    }
118

119
    @HostListener('keydown', ['$event'])
120
    handleKeydown(event: KeyboardEvent): void {
118✔
121
        if ((event.keyCode === ENTER || event.keyCode === SPACE) && !hasModifierKey(event)) {
118✔
122
            this.selectViaInteraction();
123
            event.preventDefault();
124
        }
48✔
125
    }
48✔
126

127
    selectViaInteraction(): void {
UNCOV
128
        if (!this.disabled) {
×
129
            this._selected = this.parent.isMultiple ? !this._selected : true;
130
            this.cdr.markForCheck();
78✔
131
            this.emitSelectionChangeEvent(true);
114✔
132
        }
133
    }
134

1✔
135
    select(event?: Event): void {
1✔
136
        if (!this.disabled) {
137
            if (!this._selected) {
138
                this._selected = true;
139
                this.emitSelectionChangeEvent();
140
                this.cdr.markForCheck();
141
            }
142
        }
143
    }
144

145
    deselect(): void {
146
        if (this._selected || this.disabled) {
147
            this._selected = false;
148
            this.emitSelectionChangeEvent();
149
            this.cdr.markForCheck();
150
        }
151
    }
152

153
    hideOption() {
1✔
154
        if (!this._hidden) {
155
            this._hidden = true;
156
            this.visibleChange.emit({ option: this });
157
            this.cdr.markForCheck();
158
        }
159
    }
160

161
    showOption() {
162
        if (this._hidden) {
163
            this._hidden = false;
164
            this.visibleChange.emit({ option: this });
165
            this.cdr.markForCheck();
166
        }
167
    }
168

169
    matchSearchText(searchText: string): boolean {
170
        if (this.thySearchKey) {
171
            if (this.thySearchKey.toLowerCase().indexOf(searchText.toLowerCase()) >= 0) {
172
                return true;
173
            } else {
174
                return false;
175
            }
176
        } else {
177
            if (this.thyLabelText.toLowerCase().indexOf(searchText.toLowerCase()) >= 0) {
178
                return true;
179
            } else {
180
                return false;
181
            }
182
        }
183
    }
184

185
    setActiveStyles(): void {
186
        this.getHostElement().classList.add('hover');
187
        this.cdr.markForCheck();
188
    }
189

190
    setInactiveStyles(): void {
191
        this.getHostElement().classList.remove('hover');
192
        this.cdr.markForCheck();
193
    }
194

195
    getLabel(): string {
196
        return '';
197
    }
198

199
    private emitSelectionChangeEvent(isUserInput = false): void {
200
        this.selectionChange.emit(new ThyOptionSelectionChangeEvent(this, isUserInput));
201
    }
202

203
    ngOnDestroy() {}
204
}
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