Skip to content

Commit a35c87c

Browse files
author
Andrea Barbasso
committed
[DSC-2860] try some fixes for e2e errors in pipelines
1 parent 1670f57 commit a35c87c

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

src/app/app.component.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
Component,
1111
HostListener,
1212
Inject,
13+
OnDestroy,
1314
OnInit,
1415
PLATFORM_ID,
1516
} from '@angular/core';
@@ -31,13 +32,15 @@ import { TranslateService } from '@ngx-translate/core';
3132
import {
3233
BehaviorSubject,
3334
Observable,
35+
Subject,
3436
} from 'rxjs';
3537
import {
3638
delay,
3739
distinctUntilChanged,
3840
map,
3941
switchMap,
4042
take,
43+
takeUntil,
4144
withLatestFrom,
4245
} from 'rxjs/operators';
4346

@@ -78,10 +81,15 @@ import { SocialService } from './social/social.service';
7881
SocialComponent,
7982
],
8083
})
81-
export class AppComponent implements OnInit, AfterViewInit {
84+
export class AppComponent implements OnInit, AfterViewInit, OnDestroy {
8285
notificationOptions;
8386
models;
8487

88+
/**
89+
* Subject to signal component destruction and clean up subscriptions
90+
*/
91+
private destroy$: Subject<void> = new Subject<void>();
92+
8593
/**
8694
* Whether or not the authentication is currently blocking the UI
8795
*/
@@ -172,6 +180,7 @@ export class AppComponent implements OnInit, AfterViewInit {
172180
take(1),
173181
map((currentUrl) => [currentUrl, event]),
174182
)),
183+
takeUntil(this.destroy$),
175184
).subscribe(([currentUrl, event]: [string, any]) => {
176185
if (event instanceof NavigationStart) {
177186
const nextUrl = event.url;
@@ -188,6 +197,11 @@ export class AppComponent implements OnInit, AfterViewInit {
188197
});
189198
}
190199

200+
ngOnDestroy(): void {
201+
this.destroy$.next();
202+
this.destroy$.complete();
203+
}
204+
191205
@HostListener('window:resize', ['$event'])
192206
public onResize(event): void {
193207
this.dispatchWindowSize(event.target.innerWidth, event.target.innerHeight);
@@ -202,7 +216,10 @@ export class AppComponent implements OnInit, AfterViewInit {
202216
private trackIdleModal() {
203217
const isIdle$ = this.authService.isUserIdle();
204218
const isAuthenticated$ = this.authService.isAuthenticated();
205-
isIdle$.pipe(withLatestFrom(isAuthenticated$))
219+
isIdle$.pipe(
220+
withLatestFrom(isAuthenticated$),
221+
takeUntil(this.destroy$),
222+
)
206223
.subscribe(([userIdle, authenticated]) => {
207224
if (userIdle && authenticated) {
208225
if (!this.idleModalOpen) {

src/app/shared/mocks/theme-service.mock.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { of as observableOf } from 'rxjs';
1+
import {
2+
BehaviorSubject,
3+
of as observableOf,
4+
} from 'rxjs';
25

36
import { ThemeConfig } from '../../../config/theme.config';
47
import { isNotEmpty } from '../empty.util';
@@ -12,6 +15,8 @@ export function getMockThemeService(themeName = 'base', themes?: ThemeConfig[]):
1215
listenForRouteChanges: undefined,
1316
});
1417

18+
Object.defineProperty(spy, 'isThemeLoading$', { value: new BehaviorSubject(false) });
19+
1520
if (isNotEmpty(themes)) {
1621
spy.getThemeConfigFor.and.callFake((name: string) => themes.find(theme => theme.name === name));
1722
}

0 commit comments

Comments
 (0)