Skip to content

Commit

Permalink
fix(stark-ui): update rxjs and @ngrx
Browse files Browse the repository at this point in the history
  • Loading branch information
mhenkens committed Feb 7, 2024
1 parent cd9c317 commit e08c19d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -989,8 +989,7 @@ describe("Service: StarkRoutingService", () => {
});

it("should reload the current page", (done: DoneFn) => {

spyOn($state, "reload").and.returnValue(<any>(throwError("Reload has failed").toPromise()));
spyOn($state, "reload").and.returnValue(<any>throwError("Reload has failed").toPromise());

const statesConfig: StateDeclaration[] = $state.get();
expect(statesConfig.length).toBe(numberOfMockStates);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @angular-eslint/no-lifecycle-call */
import { Observable, Observer, of, Subject, Subscriber, throwError } from "rxjs";
import {Observable, Observer, of, Subject, Subscriber, TeardownLogic, throwError} from "rxjs";
import { AbstractStarkSearchComponent, StarkGenericSearchService } from "../classes";
import { MockStarkLoggingService } from "@nationalbankbelgium/stark-core/testing";
import { StarkResource } from "@nationalbankbelgium/stark-core";
Expand Down Expand Up @@ -412,8 +412,8 @@ interface SearchCriteria {
uuid: string;
}

function createObservableOf<T>(value: T, teardown: Function): Observable<T> {
return new Observable((subscriber: Subscriber<T>): Function => {
function createObservableOf<T>(value: T, teardown: TeardownLogic): Observable<T> {
return new Observable((subscriber: Subscriber<T>): TeardownLogic => {
subscriber.next(value);
return teardown;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe("ToastNotificationService", () => {

expect(service.snackBar.openFromComponent).toHaveBeenCalledTimes(0);

expect(service.currentToastResult$).not.toBeDefined();
expect((<any>service).currentToastResult$).not.toBeDefined();

showObs.subscribe((ret: StarkToastNotificationResult) => {
expect(ret).toBe(StarkToastNotificationResult.CLOSED_BY_NEW_TOAST);
Expand All @@ -106,11 +106,9 @@ describe("ToastNotificationService", () => {

expect(service.snackBar.openFromComponent).toHaveBeenCalledTimes(1);

expect(service.currentToastResult$).not.toBeNull();
expect(service.currentToastResult$).toBeDefined();
if (service.currentToastResult$) {
expect(service.currentToastResult$.closed).toBe(false);
}
expect((<any>service).currentToastResult$).not.toBeNull();
expect((<any>service).currentToastResult$).toBeDefined();


showObs = service.show(message);

Expand All @@ -120,7 +118,7 @@ describe("ToastNotificationService", () => {
expect(showObs).not.toBeNull();
expect(showObs).toBeDefined();

expect(service.currentToastResult$).not.toBeDefined();
expect((<any>service).currentToastResult$).not.toBeDefined();

expect(service.snackBar.openFromComponent).toHaveBeenCalledTimes(1);

Expand All @@ -132,11 +130,9 @@ describe("ToastNotificationService", () => {

expect(service.snackBar.openFromComponent).toHaveBeenCalledTimes(2);

expect(service.currentToastResult$).not.toBeNull();
expect(service.currentToastResult$).toBeDefined();
if (service.currentToastResult$) {
expect(service.currentToastResult$.closed).toBe(false);
}
expect((<any>service).currentToastResult$).not.toBeNull();
expect((<any>service).currentToastResult$).toBeDefined();


/** Mimic MatSnackBar's behavior */
observer.next({ dismissedByAction: false });
Expand All @@ -153,20 +149,20 @@ describe("ToastNotificationService", () => {

tick();

if (service.currentToastResult$) {
expect(service.currentToastResult$.closed).toBe(false);
}
spyOn((<any>service).currentToastResult$, "complete");

const privateObserver: Observer<StarkToastNotificationResult> = (<any>service).currentToastResult$

expect(privateObserver.complete).not.toHaveBeenCalled();

service.hide();

/** Mimic MatSnackBar's behavior */
observer.next({ dismissedByAction: true });

tick();

if (service.currentToastResult$) {
expect(service.currentToastResult$.closed).toBe(true);
}
expect(privateObserver.complete).toHaveBeenCalled();
}));
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class StarkToastNotificationServiceImpl implements StarkToastNotification
/**
* Observer linked to the currently displayed toast notification
*/
public currentToastResult$?: Observer<StarkToastNotificationResult>;
private currentToastResult$?: Observer<StarkToastNotificationResult>;

/**
* Reference of the currently displayed toast notification
Expand Down Expand Up @@ -58,7 +58,7 @@ export class StarkToastNotificationServiceImpl implements StarkToastNotification
}

public show(message: StarkToastMessage): Observable<StarkToastNotificationResult> {
if (this.currentToastResult$ && !this.currentToastResult$.closed) {
if (this.currentToastResult$) {
this.currentToastResult$.next(StarkToastNotificationResult.CLOSED_BY_NEW_TOAST);
this.currentToastResult$.complete();
this.currentToastResult$ = undefined;
Expand All @@ -73,7 +73,7 @@ export class StarkToastNotificationServiceImpl implements StarkToastNotification
tap((toastDismissedEvent: MatSnackBarDismiss) => {
// emit on the observer only if it is the current toast
// otherwise, it means it is a previous toast that is being closed by a new one
if (this.currentToastResult$ === observer && !observer.closed) {
if (this.currentToastResult$ === observer) {
if (!toastDismissedEvent.dismissedByAction) {
observer.next(StarkToastNotificationResult.CLOSED_ON_DELAY_TIMEOUT);
} else {
Expand All @@ -82,14 +82,15 @@ export class StarkToastNotificationServiceImpl implements StarkToastNotification
this.ref.tick();
}
observer.complete();
this.currentToastResult$ = undefined;
})
)
.subscribe();
});
}

public hide(): void {
if (this.currentToastResult$ && !this.currentToastResult$.closed) {
if (this.currentToastResult$) {
this.currentToastResult$.next(StarkToastNotificationResult.HIDDEN);
this.currentToastResult$.complete();
this.currentToastResult$ = undefined;
Expand Down

0 comments on commit e08c19d

Please sign in to comment.