mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-17 15:03:07 +00:00
PARTIAL TEST, TO VERIFY
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
// import @ngrx
|
||||
import { Action } from '@ngrx/store';
|
||||
|
||||
// import type function
|
||||
import { type } from '../../shared/ngrx/type';
|
||||
|
||||
// import models
|
||||
import { Notification } from './models/notification.model';
|
||||
import { INotification } from './models/notification.model';
|
||||
|
||||
export const NotificationsActionTypes = {
|
||||
NEW_NOTIFICATION: type('dspace/notifications/NEW_NOTIFICATION'),
|
||||
@@ -23,9 +21,9 @@ export const NotificationsActionTypes = {
|
||||
*/
|
||||
export class NewNotificationAction implements Action {
|
||||
public type: string = NotificationsActionTypes.NEW_NOTIFICATION;
|
||||
payload: Notification;
|
||||
payload: INotification;
|
||||
|
||||
constructor(notification: Notification) {
|
||||
constructor(notification: INotification) {
|
||||
this.payload = notification;
|
||||
}
|
||||
}
|
||||
@@ -37,9 +35,9 @@ export class NewNotificationAction implements Action {
|
||||
*/
|
||||
export class NewNotificationWithTimerAction implements Action {
|
||||
public type: string = NotificationsActionTypes.NEW_NOTIFICATION_WITH_TIMER;
|
||||
payload: Notification;
|
||||
payload: INotification;
|
||||
|
||||
constructor(notification: Notification) {
|
||||
constructor(notification: INotification) {
|
||||
this.payload = notification;
|
||||
}
|
||||
}
|
||||
|
@@ -38,7 +38,6 @@ export class NotificationsEffects {
|
||||
/**
|
||||
* @constructor
|
||||
* @param {Actions} actions$
|
||||
* @param {AuthService} authService
|
||||
* @param {Store} store
|
||||
*/
|
||||
constructor(private actions$: Actions,
|
||||
|
81
src/app/shared/notifications/notifications.reducers.spec.ts
Normal file
81
src/app/shared/notifications/notifications.reducers.spec.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
import { notificationsReducer } from './notifications.reducers';
|
||||
import { NewNotificationAction, RemoveAllNotificationsAction, RemoveNotificationAction } from './notifications.actions';
|
||||
import { NotificationsService } from './notifications.service';
|
||||
import { fakeAsync, inject, TestBed, tick } from '@angular/core/testing';
|
||||
import { NotificationsBoardComponent } from './notifications-board/notifications-board.component';
|
||||
import { StoreModule } from '@ngrx/store';
|
||||
import { NotificationComponent } from './notification/notification.component';
|
||||
import { NotificationOptions } from './models/notification-options.model';
|
||||
import { NotificationAnimationsType } from './models/notification-animations-type';
|
||||
import { NotificationType } from './models/notification-type';
|
||||
import { Notification } from './models/notification.model';
|
||||
import { uniqueId } from 'lodash';
|
||||
|
||||
fdescribe('Notification reducers', () => {
|
||||
|
||||
beforeEach(async () => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [NotificationComponent, NotificationsBoardComponent],
|
||||
providers: [NotificationsService],
|
||||
imports: [
|
||||
StoreModule.forRoot({notificationsReducer}),
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle state for add, remove and removeAll', fakeAsync((inject([NotificationsService], (service: NotificationsService) => {
|
||||
const options = new NotificationOptions(
|
||||
10000,
|
||||
false,
|
||||
NotificationAnimationsType.Rotate);
|
||||
const notification1 = new Notification(uniqueId(), NotificationType.Success, 'title1', 'content', options, null);
|
||||
const notification2 = new Notification(uniqueId(), NotificationType.Success, 'title2', 'content', options, null);
|
||||
const notification3 = new Notification(uniqueId(), NotificationType.Success, 'title3', 'content', options, null);
|
||||
const notification4 = new Notification(uniqueId(), NotificationType.Success, 'title4', 'content', options, null);
|
||||
const html = '<p>I\'m a mock test</p>';
|
||||
const notification5 = new Notification(uniqueId(), NotificationType.Success, null, null, options, html);
|
||||
|
||||
console.log(notification1.id);
|
||||
console.log(notification2.id);
|
||||
console.log(notification3.id);
|
||||
console.log(notification4.id);
|
||||
console.log(notification5.id);
|
||||
|
||||
|
||||
|
||||
let state = notificationsReducer(undefined, new NewNotificationAction(notification1));
|
||||
tick(2000);
|
||||
console.log('Length: #' + state.length);
|
||||
expect(state.length).toEqual(1);
|
||||
|
||||
state = notificationsReducer(undefined, new NewNotificationAction(notification2));
|
||||
tick(2000);
|
||||
console.log('Length: #' + state.length);
|
||||
expect(state.length).toEqual(2);
|
||||
|
||||
state = notificationsReducer(undefined, new NewNotificationAction(notification3));
|
||||
tick(2000);
|
||||
console.log('Length: #' + state.length);
|
||||
expect(state.length).toEqual(3);
|
||||
|
||||
state = notificationsReducer(undefined, new NewNotificationAction(notification4));
|
||||
tick(2000);
|
||||
console.log('Length: #' + state.length);
|
||||
expect(state.length).toEqual(4);
|
||||
|
||||
state = notificationsReducer(undefined, new NewNotificationAction(notification5));
|
||||
tick(2000);
|
||||
console.log('Length: #' + state.length);
|
||||
expect(state.length).toEqual(5);
|
||||
|
||||
state = notificationsReducer(undefined, new RemoveNotificationAction(notification4.id));
|
||||
expect(state.length).toEqual(4);
|
||||
state = notificationsReducer(undefined, new RemoveNotificationAction(notification5.id));
|
||||
expect(state.length).toEqual(3);
|
||||
|
||||
state = notificationsReducer(undefined, new RemoveAllNotificationsAction());
|
||||
expect(state.length).toEqual(0);
|
||||
})
|
||||
))
|
||||
);
|
||||
});
|
@@ -1,13 +1,17 @@
|
||||
import { inject, TestBed } from '@angular/core/testing';
|
||||
import { fakeAsync, inject, TestBed, tick } from '@angular/core/testing';
|
||||
import { NotificationsService } from './notifications.service';
|
||||
import { NotificationType } from './models/notification-type';
|
||||
import { NotificationOptions } from './models/notification-options.model';
|
||||
import { NotificationAnimationsType } from './models/notification-animations-type';
|
||||
import { NotificationsBoardComponent } from './notifications-board/notifications-board.component';
|
||||
import { NotificationComponent } from './notification/notification.component';
|
||||
import { StoreModule } from '@ngrx/store';
|
||||
import { Store, StoreModule } from '@ngrx/store';
|
||||
import { notificationsReducer } from './notifications.reducers';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
// import 'rxjs/add/observable/of';
|
||||
import { AppState } from '../../app.reducer';
|
||||
import { notificationsStateSelector } from './selectors';
|
||||
import { PromiseObservable } from 'rxjs/observable/PromiseObservable';
|
||||
|
||||
describe('NotificationsService', () => {
|
||||
beforeEach(async () => {
|
||||
@@ -20,6 +24,8 @@ describe('NotificationsService', () => {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
it('Default options',
|
||||
inject([NotificationsService], (service: NotificationsService) => {
|
||||
const notification = service.success('Title', Observable.of('Content'));
|
||||
@@ -29,7 +35,7 @@ describe('NotificationsService', () => {
|
||||
|
||||
it('Success method',
|
||||
inject([NotificationsService], (service: NotificationsService) => {
|
||||
const notification = service.success(Observable.of('Title'), Observable.of('Content'));
|
||||
const notification = service.success('Title', 'Content');
|
||||
expect(notification.id !== undefined).toBeTruthy();
|
||||
expect(notification.type).toBe(NotificationType.Success);
|
||||
expect(notification.title).toBe(Observable.of('Title'));
|
||||
@@ -102,4 +108,48 @@ describe('NotificationsService', () => {
|
||||
})
|
||||
);
|
||||
|
||||
it('Remove',
|
||||
inject([NotificationsService, Store], fakeAsync((service: NotificationsService, store: Store<AppState>) => {
|
||||
const options = new NotificationOptions(
|
||||
10000,
|
||||
false,
|
||||
NotificationAnimationsType.Rotate);
|
||||
|
||||
const id = 'notificationsReducer';
|
||||
// let state = store[id];
|
||||
//
|
||||
// // let notifications = store.select(notificationsStateSelector);
|
||||
// store.subscribe((state) => {
|
||||
// const id = 'notificationsReducer';
|
||||
// console.log('Length: ' + state[id].length);
|
||||
// // state[id].forEach( (n, i) => {
|
||||
// // console.log('Notification #' + i);
|
||||
// // console.log(n);
|
||||
// });
|
||||
const notification1 = service.success('Title', Observable.of('Content'));
|
||||
tick(2000);
|
||||
expect(store[id].length).toBe(1);
|
||||
const notification2 = service.error(Observable.of('Title'), Observable.of('Content'));
|
||||
tick(2000);
|
||||
expect(store[id].length).toBe(2);
|
||||
const notification3 = service.warning(Observable.of('Title'), Observable.of('Content'));
|
||||
tick(2000);
|
||||
expect(store[id].length).toBe(3);
|
||||
const notification4 = service.info(Observable.of('Title'), Observable.of('Content'));
|
||||
tick(2000);
|
||||
expect(store[id].length).toBe(4);
|
||||
const html = '<p>I\'m a mock test</p>';
|
||||
const notification5 = service.success(null, null, options, html);
|
||||
tick(2000);
|
||||
expect(store[id].length).toBe(5);
|
||||
|
||||
// expect(notifications)
|
||||
|
||||
service.remove(notification1);
|
||||
tick(2000);
|
||||
expect(store[id].length).toBe(0);
|
||||
|
||||
}) )
|
||||
);
|
||||
|
||||
});
|
||||
|
Reference in New Issue
Block a user