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

67611: Test cases

parent 1402dd91
No related branches found
No related tags found
No related merge requests found
......@@ -23,6 +23,7 @@ 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';
import { ExternalSourceEntry } from '../shared/external-source-entry.model';
describe('ItemDataService', () => {
let scheduler: TestScheduler;
......@@ -202,4 +203,24 @@ describe('ItemDataService', () => {
});
});
describe('importExternalSourceEntry', () => {
let result;
const externalSourceEntry = Object.assign(new ExternalSourceEntry(), {
display: 'John, Doe',
value: 'John, Doe',
self: 'http://test-rest.com/server/api/integration/externalSources/orcidV2/entryValues/0000-0003-4851-8004'
});
beforeEach(() => {
service = initTestService();
spyOn(requestService, 'configure');
result = service.importExternalSourceEntry(externalSourceEntry, 'collection-id');
});
it('should configure a POST request', () => {
result.subscribe(() => expect(requestService.configure).toHaveBeenCalledWith(jasmine.any(PostRequest), undefined));
});
});
});
......@@ -10,11 +10,14 @@ import { SearchResult } from '../../shared/search/search-result.model';
import { Item } from '../shared/item.model';
import { skip, take } from 'rxjs/operators';
import { ExternalSource } from '../shared/external-source.model';
import { RequestService } from './request.service';
import { of as observableOf } from 'rxjs';
describe('LookupRelationService', () => {
fdescribe('LookupRelationService', () => {
let service: LookupRelationService;
let externalSourceService: ExternalSourceService;
let searchService: SearchService;
let requestService: RequestService;
const totalExternal = 8;
const optionsWithQuery = new PaginatedSearchOptions({ query: 'test-query' });
......@@ -35,15 +38,18 @@ describe('LookupRelationService', () => {
name: 'orcidV2',
hierarchical: false
});
const searchServiceEndpoint = 'http://test-rest.com/server/api/core/search';
function init() {
externalSourceService = jasmine.createSpyObj('externalSourceService', {
getExternalSourceEntries: createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo({ elementsPerPage: 1, totalElements: totalExternal, totalPages: totalExternal, currentPage: 1 }), [{}]))
});
searchService = jasmine.createSpyObj('searchService', {
search: createSuccessfulRemoteDataObject$(createPaginatedList(localResults))
search: createSuccessfulRemoteDataObject$(createPaginatedList(localResults)),
getEndpoint: observableOf(searchServiceEndpoint)
});
service = new LookupRelationService(externalSourceService, searchService);
requestService = jasmine.createSpyObj('requestService', ['removeByHrefSubstring']);
service = new LookupRelationService(externalSourceService, searchService, requestService);
}
beforeEach(() => {
......@@ -113,4 +119,14 @@ describe('LookupRelationService', () => {
});
});
});
describe('removeLocalResultsCache', () => {
beforeEach(() => {
service.removeLocalResultsCache();
});
it('should call requestService\'s removeByHrefSubstring with the search endpoint', () => {
expect(requestService.removeByHrefSubstring).toHaveBeenCalledWith(searchServiceEndpoint);
});
});
});
......@@ -3,7 +3,7 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { VarDirective } from '../../../../../utils/var.directive';
import { TranslateModule } from '@ngx-translate/core';
import { RouterTestingModule } from '@angular/router/testing';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { EventEmitter, NO_ERRORS_SCHEMA } from '@angular/core';
import { PaginatedSearchOptions } from '../../../../../search/paginated-search-options.model';
import { SearchConfigurationService } from '../../../../../../core/shared/search/search-configuration.service';
import { of as observableOf } from 'rxjs/internal/observable/of';
......@@ -18,12 +18,20 @@ import { ExternalSource } from '../../../../../../core/shared/external-source.mo
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { By } from '@angular/platform-browser';
import { ExternalSourceEntry } from '../../../../../../core/shared/external-source-entry.model';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { SelectableListService } from '../../../../../object-list/selectable-list/selectable-list.service';
import { Item } from '../../../../../../core/shared/item.model';
import { Collection } from '../../../../../../core/shared/collection.model';
import { RelationshipOptions } from '../../../models/relationship-options.model';
import { ExternalSourceEntryImportModalComponent } from './external-source-entry-import-modal/external-source-entry-import-modal.component';
describe('DsDynamicLookupRelationExternalSourceTabComponent', () => {
fdescribe('DsDynamicLookupRelationExternalSourceTabComponent', () => {
let component: DsDynamicLookupRelationExternalSourceTabComponent;
let fixture: ComponentFixture<DsDynamicLookupRelationExternalSourceTabComponent>;
let pSearchOptions;
let externalSourceService;
let selectableListService;
let modalService;
const externalSource = {
id: 'orcidV2',
......@@ -68,6 +76,10 @@ describe('DsDynamicLookupRelationExternalSourceTabComponent', () => {
}
})
] as ExternalSourceEntry[];
const item = Object.assign(new Item(), { id: 'submission-item' });
const collection = Object.assign(new Collection(), { id: 'submission-collection' });
const relationship = Object.assign(new RelationshipOptions(), { relationshipType: 'isAuthorOfPublication' });
const label = 'Author';
function init() {
pSearchOptions = new PaginatedSearchOptions({
......@@ -76,20 +88,22 @@ describe('DsDynamicLookupRelationExternalSourceTabComponent', () => {
externalSourceService = jasmine.createSpyObj('externalSourceService', {
getExternalSourceEntries: createSuccessfulRemoteDataObject$(createPaginatedList(externalEntries))
});
selectableListService = jasmine.createSpyObj('selectableListService', ['selectSingle']);
}
beforeEach(async(() => {
init();
TestBed.configureTestingModule({
declarations: [DsDynamicLookupRelationExternalSourceTabComponent, VarDirective],
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([]), BrowserAnimationsModule],
imports: [TranslateModule.forRoot(), RouterTestingModule.withRoutes([]), NgbModule.forRoot(), BrowserAnimationsModule],
providers: [
{
provide: SearchConfigurationService, useValue: {
paginatedSearchOptions: observableOf(pSearchOptions)
}
},
{ provide: ExternalSourceService, useValue: externalSourceService }
{ provide: ExternalSourceService, useValue: externalSourceService },
{ provide: SelectableListService, useValue: selectableListService }
],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
......@@ -99,13 +113,18 @@ describe('DsDynamicLookupRelationExternalSourceTabComponent', () => {
fixture = TestBed.createComponent(DsDynamicLookupRelationExternalSourceTabComponent);
component = fixture.componentInstance;
component.externalSource = externalSource;
component.item = item;
component.collection = collection;
component.relationship = relationship;
component.label = label;
modalService = (component as any).modalService;
fixture.detectChanges();
});
describe('when the external entries finished loading successfully', () => {
it('should display a ds-viewable-collection component', () => {
const collection = fixture.debugElement.query(By.css('ds-viewable-collection'));
expect(collection).toBeDefined();
const viewableCollection = fixture.debugElement.query(By.css('ds-viewable-collection'));
expect(viewableCollection).toBeDefined();
});
});
......@@ -116,8 +135,8 @@ describe('DsDynamicLookupRelationExternalSourceTabComponent', () => {
});
it('should not display a ds-viewable-collection component', () => {
const collection = fixture.debugElement.query(By.css('ds-viewable-collection'));
expect(collection).toBeNull();
const viewableCollection = fixture.debugElement.query(By.css('ds-viewable-collection'));
expect(viewableCollection).toBeNull();
});
it('should display a ds-loading component', () => {
......@@ -133,8 +152,8 @@ describe('DsDynamicLookupRelationExternalSourceTabComponent', () => {
});
it('should not display a ds-viewable-collection component', () => {
const collection = fixture.debugElement.query(By.css('ds-viewable-collection'));
expect(collection).toBeNull();
const viewableCollection = fixture.debugElement.query(By.css('ds-viewable-collection'));
expect(viewableCollection).toBeNull();
});
it('should display a ds-error component', () => {
......@@ -150,8 +169,8 @@ describe('DsDynamicLookupRelationExternalSourceTabComponent', () => {
});
it('should not display a ds-viewable-collection component', () => {
const collection = fixture.debugElement.query(By.css('ds-viewable-collection'));
expect(collection).toBeNull();
const viewableCollection = fixture.debugElement.query(By.css('ds-viewable-collection'));
expect(viewableCollection).toBeNull();
});
it('should display a message the list is empty', () => {
......@@ -159,4 +178,15 @@ describe('DsDynamicLookupRelationExternalSourceTabComponent', () => {
expect(empty).not.toBeNull();
});
});
describe('import', () => {
beforeEach(() => {
spyOn(modalService, 'open').and.returnValue(Object.assign({ componentInstance: Object.assign({ importedObject: new EventEmitter<any>() }) }));
component.import(externalEntries[0]);
});
it('should open a new ExternalSourceEntryImportModalComponent', () => {
expect(modalService.open).toHaveBeenCalledWith(ExternalSourceEntryImportModalComponent, jasmine.any(Object))
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment