| /******************************************************************************** |
| * Copyright (c) 2020 Contributors to the Eclipse Foundation |
| * |
| * See the NOTICE file(s) distributed with this work for additional |
| * information regarding copyright ownership. |
| * |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License v. 2.0 which is available at |
| * http://www.eclipse.org/legal/epl-2.0. |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| ********************************************************************************/ |
| import { async } from '@angular/core/testing'; |
| import { InternalPersonDetailsSandBox } from '@app/pages/persons/internal-person/internal-person-details/internal-person-details.sandbox'; |
| import { of } from 'rxjs'; |
| import * as internalPersonActions from '@app/shared/store/actions/persons/internal-person.action'; |
| import { InternalPerson } from '@app/shared/models'; |
| |
| describe('InternalPersonDetailsSandBox', () => { |
| let component: InternalPersonDetailsSandBox; |
| let utilService: any; |
| let appState: any; |
| let actionSubject: any; |
| let router: any; |
| |
| beforeEach(async(() => { |
| router = { navigateByUrl() {} } as any; |
| appState = { dispatch:()=> {}, pipe: () => of(true), select:()=> of(true) } as any; |
| actionSubject = { pipe: () => of(true) } as any; |
| utilService = { displayNotification: () => {} } as any; |
| })); |
| |
| beforeEach(() => { |
| component = new InternalPersonDetailsSandBox(appState, utilService, actionSubject, router); |
| }); |
| |
| it('should create', () => { |
| expect(component).toBeTruthy(); |
| }); |
| |
| it('should call dispatch if load an internal person', () => { |
| const spy = spyOn(appState, 'dispatch'); |
| component.loadInternalPerson('ID'); |
| expect(spy).toHaveBeenCalledWith( Object({ payload: 'ID', type: internalPersonActions.loadInternalPersonDetail.type })); |
| }); |
| |
| it('should call dispatch if persist an internal person', () => { |
| const spy = spyOn(appState, 'dispatch'); |
| const routerSpy = spyOn(router, 'navigateByUrl'); |
| const internalPerson = new InternalPerson; |
| component.persistInternalPerson(internalPerson); |
| expect(spy).toHaveBeenCalledWith( Object({ payload: internalPerson, type: internalPersonActions.persistInternalPersonDetail.type })); |
| expect(routerSpy).toHaveBeenCalled(); |
| }); |
| |
| it('should call dispatch if updatingState', () => { |
| const spy = spyOn(appState, 'dispatch'); |
| component.updatingState(); |
| expect(spy).toHaveBeenCalled(); |
| }); |
| |
| it('should call unregister subscibtions if call ngOnDestroy', () => { |
| const spy = spyOn(component as any, 'unregisterEvents'); |
| component.ngOnDestroy(); |
| expect(spy).toHaveBeenCalled(); |
| }); |
| }); |