Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/rxjs #3713

Merged
merged 5 commits into from
Feb 7, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(stark-ui): update rxjs and @ngrx
mhenkens committed Feb 7, 2024
commit e08c19dc49a67714ac028b6faee0c0493cce7aee
Original file line number Diff line number Diff line change
@@ -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);
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";
@@ -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;
});
Original file line number Diff line number Diff line change
@@ -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);
@@ -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);

@@ -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);

@@ -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 });
@@ -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 });

mhenkens marked this conversation as resolved.
Show resolved Hide resolved
tick();

if (service.currentToastResult$) {
expect(service.currentToastResult$.closed).toBe(true);
}
expect(privateObserver.complete).toHaveBeenCalled();
}));
});
});
Original file line number Diff line number Diff line change
@@ -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>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why changing this from public to private ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because we refactor and this due to the fact the Oberver interface do not contain closed property anymore


/**
* Reference of the currently displayed toast notification
@@ -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;
@@ -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 {
@@ -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;