Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { inject, TestBed } from '@angular/core/testing';
import { Subject } from 'rxjs';

import { NotifierAction } from '../models/notifier-action.model';
import { NotifierConfig } from '../models/notifier-config.model';
Expand Down Expand Up @@ -170,6 +171,16 @@ describe('Notifier Service', () => {
it('should return the configuration', () => {
expect(service.getConfig()).toEqual(testNotifierConfig);
});

it('should return the notification action', () => {
const testNotificationId = 'ID_FAKE';
const expectedAction: NotifierAction = {
payload: testNotificationId,
type: 'HIDE',
};
service.actionStream.subscribe((action) => expect(action).toEqual(expectedAction));
service.hide(testNotificationId);
});
});

/**
Expand All @@ -180,6 +191,7 @@ class MockNotifierQueueService extends NotifierQueueService {
* Last action
*/
public lastAction: NotifierAction;
public actionStream = new Subject<NotifierAction>();

/**
* Push a new action to the queue
Expand All @@ -190,5 +202,6 @@ class MockNotifierQueueService extends NotifierQueueService {
*/
public push(action: NotifierAction): void {
this.lastAction = action;
this.actionStream.next(action);
}
}
11 changes: 11 additions & 0 deletions projects/angular-notifier/src/lib/services/notifier.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Inject, Injectable } from '@angular/core';
import { Observable } from 'rxjs';

import { NotifierAction } from '../models/notifier-action.model';
import { NotifierConfig } from '../models/notifier-config.model';
import { NotifierNotificationOptions } from '../models/notifier-notification.model';
import { NotifierConfigToken } from '../notifier.tokens';
Expand Down Expand Up @@ -44,6 +46,15 @@ export class NotifierService {
return this.config;
}

/**
* Get the observable for handling actions
*
* @returns Observable of NotifierAction
*/
public get actionStream(): Observable<NotifierAction> {
return this.queueService.actionStream.asObservable();
}

/**
* API: Show a new notification
*
Expand Down