OK-492 FE Unit tests shift change overview
diff --git a/src/app/pages/shift-change-overview/shift-change-overview.component.spec.ts b/src/app/pages/shift-change-overview/shift-change-overview.component.spec.ts
index b824787..e5b72c2 100644
--- a/src/app/pages/shift-change-overview/shift-change-overview.component.spec.ts
+++ b/src/app/pages/shift-change-overview/shift-change-overview.component.spec.ts
@@ -1,25 +1,234 @@
 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
-
+import { By } from '@angular/platform-browser';
+import { click } from '../../testing/index';
+import { NgModule } from '@angular/core';
+import { DebugElement, EventEmitter, SimpleChange } from '@angular/core';
+import { FormsModule } from '@angular/forms';
+import { MdDialogModule, MaterialModule, MdDialog, MdDialogConfig, Overlay, OverlayContainer, OVERLAY_PROVIDERS } from '@angular/material';
+import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
+import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
+import { AbstractListComponent } from '../../lists/abstract-list/abstract-list.component';
+import { AbstractMockObservableService } from '../../common/abstract-mock-observable.service';
+import { MockComponent } from '../../testing/mock.component';
+import { Router } from '@angular/router';
+import { User } from '../../model/user';
+import { SessionContext } from '../../common/session-context';
+import { FormattedTimestampPipe } from '../../common-components/pipes/formatted-timestamp.pipe';
+import { StringToDatePipe } from '../../common-components/pipes/string-to-date.pipe';
+import { DaterangepickerConfig } from 'ng2-daterangepicker';
+import { NotificationService } from '../../services/notification.service';
+import { ResponsibilityService } from '../../services/responsibility.service';
+import { MessageService } from '../../services/message.service';
+import { EntryComponent } from '../../dialogs/entry/entry.component';
+import { MainNavigationComponent } from '../../common-components/main-navigation/main-navigation.component';
 import { ShiftChangeOverviewComponent } from './shift-change-overview.component';
