blob: fdea3a8a17569c863822139de472d110826613a1 [file] [log] [blame]
/********************************************************************************
* 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 { ExternalPersonDetailsSandBox } from '@app/pages/persons/external-person/external-person-details/external-person-details.sandbox';
import { of } from 'rxjs';
import * as externalPersonActions from '@app/shared/store/actions/persons/external-person.action';
import { ExternalPerson } from '@app/shared/models';
describe('ExternalPersonDetailsSandBox', () => {
let component: ExternalPersonDetailsSandBox;
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 ExternalPersonDetailsSandBox(appState, utilService, actionSubject, router);
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should call dispatch if load an external person', () => {
const spy = spyOn(appState, 'dispatch');
component.loadExternalPerson('ID');
expect(spy).toHaveBeenCalledWith( Object({ payload: 'ID', type: externalPersonActions.loadExternalPersonDetail.type }));
});
it('should call dispatch if persist an external person', () => {
const spy = spyOn(appState, 'dispatch');
const routerSpy = spyOn(router, 'navigateByUrl');
const externalPerson = new ExternalPerson;
component.persistExternalPerson(externalPerson);
expect(spy).toHaveBeenCalledWith( Object({ payload: externalPerson, type: externalPersonActions.persistExternalPersonDetail.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();
});
});