From 5ab1062aed35cec1214bbc89ee678064a00758f8 Mon Sep 17 00:00:00 2001
From: Giuseppe <giuseppe.digilio@4science.it>
Date: Wed, 3 Oct 2018 12:12:12 +0200
Subject: [PATCH] Fixed NotificationsService and NotificationComponent tests

---
 .../notification.component.spec.ts            | 21 +++++++--
 .../notifications.service.spec.ts             | 44 ++++++++++++-------
 2 files changed, 46 insertions(+), 19 deletions(-)

diff --git a/src/app/shared/notifications/notification/notification.component.spec.ts b/src/app/shared/notifications/notification/notification.component.spec.ts
index c7a3487ac1..72c9d93841 100644
--- a/src/app/shared/notifications/notification/notification.component.spec.ts
+++ b/src/app/shared/notifications/notification/notification.component.spec.ts
@@ -13,6 +13,9 @@ import { NotificationOptions } from '../models/notification-options.model';
 import { INotificationBoardOptions } from '../../../../config/notifications-config.interfaces';
 import { GlobalConfig } from '../../../../config/global-config.interface';
 import { Notification } from '../models/notification.model';
+import { TranslateLoader, TranslateModule, TranslateService } from '@ngx-translate/core';
+import { MockTranslateLoader } from '../../mocks/mock-translate-loader';
+import { GLOBAL_CONFIG } from '../../../../config';
 
 describe('NotificationComponent', () => {
 
@@ -39,18 +42,28 @@ describe('NotificationComponent', () => {
         animate: 'scale'
       }as INotificationBoardOptions,
     } as any;
-    const service = new NotificationsService(envConfig, store);
 
     TestBed.configureTestingModule({
       imports: [
         BrowserModule,
         BrowserAnimationsModule,
-        StoreModule.forRoot({notificationsReducer})],
+        StoreModule.forRoot({notificationsReducer}),
+        TranslateModule.forRoot({
+          loader: {
+            provide: TranslateLoader,
+            useClass: MockTranslateLoader
+          }
+        })],
       declarations: [NotificationComponent], // declare the test component
       providers: [
-        { provide: NotificationsService, useValue: service },
-        ChangeDetectorRef]
+        { provide: GLOBAL_CONFIG, useValue: envConfig },
+        { provide: Store, useValue: store },
+        ChangeDetectorRef,
+        NotificationsService,
+        TranslateService,
+        ]
     }).compileComponents();  // compile template and css
+
   }));
 
   beforeEach(()  => {
diff --git a/src/app/shared/notifications/notifications.service.spec.ts b/src/app/shared/notifications/notifications.service.spec.ts
index e5af2860a1..1452307821 100644
--- a/src/app/shared/notifications/notifications.service.spec.ts
+++ b/src/app/shared/notifications/notifications.service.spec.ts
@@ -10,36 +10,50 @@ import { NewNotificationAction, RemoveAllNotificationsAction, RemoveNotification
 import { Notification } from './models/notification.model';
 import { NotificationType } from './models/notification-type';
 import { GlobalConfig } from '../../../config/global-config.interface';
+import { TranslateLoader, TranslateModule, TranslateService } from '@ngx-translate/core';
+import { MockTranslateLoader } from '../mocks/mock-translate-loader';
+import { GLOBAL_CONFIG } from '../../../config';
 
 describe('NotificationsService test', () => {
   const store: Store<Notification> = jasmine.createSpyObj('store', {
     dispatch: {},
     select: Observable.of(true)
   });
-  let service;
+  let service: NotificationsService;
   let envConfig: GlobalConfig;
 
+  envConfig = {
+    notifications: {
+      rtl: false,
+      position: ['top', 'right'],
+      maxStack: 8,
+      timeOut: 5000,
+      clickToClose: true,
+      animate: 'scale'
+    },
+  } as any;
+
   beforeEach(async () => {
     TestBed.configureTestingModule({
-      declarations: [NotificationComponent, NotificationsBoardComponent],
-      providers: [NotificationsService],
       imports: [
         StoreModule.forRoot({notificationsReducer}),
+        TranslateModule.forRoot({
+          loader: {
+            provide: TranslateLoader,
+            useClass: MockTranslateLoader
+          }
+        })
+      ],
+      declarations: [NotificationComponent, NotificationsBoardComponent],
+      providers: [
+        { provide: GLOBAL_CONFIG, useValue: envConfig },
+        { provide: Store, useValue: store },
+        NotificationsService,
+        TranslateService
       ]
     });
 
-    envConfig = {
-      notifications: {
-        rtl: false,
-        position: ['top', 'right'],
-        maxStack: 8,
-        timeOut: 5000,
-        clickToClose: true,
-        animate: 'scale'
-      },
-    } as any;
-
-    service = new NotificationsService(envConfig, store);
+    service = TestBed.get(NotificationsService);
   });
 
   it('Success method should dispatch NewNotificationAction with proper parameter', () => {
-- 
GitLab