blob: 440082b60663b34a88bf4532e2a5a0726c65ad15 [file] [log] [blame]
import { logging } from 'protractor';
/********************************************************************************
* 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 { GridFailureDetailsComponent } from '@grid-failure-information-app/pages/grid-failure/grid-failure-details/grid-failure-details.component';
import { of } from 'rxjs';
import { Store } from '@ngrx/store';
import { State } from '@grid-failure-information-app/shared/store';
import { async } from '@angular/core/testing';
import { Globals } from '@grid-failure-information-app/shared/constants/globals';
describe('GridFailureDetailsComponent', () => {
let component: GridFailureDetailsComponent;
let gridFailureSandbox: any;
let gridFailureDetailsFormResponse: any = {
value: {
failureBegin: 'test1',
failureEndPlanned: 'test2',
failureEndResupplied: 'test3',
},
controls: {
postcode: { value: null },
stationDescription: { value: null },
latitude: { value: null },
} as any,
};
let appState: Store<State>;
beforeEach(() => {
appState = { dispatch: () => {}, pipe: () => of(true), select: () => of(true) } as any;
gridFailureSandbox = {
clearGridFailureData() {},
registerEvents() {},
endSubscriptions() {},
resetCoords() {},
resetStationId() {},
resetPostCode() {},
disableUnnecessaryRequiredProperties() {},
gridFailureDetailsFormState$: of(gridFailureDetailsFormResponse as any),
isAddressLoaded() {
return of(true);
},
} as any;
component = new GridFailureDetailsComponent(gridFailureSandbox, appState);
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should end subscriptions in Sandbox before the component going away ', async(() => {
let component = new GridFailureDetailsComponent(gridFailureSandbox, appState);
let spy = spyOn(gridFailureSandbox, 'endSubscriptions');
component.ngOnDestroy();
expect(spy).toHaveBeenCalled();
}));
it('should registerEvents OnInit', () => {
let spy = spyOn(gridFailureSandbox, 'registerEvents');
component.ngOnInit();
expect(spy).toHaveBeenCalled();
});
it('checks if resetCoords(value: string) works fine', async(() => {
let spy1 = spyOn(gridFailureSandbox, 'resetCoords');
let spy2 = spyOn(gridFailureSandbox, 'resetStationId');
component.resetCoords('1');
expect(spy1).not.toHaveBeenCalled();
expect(spy2).not.toHaveBeenCalled();
component.resetCoords(null);
expect(spy1).toHaveBeenCalled();
expect(spy2).toHaveBeenCalled();
}));
it('checks if disableUnnecessaryRequiredProperties works fine', async(() => {
component.failureLocationView = Globals.FAILURE_LOCATION_NS;
const spy = spyOn(gridFailureSandbox, 'disableUnnecessaryRequiredProperties');
component.disableUnnecessaryRequiredProperties();
expect(spy).toHaveBeenCalled();
}));
it('checks if _initialFailureLocationState works fine', async(() => {
component.failureLocationView === Globals.FAILURE_LOCATION_MAP;
//MAP
component.gridFailureDetailsSandbox.currentFormState = {
...component.gridFailureDetailsSandbox.currentFormState,
controls: {
housenumber: { value: null } as any,
radius: { value: null } as any,
latitude: { value: null } as any,
longitude: { value: null } as any,
} as any,
};
(component as any)._initialFailureLocationState();
expect(component.mapInteractionMode).toBeTruthy();
//NS
component.gridFailureDetailsSandbox.currentFormState = {
...component.gridFailureDetailsSandbox.currentFormState,
controls: {
housenumber: { value: null } as any,
radius: { value: 100 } as any,
latitude: { value: 11 } as any,
longitude: { value: 22 } as any,
} as any,
};
(component as any)._initialFailureLocationState();
expect(component.mapInteractionMode).toBeFalsy();
//MS
component.gridFailureDetailsSandbox.currentFormState = {
...component.gridFailureDetailsSandbox.currentFormState,
controls: {
housenumber: { value: 44 } as any,
radius: { value: null } as any,
latitude: { value: 11 } as any,
longitude: { value: 12 } as any,
} as any,
};
(component as any)._initialFailureLocationState();
expect(component.mapInteractionMode).toBeFalsy();
}));
});