blob: c0c0e99e414bf95c35ba27037644e86ba1276b39 [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 { TableComponent } from '@grid-failure-information-table-app/app/app.component';
import { AppTableService } from '@grid-failure-information-table-app/app/app-table.service';
import { GridFailure } from '@grid-failure-information-app/shared/models';
import { of } from 'rxjs';
describe('AppComponent', () => {
let component: TableComponent;
let service: AppTableService;
let gridFailureMapListAll: GridFailure[] = [];
beforeEach(() => {
service = {
loadGridFailureData: () => of(true)
} as any;
gridFailureMapListAll = [new GridFailure({ postcode: '007' }), new GridFailure({ postcode: '4711' }), new GridFailure({ postcode: '0815' })];
component = new TableComponent(service);
(component as any)._gridFailuresAll = gridFailureMapListAll;
component.gridFailures = gridFailureMapListAll.map(i => Object.assign(i));
});
it('should create the app', () => {
expect(component).toBeTruthy();
});
it('should call loadGridFailureData', () => {
const spy: any = spyOn(component['_appTableService'], 'loadGridFailureData').and.returnValue(of({} as any));
component.ngOnInit();
expect(spy).toHaveBeenCalled();
});
it('should set initial sorting', () => {
let sortModel;
let params = { api: { setSortModel: sortModel = {} } };
component['_gridApi'] = params.api;
const spy: any = spyOn(component['_gridApi'], 'setSortModel');
component.onGridReady(params);
expect(spy).toHaveBeenCalled();
});
it('should assign all gridfailures to table', () => {
component.postcode = '';
expect(component.gridFailures.length).toEqual(gridFailureMapListAll.length);
});
it('should assign only gridfailures with postcode 007 to table', () => {
component.postcode = '007';
expect(component.gridFailures.length).toEqual(1);
expect(component.gridFailures[0].postcode).toEqual('007');
});
});