Skip to content
Snippets Groups Projects
Commit a2fb8a31 authored by Kristof De Langhe's avatar Kristof De Langhe
Browse files

62589: Added tests for more coverage

parent 145ed346
Branches
Tags
No related merge requests found
......@@ -67,8 +67,12 @@ describe('CollectionItemMapperComponent', () => {
sort: new SortOptions('dc.title', SortDirection.ASC),
scope: mockCollection.id
}));
const url = 'http://test.url';
const urlWithParam = url + '?param=value';
const routerStub = Object.assign(new RouterStub(), {
url: 'http://test.url'
url: urlWithParam,
navigateByUrl: {},
navigate: {}
});
const searchConfigServiceStub = {
paginatedSearchOptions: mockSearchOptions
......@@ -168,4 +172,41 @@ describe('CollectionItemMapperComponent', () => {
});
});
describe('tabChange', () => {
beforeEach(() => {
spyOn(routerStub, 'navigateByUrl');
comp.tabChange({});
});
it('should navigate to the same page to remove parameters', () => {
expect(router.navigateByUrl).toHaveBeenCalledWith(url);
});
});
describe('buildQuery', () => {
const query = 'query';
const expected = `-location.coll:\"${mockCollection.id}\" AND ${query}`;
let result;
beforeEach(() => {
result = comp.buildQuery(mockCollection.id, query);
});
it('should build a solr query to exclude the provided collection', () => {
expect(result).toEqual(expected);
})
});
describe('onCancel', () => {
beforeEach(() => {
spyOn(routerStub, 'navigate');
comp.onCancel();
});
it('should navigate to the collection page', () => {
expect(router.navigate).toHaveBeenCalledWith(['/collections/', mockCollection.id]);
});
});
});
......@@ -36,6 +36,7 @@ import { PaginationComponent } from '../../../shared/pagination/pagination.compo
import { EnumKeysPipe } from '../../../shared/utils/enum-keys-pipe';
import { VarDirective } from '../../../shared/utils/var.directive';
import { SearchFormComponent } from '../../../shared/search-form/search-form.component';
import { Collection } from '../../../core/shared/collection.model';
describe('ItemCollectionMapperComponent', () => {
let comp: ItemCollectionMapperComponent;
......@@ -48,6 +49,7 @@ describe('ItemCollectionMapperComponent', () => {
let notificationsService: NotificationsService;
let itemDataService: ItemDataService;
const mockCollection = Object.assign(new Collection(), { id: 'collection1' });
const mockItem: Item = Object.assign(new Item(), {
id: '932c7d50-d85a-44cb-b9dc-b427b12877bd',
name: 'test-item'
......@@ -61,8 +63,12 @@ describe('ItemCollectionMapperComponent', () => {
}),
sort: new SortOptions('dc.title', SortDirection.ASC)
}));
const url = 'http://test.url';
const urlWithParam = url + '?param=value';
const routerStub = Object.assign(new RouterStub(), {
url: 'http://test.url'
url: urlWithParam,
navigateByUrl: {},
navigate: {}
});
const searchConfigServiceStub = {
paginatedSearchOptions: mockSearchOptions
......@@ -159,4 +165,41 @@ describe('ItemCollectionMapperComponent', () => {
});
});
describe('tabChange', () => {
beforeEach(() => {
spyOn(routerStub, 'navigateByUrl');
comp.tabChange({});
});
it('should navigate to the same page to remove parameters', () => {
expect(router.navigateByUrl).toHaveBeenCalledWith(url);
});
});
describe('buildQuery', () => {
const query = 'query';
const expected = `${query} AND -search.resourceid:${mockCollection.id}`;
let result;
beforeEach(() => {
result = comp.buildQuery([mockCollection], query);
});
it('should build a solr query to exclude the provided collection', () => {
expect(result).toEqual(expected);
})
});
describe('onCancel', () => {
beforeEach(() => {
spyOn(routerStub, 'navigate');
comp.onCancel();
});
it('should navigate to the item page', () => {
expect(router.navigate).toHaveBeenCalledWith(['/items/', mockItem.id]);
});
});
});
import { CollectionDataService } from './collection-data.service';
import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-service-stub';
import { getMockRequestService } from '../../shared/mocks/mock-request.service';
import { HALEndpointService } from '../shared/hal-endpoint.service';
import { RequestService } from './request.service';
import { ObjectCacheService } from '../cache/object-cache.service';
import { GetRequest } from './request.models';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
describe('CollectionDataService', () => {
let service: CollectionDataService;
let objectCache: ObjectCacheService;
let requestService: RequestService;
let halService: HALEndpointService;
let rdbService: RemoteDataBuildService;
const url = 'fake-collections-url';
beforeEach(() => {
objectCache = jasmine.createSpyObj('objectCache', {
remove: jasmine.createSpy('remove')
});
requestService = getMockRequestService();
halService = Object.assign(new HALEndpointServiceStub(url));
rdbService = jasmine.createSpyObj('rdbService', {
buildList: jasmine.createSpy('buildList')
});
service = new CollectionDataService(requestService, rdbService, null, null, null, objectCache, halService, null, null, null);
});
describe('getMappedItems', () => {
let result;
beforeEach(() => {
result = service.getMappedItems('collection-id');
});
it('should configure a GET request', () => {
expect(requestService.configure).toHaveBeenCalledWith(jasmine.any(GetRequest), undefined);
});
});
describe('clearMappedItemsRequests', () => {
beforeEach(() => {
service.clearMappedItemsRequests('collection-id');
});
it('should remote request cache', () => {
expect(requestService.removeByHrefSubstring).toHaveBeenCalled();
});
});
});
......@@ -7,7 +7,14 @@ import { CoreState } from '../core.reducers';
import { ItemDataService } from './item-data.service';
import { RequestService } from './request.service';
import { HALEndpointService } from '../shared/hal-endpoint.service';
import { FindAllOptions, RestRequest } from './request.models';
import {
DeleteRequest,
FindAllOptions,
GetRequest,
MappedCollectionsRequest,
PostRequest,
RestRequest
} from './request.models';
import { ObjectCacheService } from '../cache/object-cache.service';
import { Observable } from 'rxjs';
import { RestResponse } from '../cache/response.models';
......@@ -16,12 +23,13 @@ import { NormalizedObjectBuildService } from '../cache/builders/normalized-objec
import { HttpClient } from '@angular/common/http';
import { RequestEntry } from './request.reducer';
import { of as observableOf } from 'rxjs';
import { getMockRequestService } from '../../shared/mocks/mock-request.service';
describe('ItemDataService', () => {
let scheduler: TestScheduler;
let service: ItemDataService;
let bs: BrowseService;
const requestService = {
const requestService = Object.assign(getMockRequestService(), {
generateRequestId(): string {
return scopeID;
},
......@@ -32,9 +40,14 @@ describe('ItemDataService', () => {
const responseCacheEntry = new RequestEntry();
responseCacheEntry.response = new RestResponse(true, 200, 'OK');
return observableOf(responseCacheEntry);
},
removeByHrefSubstring(href: string) {
// Do nothing
}
} as RequestService;
const rdbService = {} as RemoteDataBuildService;
}) as RequestService;
const rdbService = jasmine.createSpyObj('rdbService', {
toRemoteDataObservable: observableOf({})
});
const store = {} as Store<CoreState>;
const objectCache = {} as ObjectCacheService;
......@@ -162,4 +175,32 @@ describe('ItemDataService', () => {
});
});
describe('removeMappingFromCollection', () => {
let result;
beforeEach(() => {
service = initTestService();
spyOn(requestService, 'configure');
result = service.removeMappingFromCollection('item-id', 'collection-id');
});
it('should configure a DELETE request', () => {
result.subscribe(() => expect(requestService.configure).toHaveBeenCalledWith(jasmine.any(DeleteRequest), undefined));
});
});
describe('mapToCollection', () => {
let result;
beforeEach(() => {
service = initTestService();
spyOn(requestService, 'configure');
result = service.mapToCollection('item-id', 'collection-href');
});
it('should configure a POST request', () => {
result.subscribe(() => expect(requestService.configure).toHaveBeenCalledWith(jasmine.any(PostRequest), undefined));
});
});
});
......@@ -101,4 +101,18 @@ describe('ItemSelectComponent', () => {
expect(comp.confirm.emit).toHaveBeenCalled();
});
});
describe('when cancel is clicked', () => {
let cancelButton: HTMLButtonElement;
beforeEach(() => {
cancelButton = fixture.debugElement.query(By.css('button.collection-cancel')).nativeElement;
spyOn(comp.cancel, 'emit').and.callThrough();
});
it('should emit a cancel event',() => {
cancelButton.click();
expect(comp.cancel.emit).toHaveBeenCalled();
});
});
});
......@@ -123,4 +123,18 @@ describe('ItemSelectComponent', () => {
expect(comp.confirm.emit).toHaveBeenCalled();
});
});
describe('when cancel is clicked', () => {
let cancelButton: HTMLButtonElement;
beforeEach(() => {
cancelButton = fixture.debugElement.query(By.css('button.item-cancel')).nativeElement;
spyOn(comp.cancel, 'emit').and.callThrough();
});
it('should emit a cancel event',() => {
cancelButton.click();
expect(comp.cancel.emit).toHaveBeenCalled();
});
});
});
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment