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

@@ -21,6 +21,7 @@ import { RequestService } from './request.service';
import { ActionsSubject, Store } from '@ngrx/store'; import { ActionsSubject, Store } from '@ngrx/store';
import { TestScheduler } from 'rxjs/testing'; import { TestScheduler } from 'rxjs/testing';
import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject'; import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject';
import { IndexState } from '../index/index.reducer';
describe('RequestService', () => { describe('RequestService', () => {
let scheduler: TestScheduler; let scheduler: TestScheduler;
@@ -29,6 +30,7 @@ describe('RequestService', () => {
let objectCache: ObjectCacheService; let objectCache: ObjectCacheService;
let uuidService: UUIDService; let uuidService: UUIDService;
let store: Store<CoreState>; let store: Store<CoreState>;
let indexStore: Store<IndexState>;
const testUUID = '5f2a0d2a-effa-4d54-bd54-5663b960f9eb'; const testUUID = '5f2a0d2a-effa-4d54-bd54-5663b960f9eb';
const testHref = 'https://rest.api/endpoint/selfLink'; const testHref = 'https://rest.api/endpoint/selfLink';
@@ -48,7 +50,8 @@ describe('RequestService', () => {
uuidService = getMockUUIDService(); uuidService = getMockUUIDService();
store = new Store<CoreState>(new BehaviorSubject({}), new ActionsSubject(), null); store = new Store<CoreState>(undefined, new ActionsSubject(), null);
indexStore = new Store<IndexState>(undefined, new ActionsSubject(), null);
selectSpy = spyOnProperty(ngrx, 'select'); selectSpy = spyOnProperty(ngrx, 'select');
selectSpy.and.callFake(() => { selectSpy.and.callFake(() => {
return () => { return () => {
@@ -59,7 +62,8 @@ describe('RequestService', () => {
service = new RequestService( service = new RequestService(
objectCache, objectCache,
uuidService, uuidService,
store store,
indexStore
); );
serviceAsAny = service as any; serviceAsAny = service as any;
}); });

View File

@@ -32,6 +32,7 @@ import { MockTranslateLoader } from '../../shared/mocks/mock-translate-loader';
import { BrowseService } from '../browse/browse.service'; import { BrowseService } from '../browse/browse.service';
import { HALEndpointService } from '../shared/hal-endpoint.service'; import { HALEndpointService } from '../shared/hal-endpoint.service';
import { EmptyError } from 'rxjs/internal-compatibility'; import { EmptyError } from 'rxjs/internal-compatibility';
import { IndexState } from '../index/index.reducer';
/* tslint:disable:max-classes-per-file */ /* tslint:disable:max-classes-per-file */
@Component({ @Component({
@@ -60,6 +61,7 @@ describe('MetadataService', () => {
let title: Title; let title: Title;
let store: Store<CoreState>; let store: Store<CoreState>;
let indexStore: Store<IndexState>;
let objectCacheService: ObjectCacheService; let objectCacheService: ObjectCacheService;
let requestService: RequestService; let requestService: RequestService;
@@ -78,11 +80,12 @@ describe('MetadataService', () => {
beforeEach(() => { beforeEach(() => {
store = new Store<CoreState>(undefined, undefined, undefined); store = new Store<CoreState>(undefined, undefined, undefined);
indexStore = new Store<IndexState>(undefined, undefined, undefined);
spyOn(store, 'dispatch'); spyOn(store, 'dispatch');
objectCacheService = new ObjectCacheService(store); objectCacheService = new ObjectCacheService(store);
uuidService = new UUIDService(); uuidService = new UUIDService();
requestService = new RequestService(objectCacheService, uuidService, store); requestService = new RequestService(objectCacheService, uuidService, store, indexStore);
remoteDataBuildService = new RemoteDataBuildService(objectCacheService, requestService); remoteDataBuildService = new RemoteDataBuildService(objectCacheService, requestService);
TestBed.configureTestingModule({ TestBed.configureTestingModule({

View File

@@ -1,6 +1,5 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing'; import { RouterTestingModule } from '@angular/router/testing';
import { Observable } from 'rxjs/Observable';
import { RemoteData } from '../../../core/data/remote-data'; import { RemoteData } from '../../../core/data/remote-data';
import { PaginatedList } from '../../../core/data/paginated-list'; import { PaginatedList } from '../../../core/data/paginated-list';
import { PageInfo } from '../../../core/shared/page-info.model'; import { PageInfo } from '../../../core/shared/page-info.model';
@@ -15,6 +14,7 @@ import { NO_ERRORS_SCHEMA } from '@angular/core';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import { CollectionSelectComponent } from './collection-select.component'; import { CollectionSelectComponent } from './collection-select.component';
import { Collection } from '../../../core/shared/collection.model'; import { Collection } from '../../../core/shared/collection.model';
import { of } from 'rxjs/internal/observable/of';
describe('ItemSelectComponent', () => { describe('ItemSelectComponent', () => {
let comp: CollectionSelectComponent; let comp: CollectionSelectComponent;
@@ -31,7 +31,7 @@ describe('ItemSelectComponent', () => {
name: 'name2' name: 'name2'
}) })
]; ];
const mockCollections = Observable.of(new RemoteData(false, false, true, null, new PaginatedList(new PageInfo(), mockCollectionList))); const mockCollections = of(new RemoteData(false, false, true, null, new PaginatedList(new PageInfo(), mockCollectionList)));
const mockPaginationOptions = Object.assign(new PaginationComponentOptions(), { const mockPaginationOptions = Object.assign(new PaginationComponentOptions(), {
id: 'search-page-configuration', id: 'search-page-configuration',
pageSize: 10, pageSize: 10,

View File

@@ -2,7 +2,6 @@ import { ItemSelectComponent } from './item-select.component';
import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing'; import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing'; import { RouterTestingModule } from '@angular/router/testing';
import { Item } from '../../../core/shared/item.model'; import { Item } from '../../../core/shared/item.model';
import { Observable } from 'rxjs/Observable';
import { RemoteData } from '../../../core/data/remote-data'; import { RemoteData } from '../../../core/data/remote-data';
import { PaginatedList } from '../../../core/data/paginated-list'; import { PaginatedList } from '../../../core/data/paginated-list';
import { PageInfo } from '../../../core/shared/page-info.model'; import { PageInfo } from '../../../core/shared/page-info.model';
@@ -15,6 +14,7 @@ import { HostWindowService } from '../../host-window.service';
import { HostWindowServiceStub } from '../../testing/host-window-service-stub'; import { HostWindowServiceStub } from '../../testing/host-window-service-stub';
import { NO_ERRORS_SCHEMA } from '@angular/core'; import { NO_ERRORS_SCHEMA } from '@angular/core';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import { of } from 'rxjs/internal/observable/of';
describe('ItemSelectComponent', () => { describe('ItemSelectComponent', () => {
let comp: ItemSelectComponent; let comp: ItemSelectComponent;
@@ -24,7 +24,7 @@ describe('ItemSelectComponent', () => {
const mockItemList = [ const mockItemList = [
Object.assign(new Item(), { Object.assign(new Item(), {
id: 'id1', id: 'id1',
bitstreams: Observable.of({}), bitstreams: of({}),
metadata: [ metadata: [
{ {
key: 'dc.title', key: 'dc.title',
@@ -39,7 +39,7 @@ describe('ItemSelectComponent', () => {
}), }),
Object.assign(new Item(), { Object.assign(new Item(), {
id: 'id2', id: 'id2',
bitstreams: Observable.of({}), bitstreams: of({}),
metadata: [ metadata: [
{ {
key: 'dc.title', key: 'dc.title',
@@ -53,7 +53,7 @@ describe('ItemSelectComponent', () => {
}] }]
}) })
]; ];
const mockItems = Observable.of(new RemoteData(false, false, true, null, new PaginatedList(new PageInfo(), mockItemList))); const mockItems = of(new RemoteData(false, false, true, null, new PaginatedList(new PageInfo(), mockItemList)));
const mockPaginationOptions = Object.assign(new PaginationComponentOptions(), { const mockPaginationOptions = Object.assign(new PaginationComponentOptions(), {
id: 'search-page-configuration', id: 'search-page-configuration',
pageSize: 10, pageSize: 10,

View File

@@ -5,6 +5,7 @@ import {
} from './object-select.actions'; } from './object-select.actions';
import { objectSelectionReducer } from './object-select.reducer'; import { objectSelectionReducer } from './object-select.reducer';
const key = 'key';
const objectId1 = 'id1'; const objectId1 = 'id1';
const objectId2 = 'id2'; const objectId2 = 'id2';
@@ -12,7 +13,7 @@ class NullAction extends ObjectSelectionSelectAction {
type = null; type = null;
constructor() { constructor() {
super(undefined); super(undefined, undefined);
} }
} }
@@ -20,7 +21,8 @@ describe('objectSelectionReducer', () => {
it('should return the current state when no valid actions have been made', () => { it('should return the current state when no valid actions have been made', () => {
const state = {}; const state = {};
state[objectId1] = { checked: true }; state[key] = {};
state[key][objectId1] = { checked: true };
const action = new NullAction(); const action = new NullAction();
const newState = objectSelectionReducer(state, action); const newState = objectSelectionReducer(state, action);
@@ -36,63 +38,68 @@ describe('objectSelectionReducer', () => {
}); });
it('should set checked to true in response to the INITIAL_SELECT action', () => { it('should set checked to true in response to the INITIAL_SELECT action', () => {
const action = new ObjectSelectionInitialSelectAction(objectId1); const action = new ObjectSelectionInitialSelectAction(key, objectId1);
const newState = objectSelectionReducer(undefined, action); const newState = objectSelectionReducer(undefined, action);
expect(newState[objectId1].checked).toBeTruthy(); expect(newState[key][objectId1].checked).toBeTruthy();
}); });
it('should set checked to true in response to the INITIAL_DESELECT action', () => { it('should set checked to true in response to the INITIAL_DESELECT action', () => {
const action = new ObjectSelectionInitialDeselectAction(objectId1); const action = new ObjectSelectionInitialDeselectAction(key, objectId1);
const newState = objectSelectionReducer(undefined, action); const newState = objectSelectionReducer(undefined, action);
expect(newState[objectId1].checked).toBeFalsy(); expect(newState[key][objectId1].checked).toBeFalsy();
}); });
it('should set checked to true in response to the SELECT action', () => { it('should set checked to true in response to the SELECT action', () => {
const state = {}; const state = {};
state[objectId1] = { checked: false }; state[key] = {};
const action = new ObjectSelectionSelectAction(objectId1); state[key][objectId1] = { checked: false };
const action = new ObjectSelectionSelectAction(key, objectId1);
const newState = objectSelectionReducer(state, action); const newState = objectSelectionReducer(state, action);
expect(newState[objectId1].checked).toBeTruthy(); expect(newState[key][objectId1].checked).toBeTruthy();
}); });
it('should set checked to false in response to the DESELECT action', () => { it('should set checked to false in response to the DESELECT action', () => {
const state = {}; const state = {};
state[objectId1] = { checked: true }; state[key] = {};
const action = new ObjectSelectionDeselectAction(objectId1); state[key][objectId1] = { checked: true };
const action = new ObjectSelectionDeselectAction(key, objectId1);
const newState = objectSelectionReducer(state, action); const newState = objectSelectionReducer(state, action);
expect(newState[objectId1].checked).toBeFalsy(); expect(newState[key][objectId1].checked).toBeFalsy();
}); });
it('should set checked from false to true in response to the SWITCH action', () => { it('should set checked from false to true in response to the SWITCH action', () => {
const state = {}; const state = {};
state[objectId1] = { checked: false }; state[key] = {};
const action = new ObjectSelectionSwitchAction(objectId1); state[key][objectId1] = { checked: false };
const action = new ObjectSelectionSwitchAction(key, objectId1);
const newState = objectSelectionReducer(state, action); const newState = objectSelectionReducer(state, action);
expect(newState[objectId1].checked).toBeTruthy(); expect(newState[key][objectId1].checked).toBeTruthy();
}); });
it('should set checked from true to false in response to the SWITCH action', () => { it('should set checked from true to false in response to the SWITCH action', () => {
const state = {}; const state = {};
state[objectId1] = { checked: true }; state[key] = {};
const action = new ObjectSelectionSwitchAction(objectId1); state[key][objectId1] = { checked: true };
const action = new ObjectSelectionSwitchAction(key, objectId1);
const newState = objectSelectionReducer(state, action); const newState = objectSelectionReducer(state, action);
expect(newState[objectId1].checked).toBeFalsy(); expect(newState[key][objectId1].checked).toBeFalsy();
}); });
it('should set reset the state in response to the RESET action', () => { it('should reset the state in response to the RESET action', () => {
const state = {}; const state = {};
state[objectId1] = { checked: true }; state[key] = {};
state[objectId2] = { checked: false }; state[key][objectId1] = { checked: true };
const action = new ObjectSelectionResetAction(undefined); state[key][objectId2] = { checked: false };
const action = new ObjectSelectionResetAction(key, undefined);
const newState = objectSelectionReducer(state, action); const newState = objectSelectionReducer(state, action);
expect(newState).toEqual({}); expect(newState[key]).toEqual({});
}); });
}); });

View File

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