mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-08 02:24:11 +00:00
fixed some tests
This commit is contained in:
@@ -96,8 +96,8 @@ describe('SearchFacetFilterComponent', () => {
|
||||
link = comp.getSearchLink();
|
||||
});
|
||||
|
||||
it('should return the value of the uiSearchRoute variable in the filter service', () => {
|
||||
expect(link).toEqual(filterService.uiSearchRoute);
|
||||
it('should return the value of the searchLink variable in the filter service', () => {
|
||||
expect(link).toEqual(filterService.searchLink);
|
||||
});
|
||||
});
|
||||
|
||||
|
@@ -46,7 +46,7 @@ describe('SearchFilterService', () => {
|
||||
};
|
||||
|
||||
const searchServiceStub: any = {
|
||||
searchLink: '/search'
|
||||
uiSearchRoute: '/search'
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -199,7 +199,7 @@ describe('SearchFilterService', () => {
|
||||
});
|
||||
|
||||
it('should return the value of uiSearchRoute in the search service', () => {
|
||||
expect(link).toEqual(searchServiceStub.searchLink);
|
||||
expect(link).toEqual(searchServiceStub.uiSearchRoute);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -8,6 +8,12 @@ import { SearchService } from './search.service';
|
||||
import { ItemDataService } from './../../core/data/item-data.service';
|
||||
import { ViewMode } from '../../+search-page/search-options.model';
|
||||
import { RouteService } from '../../shared/route.service';
|
||||
import { GLOBAL_CONFIG } from '../../../config';
|
||||
import { RemoteDataBuildService } from '../../core/cache/builders/remote-data-build.service';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { RequestService } from '../../core/data/request.service';
|
||||
import { ResponseCacheService } from '../../core/cache/response-cache.service';
|
||||
import { ActivatedRouteStub } from '../../shared/testing/active-router-stub';
|
||||
|
||||
@Component({ template: '' })
|
||||
class DummyComponent { }
|
||||
@@ -29,6 +35,11 @@ describe('SearchService', () => {
|
||||
providers: [
|
||||
{ provide: ItemDataService, useValue: {} },
|
||||
{ provide: RouteService, useValue: {} },
|
||||
{ provide: ResponseCacheService, useValue: {} },
|
||||
{ provide: RequestService, useValue: {} },
|
||||
{ provide: ActivatedRoute, useValue: new ActivatedRouteStub() },
|
||||
{ provide: RemoteDataBuildService, useValue: {} },
|
||||
{ provide: GLOBAL_CONFIG, useValue: {} },
|
||||
SearchService
|
||||
],
|
||||
});
|
||||
|
@@ -6,12 +6,10 @@ import { ViewMode } from '../../+search-page/search-options.model';
|
||||
import { GLOBAL_CONFIG } from '../../../config';
|
||||
import { GlobalConfig } from '../../../config/global-config.interface';
|
||||
import { RemoteDataBuildService } from '../../core/cache/builders/remote-data-build.service';
|
||||
import { NormalizedDSpaceObject } from '../../core/cache/models/normalized-dspace-object.model';
|
||||
import { SortOptions } from '../../core/cache/models/sort-options.model';
|
||||
import { SearchSuccessResponse } from '../../core/cache/response-cache.models';
|
||||
import { ResponseCacheEntry } from '../../core/cache/response-cache.reducer';
|
||||
import { ResponseCacheService } from '../../core/cache/response-cache.service';
|
||||
import { ItemDataService } from '../../core/data/item-data.service';
|
||||
import { PaginatedList } from '../../core/data/paginated-list';
|
||||
import { ResponseParsingService } from '../../core/data/parsing.service';
|
||||
import { RemoteData } from '../../core/data/remote-data';
|
||||
@@ -125,11 +123,10 @@ export class SearchService extends HALEndpointService implements OnDestroy {
|
||||
args.push(`sort=${searchOptions.sort.field},${searchOptions.sort.direction}`);
|
||||
}
|
||||
if (isNotEmpty(searchOptions.pagination)) {
|
||||
args.push(`page=${searchOptions.pagination.currentPage}`);
|
||||
args.push(`page=${searchOptions.pagination.currentPage - 1}`);
|
||||
args.push(`size=${searchOptions.pagination.pageSize}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (isNotEmpty(args)) {
|
||||
url = new URLCombiner(url, `?${args.join('&')}`).toString();
|
||||
}
|
||||
@@ -233,8 +230,8 @@ export class SearchService extends HALEndpointService implements OnDestroy {
|
||||
payload.push({
|
||||
value: value,
|
||||
count: Math.floor(Math.random() * 20) + 20 * (totalFilters - i), // make sure first results have the highest (random) count
|
||||
search: decodeURI(this.router.url) + (this.router.url.includes('?') ? '&' : '?') + filterConfig.paramName + '=' + value
|
||||
});
|
||||
search: (decodeURI(this.router.url) + (this.router.url.includes('?') ? '&' : '?') + filterConfig.paramName + '=' + value)}
|
||||
);
|
||||
}
|
||||
}
|
||||
const requestPending = false;
|
||||
|
42
src/app/core/cache/object-cache.service.spec.ts
vendored
42
src/app/core/cache/object-cache.service.spec.ts
vendored
@@ -2,22 +2,10 @@ import { Store } from '@ngrx/store';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
|
||||
import { ObjectCacheService } from './object-cache.service';
|
||||
import { CacheableObject } from './object-cache.reducer';
|
||||
import { AddToObjectCacheAction, RemoveFromObjectCacheAction } from './object-cache.actions';
|
||||
import { CoreState } from '../core.reducers';
|
||||
import { ResourceType } from '../shared/resource-type';
|
||||
|
||||
class TestClass implements CacheableObject {
|
||||
constructor(
|
||||
public self: string,
|
||||
public foo: string,
|
||||
public type = ResourceType.Item
|
||||
) { }
|
||||
|
||||
test(): string {
|
||||
return this.foo + this.self;
|
||||
}
|
||||
}
|
||||
import { NormalizedItem } from './models/normalized-item.model';
|
||||
|
||||
describe('ObjectCacheService', () => {
|
||||
let service: ObjectCacheService;
|
||||
@@ -28,7 +16,7 @@ describe('ObjectCacheService', () => {
|
||||
const msToLive = 900000;
|
||||
const objectToCache = {
|
||||
self: selfLink,
|
||||
foo: 'bar'
|
||||
type: ResourceType.Item
|
||||
};
|
||||
const cacheEntry = {
|
||||
data: objectToCache,
|
||||
@@ -65,13 +53,13 @@ describe('ObjectCacheService', () => {
|
||||
it('should return an observable of the cached object with the specified self link and type', () => {
|
||||
spyOn(store, 'select').and.returnValue(Observable.of(cacheEntry));
|
||||
|
||||
let testObj: any;
|
||||
// due to the implementation of spyOn above, this subscribe will be synchronous
|
||||
service.getBySelfLink(selfLink).take(1).subscribe((o) => testObj = o);
|
||||
expect(testObj.self).toBe(selfLink);
|
||||
expect(testObj.foo).toBe('bar');
|
||||
service.getBySelfLink(selfLink).take(1).subscribe((o) => {
|
||||
expect(o.self).toBe(selfLink);
|
||||
// this only works if testObj is an instance of TestClass
|
||||
expect(testObj.test()).toBe('bar' + selfLink);
|
||||
expect(o instanceof NormalizedItem).toBeTruthy();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should not return a cached object that has exceeded its time to live', () => {
|
||||
@@ -86,16 +74,14 @@ describe('ObjectCacheService', () => {
|
||||
|
||||
describe('getList', () => {
|
||||
it('should return an observable of the array of cached objects with the specified self link and type', () => {
|
||||
spyOn(service, 'getBySelfLink').and.returnValue(Observable.of(new TestClass(selfLink, 'bar')));
|
||||
const item = new NormalizedItem();
|
||||
item.self = selfLink;
|
||||
spyOn(service, 'getBySelfLink').and.returnValue(Observable.of(item));
|
||||
|
||||
let testObjs: any[];
|
||||
service.getList([selfLink, selfLink]).take(1).subscribe((arr) => testObjs = arr);
|
||||
expect(testObjs[0].self).toBe(selfLink);
|
||||
expect(testObjs[0].foo).toBe('bar');
|
||||
expect(testObjs[0].test()).toBe('bar' + selfLink);
|
||||
expect(testObjs[1].self).toBe(selfLink);
|
||||
expect(testObjs[1].foo).toBe('bar');
|
||||
expect(testObjs[1].test()).toBe('bar' + selfLink);
|
||||
service.getList([selfLink, selfLink]).take(1).subscribe((arr) => {
|
||||
expect(arr[0].self).toBe(selfLink);
|
||||
expect(arr[0] instanceof NormalizedItem).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
@@ -126,7 +126,7 @@ describe('ComColDataService', () => {
|
||||
it('should fetch the scope Community from the cache', () => {
|
||||
scheduler.schedule(() => service.getScopedEndpoint(scopeID).subscribe());
|
||||
scheduler.flush();
|
||||
expect(objectCache.getByUUID).toHaveBeenCalledWith(scopeID, NormalizedCommunity);
|
||||
expect(objectCache.getByUUID).toHaveBeenCalledWith(scopeID);
|
||||
});
|
||||
|
||||
it('should return the endpoint to fetch resources within the given scope', () => {
|
||||
|
@@ -271,7 +271,7 @@ describe('Pagination component', () => {
|
||||
|
||||
changePage(testFixture, 3);
|
||||
tick();
|
||||
expect(routerStub.navigate).toHaveBeenCalledWith([], { queryParams: { pageId: 'test', page: 3, pageSize: 10, sortDirection: 0, sortField: 'name' } });
|
||||
expect(routerStub.navigate).toHaveBeenCalledWith([], { queryParams: { pageId: 'test', page: 3, pageSize: 10, sortDirection: 'ASC', sortField: 'dc.title' } });
|
||||
|
||||
}));
|
||||
|
||||
@@ -282,7 +282,7 @@ describe('Pagination component', () => {
|
||||
|
||||
changePageSize(testFixture, '20');
|
||||
tick();
|
||||
expect(routerStub.navigate).toHaveBeenCalledWith([], { queryParams: { pageId: 'test', page: 1, pageSize: 20, sortDirection: 0, sortField: 'name' } });
|
||||
expect(routerStub.navigate).toHaveBeenCalledWith([], { queryParams: { pageId: 'test', page: 1, pageSize: 20, sortDirection: 'ASC', sortField: 'dc.title' } });
|
||||
}));
|
||||
|
||||
it('should set correct values', fakeAsync(() => {
|
||||
|
@@ -11,6 +11,12 @@ import { ItemDataService } from './../../core/data/item-data.service';
|
||||
import { ViewModeSwitchComponent } from './view-mode-switch.component';
|
||||
import { ViewMode } from '../../+search-page/search-options.model';
|
||||
import { RouteService } from '../route.service';
|
||||
import { ResponseCacheService } from '../../core/cache/response-cache.service';
|
||||
import { RequestService } from '../../core/data/request.service';
|
||||
import { RemoteDataBuildService } from '../../core/cache/builders/remote-data-build.service';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { GLOBAL_CONFIG } from '../../../config';
|
||||
import { ActivatedRouteStub } from '../testing/active-router-stub';
|
||||
|
||||
@Component({ template: '' })
|
||||
class DummyComponent { }
|
||||
@@ -21,7 +27,7 @@ describe('ViewModeSwitchComponent', () => {
|
||||
let searchService: SearchService;
|
||||
let listButton: HTMLElement;
|
||||
let gridButton: HTMLElement;
|
||||
|
||||
let route = new ActivatedRouteStub();
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
@@ -42,6 +48,11 @@ describe('ViewModeSwitchComponent', () => {
|
||||
providers: [
|
||||
{ provide: ItemDataService, useValue: {} },
|
||||
{ provide: RouteService, useValue: {} },
|
||||
{ provide: ResponseCacheService, useValue: {} },
|
||||
{ provide: RequestService, useValue: {} },
|
||||
{ provide: ActivatedRoute, useValue: route },
|
||||
{ provide: RemoteDataBuildService, useValue: {} },
|
||||
{ provide: GLOBAL_CONFIG, useValue: {} },
|
||||
SearchService
|
||||
],
|
||||
}).compileComponents();
|
||||
@@ -59,6 +70,7 @@ describe('ViewModeSwitchComponent', () => {
|
||||
|
||||
it('should set list button as active when on list mode', fakeAsync(() => {
|
||||
searchService.setViewMode(ViewMode.List);
|
||||
route = new ActivatedRouteStub([{view: ViewMode.List}])
|
||||
tick();
|
||||
fixture.detectChanges();
|
||||
expect(comp.currentMode).toBe(ViewMode.List);
|
||||
@@ -68,6 +80,7 @@ describe('ViewModeSwitchComponent', () => {
|
||||
|
||||
it('should set grid button as active when on grid mode', fakeAsync(() => {
|
||||
searchService.setViewMode(ViewMode.Grid);
|
||||
route = new ActivatedRouteStub([{view: ViewMode.Grid}])
|
||||
tick();
|
||||
fixture.detectChanges();
|
||||
expect(comp.currentMode).toBe(ViewMode.Grid);
|
||||
|
Reference in New Issue
Block a user