mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-08 02:24:11 +00:00
68405: test fixes; tbc
This commit is contained in:

committed by
Art Lowel

parent
f17e204712
commit
a52650e62a
@@ -1,42 +1,43 @@
|
|||||||
|
import { CommonModule } from '@angular/common';
|
||||||
|
import { EventEmitter } from '@angular/core';
|
||||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
import { FormsModule } from '@angular/forms';
|
||||||
|
import { By } from '@angular/platform-browser';
|
||||||
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
import { RouterTestingModule } from '@angular/router/testing';
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
||||||
import { CommonModule } from '@angular/common';
|
|
||||||
import { ItemCollectionMapperComponent } from './item-collection-mapper.component';
|
|
||||||
import { ActivatedRoute, Router } from '@angular/router';
|
|
||||||
import { NotificationsService } from '../../../shared/notifications/notifications.service';
|
|
||||||
import { ItemDataService } from '../../../core/data/item-data.service';
|
|
||||||
import { RemoteData } from '../../../core/data/remote-data';
|
|
||||||
import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model';
|
|
||||||
import { SortDirection, SortOptions } from '../../../core/cache/models/sort-options.model';
|
|
||||||
import { RouterStub } from '../../../shared/testing/router-stub';
|
|
||||||
import { ActivatedRouteStub } from '../../../shared/testing/active-router-stub';
|
|
||||||
import { EventEmitter } from '@angular/core';
|
|
||||||
import { SearchServiceStub } from '../../../shared/testing/search-service-stub';
|
|
||||||
import { PaginatedList } from '../../../core/data/paginated-list';
|
|
||||||
import { PageInfo } from '../../../core/shared/page-info.model';
|
|
||||||
import { FormsModule } from '@angular/forms';
|
|
||||||
import { TranslateModule, TranslateService } from '@ngx-translate/core';
|
import { TranslateModule, TranslateService } from '@ngx-translate/core';
|
||||||
import { NotificationsServiceStub } from '../../../shared/testing/notifications-service-stub';
|
|
||||||
import { HostWindowService } from '../../../shared/host-window.service';
|
|
||||||
import { HostWindowServiceStub } from '../../../shared/testing/host-window-service-stub';
|
|
||||||
import { By } from '@angular/platform-browser';
|
|
||||||
import { Item } from '../../../core/shared/item.model';
|
|
||||||
import { ObjectSelectService } from '../../../shared/object-select/object-select.service';
|
|
||||||
import { ObjectSelectServiceStub } from '../../../shared/testing/object-select-service-stub';
|
|
||||||
import { of } from 'rxjs/internal/observable/of';
|
import { of } from 'rxjs/internal/observable/of';
|
||||||
|
import { SortDirection, SortOptions } from '../../../core/cache/models/sort-options.model';
|
||||||
import { RestResponse } from '../../../core/cache/response.models';
|
import { RestResponse } from '../../../core/cache/response.models';
|
||||||
import { CollectionSelectComponent } from '../../../shared/object-select/collection-select/collection-select.component';
|
import { CollectionDataService } from '../../../core/data/collection-data.service';
|
||||||
import { PaginationComponent } from '../../../shared/pagination/pagination.component';
|
import { ItemDataService } from '../../../core/data/item-data.service';
|
||||||
import { EnumKeysPipe } from '../../../shared/utils/enum-keys-pipe';
|
import { PaginatedList } from '../../../core/data/paginated-list';
|
||||||
import { VarDirective } from '../../../shared/utils/var.directive';
|
import { RemoteData } from '../../../core/data/remote-data';
|
||||||
import { SearchFormComponent } from '../../../shared/search-form/search-form.component';
|
|
||||||
import { Collection } from '../../../core/shared/collection.model';
|
import { Collection } from '../../../core/shared/collection.model';
|
||||||
import { ErrorComponent } from '../../../shared/error/error.component';
|
import { Item } from '../../../core/shared/item.model';
|
||||||
import { LoadingComponent } from '../../../shared/loading/loading.component';
|
import { PageInfo } from '../../../core/shared/page-info.model';
|
||||||
import { SearchConfigurationService } from '../../../core/shared/search/search-configuration.service';
|
import { SearchConfigurationService } from '../../../core/shared/search/search-configuration.service';
|
||||||
import { SearchService } from '../../../core/shared/search/search.service';
|
import { SearchService } from '../../../core/shared/search/search.service';
|
||||||
|
import { ErrorComponent } from '../../../shared/error/error.component';
|
||||||
|
import { HostWindowService } from '../../../shared/host-window.service';
|
||||||
|
import { LoadingComponent } from '../../../shared/loading/loading.component';
|
||||||
|
import { NotificationsService } from '../../../shared/notifications/notifications.service';
|
||||||
|
import { CollectionSelectComponent } from '../../../shared/object-select/collection-select/collection-select.component';
|
||||||
|
import { ObjectSelectService } from '../../../shared/object-select/object-select.service';
|
||||||
|
import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model';
|
||||||
|
import { PaginationComponent } from '../../../shared/pagination/pagination.component';
|
||||||
|
import { SearchFormComponent } from '../../../shared/search-form/search-form.component';
|
||||||
import { PaginatedSearchOptions } from '../../../shared/search/paginated-search-options.model';
|
import { PaginatedSearchOptions } from '../../../shared/search/paginated-search-options.model';
|
||||||
|
import { ActivatedRouteStub } from '../../../shared/testing/active-router-stub';
|
||||||
|
import { HostWindowServiceStub } from '../../../shared/testing/host-window-service-stub';
|
||||||
|
import { NotificationsServiceStub } from '../../../shared/testing/notifications-service-stub';
|
||||||
|
import { ObjectSelectServiceStub } from '../../../shared/testing/object-select-service-stub';
|
||||||
|
import { RouterStub } from '../../../shared/testing/router-stub';
|
||||||
|
import { SearchServiceStub } from '../../../shared/testing/search-service-stub';
|
||||||
|
import { EnumKeysPipe } from '../../../shared/utils/enum-keys-pipe';
|
||||||
|
import { VarDirective } from '../../../shared/utils/var.directive';
|
||||||
|
import { ItemCollectionMapperComponent } from './item-collection-mapper.component';
|
||||||
|
|
||||||
describe('ItemCollectionMapperComponent', () => {
|
describe('ItemCollectionMapperComponent', () => {
|
||||||
let comp: ItemCollectionMapperComponent;
|
let comp: ItemCollectionMapperComponent;
|
||||||
@@ -109,7 +110,8 @@ describe('ItemCollectionMapperComponent', () => {
|
|||||||
{ provide: SearchService, useValue: searchServiceStub },
|
{ provide: SearchService, useValue: searchServiceStub },
|
||||||
{ provide: ObjectSelectService, useValue: new ObjectSelectServiceStub() },
|
{ provide: ObjectSelectService, useValue: new ObjectSelectServiceStub() },
|
||||||
{ provide: TranslateService, useValue: translateServiceStub },
|
{ provide: TranslateService, useValue: translateServiceStub },
|
||||||
{ provide: HostWindowService, useValue: new HostWindowServiceStub(0) }
|
{ provide: HostWindowService, useValue: new HostWindowServiceStub(0) },
|
||||||
|
{ provide: CollectionDataService, useValue: {} }
|
||||||
]
|
]
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
}));
|
}));
|
||||||
|
@@ -1,20 +1,38 @@
|
|||||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
import { HttpClient } from '@angular/common/http';
|
||||||
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
|
||||||
import { MockTranslateLoader } from '../../../../shared/mocks/mock-translate-loader';
|
|
||||||
import { GenericItemPageFieldComponent } from '../../field-components/specific-field/generic/generic-item-page-field.component';
|
|
||||||
import { TruncatePipe } from '../../../../shared/utils/truncate.pipe';
|
|
||||||
import { ItemDataService } from '../../../../core/data/item-data.service';
|
|
||||||
import { TruncatableService } from '../../../../shared/truncatable/truncatable.service';
|
|
||||||
import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
|
import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
import { Item } from '../../../../core/shared/item.model';
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
import { PaginatedList } from '../../../../core/data/paginated-list';
|
|
||||||
import { PageInfo } from '../../../../core/shared/page-info.model';
|
|
||||||
import { By } from '@angular/platform-browser';
|
import { By } from '@angular/platform-browser';
|
||||||
|
import { Store } from '@ngrx/store';
|
||||||
|
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
||||||
|
import { Observable } from 'rxjs/internal/Observable';
|
||||||
|
import { NormalizedObjectBuildService } from '../../../../core/cache/builders/normalized-object-build.service';
|
||||||
|
import { RemoteDataBuildService } from '../../../../core/cache/builders/remote-data-build.service';
|
||||||
|
import { ObjectCacheService } from '../../../../core/cache/object-cache.service';
|
||||||
|
import { BundleDataService } from '../../../../core/data/bundle-data.service';
|
||||||
|
import { CommunityDataService } from '../../../../core/data/community-data.service';
|
||||||
|
import { DefaultChangeAnalyzer } from '../../../../core/data/default-change-analyzer.service';
|
||||||
|
import { DSOChangeAnalyzer } from '../../../../core/data/dso-change-analyzer.service';
|
||||||
|
import { ItemDataService } from '../../../../core/data/item-data.service';
|
||||||
|
import { PaginatedList } from '../../../../core/data/paginated-list';
|
||||||
|
import { RelationshipService } from '../../../../core/data/relationship.service';
|
||||||
|
import { RemoteData } from '../../../../core/data/remote-data';
|
||||||
|
import { FindListOptions } from '../../../../core/data/request.models';
|
||||||
|
import { Bitstream } from '../../../../core/shared/bitstream.model';
|
||||||
|
import { Bundle } from '../../../../core/shared/bundle.model';
|
||||||
|
import { HALEndpointService } from '../../../../core/shared/hal-endpoint.service';
|
||||||
|
import { Item } from '../../../../core/shared/item.model';
|
||||||
|
import { MetadataMap } from '../../../../core/shared/metadata.models';
|
||||||
|
import { PageInfo } from '../../../../core/shared/page-info.model';
|
||||||
|
import { UUIDService } from '../../../../core/shared/uuid.service';
|
||||||
|
import { MockTranslateLoader } from '../../../../shared/mocks/mock-translate-loader';
|
||||||
|
import { NotificationsService } from '../../../../shared/notifications/notifications.service';
|
||||||
|
import { createSuccessfulRemoteDataObject$ } from '../../../../shared/testing/utils';
|
||||||
|
import { TruncatableService } from '../../../../shared/truncatable/truncatable.service';
|
||||||
|
import { FollowLinkConfig } from '../../../../shared/utils/follow-link-config.model';
|
||||||
|
import { TruncatePipe } from '../../../../shared/utils/truncate.pipe';
|
||||||
|
import { GenericItemPageFieldComponent } from '../../field-components/specific-field/generic/generic-item-page-field.component';
|
||||||
import { createRelationshipsObservable } from '../shared/item.component.spec';
|
import { createRelationshipsObservable } from '../shared/item.component.spec';
|
||||||
import { PublicationComponent } from './publication.component';
|
import { PublicationComponent } from './publication.component';
|
||||||
import { MetadataMap } from '../../../../core/shared/metadata.models';
|
|
||||||
import { createSuccessfulRemoteDataObject$ } from '../../../../shared/testing/utils';
|
|
||||||
import { RelationshipService } from '../../../../core/data/relationship.service';
|
|
||||||
|
|
||||||
const mockItem: Item = Object.assign(new Item(), {
|
const mockItem: Item = Object.assign(new Item(), {
|
||||||
bundles: createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), [])),
|
bundles: createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), [])),
|
||||||
@@ -22,11 +40,20 @@ const mockItem: Item = Object.assign(new Item(), {
|
|||||||
relationships: createRelationshipsObservable()
|
relationships: createRelationshipsObservable()
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('PublicationComponent', () => {
|
fdescribe('PublicationComponent', () => {
|
||||||
let comp: PublicationComponent;
|
let comp: PublicationComponent;
|
||||||
let fixture: ComponentFixture<PublicationComponent>;
|
let fixture: ComponentFixture<PublicationComponent>;
|
||||||
|
|
||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
|
const mockBundleDataService = {
|
||||||
|
findAllByItem: undefined,
|
||||||
|
findByItemAndName(item: Item, bundleName: string, ...linksToFollow: Array<FollowLinkConfig<Bundle>>): Observable<RemoteData<Bitstream>> {
|
||||||
|
return createSuccessfulRemoteDataObject$(new Bitstream());
|
||||||
|
},
|
||||||
|
findAllByBundle(bundle: Bundle, options?: FindListOptions, ...linksToFollow: Array<FollowLinkConfig<Bitstream>>): Observable<RemoteData<PaginatedList<Bitstream>>> {
|
||||||
|
return createSuccessfulRemoteDataObject$(new PaginatedList(new PageInfo(), [new Bitstream()]));
|
||||||
|
}
|
||||||
|
};
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [TranslateModule.forRoot({
|
imports: [TranslateModule.forRoot({
|
||||||
loader: {
|
loader: {
|
||||||
@@ -36,14 +63,26 @@ describe('PublicationComponent', () => {
|
|||||||
})],
|
})],
|
||||||
declarations: [PublicationComponent, GenericItemPageFieldComponent, TruncatePipe],
|
declarations: [PublicationComponent, GenericItemPageFieldComponent, TruncatePipe],
|
||||||
providers: [
|
providers: [
|
||||||
{provide: ItemDataService, useValue: {}},
|
{ provide: ItemDataService, useValue: {} },
|
||||||
{provide: TruncatableService, useValue: {}},
|
{ provide: TruncatableService, useValue: {} },
|
||||||
{provide: RelationshipService, useValue: {}}
|
{ provide: RelationshipService, useValue: {} },
|
||||||
|
{ provide: ObjectCacheService, useValue: {} },
|
||||||
|
{ provide: UUIDService, useValue: {} },
|
||||||
|
{ provide: Store, useValue: {} },
|
||||||
|
{ provide: RemoteDataBuildService, useValue: {} },
|
||||||
|
{ provide: NormalizedObjectBuildService, useValue: {} },
|
||||||
|
{ provide: CommunityDataService, useValue: {} },
|
||||||
|
{ provide: HALEndpointService, useValue: {} },
|
||||||
|
{ provide: NotificationsService, useValue: {} },
|
||||||
|
{ provide: HttpClient, useValue: {} },
|
||||||
|
{ provide: DSOChangeAnalyzer, useValue: {} },
|
||||||
|
{ provide: DefaultChangeAnalyzer, useValue: {} },
|
||||||
|
{ provide: BundleDataService, useValue: mockBundleDataService },
|
||||||
],
|
],
|
||||||
|
|
||||||
schemas: [NO_ERRORS_SCHEMA]
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
}).overrideComponent(PublicationComponent, {
|
}).overrideComponent(PublicationComponent, {
|
||||||
set: {changeDetection: ChangeDetectionStrategy.Default}
|
set: { changeDetection: ChangeDetectionStrategy.Default }
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import { LookupGuard } from './lookup-guard';
|
|
||||||
import { of as observableOf } from 'rxjs';
|
import { of as observableOf } from 'rxjs';
|
||||||
import { IdentifierType } from '../core/data/request.models';
|
import { IdentifierType } from '../core/data/request.models';
|
||||||
|
import { LookupGuard } from './lookup-guard';
|
||||||
|
|
||||||
describe('LookupGuard', () => {
|
describe('LookupGuard', () => {
|
||||||
let dsoService: any;
|
let dsoService: any;
|
||||||
@@ -8,7 +8,7 @@ describe('LookupGuard', () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
dsoService = {
|
dsoService = {
|
||||||
findById: jasmine.createSpy('findById').and.returnValue(observableOf({ hasFailed: false,
|
findByIdAndIDType: jasmine.createSpy('findByIdAndIDType').and.returnValue(observableOf({ hasFailed: false,
|
||||||
hasSucceeded: true }))
|
hasSucceeded: true }))
|
||||||
};
|
};
|
||||||
guard = new LookupGuard(dsoService);
|
guard = new LookupGuard(dsoService);
|
||||||
@@ -22,7 +22,7 @@ describe('LookupGuard', () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
guard.canActivate(scopedRoute as any, undefined);
|
guard.canActivate(scopedRoute as any, undefined);
|
||||||
expect(dsoService.findById).toHaveBeenCalledWith('123456789/1234', IdentifierType.HANDLE)
|
expect(dsoService.findByIdAndIDType).toHaveBeenCalledWith('123456789/1234', IdentifierType.HANDLE)
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call findByIdAndIDType with handle params', () => {
|
it('should call findByIdAndIDType with handle params', () => {
|
||||||
@@ -33,7 +33,7 @@ describe('LookupGuard', () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
guard.canActivate(scopedRoute as any, undefined);
|
guard.canActivate(scopedRoute as any, undefined);
|
||||||
expect(dsoService.findById).toHaveBeenCalledWith('123456789%2F1234', IdentifierType.HANDLE)
|
expect(dsoService.findByIdAndIDType).toHaveBeenCalledWith('123456789%2F1234', IdentifierType.HANDLE)
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call findByIdAndIDType with UUID params', () => {
|
it('should call findByIdAndIDType with UUID params', () => {
|
||||||
@@ -44,7 +44,7 @@ describe('LookupGuard', () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
guard.canActivate(scopedRoute as any, undefined);
|
guard.canActivate(scopedRoute as any, undefined);
|
||||||
expect(dsoService.findById).toHaveBeenCalledWith('34cfed7c-f597-49ef-9cbe-ea351f0023c2', IdentifierType.UUID)
|
expect(dsoService.findByIdAndIDType).toHaveBeenCalledWith('34cfed7c-f597-49ef-9cbe-ea351f0023c2', IdentifierType.UUID)
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -3,15 +3,16 @@ import { async, TestBed } from '@angular/core/testing';
|
|||||||
import { Store, StoreModule } from '@ngrx/store';
|
import { Store, StoreModule } from '@ngrx/store';
|
||||||
|
|
||||||
import { GlobalConfig } from '../../../config/global-config.interface';
|
import { GlobalConfig } from '../../../config/global-config.interface';
|
||||||
import { AuthStatusResponse } from '../cache/response.models';
|
|
||||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
|
||||||
import { AuthStatus } from './models/auth-status.model';
|
|
||||||
import { AuthResponseParsingService } from './auth-response-parsing.service';
|
|
||||||
import { AuthGetRequest, AuthPostRequest } from '../data/request.models';
|
|
||||||
import { MockStore } from '../../shared/testing/mock-store';
|
import { MockStore } from '../../shared/testing/mock-store';
|
||||||
|
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||||
|
import { AuthStatusResponse } from '../cache/response.models';
|
||||||
|
import { AuthGetRequest, AuthPostRequest } from '../data/request.models';
|
||||||
|
import { AuthResponseParsingService } from './auth-response-parsing.service';
|
||||||
|
import { AuthStatus } from './models/auth-status.model';
|
||||||
|
|
||||||
describe('AuthResponseParsingService', () => {
|
describe('AuthResponseParsingService', () => {
|
||||||
let service: AuthResponseParsingService;
|
let service: AuthResponseParsingService;
|
||||||
|
let linkServiceStub: any;
|
||||||
|
|
||||||
const EnvConfig: GlobalConfig = { cache: { msToLive: 1000 } } as any;
|
const EnvConfig: GlobalConfig = { cache: { msToLive: 1000 } } as any;
|
||||||
let store: any;
|
let store: any;
|
||||||
@@ -30,7 +31,10 @@ describe('AuthResponseParsingService', () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
store = TestBed.get(Store);
|
store = TestBed.get(Store);
|
||||||
objectCacheService = new ObjectCacheService(store as any);
|
linkServiceStub = jasmine.createSpyObj({
|
||||||
|
removeResolvedLinks: {}
|
||||||
|
});
|
||||||
|
objectCacheService = new ObjectCacheService(store as any, linkServiceStub);
|
||||||
service = new AuthResponseParsingService(EnvConfig, objectCacheService);
|
service = new AuthResponseParsingService(EnvConfig, objectCacheService);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -141,6 +145,7 @@ describe('AuthResponseParsingService', () => {
|
|||||||
it('should return a AuthStatusResponse if data contains a valid endpoint response', () => {
|
it('should return a AuthStatusResponse if data contains a valid endpoint response', () => {
|
||||||
const response = service.parse(validRequest2, validResponse2);
|
const response = service.parse(validRequest2, validResponse2);
|
||||||
expect(response.constructor).toBe(AuthStatusResponse);
|
expect(response.constructor).toBe(AuthStatusResponse);
|
||||||
|
expect(linkServiceStub.removeResolvedLinks).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return a AuthStatusResponse if data contains an empty 404 endpoint response', () => {
|
it('should return a AuthStatusResponse if data contains an empty 404 endpoint response', () => {
|
||||||
|
@@ -44,8 +44,8 @@ describe('BrowseService', () => {
|
|||||||
'dc.date.issued'
|
'dc.date.issued'
|
||||||
],
|
],
|
||||||
_links: {
|
_links: {
|
||||||
self: 'https://rest.api/discover/browses/dateissued',
|
self: { href: 'https://rest.api/discover/browses/dateissued' },
|
||||||
items: 'https://rest.api/discover/browses/dateissued/items'
|
items: { href: 'https://rest.api/discover/browses/dateissued/items' }
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
Object.assign(new BrowseDefinition(), {
|
Object.assign(new BrowseDefinition(), {
|
||||||
@@ -72,9 +72,9 @@ describe('BrowseService', () => {
|
|||||||
'dc.creator'
|
'dc.creator'
|
||||||
],
|
],
|
||||||
_links: {
|
_links: {
|
||||||
self: 'https://rest.api/discover/browses/author',
|
self: { href: 'https://rest.api/discover/browses/author' },
|
||||||
entries: 'https://rest.api/discover/browses/author/entries',
|
entries: { href: 'https://rest.api/discover/browses/author/entries' },
|
||||||
items: 'https://rest.api/discover/browses/author/items'
|
items: { href: 'https://rest.api/discover/browses/author/items' }
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
@@ -125,9 +125,11 @@ describe('BrowseService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return a RemoteData object containing the correct BrowseDefinition[]', () => {
|
it('should return a RemoteData object containing the correct BrowseDefinition[]', () => {
|
||||||
const expected = cold('--a-', { a: {
|
const expected = cold('--a-', {
|
||||||
payload: browseDefinitions
|
a: {
|
||||||
}});
|
payload: browseDefinitions
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
expect(service.getBrowseDefinitions()).toBeObservable(expected);
|
expect(service.getBrowseDefinitions()).toBeObservable(expected);
|
||||||
});
|
});
|
||||||
@@ -142,9 +144,11 @@ describe('BrowseService', () => {
|
|||||||
rdbService = getMockRemoteDataBuildService();
|
rdbService = getMockRemoteDataBuildService();
|
||||||
service = initTestService();
|
service = initTestService();
|
||||||
spyOn(service, 'getBrowseDefinitions').and
|
spyOn(service, 'getBrowseDefinitions').and
|
||||||
.returnValue(hot('--a-', { a: {
|
.returnValue(hot('--a-', {
|
||||||
|
a: {
|
||||||
payload: browseDefinitions
|
payload: browseDefinitions
|
||||||
}}));
|
}
|
||||||
|
}));
|
||||||
spyOn(rdbService, 'toRemoteDataObservable').and.callThrough();
|
spyOn(rdbService, 'toRemoteDataObservable').and.callThrough();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -215,9 +219,11 @@ describe('BrowseService', () => {
|
|||||||
rdbService = getMockRemoteDataBuildService();
|
rdbService = getMockRemoteDataBuildService();
|
||||||
service = initTestService();
|
service = initTestService();
|
||||||
spyOn(service, 'getBrowseDefinitions').and
|
spyOn(service, 'getBrowseDefinitions').and
|
||||||
.returnValue(hot('--a-', { a: {
|
.returnValue(hot('--a-', {
|
||||||
|
a: {
|
||||||
payload: browseDefinitions
|
payload: browseDefinitions
|
||||||
}}));
|
}
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the URL for the given metadataKey and linkPath', () => {
|
it('should return the URL for the given metadataKey and linkPath', () => {
|
||||||
@@ -288,9 +294,11 @@ describe('BrowseService', () => {
|
|||||||
rdbService = getMockRemoteDataBuildService();
|
rdbService = getMockRemoteDataBuildService();
|
||||||
service = initTestService();
|
service = initTestService();
|
||||||
spyOn(service, 'getBrowseDefinitions').and
|
spyOn(service, 'getBrowseDefinitions').and
|
||||||
.returnValue(hot('--a-', { a: {
|
.returnValue(hot('--a-', {
|
||||||
|
a: {
|
||||||
payload: browseDefinitions
|
payload: browseDefinitions
|
||||||
}}));
|
}
|
||||||
|
}));
|
||||||
spyOn(rdbService, 'toRemoteDataObservable').and.callThrough();
|
spyOn(rdbService, 'toRemoteDataObservable').and.callThrough();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -107,13 +107,6 @@ export class RemoteDataBuildService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log('RD', new RemoteData(
|
|
||||||
requestPending,
|
|
||||||
responsePending,
|
|
||||||
isSuccessful,
|
|
||||||
error,
|
|
||||||
payload
|
|
||||||
));
|
|
||||||
return new RemoteData(
|
return new RemoteData(
|
||||||
requestPending,
|
requestPending,
|
||||||
responsePending,
|
responsePending,
|
||||||
@@ -126,7 +119,6 @@ export class RemoteDataBuildService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
buildList<T extends CacheableObject>(href$: string | Observable<string>, ...linksToFollow: Array<FollowLinkConfig<T>>): Observable<RemoteData<PaginatedList<T>>> {
|
buildList<T extends CacheableObject>(href$: string | Observable<string>, ...linksToFollow: Array<FollowLinkConfig<T>>): Observable<RemoteData<PaginatedList<T>>> {
|
||||||
console.log('rdbBuildList')
|
|
||||||
if (typeof href$ === 'string') {
|
if (typeof href$ === 'string') {
|
||||||
href$ = observableOf(href$);
|
href$ = observableOf(href$);
|
||||||
}
|
}
|
||||||
@@ -135,7 +127,6 @@ export class RemoteDataBuildService {
|
|||||||
const tDomainList$ = requestEntry$.pipe(
|
const tDomainList$ = requestEntry$.pipe(
|
||||||
getResourceLinksFromResponse(),
|
getResourceLinksFromResponse(),
|
||||||
switchMap((resourceUUIDs: string[]) => {
|
switchMap((resourceUUIDs: string[]) => {
|
||||||
console.log('resourceUUIDs', resourceUUIDs)
|
|
||||||
return this.objectCache.getList(resourceUUIDs).pipe(
|
return this.objectCache.getList(resourceUUIDs).pipe(
|
||||||
map((normList: Array<NormalizedObject<T>>) => {
|
map((normList: Array<NormalizedObject<T>>) => {
|
||||||
return normList.map((normalized: NormalizedObject<T>) => {
|
return normList.map((normalized: NormalizedObject<T>) => {
|
||||||
@@ -149,7 +140,6 @@ export class RemoteDataBuildService {
|
|||||||
const pageInfo$ = requestEntry$.pipe(
|
const pageInfo$ = requestEntry$.pipe(
|
||||||
filterSuccessfulResponses(),
|
filterSuccessfulResponses(),
|
||||||
map((response: DSOSuccessResponse) => {
|
map((response: DSOSuccessResponse) => {
|
||||||
console.log('rdb pageInfo', response)
|
|
||||||
if (hasValue((response as DSOSuccessResponse).pageInfo)) {
|
if (hasValue((response as DSOSuccessResponse).pageInfo)) {
|
||||||
const resPageInfo = (response as DSOSuccessResponse).pageInfo;
|
const resPageInfo = (response as DSOSuccessResponse).pageInfo;
|
||||||
if (isNotEmpty(resPageInfo) && resPageInfo.currentPage >= 0) {
|
if (isNotEmpty(resPageInfo) && resPageInfo.currentPage >= 0) {
|
||||||
@@ -163,7 +153,6 @@ export class RemoteDataBuildService {
|
|||||||
|
|
||||||
const payload$ = observableCombineLatest(tDomainList$, pageInfo$).pipe(
|
const payload$ = observableCombineLatest(tDomainList$, pageInfo$).pipe(
|
||||||
map(([tDomainList, pageInfo]) => {
|
map(([tDomainList, pageInfo]) => {
|
||||||
console.log('rdb domainlist', tDomainList)
|
|
||||||
return new PaginatedList(pageInfo, tDomainList);
|
return new PaginatedList(pageInfo, tDomainList);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
37
src/app/core/cache/object-cache.service.spec.ts
vendored
37
src/app/core/cache/object-cache.service.spec.ts
vendored
@@ -1,26 +1,27 @@
|
|||||||
import * as ngrx from '@ngrx/store';
|
import * as ngrx from '@ngrx/store';
|
||||||
import { Store } from '@ngrx/store';
|
import { Store } from '@ngrx/store';
|
||||||
|
import { Operation } from 'fast-json-patch';
|
||||||
import { of as observableOf } from 'rxjs';
|
import { of as observableOf } from 'rxjs';
|
||||||
|
import { first } from 'rxjs/operators';
|
||||||
import { ObjectCacheService } from './object-cache.service';
|
import { CoreState } from '../core.reducers';
|
||||||
|
import { RestRequestMethod } from '../data/rest-request-method';
|
||||||
|
import { Item } from '../shared/item.model';
|
||||||
|
import { NormalizedItem } from './models/normalized-item.model';
|
||||||
import {
|
import {
|
||||||
AddPatchObjectCacheAction,
|
AddPatchObjectCacheAction,
|
||||||
AddToObjectCacheAction,
|
AddToObjectCacheAction,
|
||||||
ApplyPatchObjectCacheAction,
|
ApplyPatchObjectCacheAction,
|
||||||
RemoveFromObjectCacheAction
|
RemoveFromObjectCacheAction
|
||||||
} from './object-cache.actions';
|
} from './object-cache.actions';
|
||||||
import { CoreState } from '../core.reducers';
|
|
||||||
import { NormalizedItem } from './models/normalized-item.model';
|
|
||||||
import { first } from 'rxjs/operators';
|
|
||||||
import { Operation } from 'fast-json-patch';
|
|
||||||
import { RestRequestMethod } from '../data/rest-request-method';
|
|
||||||
import { AddToSSBAction } from './server-sync-buffer.actions';
|
|
||||||
import { Patch } from './object-cache.reducer';
|
import { Patch } from './object-cache.reducer';
|
||||||
import { Item } from '../shared/item.model';
|
|
||||||
|
import { ObjectCacheService } from './object-cache.service';
|
||||||
|
import { AddToSSBAction } from './server-sync-buffer.actions';
|
||||||
|
|
||||||
describe('ObjectCacheService', () => {
|
describe('ObjectCacheService', () => {
|
||||||
let service: ObjectCacheService;
|
let service: ObjectCacheService;
|
||||||
let store: Store<CoreState>;
|
let store: Store<CoreState>;
|
||||||
|
let linkServiceStub;
|
||||||
|
|
||||||
const selfLink = 'https://rest.api/endpoint/1698f1d3-be98-4c51-9fd8-6bfedcbd59b7';
|
const selfLink = 'https://rest.api/endpoint/1698f1d3-be98-4c51-9fd8-6bfedcbd59b7';
|
||||||
const requestUUID = '4d3a4ce8-a375-4b98-859b-39f0a014d736';
|
const requestUUID = '4d3a4ce8-a375-4b98-859b-39f0a014d736';
|
||||||
@@ -28,7 +29,10 @@ describe('ObjectCacheService', () => {
|
|||||||
const msToLive = 900000;
|
const msToLive = 900000;
|
||||||
let objectToCache = {
|
let objectToCache = {
|
||||||
self: selfLink,
|
self: selfLink,
|
||||||
type: Item.type
|
type: Item.type,
|
||||||
|
_links: {
|
||||||
|
self: { href: selfLink }
|
||||||
|
}
|
||||||
};
|
};
|
||||||
let cacheEntry;
|
let cacheEntry;
|
||||||
let invalidCacheEntry;
|
let invalidCacheEntry;
|
||||||
@@ -37,7 +41,10 @@ describe('ObjectCacheService', () => {
|
|||||||
function init() {
|
function init() {
|
||||||
objectToCache = {
|
objectToCache = {
|
||||||
self: selfLink,
|
self: selfLink,
|
||||||
type: Item.type
|
type: Item.type,
|
||||||
|
_links: {
|
||||||
|
self: { href: selfLink }
|
||||||
|
}
|
||||||
};
|
};
|
||||||
cacheEntry = {
|
cacheEntry = {
|
||||||
data: objectToCache,
|
data: objectToCache,
|
||||||
@@ -50,8 +57,11 @@ describe('ObjectCacheService', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
init();
|
init();
|
||||||
store = new Store<CoreState>(undefined, undefined, undefined);
|
store = new Store<CoreState>(undefined, undefined, undefined);
|
||||||
|
linkServiceStub = jasmine.createSpyObj({
|
||||||
|
removeResolvedLinks: {}
|
||||||
|
});
|
||||||
spyOn(store, 'dispatch');
|
spyOn(store, 'dispatch');
|
||||||
service = new ObjectCacheService(store);
|
service = new ObjectCacheService(store, linkServiceStub);
|
||||||
|
|
||||||
spyOn(Date.prototype, 'getTime').and.callFake(() => {
|
spyOn(Date.prototype, 'getTime').and.callFake(() => {
|
||||||
return timestamp;
|
return timestamp;
|
||||||
@@ -62,6 +72,7 @@ describe('ObjectCacheService', () => {
|
|||||||
it('should dispatch an ADD action with the object to add, the time to live, and the current timestamp', () => {
|
it('should dispatch an ADD action with the object to add, the time to live, and the current timestamp', () => {
|
||||||
service.add(objectToCache, msToLive, requestUUID);
|
service.add(objectToCache, msToLive, requestUUID);
|
||||||
expect(store.dispatch).toHaveBeenCalledWith(new AddToObjectCacheAction(objectToCache, timestamp, msToLive, requestUUID));
|
expect(store.dispatch).toHaveBeenCalledWith(new AddToObjectCacheAction(objectToCache, timestamp, msToLive, requestUUID));
|
||||||
|
expect(linkServiceStub.removeResolvedLinks).toHaveBeenCalledWith(objectToCache);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -127,7 +138,7 @@ describe('ObjectCacheService', () => {
|
|||||||
expect(service.hasBySelfLink(selfLink)).toBe(true);
|
expect(service.hasBySelfLink(selfLink)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return false if the object with the supplied self link isn't cached", () => {
|
it('should return false if the object with the supplied self link isn\'t cached', () => {
|
||||||
spyOnProperty(ngrx, 'select').and.callFake(() => {
|
spyOnProperty(ngrx, 'select').and.callFake(() => {
|
||||||
return () => {
|
return () => {
|
||||||
return () => observableOf(undefined);
|
return () => observableOf(undefined);
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
|
import { ErrorResponse, GenericSuccessResponse } from '../cache/response.models';
|
||||||
|
import { DSpaceRESTV2Response } from '../dspace-rest-v2/dspace-rest-v2-response.model';
|
||||||
|
import { BrowseDefinition } from '../shared/browse-definition.model';
|
||||||
import { BrowseResponseParsingService } from './browse-response-parsing.service';
|
import { BrowseResponseParsingService } from './browse-response-parsing.service';
|
||||||
import { BrowseEndpointRequest } from './request.models';
|
import { BrowseEndpointRequest } from './request.models';
|
||||||
import { GenericSuccessResponse, ErrorResponse } from '../cache/response.models';
|
|
||||||
import { BrowseDefinition } from '../shared/browse-definition.model';
|
|
||||||
import { DSpaceRESTV2Response } from '../dspace-rest-v2/dspace-rest-v2-response.model';
|
|
||||||
|
|
||||||
describe('BrowseResponseParsingService', () => {
|
describe('BrowseResponseParsingService', () => {
|
||||||
let service: BrowseResponseParsingService;
|
let service: BrowseResponseParsingService;
|
||||||
@@ -117,8 +117,8 @@ describe('BrowseResponseParsingService', () => {
|
|||||||
'dc.date.issued'
|
'dc.date.issued'
|
||||||
],
|
],
|
||||||
_links: {
|
_links: {
|
||||||
self: 'https://rest.api/discover/browses/dateissued',
|
self: { href: 'https://rest.api/discover/browses/dateissued' },
|
||||||
items: 'https://rest.api/discover/browses/dateissued/items'
|
items: { href: 'https://rest.api/discover/browses/dateissued/items' }
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
Object.assign(new BrowseDefinition(), {
|
Object.assign(new BrowseDefinition(), {
|
||||||
@@ -143,9 +143,9 @@ describe('BrowseResponseParsingService', () => {
|
|||||||
'dc.creator'
|
'dc.creator'
|
||||||
],
|
],
|
||||||
_links: {
|
_links: {
|
||||||
self: 'https://rest.api/discover/browses/author',
|
self: { href: 'https://rest.api/discover/browses/author' },
|
||||||
entries: 'https://rest.api/discover/browses/author/entries',
|
entries: { href: 'https://rest.api/discover/browses/author/entries' },
|
||||||
items: 'https://rest.api/discover/browses/author/items'
|
items: { href: 'https://rest.api/discover/browses/author/items' }
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
|
@@ -1,25 +1,25 @@
|
|||||||
|
import { HttpClient } from '@angular/common/http';
|
||||||
import { Store } from '@ngrx/store';
|
import { Store } from '@ngrx/store';
|
||||||
import { cold, getTestScheduler, hot } from 'jasmine-marbles';
|
import { cold, getTestScheduler, hot } from 'jasmine-marbles';
|
||||||
|
import { Observable, of as observableOf } from 'rxjs';
|
||||||
import { TestScheduler } from 'rxjs/testing';
|
import { TestScheduler } from 'rxjs/testing';
|
||||||
import { GlobalConfig } from '../../../config';
|
import { GlobalConfig } from '../../../config';
|
||||||
import { getMockRequestService } from '../../shared/mocks/mock-request.service';
|
import { getMockRequestService } from '../../shared/mocks/mock-request.service';
|
||||||
|
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
||||||
|
import { NormalizedObjectBuildService } from '../cache/builders/normalized-object-build.service';
|
||||||
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
|
||||||
|
import { NormalizedObject } from '../cache/models/normalized-object.model';
|
||||||
import { ObjectCacheService } from '../cache/object-cache.service';
|
import { ObjectCacheService } from '../cache/object-cache.service';
|
||||||
import { CoreState } from '../core.reducers';
|
import { CoreState } from '../core.reducers';
|
||||||
|
import { Community } from '../shared/community.model';
|
||||||
|
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||||
|
import { Item } from '../shared/item.model';
|
||||||
import { ComColDataService } from './comcol-data.service';
|
import { ComColDataService } from './comcol-data.service';
|
||||||
import { CommunityDataService } from './community-data.service';
|
import { CommunityDataService } from './community-data.service';
|
||||||
import { FindListOptions, FindByIDRequest } from './request.models';
|
|
||||||
import { RequestService } from './request.service';
|
|
||||||
import { NormalizedObject } from '../cache/models/normalized-object.model';
|
|
||||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
|
||||||
import { RequestEntry } from './request.reducer';
|
|
||||||
import {Observable, of as observableOf} from 'rxjs';
|
|
||||||
import { NotificationsService } from '../../shared/notifications/notifications.service';
|
|
||||||
import { HttpClient } from '@angular/common/http';
|
|
||||||
import { NormalizedObjectBuildService } from '../cache/builders/normalized-object-build.service';
|
|
||||||
import { DSOChangeAnalyzer } from './dso-change-analyzer.service';
|
import { DSOChangeAnalyzer } from './dso-change-analyzer.service';
|
||||||
import { Item } from '../shared/item.model';
|
import { FindByIDRequest, FindListOptions } from './request.models';
|
||||||
import { Community } from '../shared/community.model';
|
import { RequestEntry } from './request.reducer';
|
||||||
|
import { RequestService } from './request.service';
|
||||||
|
|
||||||
const LINK_NAME = 'test';
|
const LINK_NAME = 'test';
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ class TestService extends ComColDataService<any> {
|
|||||||
|
|
||||||
/* tslint:enable:max-classes-per-file */
|
/* tslint:enable:max-classes-per-file */
|
||||||
|
|
||||||
describe('ComColDataService', () => {
|
fdescribe('ComColDataService', () => {
|
||||||
let scheduler: TestScheduler;
|
let scheduler: TestScheduler;
|
||||||
let service: TestService;
|
let service: TestService;
|
||||||
let requestService: RequestService;
|
let requestService: RequestService;
|
||||||
|
@@ -14,6 +14,7 @@ import { GenericSuccessResponse, RestResponse } from '../cache/response.models';
|
|||||||
import { CoreState } from '../core.reducers';
|
import { CoreState } from '../core.reducers';
|
||||||
import { HttpOptions } from '../dspace-rest-v2/dspace-rest-v2.service';
|
import { HttpOptions } from '../dspace-rest-v2/dspace-rest-v2.service';
|
||||||
import { Collection } from '../shared/collection.model';
|
import { Collection } from '../shared/collection.model';
|
||||||
|
import { ExternalSourceEntry } from '../shared/external-source-entry.model';
|
||||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||||
import { Item } from '../shared/item.model';
|
import { Item } from '../shared/item.model';
|
||||||
import { ITEM } from '../shared/item.resource-type';
|
import { ITEM } from '../shared/item.resource-type';
|
||||||
|
@@ -69,10 +69,7 @@ describe('RelationshipTypeService', () => {
|
|||||||
/* tslint:enable:no-empty */
|
/* tslint:enable:no-empty */
|
||||||
}) as ObjectCacheService;
|
}) as ObjectCacheService;
|
||||||
|
|
||||||
itemService = jasmine.createSpyObj('itemService', {
|
itemService = undefined;
|
||||||
// findById: (uuid) => new RemoteData(false, false, true, undefined, relatedItems.find((relatedItem) => relatedItem.id === uuid)),
|
|
||||||
// findByHref: createSuccessfulRemoteDataObject$(relatedItems[0])
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
function initTestService() {
|
function initTestService() {
|
||||||
|
@@ -16,7 +16,7 @@ import { DeleteRequest } from './request.models';
|
|||||||
import { RequestEntry } from './request.reducer';
|
import { RequestEntry } from './request.reducer';
|
||||||
import { RequestService } from './request.service';
|
import { RequestService } from './request.service';
|
||||||
|
|
||||||
fdescribe('RelationshipService', () => {
|
describe('RelationshipService', () => {
|
||||||
let service: RelationshipService;
|
let service: RelationshipService;
|
||||||
let requestService: RequestService;
|
let requestService: RequestService;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user