mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-14 13:33:03 +00:00
fix test
This commit is contained in:
@@ -1,262 +1,103 @@
|
|||||||
import { inject, TestBed } from '@angular/core/testing';
|
import { inject, TestBed } from '@angular/core/testing';
|
||||||
import { NotificationsService } from './notifications.service';
|
import { NotificationsService } from './notifications.service';
|
||||||
import {defaultIcons} from '../interfaces/icons';
|
import { NotificationType } from './models/notification-type';
|
||||||
import {NotificationEvent} from '../interfaces/notification-event.type';
|
import { NotificationOptions } from './models/notification-options.model';
|
||||||
import {Notification} from '../interfaces/notification.type';
|
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 { notificationsReducer } from './notifications.reducers';
|
||||||
|
|
||||||
describe('NotificationsService', () => {
|
describe('NotificationsService', () => {
|
||||||
|
beforeEach(async () => {
|
||||||
beforeEach(() => {
|
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
declarations: [],
|
declarations: [NotificationComponent, NotificationsBoardComponent],
|
||||||
providers: [NotificationsService],
|
providers: [NotificationsService],
|
||||||
|
imports: [
|
||||||
|
StoreModule.forRoot({notificationsReducer}),
|
||||||
|
]
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
let defaultNotification = {
|
it('Default options',
|
||||||
id: '0',
|
|
||||||
title: 'Test title',
|
|
||||||
type: 'success',
|
|
||||||
icon: defaultIcons.success,
|
|
||||||
content: 'Test Content',
|
|
||||||
timeOut: 0,
|
|
||||||
maxLength: 0,
|
|
||||||
clickToClose: true,
|
|
||||||
clickIconToClose: false,
|
|
||||||
showProgressBar: true,
|
|
||||||
pauseOnHover: true,
|
|
||||||
theClass: 'initial',
|
|
||||||
rtl: false,
|
|
||||||
animate: 'fromRight',
|
|
||||||
createdOn: new Date(),
|
|
||||||
destroyedOn: new Date()
|
|
||||||
};
|
|
||||||
|
|
||||||
it('Service instantiates',
|
|
||||||
inject([NotificationsService], (service: NotificationsService) => {
|
inject([NotificationsService], (service: NotificationsService) => {
|
||||||
expect(service instanceof NotificationsService).toBeTruthy();
|
const notification = service.success('Title', 'Content');
|
||||||
})
|
expect(notification.options.clickToClose).toBe(true);
|
||||||
);
|
|
||||||
|
|
||||||
it('If override is not set, id is randomly generated',
|
|
||||||
inject([NotificationsService], (service: NotificationsService) => {
|
|
||||||
|
|
||||||
let notificationEvent: NotificationEvent = null;
|
|
||||||
|
|
||||||
service.emitter.subscribe(item => notificationEvent = item);
|
|
||||||
|
|
||||||
service.set(defaultNotification, true);
|
|
||||||
|
|
||||||
expect(notificationEvent.command).toBe('set');
|
|
||||||
expect(notificationEvent.notification.id !== '0').toBeTruthy();
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
it('If override id is set its used',
|
|
||||||
inject([NotificationsService], (service: NotificationsService) => {
|
|
||||||
let notificationEvent: NotificationEvent = null,
|
|
||||||
override = {id: '1'};
|
|
||||||
|
|
||||||
service.emitter.subscribe(item => notificationEvent = item);
|
|
||||||
|
|
||||||
service.set(Object.assign(defaultNotification, {override: override}), true);
|
|
||||||
|
|
||||||
expect(notificationEvent.notification.id).toBe('1');
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
it('Success method',
|
it('Success method',
|
||||||
inject([NotificationsService], (service: NotificationsService) => {
|
inject([NotificationsService], (service: NotificationsService) => {
|
||||||
let notificationEvent: NotificationEvent = null;
|
const notification = service.success('Title', 'Content');
|
||||||
service.emitter.subscribe(item => notificationEvent = item);
|
|
||||||
|
|
||||||
let notification: Notification = service.success('Title', 'Message');
|
|
||||||
|
|
||||||
expect(notification.id !== undefined).toBeTruthy();
|
expect(notification.id !== undefined).toBeTruthy();
|
||||||
expect(notification.type).toBe('success');
|
expect(notification.type).toBe(NotificationType.Success);
|
||||||
expect(notification.icon).toBe(defaultIcons.success);
|
|
||||||
|
|
||||||
expect(notification.title).toBe('Title');
|
expect(notification.title).toBe('Title');
|
||||||
expect(notification.content).toBe('Message');
|
expect(notification.content).toBe('Content');
|
||||||
expect(notification.override).toBeUndefined();
|
|
||||||
expect(notification.html).toBeUndefined();
|
expect(notification.html).toBeUndefined();
|
||||||
expect(notification.state).toBeUndefined();
|
expect(notification.options.timeOut).toBe(0);
|
||||||
expect(notification.createdOn).toBeUndefined();
|
expect(notification.options.clickToClose).toBeTruthy();
|
||||||
expect(notification.destroyedOn).toBeUndefined();
|
expect(notification.options.animate).toBe(NotificationAnimationsType.Scale);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
it('Error method',
|
it('Error method',
|
||||||
inject([NotificationsService], (service: NotificationsService) => {
|
inject([NotificationsService], (service: NotificationsService) => {
|
||||||
let notificationEvent: NotificationEvent = null;
|
const notification = service.error('Title', 'Content');
|
||||||
service.emitter.subscribe(item => notificationEvent = item);
|
|
||||||
|
|
||||||
let notification: Notification = service.error('Title', 'Message');
|
|
||||||
|
|
||||||
expect(notification.id !== undefined).toBeTruthy();
|
expect(notification.id !== undefined).toBeTruthy();
|
||||||
expect(notification.type).toBe('error');
|
expect(notification.type).toBe(NotificationType.Error);
|
||||||
expect(notification.icon).toBe(defaultIcons.error);
|
|
||||||
|
|
||||||
expect(notification.title).toBe('Title');
|
expect(notification.title).toBe('Title');
|
||||||
expect(notification.content).toBe('Message');
|
expect(notification.content).toBe('Content');
|
||||||
expect(notification.override).toBeUndefined();
|
|
||||||
expect(notification.html).toBeUndefined();
|
expect(notification.html).toBeUndefined();
|
||||||
expect(notification.state).toBeUndefined();
|
expect(notification.options.timeOut).toBe(0);
|
||||||
expect(notification.createdOn).toBeUndefined();
|
expect(notification.options.clickToClose).toBeTruthy();
|
||||||
expect(notification.destroyedOn).toBeUndefined();
|
expect(notification.options.animate).toBe(NotificationAnimationsType.Scale);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
it('Warning method',
|
||||||
it('Alert method',
|
|
||||||
inject([NotificationsService], (service: NotificationsService) => {
|
inject([NotificationsService], (service: NotificationsService) => {
|
||||||
let notificationEvent: NotificationEvent = null;
|
const notification = service.warning('Title', 'Content');
|
||||||
service.emitter.subscribe(item => notificationEvent = item);
|
|
||||||
|
|
||||||
let notification: Notification = service.alert('Title', 'Message');
|
|
||||||
|
|
||||||
expect(notification.id !== undefined).toBeTruthy();
|
expect(notification.id !== undefined).toBeTruthy();
|
||||||
expect(notification.type).toBe('alert');
|
expect(notification.type).toBe(NotificationType.Warning);
|
||||||
expect(notification.icon).toBe(defaultIcons.alert);
|
|
||||||
|
|
||||||
expect(notification.title).toBe('Title');
|
expect(notification.title).toBe('Title');
|
||||||
expect(notification.content).toBe('Message');
|
expect(notification.content).toBe('Content');
|
||||||
expect(notification.override).toBeUndefined();
|
|
||||||
expect(notification.html).toBeUndefined();
|
expect(notification.html).toBeUndefined();
|
||||||
expect(notification.state).toBeUndefined();
|
expect(notification.options.timeOut).toBe(0);
|
||||||
expect(notification.createdOn).toBeUndefined();
|
expect(notification.options.clickToClose).toBeTruthy();
|
||||||
expect(notification.destroyedOn).toBeUndefined();
|
expect(notification.options.animate).toBe(NotificationAnimationsType.Scale);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
it('Info method',
|
it('Info method',
|
||||||
inject([NotificationsService], (service: NotificationsService) => {
|
inject([NotificationsService], (service: NotificationsService) => {
|
||||||
let notificationEvent: NotificationEvent = null;
|
const notification = service.info('Title', 'Content');
|
||||||
service.emitter.subscribe(item => notificationEvent = item);
|
|
||||||
|
|
||||||
let notification: Notification = service.info('Title', 'Message');
|
|
||||||
|
|
||||||
expect(notification.id !== undefined).toBeTruthy();
|
expect(notification.id !== undefined).toBeTruthy();
|
||||||
expect(notification.type).toBe('info');
|
expect(notification.type).toBe(NotificationType.Info);
|
||||||
expect(notification.icon).toBe(defaultIcons.info);
|
|
||||||
|
|
||||||
expect(notification.title).toBe('Title');
|
expect(notification.title).toBe('Title');
|
||||||
expect(notification.content).toBe('Message');
|
expect(notification.content).toBe('Content');
|
||||||
expect(notification.override).toBeUndefined();
|
|
||||||
expect(notification.html).toBeUndefined();
|
expect(notification.html).toBeUndefined();
|
||||||
expect(notification.state).toBeUndefined();
|
expect(notification.options.timeOut).toBe(0);
|
||||||
expect(notification.createdOn).toBeUndefined();
|
expect(notification.options.clickToClose).toBeTruthy();
|
||||||
expect(notification.destroyedOn).toBeUndefined();
|
expect(notification.options.animate).toBe(NotificationAnimationsType.Scale);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
it('Warn method',
|
it('Html content',
|
||||||
inject([NotificationsService], (service: NotificationsService) => {
|
inject([NotificationsService], (service: NotificationsService) => {
|
||||||
let notificationEvent: NotificationEvent = null;
|
const options = new NotificationOptions(
|
||||||
service.emitter.subscribe(item => notificationEvent = item);
|
10000,
|
||||||
|
false,
|
||||||
let notification: Notification = service.warn('Title', 'Message');
|
NotificationAnimationsType.Rotate);
|
||||||
|
const html = '<p>I\'m a mock test</p>';
|
||||||
|
const notification = service.success(null, null, options, html);
|
||||||
expect(notification.id !== undefined).toBeTruthy();
|
expect(notification.id !== undefined).toBeTruthy();
|
||||||
expect(notification.type).toBe('warn');
|
expect(notification.type).toBe(NotificationType.Success);
|
||||||
expect(notification.icon).toBe(defaultIcons.warn);
|
expect(notification.title).toBeNull();
|
||||||
|
expect(notification.content).toBeNull();
|
||||||
expect(notification.title).toBe('Title');
|
expect(notification.html).not.toBeNull();
|
||||||
expect(notification.content).toBe('Message');
|
expect(notification.options.timeOut).toBe(10000);
|
||||||
expect(notification.override).toBeUndefined();
|
expect(notification.options.clickToClose).toBeFalsy();
|
||||||
expect(notification.html).toBeUndefined();
|
expect(notification.options.animate).toBe(NotificationAnimationsType.Rotate);
|
||||||
expect(notification.state).toBeUndefined();
|
|
||||||
expect(notification.createdOn).toBeUndefined();
|
|
||||||
expect(notification.destroyedOn).toBeUndefined();
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
it('Bare method',
|
|
||||||
inject([NotificationsService], (service: NotificationsService) => {
|
|
||||||
let notificationEvent: NotificationEvent = null;
|
|
||||||
service.emitter.subscribe(item => notificationEvent = item);
|
|
||||||
|
|
||||||
let notification: Notification = service.bare('Title', 'Message');
|
|
||||||
|
|
||||||
expect(notification.id !== undefined).toBeTruthy();
|
|
||||||
expect(notification.type).toBe('bare');
|
|
||||||
expect(notification.icon).toBe('bare');
|
|
||||||
|
|
||||||
expect(notification.title).toBe('Title');
|
|
||||||
expect(notification.content).toBe('Message');
|
|
||||||
expect(notification.override).toBeUndefined();
|
|
||||||
expect(notification.html).toBeUndefined();
|
|
||||||
expect(notification.state).toBeUndefined();
|
|
||||||
expect(notification.createdOn).toBeUndefined();
|
|
||||||
expect(notification.destroyedOn).toBeUndefined();
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
it('Create method',
|
|
||||||
inject([NotificationsService], (service: NotificationsService) => {
|
|
||||||
let notificationEvent: NotificationEvent = null;
|
|
||||||
service.emitter.subscribe(item => notificationEvent = item);
|
|
||||||
|
|
||||||
let notification: Notification = service.create('Title', 'Message', 'create');
|
|
||||||
|
|
||||||
expect(notification.id !== undefined).toBeTruthy();
|
|
||||||
expect(notification.type).toBe('create');
|
|
||||||
// expect(notification.icon).toBe('bare');
|
|
||||||
|
|
||||||
expect(notification.title).toBe('Title');
|
|
||||||
expect(notification.content).toBe('Message');
|
|
||||||
expect(notification.override).toBeUndefined();
|
|
||||||
expect(notification.html).toBeUndefined();
|
|
||||||
expect(notification.state).toBeUndefined();
|
|
||||||
expect(notification.createdOn).toBeUndefined();
|
|
||||||
expect(notification.destroyedOn).toBeUndefined();
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
it('Html method',
|
|
||||||
inject([NotificationsService], (service: NotificationsService) => {
|
|
||||||
let notificationEvent: NotificationEvent = null;
|
|
||||||
service.emitter.subscribe(item => notificationEvent = item);
|
|
||||||
|
|
||||||
let notification: Notification = service.html('<B>Title</B>', 'success');
|
|
||||||
|
|
||||||
expect(notification.id !== undefined).toBeTruthy();
|
|
||||||
expect(notification.type).toBe('success');
|
|
||||||
expect(notification.icon).toBe('bare');
|
|
||||||
|
|
||||||
expect(notification.title).toBeUndefined();
|
|
||||||
expect(notification.content).toBeUndefined();
|
|
||||||
expect(notification.override).toBeUndefined();
|
|
||||||
expect(notification.html).toBe('<B>Title</B>');
|
|
||||||
expect(notification.state).toBeUndefined();
|
|
||||||
expect(notification.createdOn).toBeUndefined();
|
|
||||||
expect(notification.destroyedOn).toBeUndefined();
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
it('Empty remove emits cleanAll command',
|
|
||||||
inject([NotificationsService], (service: NotificationsService) => {
|
|
||||||
let notificationEvent: NotificationEvent = null;
|
|
||||||
service.emitter.subscribe(item => notificationEvent = item);
|
|
||||||
|
|
||||||
service.remove();
|
|
||||||
|
|
||||||
expect(notificationEvent.command).toBe('cleanAll');
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
it('Remove with id emits clean command',
|
|
||||||
inject([NotificationsService], (service: NotificationsService) => {
|
|
||||||
let notificationEvent: NotificationEvent = null;
|
|
||||||
service.emitter.subscribe(item => notificationEvent = item);
|
|
||||||
|
|
||||||
service.remove('1');
|
|
||||||
|
|
||||||
expect(notificationEvent.command).toBe('clean');
|
|
||||||
expect(notificationEvent.id).toBe('1');
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@@ -15,8 +15,7 @@ import { DomSanitizer } from '@angular/platform-browser';
|
|||||||
@Injectable()
|
@Injectable()
|
||||||
export class NotificationsService {
|
export class NotificationsService {
|
||||||
|
|
||||||
constructor(private store: Store<Notification>,
|
constructor(private store: Store<Notification>) {
|
||||||
private domSanitizer: DomSanitizer,) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private add(notification: Notification) {
|
private add(notification: Notification) {
|
||||||
|
Reference in New Issue
Block a user