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

atinc / ngx-tethys / c572ad56-6796-461c-8809-6e2d7ed05a21

16 Apr 2025 06:23AM UTC coverage: 90.271% (+0.001%) from 90.27%
c572ad56-6796-461c-8809-6e2d7ed05a21

Pull #3341

circleci

minlovehua
refactor(all): resolve 30 circular denpendencies TINFR-1830
Pull Request #3341: refactor(all): resolve 30 circular denpendencies TINFR-1830

5614 of 6878 branches covered (81.62%)

Branch coverage included in aggregate %.

89 of 94 new or added lines in 38 files covered. (94.68%)

64 existing lines in 12 files now uncovered.

13370 of 14152 relevant lines covered (94.47%)

922.06 hits per line

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

92.94
/src/guider/guider-ref.ts
1
import { Router } from '@angular/router';
2
import { helpers } from 'ngx-tethys/util';
3
import { DOCUMENT } from '@angular/common';
4
import { ThyPopover } from 'ngx-tethys/popover';
5
import { IThyGuiderManager, IThyGuiderRef } from './guider.interface';
6
import { ThyGuiderStepRef } from './guider-step-ref';
7
import { Observable, ReplaySubject, Subject } from 'rxjs';
8
import { ThyGuiderConfig, ThyGuiderStep } from './guider.class';
9
import { Inject, NgZone, RendererFactory2 } from '@angular/core';
10
import { Overlay } from '@angular/cdk/overlay';
11

12
export class ThyGuiderRef implements IThyGuiderRef {
27✔
13
    public steps: ThyGuiderStep[];
27✔
14

27✔
15
    private stepChange$: ReplaySubject<ThyGuiderStep> = new ReplaySubject<ThyGuiderStep>();
27✔
16

27✔
17
    private guiderEnded$ = new Subject<ThyGuiderStep>();
27✔
18

27✔
19
    private closed$ = new Subject<ThyGuiderStep>();
27✔
20

27✔
21
    private targetClicked$ = new Subject<ThyGuiderStep>();
27✔
22

27✔
23
    private currentStep: ThyGuiderStep;
27✔
24

27✔
25
    private currentStepIndex: number;
50✔
26

27
    private stepsRef: ThyGuiderStepRef[];
27✔
28

29
    constructor(
30
        public config: ThyGuiderConfig,
13✔
31
        private rendererFactory: RendererFactory2,
32
        private popover: ThyPopover,
33
        private router: Router,
1✔
34
        private guiderManager: IThyGuiderManager,
35
        private ngZone: NgZone,
36
        private overlay: Overlay,
27✔
37
        @Inject(DOCUMENT) private document: any
38
    ) {
39
        this.stepsRef = config.steps.map((step, index) => {
2✔
40
            return new ThyGuiderStepRef(step, index, this.rendererFactory, this.popover, this.guiderManager, this.overlay, this.document);
41
        });
42
        this.steps = config.steps;
13✔
43
    }
13✔
44

45
    public stepChange(): Observable<ThyGuiderStep> {
46
        return this.stepChange$.asObservable();
1!
UNCOV
47
    }
×
48

49
    public ended(): Subject<ThyGuiderStep> {
1✔
50
        return this.guiderEnded$;
51
    }
52

1!
NEW
53
    public closed(): Subject<ThyGuiderStep> {
×
54
        return this.closed$;
55
    }
1✔
56

57
    public targetClicked(): Subject<ThyGuiderStep> {
58
        return this.targetClicked$;
7✔
59
    }
6✔
60

6✔
61
    public start(startWith?: number) {
62
        this.to(startWith);
1!
63

2✔
64
        return this.stepChange();
1✔
65
    }
1✔
66

67
    public next(): void {
68
        if (this.currentStepIndex + 1 > this.steps.length) {
69
            return;
22✔
70
        }
22✔
71
        this.to(this.currentStepIndex + 1);
14✔
72
    }
73

22✔
74
    public previous(): void {
22✔
75
        if (this.currentStepIndex - 1 < 0) {
76
            return;
22✔
77
        }
22✔
78

1✔
79
        this.to(this.currentStepIndex - 1);
1✔
80
    }
81

1✔
82
    public active(indexOrKey: number | string): void {
83
        if (helpers.isNumber(indexOrKey)) {
21✔
84
            this.to(indexOrKey as number);
21✔
85
            return;
21✔
86
        }
87
        if (helpers.isString(indexOrKey)) {
88
            const index = this.steps.findIndex(step => step.key === (indexOrKey as string));
89
            this.to(index);
10✔
90
            return;
10✔
91
        }
10✔
92
    }
93

94
    private to(index: number): void {
4✔
95
        this.removeExistedStep();
4✔
96

4✔
97
        if (!helpers.isNumber(index) || index >= this.steps.length || index < 0 || Number.isNaN(index)) {
98
            index = 0;
99
        }
10✔
100
        this.currentStep = this.steps[index];
16!
101
        this.currentStepIndex = index;
10✔
102

103
        // update guiderManager
104
        this.guiderManager.updateActive(this.currentStep.key, this);
105
        if (this.currentStep.route && this.currentStep.route !== this.router.url) {
21✔
106
            this.ngZone.run(() => {
107
                this.router.navigateByUrl(this.currentStep.route);
108
            });
21✔
109
            return;
21✔
110
        }
111
        setTimeout(() => {
112
            this.drawStep();
4✔
113
            this.notifyStepClicked();
4✔
114
        }, 0);
115
    }
116

43✔
117
    public close(): void {
118
        this.removeManagerActiveKey();
1✔
119
        this.stepsRef[this.currentStepIndex]?.dispose();
120
        this.closed$.next(this.currentStep);
121
    }
122

123
    public end(): void {
124
        this.close();
125
        this.guiderEnded$.next(this.currentStep);
126
        this.notifyGuiderIsFinished();
127
    }
128

129
    private removeManagerActiveKey() {
130
        const activeKey = this.guiderManager.getActive().key;
131
        if (activeKey && this.steps.some(step => step.key === activeKey)) {
132
            this.guiderManager.updateActive('', undefined);
133
        }
134
    }
135

136
    private notifyStepClicked() {
137
        this.stepChange$.next(this.currentStep);
138
    }
139

140
    private drawStep() {
141
        this.removeExistedStep();
142
        this.stepsRef[this.currentStepIndex].show(this);
143
    }
144

145
    private notifyGuiderIsFinished() {
146
        this.stepChange$.complete();
147
        this.currentStepIndex = 0;
148
    }
149

150
    private removeExistedStep() {
151
        this.stepsRef[this.currentStepIndex]?.dispose();
152
    }
153
}
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