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

atinc / ngx-tethys / d34567a7-88ab-485c-8747-d70e0471b279

28 Aug 2024 07:28AM UTC coverage: 90.464% (-0.02%) from 90.479%
d34567a7-88ab-485c-8747-d70e0471b279

push

circleci

web-flow
test: eliminate warnings and errors on the console #TINFR-482 (#3186)

5510 of 6734 branches covered (81.82%)

Branch coverage included in aggregate %.

1 of 1 new or added line in 1 file covered. (100.0%)

2 existing lines in 2 files now uncovered.

13255 of 14009 relevant lines covered (94.62%)

993.25 hits per line

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

90.63
/src/anchor/anchor-link.component.ts
1
import { Platform } from '@angular/cdk/platform';
2
import {
3
    ChangeDetectionStrategy,
4
    Component,
5
    ContentChild,
6
    ElementRef,
7
    Input,
8
    OnDestroy,
9
    OnInit,
10
    TemplateRef,
11
    ViewChild,
1✔
12
    ViewEncapsulation
13
} from '@angular/core';
45✔
14
import { useHostRenderer } from '@tethys/cdk/dom';
1✔
15

1✔
16
import { ThyAnchor } from './anchor.component';
17
import { NgIf } from '@angular/common';
18

44✔
19
/**
20
 * 锚点链接组件,可供锚点跳转
21
 * @name thy-anchor-link,thyAnchorLink
22
 */
44✔
23
@Component({
44✔
24
    selector: 'thy-link,thy-anchor-link',
44✔
25
    exportAs: 'thyLink,thyAnchorLink',
44✔
26
    preserveWhitespaces: false,
44✔
27
    template: `
44✔
28
        <a #linkTitle (click)="goToClick($event)" href="{{ thyHref }}" class="thy-anchor-link-title" title="{{ title }}">
44✔
29
            <span *ngIf="title; else titleTemplate || thyTemplate">{{ title }}</span>
44!
UNCOV
30
        </a>
×
31
        <ng-content></ng-content>
32
    `,
33
    encapsulation: ViewEncapsulation.None,
34
    changeDetection: ChangeDetectionStrategy.OnPush,
44✔
35
    standalone: true,
36
    imports: [NgIf]
37
})
6✔
38
export class ThyAnchorLink implements OnInit, OnDestroy {
39
    title: string | null = '';
40

6✔
41
    titleTemplate?: TemplateRef<any>;
42

43
    private hostRenderer = useHostRenderer();
22✔
44

45
    /**
46
     * 锚点链接
3✔
47
     */
3✔
48
    @Input() thyHref = '#';
3!
49

3✔
50
    /**
51
     * 文字内容
52
     */
53
    @Input()
44✔
54
    set thyTitle(value: string | TemplateRef<void>) {
55
        if (value instanceof TemplateRef) {
1✔
56
            this.title = null;
57
            this.titleTemplate = value;
58
        } else {
59
            this.title = value;
60
        }
1✔
61
    }
62

63
    @ContentChild('thyTemplate') thyTemplate!: TemplateRef<void>;
64

65
    @ViewChild('linkTitle', { static: true }) linkTitle!: ElementRef<HTMLAnchorElement>;
66

67
    constructor(
1✔
68
        public elementRef: ElementRef,
69
        private anchorComponent: ThyAnchor,
70
        private platform: Platform
71
    ) {
72
        this.hostRenderer.addClass('thy-anchor-link');
73
        if (elementRef.nativeElement.tagName.toLowerCase() === 'thy-link') {
74
            console.warn(`'thy-link' and 'thyLink' are deprecated, please use 'thy-anchor-link' and 'thyAnchorLink' instead.`);
75
        }
76
    }
77

78
    ngOnInit(): void {
79
        this.anchorComponent.registerLink(this);
80
    }
81

82
    getLinkTitleElement(): HTMLAnchorElement {
83
        return this.linkTitle.nativeElement;
84
    }
85

86
    setActive(): void {
87
        this.hostRenderer.addClass('thy-anchor-link-active');
88
    }
89

90
    unsetActive(): void {
91
        this.hostRenderer.removeClass('thy-anchor-link-active');
92
    }
93

94
    goToClick(e: Event): void {
95
        e.preventDefault();
96
        e.stopPropagation();
97
        if (this.platform.isBrowser) {
98
            this.anchorComponent.handleScrollTo(this);
99
        }
100
    }
101

102
    ngOnDestroy(): void {
103
        this.anchorComponent.unregisterLink(this);
104
    }
105
}
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