blob: 4b62914a075b05de33acb79337c46949aa9883eb [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 { take } from 'rxjs/operators';
import { GridFailuresEffects } from '@shared/store/effects/grid-failures.effect';
import { Subject, of, throwError } from 'rxjs';
import { GridFailure } from '@shared/models';
import * as gridFailureActions from '@shared/store/actions/grid-failures.action';
import { GridFailureApiClient } from '@pages/grid-failure/grid-failure-api-client';
import { Store } from '@ngrx/store';
describe('AddressTypes Effects', () => {
let effects: GridFailuresEffects;
let actions$: Subject<any>;
let apiClient: GridFailureApiClient;
let store: Store<any>;
let apiResponse: any = null;
beforeEach(() => {
apiClient = {
getGridFailures() {},
} as any;
store = {
dispatch() {},
} as any;
actions$ = new Subject();
effects = new GridFailuresEffects(actions$, apiClient, store);
});
it('should be truthy', () => {
expect(effects).toBeTruthy();
});
it('should equal loadGridFailuresSuccess after getGridFailures', done => {
apiResponse = [new GridFailure({ id: '1' })];
spyOn(apiClient, 'getGridFailures').and.returnValue(of(apiResponse));
effects.getGridFailures$.pipe(take(1)).subscribe(result => {
expect(result).toEqual(gridFailureActions.loadGridFailuresSuccess({ payload: apiResponse }));
});
done();
actions$.next(gridFailureActions.loadGridFailures());
});
it('should equal loadGridFailuresFail after getAddressType Error', done => {
spyOn(apiClient, 'getGridFailures').and.returnValue(throwError('x'));
effects.getGridFailures$.pipe(take(1)).subscribe(result => {
expect(result).toEqual(gridFailureActions.loadGridFailuresFail({ payload: 'x' }));
});
done();
actions$.next(gridFailureActions.loadGridFailures());
});
});