blob: b86f91bc1552d76b0b8ceae36a0660cdd696672d [file]
/********************************************************************************
* Copyright © 2018 Mettenmeier GmbH.
*
* 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, ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { of } from 'rxjs';
import { StandbylisttableComponent } from '@masterdata/components/standbylisttable/standbylisttable.component';
import { MasterdataService } from '@masterdata/services/masterdata.service';
import { SharedModule } from '@shared/shared.module';
import { AlertComponent } from '@shared/components/alert/alert.component';
import { StandbylistMockObjects } from '@shared/testing/standbylist';
import { Routes } from '@angular/router';
import { MasterdataManagementModule } from '@masterdata/masterdata-management.module';
import { MessageService } from 'primeng/components/common/messageservice';
const standbygroupMockObjects = new StandbylistMockObjects;
export class MasterDataServiceMock {
getStandbyListData() {
return of(standbygroupMockObjects.STANDBYLIST_ARRAY);
}
}
describe('StandbylisttableComponent', () => {
let component: StandbylisttableComponent;
let fixture: ComponentFixture<StandbylisttableComponent>;
beforeEach(async(() => {
const routes: Routes = [
{
path: '**',
component: AlertComponent
}
];
TestBed.configureTestingModule({
declarations: [],
imports: [
SharedModule,
RouterTestingModule.withRoutes(routes),
MasterdataManagementModule // needed in order to have the LocationComponent for the openModal method
],
providers: [
MasterdataService,
MessageService,
{
provide: MasterdataService,
useClass: MasterDataServiceMock
}
]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(StandbylisttableComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should call onGridReady without error', () => {
const params = {
api: {
sizeColumnsToFit: () => { }
}
};
try {
component.onGridReady(params);
} catch (e) {
expect(e).toBeFalsy();
}
});
it('should navigate to a details view on rowClicked()', () => {
const event = { data: { id: 1 } };
component.rowClicked(event);
});
it('should open a modal and close it on any action', () => {
component.openModal();
component.modalRef.componentInstance.modalAction.next('close');
});
it('should open a modal and shouldn´t close it is the result is not "close"', () => {
component.openModal();
component.modalRef.componentInstance.modalAction.next('stay');
});
});