55946: Spec file fixes

This commit is contained in:
Kristof De Langhe
2018-11-30 17:31:09 +01:00
parent 930af49030
commit 32db97e67d
6 changed files with 71 additions and 49 deletions

View File

@@ -1,7 +1,6 @@
import { ObjectSelectService } from './object-select.service';
import { Store } from '@ngrx/store';
import { Observable } from 'rxjs/Observable';
import { ObjectSelectionsState } from './object-select.reducer';
import { ObjectSelectionListState, ObjectSelectionsState } from './object-select.reducer';
import { AppState } from '../../app.reducer';
import {
ObjectSelectionDeselectAction,
@@ -9,87 +8,96 @@ import {
ObjectSelectionInitialSelectAction, ObjectSelectionResetAction,
ObjectSelectionSelectAction, ObjectSelectionSwitchAction
} from './object-select.actions';
import { of } from 'rxjs/internal/observable/of';
describe('ObjectSelectService', () => {
let service: ObjectSelectService;
const mockKey = 'key';
const mockObjectId = 'id1';
const selectionStore: Store<ObjectSelectionListState> = jasmine.createSpyObj('selectionStore', {
/* tslint:disable:no-empty */
dispatch: {},
/* tslint:enable:no-empty */
select: of(true)
});
const store: Store<ObjectSelectionsState> = jasmine.createSpyObj('store', {
/* tslint:disable:no-empty */
dispatch: {},
/* tslint:enable:no-empty */
select: Observable.of(true)
select: of(true)
});
const appStore: Store<AppState> = jasmine.createSpyObj('appStore', {
/* tslint:disable:no-empty */
dispatch: {},
/* tslint:enable:no-empty */
select: Observable.of(true)
select: of(true)
});
beforeEach(() => {
service = new ObjectSelectService(store, appStore);
service = new ObjectSelectService(selectionStore, appStore);
});
describe('when the initialSelect method is triggered', () => {
beforeEach(() => {
service.initialSelect(mockObjectId);
service.initialSelect(mockKey, mockObjectId);
});
it('ObjectSelectionInitialSelectAction should be dispatched to the store', () => {
expect(store.dispatch).toHaveBeenCalledWith(new ObjectSelectionInitialSelectAction(mockObjectId));
expect(selectionStore.dispatch).toHaveBeenCalledWith(new ObjectSelectionInitialSelectAction(mockKey, mockObjectId));
});
});
describe('when the initialDeselect method is triggered', () => {
beforeEach(() => {
service.initialDeselect(mockObjectId);
service.initialDeselect(mockKey, mockObjectId);
});
it('ObjectSelectionInitialDeselectAction should be dispatched to the store', () => {
expect(store.dispatch).toHaveBeenCalledWith(new ObjectSelectionInitialDeselectAction(mockObjectId));
expect(selectionStore.dispatch).toHaveBeenCalledWith(new ObjectSelectionInitialDeselectAction(mockKey, mockObjectId));
});
});
describe('when the select method is triggered', () => {
beforeEach(() => {
service.select(mockObjectId);
service.select(mockKey, mockObjectId);
});
it('ObjectSelectionSelectAction should be dispatched to the store', () => {
expect(store.dispatch).toHaveBeenCalledWith(new ObjectSelectionSelectAction(mockObjectId));
expect(selectionStore.dispatch).toHaveBeenCalledWith(new ObjectSelectionSelectAction(mockKey, mockObjectId));
});
});
describe('when the deselect method is triggered', () => {
beforeEach(() => {
service.deselect(mockObjectId);
service.deselect(mockKey, mockObjectId);
});
it('ObjectSelectionDeselectAction should be dispatched to the store', () => {
expect(store.dispatch).toHaveBeenCalledWith(new ObjectSelectionDeselectAction(mockObjectId));
expect(selectionStore.dispatch).toHaveBeenCalledWith(new ObjectSelectionDeselectAction(mockKey, mockObjectId));
});
});
describe('when the switch method is triggered', () => {
beforeEach(() => {
service.switch(mockObjectId);
service.switch(mockKey, mockObjectId);
});
it('ObjectSelectionSwitchAction should be dispatched to the store', () => {
expect(store.dispatch).toHaveBeenCalledWith(new ObjectSelectionSwitchAction(mockObjectId));
expect(selectionStore.dispatch).toHaveBeenCalledWith(new ObjectSelectionSwitchAction(mockKey, mockObjectId));
});
});
describe('when the reset method is triggered', () => {
beforeEach(() => {
service.reset();
service.reset(mockKey);
});
it('ObjectSelectionInitialSelectAction should be dispatched to the store', () => {
expect(store.dispatch).toHaveBeenCalledWith(new ObjectSelectionResetAction(null));
expect(selectionStore.dispatch).toHaveBeenCalledWith(new ObjectSelectionResetAction(mockKey, null));
});
});