mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-12 12:33:07 +00:00
Merge remote-tracking branch 'community/master' into 150-List-and-grid-feedback
This commit is contained in:
38
src/app/core/cache/object-cache.effects.spec.ts
vendored
Normal file
38
src/app/core/cache/object-cache.effects.spec.ts
vendored
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
import { Observable } from 'rxjs/Observable';
|
||||||
|
import { provideMockActions } from '@ngrx/effects/testing';
|
||||||
|
import { cold, hot } from 'jasmine-marbles';
|
||||||
|
import { ObjectCacheEffects } from './object-cache.effects';
|
||||||
|
import { ResetObjectCacheTimestampsAction } from './object-cache.actions';
|
||||||
|
import { StoreActionTypes } from '../../store.actions';
|
||||||
|
|
||||||
|
describe('ObjectCacheEffects', () => {
|
||||||
|
let cacheEffects: ObjectCacheEffects;
|
||||||
|
let actions: Observable<any>;
|
||||||
|
const timestamp = 10000;
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
providers: [
|
||||||
|
ObjectCacheEffects,
|
||||||
|
provideMockActions(() => actions),
|
||||||
|
// other providers
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
cacheEffects = TestBed.get(ObjectCacheEffects);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('fixTimestampsOnRehydrate$', () => {
|
||||||
|
|
||||||
|
it('should return a RESET_TIMESTAMPS action in response to a REHYDRATE action', () => {
|
||||||
|
spyOn(Date.prototype, 'getTime').and.callFake(() => {
|
||||||
|
return timestamp;
|
||||||
|
});
|
||||||
|
actions = hot('--a-', { a: { type: StoreActionTypes.REHYDRATE, payload: {} } });
|
||||||
|
|
||||||
|
const expected = cold('--b-', { b: new ResetObjectCacheTimestampsAction(new Date().getTime()) });
|
||||||
|
|
||||||
|
expect(cacheEffects.fixTimestampsOnRehydrate).toBeObservable(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
|
|||||||
import { Actions, Effect } from '@ngrx/effects';
|
import { Actions, Effect } from '@ngrx/effects';
|
||||||
|
|
||||||
import { StoreActionTypes } from '../../store.actions';
|
import { StoreActionTypes } from '../../store.actions';
|
||||||
import { ResetObjectCacheTimestampsAction } from '../cache/object-cache.actions';
|
import { ResetObjectCacheTimestampsAction } from './object-cache.actions';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ObjectCacheEffects {
|
export class ObjectCacheEffects {
|
38
src/app/core/cache/response-cache.effects.spec.ts
vendored
Normal file
38
src/app/core/cache/response-cache.effects.spec.ts
vendored
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
import { Observable } from 'rxjs/Observable';
|
||||||
|
import { provideMockActions } from '@ngrx/effects/testing';
|
||||||
|
import { cold, hot } from 'jasmine-marbles';
|
||||||
|
import { StoreActionTypes } from '../../store.actions';
|
||||||
|
import { ResponseCacheEffects } from './response-cache.effects';
|
||||||
|
import { ResetResponseCacheTimestampsAction } from './response-cache.actions';
|
||||||
|
|
||||||
|
describe('ResponseCacheEffects', () => {
|
||||||
|
let cacheEffects: ResponseCacheEffects;
|
||||||
|
let actions: Observable<any>;
|
||||||
|
const timestamp = 10000;
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
providers: [
|
||||||
|
ResponseCacheEffects,
|
||||||
|
provideMockActions(() => actions),
|
||||||
|
// other providers
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
cacheEffects = TestBed.get(ResponseCacheEffects);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('fixTimestampsOnRehydrate$', () => {
|
||||||
|
|
||||||
|
it('should return a RESET_TIMESTAMPS action in response to a REHYDRATE action', () => {
|
||||||
|
spyOn(Date.prototype, 'getTime').and.callFake(() => {
|
||||||
|
return timestamp;
|
||||||
|
});
|
||||||
|
actions = hot('--a-', { a: { type: StoreActionTypes.REHYDRATE, payload: {} } });
|
||||||
|
|
||||||
|
const expected = cold('--b-', { b: new ResetResponseCacheTimestampsAction(new Date().getTime()) });
|
||||||
|
|
||||||
|
expect(cacheEffects.fixTimestampsOnRehydrate).toBeObservable(expected);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@@ -1,11 +1,11 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { Actions, Effect } from '@ngrx/effects';
|
import { Actions, Effect } from '@ngrx/effects';
|
||||||
|
|
||||||
import { ResetResponseCacheTimestampsAction } from '../cache/response-cache.actions';
|
import { ResetResponseCacheTimestampsAction } from './response-cache.actions';
|
||||||
import { StoreActionTypes } from '../../store.actions';
|
import { StoreActionTypes } from '../../store.actions';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class RequestCacheEffects {
|
export class ResponseCacheEffects {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When the store is rehydrated in the browser, set all cache
|
* When the store is rehydrated in the browser, set all cache
|
317
src/app/core/cache/response-cache.reducer.spec.ts
vendored
317
src/app/core/cache/response-cache.reducer.spec.ts
vendored
@@ -4,8 +4,9 @@ import { responseCacheReducer, ResponseCacheState } from './response-cache.reduc
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
ResponseCacheRemoveAction,
|
ResponseCacheRemoveAction,
|
||||||
ResetResponseCacheTimestampsAction
|
ResetResponseCacheTimestampsAction, ResponseCacheAddAction
|
||||||
} from './response-cache.actions';
|
} from './response-cache.actions';
|
||||||
|
import { RestResponse } from './response-cache.models';
|
||||||
|
|
||||||
class NullAction extends ResponseCacheRemoveAction {
|
class NullAction extends ResponseCacheRemoveAction {
|
||||||
type = null;
|
type = null;
|
||||||
@@ -16,212 +17,108 @@ class NullAction extends ResponseCacheRemoveAction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// describe('responseCacheReducer', () => {
|
describe('responseCacheReducer', () => {
|
||||||
// const keys = ['125c17f89046283c5f0640722aac9feb', 'a06c3006a41caec5d635af099b0c780c'];
|
const keys = ['125c17f89046283c5f0640722aac9feb', 'a06c3006a41caec5d635af099b0c780c'];
|
||||||
// const services = [new OpaqueToken('service1'), new OpaqueToken('service2')];
|
const msToLive = 900000;
|
||||||
// const msToLive = 900000;
|
const uuids = [
|
||||||
// const uuids = [
|
'9e32a2e2-6b91-4236-a361-995ccdc14c60',
|
||||||
// '9e32a2e2-6b91-4236-a361-995ccdc14c60',
|
'598ce822-c357-46f3-ab70-63724d02d6ad',
|
||||||
// '598ce822-c357-46f3-ab70-63724d02d6ad',
|
'be8325f7-243b-49f4-8a4b-df2b793ff3b5'
|
||||||
// 'be8325f7-243b-49f4-8a4b-df2b793ff3b5'
|
];
|
||||||
// ];
|
const testState: ResponseCacheState = {
|
||||||
// const resourceID = '9978';
|
[keys[0]]: {
|
||||||
// const paginationOptions = { 'resultsPerPage': 10, 'currentPage': 1 };
|
key: keys[0],
|
||||||
// const sortOptions = { 'field': 'id', 'direction': 0 };
|
response: new RestResponse(true, '200'),
|
||||||
// const testState = {
|
timeAdded: new Date().getTime(),
|
||||||
// [keys[0]]: {
|
msToLive: msToLive
|
||||||
// 'key': keys[0],
|
},
|
||||||
// 'service': services[0],
|
[keys[1]]: {
|
||||||
// 'resourceUUIDs': [uuids[0], uuids[1]],
|
key: keys[1],
|
||||||
// 'isLoading': false,
|
response: new RestResponse(true, '200'),
|
||||||
// 'paginationOptions': paginationOptions,
|
timeAdded: new Date().getTime(),
|
||||||
// 'sortOptions': sortOptions,
|
msToLive: msToLive
|
||||||
// 'timeAdded': new Date().getTime(),
|
}
|
||||||
// 'msToLive': msToLive
|
};
|
||||||
// },
|
deepFreeze(testState);
|
||||||
// [keys[1]]: {
|
const errorState: {} = {
|
||||||
// 'key': keys[1],
|
[keys[0]]: {
|
||||||
// 'service': services[1],
|
errorMessage: 'error',
|
||||||
// 'resourceID': resourceID,
|
resourceUUIDs: uuids
|
||||||
// 'resourceUUIDs': [uuids[2]],
|
}
|
||||||
// 'isLoading': false,
|
};
|
||||||
// 'timeAdded': new Date().getTime(),
|
deepFreeze(errorState);
|
||||||
// 'msToLive': msToLive
|
|
||||||
// }
|
it('should return the current state when no valid actions have been made', () => {
|
||||||
// };
|
const action = new NullAction();
|
||||||
// deepFreeze(testState);
|
const newState = responseCacheReducer(testState, action);
|
||||||
// const errorState: {} = {
|
|
||||||
// [keys[0]]: {
|
expect(newState).toEqual(testState);
|
||||||
// errorMessage: 'error',
|
});
|
||||||
// resourceUUIDs: uuids
|
|
||||||
// }
|
it('should start with an empty cache', () => {
|
||||||
// };
|
const action = new NullAction();
|
||||||
// deepFreeze(errorState);
|
const initialState = responseCacheReducer(undefined, action);
|
||||||
//
|
|
||||||
//
|
expect(initialState).toEqual(Object.create(null));
|
||||||
// it('should return the current state when no valid actions have been made', () => {
|
});
|
||||||
// const action = new NullAction();
|
|
||||||
// const newState = responseCacheReducer(testState, action);
|
describe('ADD', () => {
|
||||||
//
|
const addTimeAdded = new Date().getTime();
|
||||||
// expect(newState).toEqual(testState);
|
const addMsToLive = 5;
|
||||||
// });
|
const addResponse = new RestResponse(true, '200');
|
||||||
//
|
const action = new ResponseCacheAddAction(keys[0], addResponse, addTimeAdded, addMsToLive);
|
||||||
// it('should start with an empty cache', () => {
|
|
||||||
// const action = new NullAction();
|
it('should perform the action without affecting the previous state', () => {
|
||||||
// const initialState = responseCacheReducer(undefined, action);
|
// testState has already been frozen above
|
||||||
//
|
responseCacheReducer(testState, action);
|
||||||
// expect(initialState).toEqual(Object.create(null));
|
});
|
||||||
// });
|
|
||||||
//
|
it('should add the response to the cached request', () => {
|
||||||
// describe('FIND_BY_ID', () => {
|
const newState = responseCacheReducer(testState, action);
|
||||||
// const action = new ResponseCacheFindByIDAction(keys[0], services[0], resourceID);
|
expect(newState[keys[0]].timeAdded).toBe(addTimeAdded);
|
||||||
//
|
expect(newState[keys[0]].msToLive).toBe(addMsToLive);
|
||||||
// it('should perform the action without affecting the previous state', () => {
|
expect(newState[keys[0]].response).toBe(addResponse);
|
||||||
// //testState has already been frozen above
|
});
|
||||||
// responseCacheReducer(testState, action);
|
});
|
||||||
// });
|
|
||||||
//
|
describe('REMOVE', () => {
|
||||||
// it('should add the request to the cache', () => {
|
it('should perform the action without affecting the previous state', () => {
|
||||||
// const state = Object.create(null);
|
const action = new ResponseCacheRemoveAction(keys[0]);
|
||||||
// const newState = responseCacheReducer(state, action);
|
// testState has already been frozen above
|
||||||
// expect(newState[keys[0]].key).toBe(keys[0]);
|
responseCacheReducer(testState, action);
|
||||||
// expect(newState[keys[0]].service).toEqual(services[0]);
|
});
|
||||||
// expect(newState[keys[0]].resourceID).toBe(resourceID);
|
|
||||||
// });
|
it('should remove the specified request from the cache', () => {
|
||||||
//
|
const action = new ResponseCacheRemoveAction(keys[0]);
|
||||||
// it('should set responsePending to true', () => {
|
const newState = responseCacheReducer(testState, action);
|
||||||
// const state = Object.create(null);
|
expect(testState[keys[0]]).not.toBeUndefined();
|
||||||
// const newState = responseCacheReducer(state, action);
|
expect(newState[keys[0]]).toBeUndefined();
|
||||||
// expect(newState[keys[0]].responsePending).toBe(true);
|
});
|
||||||
// });
|
|
||||||
//
|
it('shouldn\'t do anything when the specified key isn\'t cached', () => {
|
||||||
// it('should remove any previous error message or resourceUUID for the request', () => {
|
const wrongKey = 'this isn\'t cached';
|
||||||
// const newState = responseCacheReducer(errorState, action);
|
const action = new ResponseCacheRemoveAction(wrongKey);
|
||||||
// expect(newState[keys[0]].resourceUUIDs.length).toBe(0);
|
const newState = responseCacheReducer(testState, action);
|
||||||
// expect(newState[keys[0]].errorMessage).toBeUndefined();
|
expect(testState[wrongKey]).toBeUndefined();
|
||||||
// });
|
expect(newState).toEqual(testState);
|
||||||
// });
|
});
|
||||||
//
|
});
|
||||||
// describe('FIND_ALL', () => {
|
|
||||||
// const action = new ResponseCacheFindAllAction(keys[0], services[0], resourceID, paginationOptions, sortOptions);
|
describe('RESET_TIMESTAMPS', () => {
|
||||||
//
|
const newTimeStamp = new Date().getTime();
|
||||||
// it('should perform the action without affecting the previous state', () => {
|
const action = new ResetResponseCacheTimestampsAction(newTimeStamp);
|
||||||
// //testState has already been frozen above
|
|
||||||
// responseCacheReducer(testState, action);
|
it('should perform the action without affecting the previous state', () => {
|
||||||
// });
|
// testState has already been frozen above
|
||||||
//
|
responseCacheReducer(testState, action);
|
||||||
// it('should add the request to the cache', () => {
|
});
|
||||||
// const state = Object.create(null);
|
|
||||||
// const newState = responseCacheReducer(state, action);
|
it('should set the timestamp of all requests in the cache', () => {
|
||||||
// expect(newState[keys[0]].key).toBe(keys[0]);
|
const newState = responseCacheReducer(testState, action);
|
||||||
// expect(newState[keys[0]].service).toEqual(services[0]);
|
Object.keys(newState).forEach((key) => {
|
||||||
// expect(newState[keys[0]].scopeID).toBe(resourceID);
|
expect(newState[key].timeAdded).toEqual(newTimeStamp);
|
||||||
// expect(newState[keys[0]].paginationOptions).toEqual(paginationOptions);
|
});
|
||||||
// expect(newState[keys[0]].sortOptions).toEqual(sortOptions);
|
});
|
||||||
// });
|
|
||||||
//
|
});
|
||||||
// it('should set responsePending to true', () => {
|
});
|
||||||
// const state = Object.create(null);
|
|
||||||
// const newState = responseCacheReducer(state, action);
|
|
||||||
// expect(newState[keys[0]].responsePending).toBe(true);
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// it('should remove any previous error message or resourceUUIDs for the request', () => {
|
|
||||||
// const newState = responseCacheReducer(errorState, action);
|
|
||||||
// expect(newState[keys[0]].resourceUUIDs.length).toBe(0);
|
|
||||||
// expect(newState[keys[0]].errorMessage).toBeUndefined();
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// describe('SUCCESS', () => {
|
|
||||||
// const successUUIDs = [uuids[0], uuids[2]];
|
|
||||||
// const successTimeAdded = new Date().getTime();
|
|
||||||
// const successMsToLive = 5;
|
|
||||||
// const action = new ResponseCacheSuccessAction(keys[0], successUUIDs, successTimeAdded, successMsToLive);
|
|
||||||
//
|
|
||||||
// it('should perform the action without affecting the previous state', () => {
|
|
||||||
// //testState has already been frozen above
|
|
||||||
// responseCacheReducer(testState, action);
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// it('should add the response to the cached request', () => {
|
|
||||||
// const newState = responseCacheReducer(testState, action);
|
|
||||||
// expect(newState[keys[0]].resourceUUIDs).toBe(successUUIDs);
|
|
||||||
// expect(newState[keys[0]].timeAdded).toBe(successTimeAdded);
|
|
||||||
// expect(newState[keys[0]].msToLive).toBe(successMsToLive);
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// it('should set responsePending to false', () => {
|
|
||||||
// const newState = responseCacheReducer(testState, action);
|
|
||||||
// expect(newState[keys[0]].responsePending).toBe(false);
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// it('should remove any previous error message for the request', () => {
|
|
||||||
// const newState = responseCacheReducer(errorState, action);
|
|
||||||
// expect(newState[keys[0]].errorMessage).toBeUndefined();
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// describe('ERROR', () => {
|
|
||||||
// const errorMsg = 'errorMsg';
|
|
||||||
// const action = new ResponseCacheErrorAction(keys[0], errorMsg);
|
|
||||||
//
|
|
||||||
// it('should perform the action without affecting the previous state', () => {
|
|
||||||
// //testState has already been frozen above
|
|
||||||
// responseCacheReducer(testState, action);
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// it('should set an error message for the request', () => {
|
|
||||||
// const newState = responseCacheReducer(errorState, action);
|
|
||||||
// expect(newState[keys[0]].errorMessage).toBe(errorMsg);
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// it('should set responsePending to false', () => {
|
|
||||||
// const newState = responseCacheReducer(testState, action);
|
|
||||||
// expect(newState[keys[0]].responsePending).toBe(false);
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// describe('REMOVE', () => {
|
|
||||||
// it('should perform the action without affecting the previous state', () => {
|
|
||||||
// const action = new ResponseCacheRemoveAction(keys[0]);
|
|
||||||
// //testState has already been frozen above
|
|
||||||
// responseCacheReducer(testState, action);
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// it('should remove the specified request from the cache', () => {
|
|
||||||
// const action = new ResponseCacheRemoveAction(keys[0]);
|
|
||||||
// const newState = responseCacheReducer(testState, action);
|
|
||||||
// expect(testState[keys[0]]).not.toBeUndefined();
|
|
||||||
// expect(newState[keys[0]]).toBeUndefined();
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// it('shouldn't do anything when the specified key isn't cached', () => {
|
|
||||||
// const wrongKey = 'this isn't cached';
|
|
||||||
// const action = new ResponseCacheRemoveAction(wrongKey);
|
|
||||||
// const newState = responseCacheReducer(testState, action);
|
|
||||||
// expect(testState[wrongKey]).toBeUndefined();
|
|
||||||
// expect(newState).toEqual(testState);
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// describe('RESET_TIMESTAMPS', () => {
|
|
||||||
// const newTimeStamp = new Date().getTime();
|
|
||||||
// const action = new ResetResponseCacheTimestampsAction(newTimeStamp);
|
|
||||||
//
|
|
||||||
// it('should perform the action without affecting the previous state', () => {
|
|
||||||
// //testState has already been frozen above
|
|
||||||
// responseCacheReducer(testState, action);
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// it('should set the timestamp of all requests in the cache', () => {
|
|
||||||
// const newState = responseCacheReducer(testState, action);
|
|
||||||
// Object.keys(newState).forEach((key) => {
|
|
||||||
// expect(newState[key].timeAdded).toEqual(newTimeStamp);
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// });
|
|
||||||
|
222
src/app/core/cache/response-cache.service.spec.ts
vendored
222
src/app/core/cache/response-cache.service.spec.ts
vendored
@@ -1,147 +1,83 @@
|
|||||||
import { OpaqueToken } from '@angular/core';
|
|
||||||
import { Observable } from 'rxjs/Observable';
|
|
||||||
import { Store } from '@ngrx/store';
|
import { Store } from '@ngrx/store';
|
||||||
|
|
||||||
import { ResponseCacheService } from './response-cache.service';
|
import { ResponseCacheService } from './response-cache.service';
|
||||||
import { ResponseCacheState, ResponseCacheEntry } from './response-cache.reducer';
|
import { Observable } from 'rxjs/Observable';
|
||||||
|
import { CoreState } from '../core.reducers';
|
||||||
|
import { RestResponse } from './response-cache.models';
|
||||||
|
import { ResponseCacheEntry } from './response-cache.reducer';
|
||||||
|
|
||||||
// describe('ResponseCacheService', () => {
|
describe('ResponseCacheService', () => {
|
||||||
// let service: ResponseCacheService;
|
let service: ResponseCacheService;
|
||||||
// let store: Store<ResponseCacheState>;
|
let store: Store<CoreState>;
|
||||||
//
|
|
||||||
// const keys = ['125c17f89046283c5f0640722aac9feb', 'a06c3006a41caec5d635af099b0c780c'];
|
const keys = ['125c17f89046283c5f0640722aac9feb', 'a06c3006a41caec5d635af099b0c780c'];
|
||||||
// const serviceTokens = [new OpaqueToken('service1'), new OpaqueToken('service2')];
|
const timestamp = new Date().getTime();
|
||||||
// const resourceID = '9978';
|
const validCacheEntry = (key) => {
|
||||||
// const paginationOptions = { 'resultsPerPage': 10, 'currentPage': 1 };
|
return {
|
||||||
// const sortOptions = { 'field': 'id', 'direction': 0 };
|
key: key,
|
||||||
// const timestamp = new Date().getTime();
|
response: new RestResponse(true, '200'),
|
||||||
// const validCacheEntry = (key) => {
|
timeAdded: timestamp,
|
||||||
// return {
|
msToLive: 24 * 60 * 60 * 1000 // a day
|
||||||
// key: key,
|
}
|
||||||
// timeAdded: timestamp,
|
};
|
||||||
// msToLive: 24 * 60 * 60 * 1000 // a day
|
const invalidCacheEntry = (key) => {
|
||||||
// }
|
return {
|
||||||
// };
|
key: key,
|
||||||
// const invalidCacheEntry = (key) => {
|
response: new RestResponse(true, '200'),
|
||||||
// return {
|
timeAdded: 0,
|
||||||
// key: key,
|
msToLive: 0
|
||||||
// timeAdded: 0,
|
}
|
||||||
// msToLive: 0
|
};
|
||||||
// }
|
|
||||||
// };
|
beforeEach(() => {
|
||||||
//
|
store = new Store<CoreState>(undefined, undefined, undefined);
|
||||||
// beforeEach(() => {
|
spyOn(store, 'dispatch');
|
||||||
// store = new Store<ResponseCacheState>(undefined, undefined, undefined);
|
service = new ResponseCacheService(store);
|
||||||
// spyOn(store, 'dispatch');
|
spyOn(Date.prototype, 'getTime').and.callFake(() => {
|
||||||
// service = new ResponseCacheService(store);
|
return timestamp;
|
||||||
// spyOn(window, 'Date').and.returnValue({ getTime: () => timestamp });
|
});
|
||||||
// });
|
});
|
||||||
//
|
|
||||||
// describe('findAll', () => {
|
describe('get', () => {
|
||||||
// beforeEach(() => {
|
it('should return an observable of the cached request with the specified key', () => {
|
||||||
// spyOn(service, 'get').and.callFake((key) => Observable.of({key: key}));
|
spyOn(store, 'select').and.callFake((...args: any[]) => {
|
||||||
// });
|
return Observable.of(validCacheEntry(keys[1]));
|
||||||
// describe('if the key isn't cached', () => {
|
});
|
||||||
// beforeEach(() => {
|
|
||||||
// spyOn(service, 'has').and.returnValue(false);
|
let testObj: ResponseCacheEntry;
|
||||||
// });
|
service.get(keys[1]).first().subscribe((entry) => {
|
||||||
// it('should dispatch a FIND_ALL action with the key, service, scopeID, paginationOptions and sortOptions', () => {
|
console.log(entry);
|
||||||
// service.findAll(keys[0], serviceTokens[0], resourceID, paginationOptions, sortOptions);
|
testObj = entry;
|
||||||
// expect(store.dispatch).toHaveBeenCalledWith(new ResponseCacheFindAllAction(keys[0], serviceTokens[0], resourceID, paginationOptions, sortOptions))
|
});
|
||||||
// });
|
expect(testObj.key).toEqual(keys[1]);
|
||||||
// it('should return an observable of the newly cached request with the specified key', () => {
|
});
|
||||||
// let result: ResponseCacheEntry;
|
|
||||||
// service.findAll(keys[0], serviceTokens[0], resourceID, paginationOptions, sortOptions).take(1).subscribe(entry => result = entry);
|
it('should not return a cached request that has exceeded its time to live', () => {
|
||||||
// expect(result.key).toEqual(keys[0]);
|
spyOn(store, 'select').and.callFake((...args: any[]) => {
|
||||||
// });
|
return Observable.of(invalidCacheEntry(keys[1]));
|
||||||
// });
|
});
|
||||||
// describe('if the key is already cached', () => {
|
|
||||||
// beforeEach(() => {
|
let getObsHasFired = false;
|
||||||
// spyOn(service, 'has').and.returnValue(true);
|
const subscription = service.get(keys[1]).subscribe((entry) => getObsHasFired = true);
|
||||||
// });
|
expect(getObsHasFired).toBe(false);
|
||||||
// it('shouldn't dispatch anything', () => {
|
subscription.unsubscribe();
|
||||||
// service.findAll(keys[0], serviceTokens[0], resourceID, paginationOptions, sortOptions);
|
});
|
||||||
// expect(store.dispatch).not.toHaveBeenCalled();
|
});
|
||||||
// });
|
|
||||||
// it('should return an observable of the existing cached request with the specified key', () => {
|
describe('has', () => {
|
||||||
// let result: ResponseCacheEntry;
|
it('should return true if the request with the supplied key is cached and still valid', () => {
|
||||||
// service.findAll(keys[0], serviceTokens[0], resourceID, paginationOptions, sortOptions).take(1).subscribe(entry => result = entry);
|
spyOn(store, 'select').and.returnValue(Observable.of(validCacheEntry(keys[1])));
|
||||||
// expect(result.key).toEqual(keys[0]);
|
expect(service.has(keys[1])).toBe(true);
|
||||||
// });
|
});
|
||||||
// });
|
|
||||||
// });
|
it('should return false if the request with the supplied key isn\'t cached', () => {
|
||||||
//
|
spyOn(store, 'select').and.returnValue(Observable.of(undefined));
|
||||||
// describe('findById', () => {
|
expect(service.has(keys[1])).toBe(false);
|
||||||
// beforeEach(() => {
|
});
|
||||||
// spyOn(service, 'get').and.callFake((key) => Observable.of({key: key}));
|
|
||||||
// });
|
it('should return false if the request with the supplied key is cached but has exceeded its time to live', () => {
|
||||||
// describe('if the key isn't cached', () => {
|
spyOn(store, 'select').and.returnValue(Observable.of(invalidCacheEntry(keys[1])));
|
||||||
// beforeEach(() => {
|
expect(service.has(keys[1])).toBe(false);
|
||||||
// spyOn(service, 'has').and.returnValue(false);
|
});
|
||||||
// });
|
});
|
||||||
// it('should dispatch a FIND_BY_ID action with the key, service, and resourceID', () => {
|
});
|
||||||
// service.findById(keys[0], serviceTokens[0], resourceID);
|
|
||||||
// expect(store.dispatch).toHaveBeenCalledWith(new ResponseCacheFindByIDAction(keys[0], serviceTokens[0], resourceID))
|
|
||||||
// });
|
|
||||||
// it('should return an observable of the newly cached request with the specified key', () => {
|
|
||||||
// let result: ResponseCacheEntry;
|
|
||||||
// service.findById(keys[0], serviceTokens[0], resourceID).take(1).subscribe(entry => result = entry);
|
|
||||||
// expect(result.key).toEqual(keys[0]);
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
// describe('if the key is already cached', () => {
|
|
||||||
// beforeEach(() => {
|
|
||||||
// spyOn(service, 'has').and.returnValue(true);
|
|
||||||
// });
|
|
||||||
// it('shouldn't dispatch anything', () => {
|
|
||||||
// service.findById(keys[0], serviceTokens[0], resourceID);
|
|
||||||
// expect(store.dispatch).not.toHaveBeenCalled();
|
|
||||||
// });
|
|
||||||
// it('should return an observable of the existing cached request with the specified key', () => {
|
|
||||||
// let result: ResponseCacheEntry;
|
|
||||||
// service.findById(keys[0], serviceTokens[0], resourceID).take(1).subscribe(entry => result = entry);
|
|
||||||
// expect(result.key).toEqual(keys[0]);
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// describe('get', () => {
|
|
||||||
// it('should return an observable of the cached request with the specified key', () => {
|
|
||||||
// spyOn(store, 'select').and.callFake((...args:Array<any>) => {
|
|
||||||
// return Observable.of(validCacheEntry(args[args.length - 1]));
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// let testObj: ResponseCacheEntry;
|
|
||||||
// service.get(keys[1]).take(1).subscribe(entry => testObj = entry);
|
|
||||||
// expect(testObj.key).toEqual(keys[1]);
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// it('should not return a cached request that has exceeded its time to live', () => {
|
|
||||||
// spyOn(store, 'select').and.callFake((...args:Array<any>) => {
|
|
||||||
// return Observable.of(invalidCacheEntry(args[args.length - 1]));
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// let getObsHasFired = false;
|
|
||||||
// const subscription = service.get(keys[1]).subscribe(entry => getObsHasFired = true);
|
|
||||||
// expect(getObsHasFired).toBe(false);
|
|
||||||
// subscription.unsubscribe();
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// describe('has', () => {
|
|
||||||
// it('should return true if the request with the supplied key is cached and still valid', () => {
|
|
||||||
// spyOn(store, 'select').and.returnValue(Observable.of(validCacheEntry(keys[1])));
|
|
||||||
// expect(service.has(keys[1])).toBe(true);
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// it('should return false if the request with the supplied key isn't cached', () => {
|
|
||||||
// spyOn(store, 'select').and.returnValue(Observable.of(undefined));
|
|
||||||
// expect(service.has(keys[1])).toBe(false);
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// it('should return false if the request with the supplied key is cached but has exceeded its time to live', () => {
|
|
||||||
// spyOn(store, 'select').and.returnValue(Observable.of(invalidCacheEntry(keys[1])));
|
|
||||||
// expect(service.has(keys[1])).toBe(false);
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
|
3
src/app/core/cache/response-cache.service.ts
vendored
3
src/app/core/cache/response-cache.service.ts
vendored
@@ -4,7 +4,7 @@ import { MemoizedSelector, Store } from '@ngrx/store';
|
|||||||
import { Observable } from 'rxjs/Observable';
|
import { Observable } from 'rxjs/Observable';
|
||||||
|
|
||||||
import { ResponseCacheEntry } from './response-cache.reducer';
|
import { ResponseCacheEntry } from './response-cache.reducer';
|
||||||
import { hasNoValue, hasValue } from '../../shared/empty.util';
|
import { hasNoValue } from '../../shared/empty.util';
|
||||||
import { ResponseCacheRemoveAction, ResponseCacheAddAction } from './response-cache.actions';
|
import { ResponseCacheRemoveAction, ResponseCacheAddAction } from './response-cache.actions';
|
||||||
import { RestResponse } from './response-cache.models';
|
import { RestResponse } from './response-cache.models';
|
||||||
import { CoreState } from '../core.reducers';
|
import { CoreState } from '../core.reducers';
|
||||||
@@ -25,7 +25,6 @@ export class ResponseCacheService {
|
|||||||
|
|
||||||
add(key: string, response: RestResponse, msToLive: number): Observable<ResponseCacheEntry> {
|
add(key: string, response: RestResponse, msToLive: number): Observable<ResponseCacheEntry> {
|
||||||
if (!this.has(key)) {
|
if (!this.has(key)) {
|
||||||
// this.store.dispatch(new ResponseCacheFindAllAction(key, service, scopeID, paginationOptions, sortOptions));
|
|
||||||
this.store.dispatch(new ResponseCacheAddAction(key, response, new Date().getTime(), msToLive));
|
this.store.dispatch(new ResponseCacheAddAction(key, response, new Date().getTime(), msToLive));
|
||||||
}
|
}
|
||||||
return this.get(key);
|
return this.get(key);
|
||||||
|
@@ -1,11 +1,11 @@
|
|||||||
|
|
||||||
import { ObjectCacheEffects } from './data/object-cache.effects';
|
import { ObjectCacheEffects } from './cache/object-cache.effects';
|
||||||
import { RequestCacheEffects } from './data/request-cache.effects';
|
import { ResponseCacheEffects } from './cache/response-cache.effects';
|
||||||
import { UUIDIndexEffects } from './index/uuid-index.effects';
|
import { UUIDIndexEffects } from './index/uuid-index.effects';
|
||||||
import { RequestEffects } from './data/request.effects';
|
import { RequestEffects } from './data/request.effects';
|
||||||
|
|
||||||
export const coreEffects = [
|
export const coreEffects = [
|
||||||
RequestCacheEffects,
|
ResponseCacheEffects,
|
||||||
RequestEffects,
|
RequestEffects,
|
||||||
ObjectCacheEffects,
|
ObjectCacheEffects,
|
||||||
UUIDIndexEffects,
|
UUIDIndexEffects,
|
||||||
|
80
src/app/core/data/request.reducer.spec.ts
Normal file
80
src/app/core/data/request.reducer.spec.ts
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
import * as deepFreeze from 'deep-freeze';
|
||||||
|
|
||||||
|
import { requestReducer, RequestState } from './request.reducer';
|
||||||
|
import {
|
||||||
|
RequestCompleteAction, RequestConfigureAction, RequestExecuteAction
|
||||||
|
} from './request.actions';
|
||||||
|
import { RestRequest } from './request.models';
|
||||||
|
|
||||||
|
class NullAction extends RequestCompleteAction {
|
||||||
|
type = null;
|
||||||
|
payload = null;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('requestReducer', () => {
|
||||||
|
const link1 = 'https://dspace7.4science.it/dspace-spring-rest/api/core/items/567a639f-f5ff-4126-807c-b7d0910808c8';
|
||||||
|
const link2 = 'https://dspace7.4science.it/dspace-spring-rest/api/core/items/1911e8a4-6939-490c-b58b-a5d70f8d91fb';
|
||||||
|
const testState: RequestState = {
|
||||||
|
[link1]: {
|
||||||
|
request: new RestRequest(link1),
|
||||||
|
requestPending: false,
|
||||||
|
responsePending: false,
|
||||||
|
completed: false
|
||||||
|
}
|
||||||
|
};
|
||||||
|
deepFreeze(testState);
|
||||||
|
|
||||||
|
it('should return the current state when no valid actions have been made', () => {
|
||||||
|
const action = new NullAction();
|
||||||
|
const newState = requestReducer(testState, action);
|
||||||
|
|
||||||
|
expect(newState).toEqual(testState);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should start with an empty state', () => {
|
||||||
|
const action = new NullAction();
|
||||||
|
const initialState = requestReducer(undefined, action);
|
||||||
|
|
||||||
|
expect(initialState).toEqual(Object.create(null));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should add the new RestRequest and set \'requestPending\' to true, \'responsePending\' to false and \'completed\' to false for the given RestRequest in the state, in response to a CONFIGURE action', () => {
|
||||||
|
const state = testState;
|
||||||
|
const request = new RestRequest(link2);
|
||||||
|
|
||||||
|
const action = new RequestConfigureAction(request);
|
||||||
|
const newState = requestReducer(state, action);
|
||||||
|
|
||||||
|
expect(newState[link2].request.href).toEqual(link2);
|
||||||
|
expect(newState[link2].requestPending).toEqual(true);
|
||||||
|
expect(newState[link2].responsePending).toEqual(false);
|
||||||
|
expect(newState[link2].completed).toEqual(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set \'requestPending\' to false, \'responsePending\' to true and leave \'completed\' untouched for the given RestRequest in the state, in response to an EXECUTE action', () => {
|
||||||
|
const state = testState;
|
||||||
|
|
||||||
|
const action = new RequestExecuteAction(link1);
|
||||||
|
const newState = requestReducer(state, action);
|
||||||
|
|
||||||
|
expect(newState[link1].request.href).toEqual(link1);
|
||||||
|
expect(newState[link1].requestPending).toEqual(false);
|
||||||
|
expect(newState[link1].responsePending).toEqual(true);
|
||||||
|
expect(newState[link1].completed).toEqual(state[link1].completed);
|
||||||
|
});
|
||||||
|
it('should leave \'requestPending\' untouched, set \'responsePending\' to false and \'completed\' to true for the given RestRequest in the state, in response to a COMPLETE action', () => {
|
||||||
|
const state = testState;
|
||||||
|
|
||||||
|
const action = new RequestCompleteAction(link1);
|
||||||
|
const newState = requestReducer(state, action);
|
||||||
|
|
||||||
|
expect(newState[link1].request.href).toEqual(link1);
|
||||||
|
expect(newState[link1].requestPending).toEqual(state[link1].requestPending);
|
||||||
|
expect(newState[link1].responsePending).toEqual(false);
|
||||||
|
expect(newState[link1].completed).toEqual(true);
|
||||||
|
});
|
||||||
|
});
|
56
src/app/core/index/uuid-index.reducer.spec.ts
Normal file
56
src/app/core/index/uuid-index.reducer.spec.ts
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
import * as deepFreeze from 'deep-freeze';
|
||||||
|
|
||||||
|
import { uuidIndexReducer, UUIDIndexState } from './uuid-index.reducer';
|
||||||
|
import { AddToUUIDIndexAction, RemoveHrefFromUUIDIndexAction } from './uuid-index.actions';
|
||||||
|
|
||||||
|
class NullAction extends AddToUUIDIndexAction {
|
||||||
|
type = null;
|
||||||
|
payload = null;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super(null, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('requestReducer', () => {
|
||||||
|
const link1 = 'https://dspace7.4science.it/dspace-spring-rest/api/core/items/567a639f-f5ff-4126-807c-b7d0910808c8';
|
||||||
|
const link2 = 'https://dspace7.4science.it/dspace-spring-rest/api/core/items/1911e8a4-6939-490c-b58b-a5d70f8d91fb';
|
||||||
|
const uuid1 = '567a639f-f5ff-4126-807c-b7d0910808c8';
|
||||||
|
const uuid2 = '1911e8a4-6939-490c-b58b-a5d70f8d91fb';
|
||||||
|
const testState: UUIDIndexState = {
|
||||||
|
[uuid1]: link1
|
||||||
|
};
|
||||||
|
deepFreeze(testState);
|
||||||
|
|
||||||
|
it('should return the current state when no valid actions have been made', () => {
|
||||||
|
const action = new NullAction();
|
||||||
|
const newState = uuidIndexReducer(testState, action);
|
||||||
|
|
||||||
|
expect(newState).toEqual(testState);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should start with an empty state', () => {
|
||||||
|
const action = new NullAction();
|
||||||
|
const initialState = uuidIndexReducer(undefined, action);
|
||||||
|
|
||||||
|
expect(initialState).toEqual(Object.create(null));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should add the \'uuid\' with the corresponding \'href\' to the state, in response to an ADD action', () => {
|
||||||
|
const state = testState;
|
||||||
|
|
||||||
|
const action = new AddToUUIDIndexAction(uuid2, link2);
|
||||||
|
const newState = uuidIndexReducer(state, action);
|
||||||
|
|
||||||
|
expect(newState[uuid2]).toEqual(link2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should remove the given \'href\' from its corresponding \'uuid\' in the state, in response to a REMOVE_HREF action', () => {
|
||||||
|
const state = testState;
|
||||||
|
|
||||||
|
const action = new RemoveHrefFromUUIDIndexAction(link1);
|
||||||
|
const newState = uuidIndexReducer(state, action);
|
||||||
|
|
||||||
|
expect(newState[uuid1]).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
151
src/app/object-list/object-list.component.spec.ts
Normal file
151
src/app/object-list/object-list.component.spec.ts
Normal file
@@ -0,0 +1,151 @@
|
|||||||
|
import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
|
||||||
|
import { ObjectListComponent } from './object-list.component';
|
||||||
|
import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
|
import { By } from '@angular/platform-browser';
|
||||||
|
|
||||||
|
describe('ObjectListComponent', () => {
|
||||||
|
let comp: ObjectListComponent;
|
||||||
|
let fixture: ComponentFixture<ObjectListComponent>;
|
||||||
|
const testEvent = {test: 'test'}
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [],
|
||||||
|
declarations: [ObjectListComponent],
|
||||||
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
|
}).overrideComponent(ObjectListComponent, {
|
||||||
|
set: { changeDetection: ChangeDetectionStrategy.Default }
|
||||||
|
}).compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(ObjectListComponent);
|
||||||
|
comp = fixture.componentInstance; // SearchPageComponent test instance
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when the pageChange output on the pagination is triggered', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
spyOn(comp, 'onPageChange');
|
||||||
|
const paginationEl = fixture.debugElement.query(By.css('ds-pagination'));
|
||||||
|
paginationEl.triggerEventHandler('pageChange', testEvent);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call onPageChange on the component', () => {
|
||||||
|
expect(comp.onPageChange).toHaveBeenCalledWith(testEvent);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when the pageSizeChange output on the pagination is triggered', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
spyOn(comp, 'onPageSizeChange');
|
||||||
|
const paginationEl = fixture.debugElement.query(By.css('ds-pagination'));
|
||||||
|
paginationEl.triggerEventHandler('pageSizeChange', testEvent);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call onPageSizeChange on the component', () => {
|
||||||
|
expect(comp.onPageSizeChange).toHaveBeenCalledWith(testEvent);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when the sortDirectionChange output on the pagination is triggered', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
spyOn(comp, 'onSortDirectionChange');
|
||||||
|
const paginationEl = fixture.debugElement.query(By.css('ds-pagination'));
|
||||||
|
paginationEl.triggerEventHandler('sortDirectionChange', testEvent);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call onSortDirectionChange on the component', () => {
|
||||||
|
expect(comp.onSortDirectionChange).toHaveBeenCalledWith(testEvent);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when the sortFieldChange output on the pagination is triggered', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
spyOn(comp, 'onSortFieldChange');
|
||||||
|
const paginationEl = fixture.debugElement.query(By.css('ds-pagination'));
|
||||||
|
paginationEl.triggerEventHandler('sortFieldChange', testEvent);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call onSortFieldChange on the component', () => {
|
||||||
|
expect(comp.onSortFieldChange).toHaveBeenCalledWith(testEvent);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when the paginationChange output on the pagination is triggered', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
spyOn(comp, 'onPaginationChange');
|
||||||
|
const paginationEl = fixture.debugElement.query(By.css('ds-pagination'));
|
||||||
|
paginationEl.triggerEventHandler('paginationChange', testEvent);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call onPaginationChange on the component', () => {
|
||||||
|
expect(comp.onPaginationChange).toHaveBeenCalledWith(testEvent);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when onPageChange is triggered with an event', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
spyOn(comp.pageChange, 'emit');
|
||||||
|
comp.onPageChange(testEvent);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should emit the value from the pageChange EventEmitter', fakeAsync(() => {
|
||||||
|
tick(1);
|
||||||
|
expect(comp.pageChange.emit).toHaveBeenCalled();
|
||||||
|
expect(comp.pageChange.emit).toHaveBeenCalledWith(testEvent);
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when onPageSizeChange is triggered with an event', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
spyOn(comp.pageSizeChange, 'emit');
|
||||||
|
comp.onPageSizeChange(testEvent);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should emit the value from the pageSizeChange EventEmitter', fakeAsync(() => {
|
||||||
|
tick(1);
|
||||||
|
expect(comp.pageSizeChange.emit).toHaveBeenCalled();
|
||||||
|
expect(comp.pageSizeChange.emit).toHaveBeenCalledWith(testEvent);
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when onSortDirectionChange is triggered with an event', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
spyOn(comp.sortDirectionChange, 'emit');
|
||||||
|
comp.onSortDirectionChange(testEvent);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should emit the value from the sortDirectionChange EventEmitter', fakeAsync(() => {
|
||||||
|
tick(1);
|
||||||
|
expect(comp.sortDirectionChange.emit).toHaveBeenCalled();
|
||||||
|
expect(comp.sortDirectionChange.emit).toHaveBeenCalledWith(testEvent);
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when onSortFieldChange is triggered with an event', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
spyOn(comp.sortFieldChange, 'emit');
|
||||||
|
comp.onSortFieldChange(testEvent);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should emit the value from the sortFieldChange EventEmitter', fakeAsync(() => {
|
||||||
|
tick(1);
|
||||||
|
expect(comp.sortFieldChange.emit).toHaveBeenCalled();
|
||||||
|
expect(comp.sortFieldChange.emit).toHaveBeenCalledWith(testEvent);
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('when onPaginationChange is triggered with an event', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
spyOn(comp.paginationChange, 'emit');
|
||||||
|
comp.onPaginationChange(testEvent);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should emit the value from the paginationChange EventEmitter', fakeAsync(() => {
|
||||||
|
tick(1);
|
||||||
|
expect(comp.paginationChange.emit).toHaveBeenCalled();
|
||||||
|
expect(comp.paginationChange.emit).toHaveBeenCalledWith(testEvent);
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
});
|
@@ -8,7 +8,7 @@
|
|||||||
(pageChange)="onPageChange($event)"
|
(pageChange)="onPageChange($event)"
|
||||||
(pageSizeChange)="onPageSizeChange($event)"
|
(pageSizeChange)="onPageSizeChange($event)"
|
||||||
(sortDirectionChange)="onSortDirectionChange($event)"
|
(sortDirectionChange)="onSortDirectionChange($event)"
|
||||||
(sortFieldChange)="onSortDirectionChange($event)"
|
(sortFieldChange)="onSortFieldChange($event)"
|
||||||
(paginationChange)="onPaginationChange($event)">
|
(paginationChange)="onPaginationChange($event)">
|
||||||
<ul *ngIf="objects?.hasSucceeded"> <!--class="list-unstyled"-->
|
<ul *ngIf="objects?.hasSucceeded"> <!--class="list-unstyled"-->
|
||||||
<li *ngFor="let object of objects?.payload">
|
<li *ngFor="let object of objects?.payload">
|
||||||
|
Reference in New Issue
Block a user