+import { RESPONSIBILITIES_SHIFT_CHANGE } from '../../test-data/responsibilities';
+import { HISTORICAL_SCHIFTCHANGES } from '../../test-data/historical-shiftchanges';
+import { USERS } from '../../test-data/users';
+
+class FakeRouter {
+  navigate(commands: any[]) {
+    return commands[0];
+  }
+}
+@NgModule({
+  declarations: [EntryComponent],
+  entryComponents: [
+    EntryComponent
+  ]
+})
+class TestModule { }
 
 describe('ShiftChangeOverviewComponent', () => {
   let component: ShiftChangeOverviewComponent;
   let fixture: ComponentFixture<ShiftChangeOverviewComponent>;
+  let sessionContext: SessionContext;
+  let router: Router;
+  let mockNotificationService: MockNotificationService;
+  //let mockReminderService: MockReminderService;
+  let mockRespService: MockResponsibilityService;
+  let messageService;
+  let routerStub: FakeRouter;
+  
+    routerStub = {
+      navigate: jasmine.createSpy('navigate').and.callThrough()
+    };
+
+  class MockResponsibilityService extends AbstractMockObservableService {
+    plannedResponsibilities = null;
+    responsibilities = null;
+    historicalResponsibilities = HISTORICAL_SCHIFTCHANGES;
+
+    getPlannedResponsibilities() {
+      const resptService = new MockResponsibilityService();
+      resptService.content = this.plannedResponsibilities;
+      return resptService;
+    };
+    getResponsibilities() {
+      const resptService = new MockResponsibilityService();
+      resptService.content = this.responsibilities;
+      return resptService;
+    }
+    getHistoricalResponsibilities(transactionId: number) {
+      const resptService = new MockResponsibilityService();
+      resptService.content = this.historicalResponsibilities;
+      return this; 
+    }
+  }
+
+  class MockNotificationService extends AbstractMockObservableService {
+    itemChanged$ = new EventEmitter();
+    itemAdded$ = new EventEmitter();
+    loadCalled = false;
+    public getOpenNotifications(notificationType: string) {
+      this.loadCalled = true;
+      return this;
+    };
+    public getFutureNotifications(notificationType: string) {
+      this.loadCalled = true;
+      return this;
+    };
+    public getFinishedNotifications(notificationType: string) {
+      this.loadCalled = true;
+      return this;
+    };
+  }
 
   beforeEach(async(() => {
+    sessionContext = new SessionContext();
+    messageService = new MessageService();
+    mockRespService = new MockResponsibilityService();    
+    //mockReminderService = new MockReminderService();
+    mockNotificationService = new MockNotificationService();
+    //mockAuthService = new MockAuthService();
+    router = new FakeRouter() as any as Router;
+
+    TestBed.overrideModule(BrowserDynamicTestingModule, {
+      set: {
+        entryComponents: [EntryComponent]
+      }
+    });
+
     TestBed.configureTestingModule({
-      declarations: [ ShiftChangeOverviewComponent ]
+      imports: [
+        FormsModule,
+        MdDialogModule,
+        BrowserAnimationsModule,
+        MaterialModule.forRoot()],
+      declarations: [ 
+        ShiftChangeOverviewComponent,
+        EntryComponent,
+        FormattedTimestampPipe,
+        StringToDatePipe,
+        MockComponent({ selector: 'app-loading-spinner' }),
+        MockComponent({ selector: 'app-entry' }),
+        MockComponent({ selector: 'input', inputs: ['options'] }),
+        MockComponent({ selector: 'app-historical-shift-changes' }),
+        MockComponent({
+          selector: 'app-responsibility', 
+          inputs: ['withButtons', 'withNames', 'responsiblitySelection']
+        }),
+        MockComponent({
+          selector: 'app-sorting', inputs: ['columnName', 'initColumnName', 'isDesc', 'defaultState']
+        }),
+        MockComponent({
+          selector: 'app-autocomplete',
+          inputs: ['responsibilityForwarding'],
+          outputs: ['responsibilityForwarding']
+        }),
+        MockComponent({
+          selector: 'app-abstract-list', inputs: [
+            'withCheckboxes', 'withEditButtons', 'isCollapsible', 'stayHidden', 'gridId', 'enforceShowReadOnly']
+        }),
+        MockComponent({
+          selector: 'app-finished-notifications', inputs: [ 
+            'responsiblitySelection',
+            'withCheckboxes', 'withEditButtons', 'withDatePicker', 'isCollapsible', 'stayHidden', 
+            'gridId', 'enforceShowReadOnly', 'shiftChangeTransactionId'
+          ]
+        }),
+        MockComponent({
+          selector: 'app-open-notifications', inputs: [ 
+            'responsiblitySelection',
+            'withCheckboxes', 'withEditButtons', 'withDatePicker', 'isCollapsible', 'stayHidden', 
+            'gridId', 'enforceShowReadOnly', 'shiftChangeTransactionId']
+        }),
+        MockComponent({
+          selector: 'app-future-notifications', inputs: [ 
+            'responsiblitySelection',
+            'withCheckboxes', 'withEditButtons', 'withDatePicker', 'isCollapsible', 'stayHidden', 
+            'gridId', 'enforceShowReadOnly', 'shiftChangeTransactionId']
+        }),
+        MockComponent({
+          selector: 'app-message-banner'
+        })
+      ],
+      providers: [
+        { provide: Router, useValue: routerStub },
+        { provide: SessionContext, useValue: sessionContext },
+        { provide: DaterangepickerConfig, useClass: DaterangepickerConfig },
+        { provide: Overlay, useClass: Overlay },
+        { provide: OVERLAY_PROVIDERS, useClass: OVERLAY_PROVIDERS },
+        
+        { provide: ResponsibilityService, useValue: mockRespService },
+        { provide: MessageService, useValue: messageService },
+        { provide: NotificationService, useValue: mockNotificationService }
+      ]
     })
     .compileComponents();
+
+    fixture = TestBed.createComponent(ShiftChangeOverviewComponent);
+    component = fixture.componentInstance;
+    
   }));
 
   beforeEach(() => {
     fixture = TestBed.createComponent(ShiftChangeOverviewComponent);
     component = fixture.componentInstance;
-    fixture.detectChanges();
+    
   });
 
-  // it('should be created', () => {
-  //   expect(component).toBeTruthy();
-  // });
+  it('should be created', () => {
+    fixture.detectChanges();
+    expect(component).toBeTruthy();
+  });
+
+  it('should navigate to overview on home-button click', () => {
+    component.gotToOverview();
+    expect(routerStub.navigate).toHaveBeenCalledWith(['/overview']);
+  });
+
+  it('should call getHistoricalResponsibilities service method and return an error', async(() => {
+    let hasBeenCalled = false;
+    sessionContext.setCurrUser(USERS[1]);
+   
+    messageService.errorOccured$.subscribe( msg => hasBeenCalled = true);
+    const transactionId = -1;
+    mockRespService.error = 'RETRIEVEHISTORICALRESPONSIBILITIES_ERROR';
+    mockRespService.content = HISTORICAL_SCHIFTCHANGES;
+
+    fixture.detectChanges();
+    mockRespService.getHistoricalResponsibilities(transactionId).subscribe((resp) => {
+      fixture.whenStable().then(() => {
+        fixture.detectChanges();
+        expect(component.sessionContext.bannerMessage.text).toEqual('Verantwortlichkeiten');
+        expect(hasBeenCalled).toBeTruthy();
+      });
+    });
+
+    component.shiftChangeDateSelected(transactionId);
+    fixture.detectChanges();
+  }));
+
+  it('should call service after ShiftChange is selected ', async(() => {
+    component.responsibilitiesContainer = null;  
+    mockRespService.content = HISTORICAL_SCHIFTCHANGES;
+
+    component.shiftChangeDateSelected(HISTORICAL_SCHIFTCHANGES.historicalResponsibilities[0].transactionId);
+    fixture.detectChanges();
+    fixture.whenStable().then(() => {
+      fixture.detectChanges();
+      expect(component.responsibilitiesContainer).toBe(HISTORICAL_SCHIFTCHANGES);
+    });
+  }));
 });