mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
[CST-5729] Finalize implementation
This commit is contained in:
@@ -11,6 +11,8 @@ import { ActivatedRoute, Router } from '@angular/router';
|
|||||||
import { getForbiddenRoute } from '../../app-routing-paths';
|
import { getForbiddenRoute } from '../../app-routing-paths';
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
|
import { SignpostingDataService } from '../../core/data/signposting-data.service';
|
||||||
|
import { ServerResponseService } from '../../core/services/server-response.service';
|
||||||
|
|
||||||
describe('BitstreamDownloadPageComponent', () => {
|
describe('BitstreamDownloadPageComponent', () => {
|
||||||
let component: BitstreamDownloadPageComponent;
|
let component: BitstreamDownloadPageComponent;
|
||||||
@@ -24,6 +26,8 @@ describe('BitstreamDownloadPageComponent', () => {
|
|||||||
let router;
|
let router;
|
||||||
|
|
||||||
let bitstream: Bitstream;
|
let bitstream: Bitstream;
|
||||||
|
let serverResponseService: jasmine.SpyObj<ServerResponseService>;
|
||||||
|
let signpostingDataService: jasmine.SpyObj<SignpostingDataService>;
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
authService = jasmine.createSpyObj('authService', {
|
authService = jasmine.createSpyObj('authService', {
|
||||||
@@ -44,8 +48,8 @@ describe('BitstreamDownloadPageComponent', () => {
|
|||||||
bitstream = Object.assign(new Bitstream(), {
|
bitstream = Object.assign(new Bitstream(), {
|
||||||
uuid: 'bitstreamUuid',
|
uuid: 'bitstreamUuid',
|
||||||
_links: {
|
_links: {
|
||||||
content: {href: 'bitstream-content-link'},
|
content: { href: 'bitstream-content-link' },
|
||||||
self: {href: 'bitstream-self-link'},
|
self: { href: 'bitstream-self-link' },
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -54,10 +58,21 @@ describe('BitstreamDownloadPageComponent', () => {
|
|||||||
bitstream: createSuccessfulRemoteDataObject(
|
bitstream: createSuccessfulRemoteDataObject(
|
||||||
bitstream
|
bitstream
|
||||||
)
|
)
|
||||||
|
}),
|
||||||
|
params: observableOf({
|
||||||
|
id: 'testid'
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
router = jasmine.createSpyObj('router', ['navigateByUrl']);
|
router = jasmine.createSpyObj('router', ['navigateByUrl']);
|
||||||
|
|
||||||
|
serverResponseService = jasmine.createSpyObj('ServerResponseService', {
|
||||||
|
setLinksetsHeader: jasmine.createSpy('setLinksetsHeader'),
|
||||||
|
});
|
||||||
|
|
||||||
|
signpostingDataService = jasmine.createSpyObj('SignpostingDataService', {
|
||||||
|
getLinksets: observableOf('test'),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function initTestbed() {
|
function initTestbed() {
|
||||||
@@ -65,12 +80,14 @@ describe('BitstreamDownloadPageComponent', () => {
|
|||||||
imports: [CommonModule, TranslateModule.forRoot()],
|
imports: [CommonModule, TranslateModule.forRoot()],
|
||||||
declarations: [BitstreamDownloadPageComponent],
|
declarations: [BitstreamDownloadPageComponent],
|
||||||
providers: [
|
providers: [
|
||||||
{provide: ActivatedRoute, useValue: activatedRoute},
|
{ provide: ActivatedRoute, useValue: activatedRoute },
|
||||||
{provide: Router, useValue: router},
|
{ provide: Router, useValue: router },
|
||||||
{provide: AuthorizationDataService, useValue: authorizationService},
|
{ provide: AuthorizationDataService, useValue: authorizationService },
|
||||||
{provide: AuthService, useValue: authService},
|
{ provide: AuthService, useValue: authService },
|
||||||
{provide: FileService, useValue: fileService},
|
{ provide: FileService, useValue: fileService },
|
||||||
{provide: HardRedirectService, useValue: hardRedirectService},
|
{ provide: HardRedirectService, useValue: hardRedirectService },
|
||||||
|
{ provide: ServerResponseService, useValue: serverResponseService },
|
||||||
|
{ provide: SignpostingDataService, useValue: signpostingDataService }
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
.compileComponents();
|
.compileComponents();
|
||||||
@@ -134,7 +151,7 @@ describe('BitstreamDownloadPageComponent', () => {
|
|||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
it('should navigate to the forbidden route', () => {
|
it('should navigate to the forbidden route', () => {
|
||||||
expect(router.navigateByUrl).toHaveBeenCalledWith(getForbiddenRoute(), {skipLocationChange: true});
|
expect(router.navigateByUrl).toHaveBeenCalledWith(getForbiddenRoute(), { skipLocationChange: true });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('when the user is not authorized and not logged in', () => {
|
describe('when the user is not authorized and not logged in', () => {
|
||||||
|
@@ -2,7 +2,7 @@ import { Component, OnInit } from '@angular/core';
|
|||||||
import { filter, map, switchMap, take } from 'rxjs/operators';
|
import { filter, map, switchMap, take } from 'rxjs/operators';
|
||||||
import { ActivatedRoute, Router } from '@angular/router';
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
import { hasValue, isNotEmpty } from '../../shared/empty.util';
|
import { hasValue, isNotEmpty } from '../../shared/empty.util';
|
||||||
import { getRemoteDataPayload} from '../../core/shared/operators';
|
import { getRemoteDataPayload } from '../../core/shared/operators';
|
||||||
import { Bitstream } from '../../core/shared/bitstream.model';
|
import { Bitstream } from '../../core/shared/bitstream.model';
|
||||||
import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service';
|
import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service';
|
||||||
import { FeatureID } from '../../core/data/feature-authorization/feature-id';
|
import { FeatureID } from '../../core/data/feature-authorization/feature-id';
|
||||||
@@ -29,7 +29,6 @@ export class BitstreamDownloadPageComponent implements OnInit {
|
|||||||
bitstream$: Observable<Bitstream>;
|
bitstream$: Observable<Bitstream>;
|
||||||
bitstreamRD$: Observable<RemoteData<Bitstream>>;
|
bitstreamRD$: Observable<RemoteData<Bitstream>>;
|
||||||
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
protected router: Router,
|
protected router: Router,
|
||||||
@@ -42,8 +41,10 @@ export class BitstreamDownloadPageComponent implements OnInit {
|
|||||||
private responseService: ServerResponseService
|
private responseService: ServerResponseService
|
||||||
) {
|
) {
|
||||||
this.route.params.subscribe(params => {
|
this.route.params.subscribe(params => {
|
||||||
this.signpostginDataService.getLinksets(params.id).pipe(take(1)).subscribe(linksets => {
|
this.signpostginDataService.getLinks(params.id).pipe(take(1)).subscribe(linksets => {
|
||||||
this.responseService.setLinksetsHeader(linksets);
|
linksets.forEach(link => {
|
||||||
|
this.responseService.setLinksetsHeader(link.href);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -1,16 +1,84 @@
|
|||||||
import { TestBed } from '@angular/core/testing';
|
import { fakeAsync, TestBed, tick } from '@angular/core/testing';
|
||||||
|
|
||||||
import { SignpostingDataService } from './signposting-data.service';
|
import { SignpostingDataService } from './signposting-data.service';
|
||||||
|
import { DspaceRestService } from '../dspace-rest/dspace-rest.service';
|
||||||
|
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||||
|
import { of } from 'rxjs';
|
||||||
|
import { SignpostingLinks } from './signposting-links.model';
|
||||||
|
import { map } from 'rxjs/operators';
|
||||||
|
|
||||||
describe('SignpostingDataService', () => {
|
describe('SignpostingDataService', () => {
|
||||||
let service: SignpostingDataService;
|
let service: SignpostingDataService;
|
||||||
|
let restServiceSpy: jasmine.SpyObj<DspaceRestService>;
|
||||||
|
let halServiceSpy: jasmine.SpyObj<HALEndpointService>;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({});
|
const restSpy = jasmine.createSpyObj('DspaceRestService', ['get', 'getWithHeaders']);
|
||||||
|
const halSpy = jasmine.createSpyObj('HALEndpointService', ['getRootHref']);
|
||||||
|
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
providers: [
|
||||||
|
SignpostingDataService,
|
||||||
|
{ provide: DspaceRestService, useValue: restSpy },
|
||||||
|
{ provide: HALEndpointService, useValue: halSpy }
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
service = TestBed.inject(SignpostingDataService);
|
service = TestBed.inject(SignpostingDataService);
|
||||||
|
restServiceSpy = TestBed.inject(DspaceRestService) as jasmine.SpyObj<DspaceRestService>;
|
||||||
|
halServiceSpy = TestBed.inject(HALEndpointService) as jasmine.SpyObj<HALEndpointService>;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be created', () => {
|
it('should be created', () => {
|
||||||
expect(service).toBeTruthy();
|
expect(service).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return signposting links', fakeAsync(() => {
|
||||||
|
const uuid = '123';
|
||||||
|
const baseUrl = 'http://localhost:8080';
|
||||||
|
|
||||||
|
halServiceSpy.getRootHref.and.returnValue(`${baseUrl}/api`);
|
||||||
|
|
||||||
|
const mockResponse: any = {
|
||||||
|
self: {
|
||||||
|
href: `${baseUrl}/signposting/links/${uuid}`
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
restServiceSpy.get.and.returnValue(of(mockResponse));
|
||||||
|
|
||||||
|
let result: SignpostingLinks;
|
||||||
|
|
||||||
|
service.getLinks(uuid).subscribe((links) => {
|
||||||
|
result = links;
|
||||||
|
});
|
||||||
|
|
||||||
|
tick();
|
||||||
|
|
||||||
|
expect(result).toEqual(mockResponse);
|
||||||
|
expect(halServiceSpy.getRootHref).toHaveBeenCalled();
|
||||||
|
expect(restServiceSpy.get).toHaveBeenCalledWith(`${baseUrl}/signposting/links/${uuid}`);
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should handle error and return false', fakeAsync(() => {
|
||||||
|
const uuid = '123';
|
||||||
|
const baseUrl = 'http://localhost:8080';
|
||||||
|
|
||||||
|
halServiceSpy.getRootHref.and.returnValue(`${baseUrl}/api`);
|
||||||
|
|
||||||
|
restServiceSpy.get.and.returnValue(of(null).pipe(map(() => {
|
||||||
|
throw new Error('Error');
|
||||||
|
})));
|
||||||
|
|
||||||
|
let result: any;
|
||||||
|
|
||||||
|
service.getLinks(uuid).subscribe((data) => {
|
||||||
|
result = data;
|
||||||
|
});
|
||||||
|
|
||||||
|
tick();
|
||||||
|
|
||||||
|
expect(result).toBeFalse();
|
||||||
|
expect(halServiceSpy.getRootHref).toHaveBeenCalled();
|
||||||
|
expect(restServiceSpy.get).toHaveBeenCalledWith(`${baseUrl}/signposting/links/${uuid}`);
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
|
@@ -1,8 +1,6 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { DspaceRestService } from '../dspace-rest/dspace-rest.service';
|
import { DspaceRestService } from '../dspace-rest/dspace-rest.service';
|
||||||
// import { HttpHeaders, HttpResponse } from '@angular/common/http';
|
|
||||||
import { catchError, map } from 'rxjs/operators';
|
import { catchError, map } from 'rxjs/operators';
|
||||||
// import { throwError } from 'rxjs';
|
|
||||||
import { Observable, of as observableOf } from 'rxjs';
|
import { Observable, of as observableOf } from 'rxjs';
|
||||||
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
import { HALEndpointService } from '../shared/hal-endpoint.service';
|
||||||
import { RawRestResponse } from '../dspace-rest/raw-rest-response.model';
|
import { RawRestResponse } from '../dspace-rest/raw-rest-response.model';
|
||||||
@@ -14,9 +12,10 @@ import { SignpostingLinks } from './signposting-links.model';
|
|||||||
})
|
})
|
||||||
export class SignpostingDataService {
|
export class SignpostingDataService {
|
||||||
|
|
||||||
constructor(private restService: DspaceRestService, protected halService: HALEndpointService) { }
|
constructor(private restService: DspaceRestService, protected halService: HALEndpointService) {
|
||||||
|
}
|
||||||
|
|
||||||
getLinks(uuid: string): Observable<SignpostingLinks> {
|
getLinks(uuid: string): Observable<SignpostingLinks[]> {
|
||||||
const baseUrl = this.halService.getRootHref().replace('/api', '');
|
const baseUrl = this.halService.getRootHref().replace('/api', '');
|
||||||
|
|
||||||
return this.restService.get(`${baseUrl}/signposting/links/${uuid}`).pipe(
|
return this.restService.get(`${baseUrl}/signposting/links/${uuid}`).pipe(
|
||||||
@@ -24,7 +23,7 @@ export class SignpostingDataService {
|
|||||||
console.error(err);
|
console.error(err);
|
||||||
return observableOf(false);
|
return observableOf(false);
|
||||||
}),
|
}),
|
||||||
map((res: SignpostingLinks) => res)
|
map((res: RawRestResponse) => res.payload as SignpostingLinks[])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -8,12 +8,7 @@ import { Observable, of as observableOf, of } from 'rxjs';
|
|||||||
import { RemoteData } from '../data/remote-data';
|
import { RemoteData } from '../data/remote-data';
|
||||||
import { Item } from '../shared/item.model';
|
import { Item } from '../shared/item.model';
|
||||||
|
|
||||||
import {
|
import { ItemMock, MockBitstream1, MockBitstream2, MockBitstream3 } from '../../shared/mocks/item.mock';
|
||||||
ItemMock,
|
|
||||||
MockBitstream1,
|
|
||||||
MockBitstream3,
|
|
||||||
MockBitstream2
|
|
||||||
} from '../../shared/mocks/item.mock';
|
|
||||||
import { createSuccessfulRemoteDataObject, createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
|
import { createSuccessfulRemoteDataObject, createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
|
||||||
import { PaginatedList } from '../data/paginated-list.model';
|
import { PaginatedList } from '../data/paginated-list.model';
|
||||||
import { Bitstream } from '../shared/bitstream.model';
|
import { Bitstream } from '../shared/bitstream.model';
|
||||||
@@ -30,6 +25,7 @@ import { getMockStore } from '@ngrx/store/testing';
|
|||||||
import { AddMetaTagAction, ClearMetaTagAction } from './meta-tag.actions';
|
import { AddMetaTagAction, ClearMetaTagAction } from './meta-tag.actions';
|
||||||
import { AuthorizationDataService } from '../data/feature-authorization/authorization-data.service';
|
import { AuthorizationDataService } from '../data/feature-authorization/authorization-data.service';
|
||||||
import { AppConfig } from '../../../config/app-config.interface';
|
import { AppConfig } from '../../../config/app-config.interface';
|
||||||
|
import { SignpostingDataService } from '../data/signposting-data.service';
|
||||||
|
|
||||||
describe('MetadataService', () => {
|
describe('MetadataService', () => {
|
||||||
let metadataService: MetadataService;
|
let metadataService: MetadataService;
|
||||||
@@ -46,6 +42,7 @@ describe('MetadataService', () => {
|
|||||||
let translateService: TranslateService;
|
let translateService: TranslateService;
|
||||||
let hardRedirectService: HardRedirectService;
|
let hardRedirectService: HardRedirectService;
|
||||||
let authorizationService: AuthorizationDataService;
|
let authorizationService: AuthorizationDataService;
|
||||||
|
let signpostingDataService: SignpostingDataService;
|
||||||
|
|
||||||
let router: Router;
|
let router: Router;
|
||||||
let store;
|
let store;
|
||||||
@@ -53,7 +50,12 @@ describe('MetadataService', () => {
|
|||||||
let appConfig: AppConfig;
|
let appConfig: AppConfig;
|
||||||
|
|
||||||
const initialState = { 'core': { metaTag: { tagsInUse: ['title', 'description'] }}};
|
const initialState = { 'core': { metaTag: { tagsInUse: ['title', 'description'] }}};
|
||||||
|
const mocklink = {
|
||||||
|
href: 'http://test.org',
|
||||||
|
rel: 'test',
|
||||||
|
type: 'test'
|
||||||
|
};
|
||||||
|
const document: any = jasmine.createSpyObj('document', ['head', 'createElement']);
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
rootService = jasmine.createSpyObj({
|
rootService = jasmine.createSpyObj({
|
||||||
@@ -90,6 +92,10 @@ describe('MetadataService', () => {
|
|||||||
isAuthorized: observableOf(true)
|
isAuthorized: observableOf(true)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
signpostingDataService = jasmine.createSpyObj('SignpostingDataService', {
|
||||||
|
getLinks: observableOf([mocklink])
|
||||||
|
});
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
store = getMockStore({ initialState });
|
store = getMockStore({ initialState });
|
||||||
spyOn(store, 'dispatch');
|
spyOn(store, 'dispatch');
|
||||||
@@ -115,7 +121,9 @@ describe('MetadataService', () => {
|
|||||||
store,
|
store,
|
||||||
hardRedirectService,
|
hardRedirectService,
|
||||||
appConfig,
|
appConfig,
|
||||||
authorizationService
|
document,
|
||||||
|
authorizationService,
|
||||||
|
signpostingDataService
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { Injectable, Inject } from '@angular/core';
|
import { Inject, Injectable } from '@angular/core';
|
||||||
|
|
||||||
import { Meta, MetaDefinition, Title } from '@angular/platform-browser';
|
import { Meta, MetaDefinition, Title } from '@angular/platform-browser';
|
||||||
import { ActivatedRoute, NavigationEnd, Router } from '@angular/router';
|
import { ActivatedRoute, NavigationEnd, Router } from '@angular/router';
|
||||||
@@ -8,12 +8,12 @@ import { TranslateService } from '@ngx-translate/core';
|
|||||||
import {
|
import {
|
||||||
BehaviorSubject,
|
BehaviorSubject,
|
||||||
combineLatest,
|
combineLatest,
|
||||||
Observable,
|
|
||||||
of as observableOf,
|
|
||||||
concat as observableConcat,
|
concat as observableConcat,
|
||||||
EMPTY
|
EMPTY,
|
||||||
|
Observable,
|
||||||
|
of as observableOf
|
||||||
} from 'rxjs';
|
} from 'rxjs';
|
||||||
import { filter, map, switchMap, take, mergeMap } from 'rxjs/operators';
|
import { filter, map, mergeMap, switchMap, take } from 'rxjs/operators';
|
||||||
|
|
||||||
import { hasNoValue, hasValue, isNotEmpty } from '../../shared/empty.util';
|
import { hasNoValue, hasValue, isNotEmpty } from '../../shared/empty.util';
|
||||||
import { DSONameService } from '../breadcrumbs/dso-name.service';
|
import { DSONameService } from '../breadcrumbs/dso-name.service';
|
||||||
@@ -25,10 +25,7 @@ import { BitstreamFormat } from '../shared/bitstream-format.model';
|
|||||||
import { Bitstream } from '../shared/bitstream.model';
|
import { Bitstream } from '../shared/bitstream.model';
|
||||||
import { DSpaceObject } from '../shared/dspace-object.model';
|
import { DSpaceObject } from '../shared/dspace-object.model';
|
||||||
import { Item } from '../shared/item.model';
|
import { Item } from '../shared/item.model';
|
||||||
import {
|
import { getFirstCompletedRemoteData, getFirstSucceededRemoteDataPayload } from '../shared/operators';
|
||||||
getFirstCompletedRemoteData,
|
|
||||||
getFirstSucceededRemoteDataPayload
|
|
||||||
} from '../shared/operators';
|
|
||||||
import { RootDataService } from '../data/root-data.service';
|
import { RootDataService } from '../data/root-data.service';
|
||||||
import { getBitstreamDownloadRoute } from '../../app-routing-paths';
|
import { getBitstreamDownloadRoute } from '../../app-routing-paths';
|
||||||
import { BundleDataService } from '../data/bundle-data.service';
|
import { BundleDataService } from '../data/bundle-data.service';
|
||||||
@@ -46,6 +43,7 @@ import { AuthorizationDataService } from '../data/feature-authorization/authoriz
|
|||||||
import { getDownloadableBitstream } from '../shared/bitstream.operators';
|
import { getDownloadableBitstream } from '../shared/bitstream.operators';
|
||||||
import { APP_CONFIG, AppConfig } from '../../../config/app-config.interface';
|
import { APP_CONFIG, AppConfig } from '../../../config/app-config.interface';
|
||||||
import { SignpostingDataService } from '../data/signposting-data.service';
|
import { SignpostingDataService } from '../data/signposting-data.service';
|
||||||
|
import { DOCUMENT } from '@angular/common';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base selector function to select the metaTag section in the store
|
* The base selector function to select the metaTag section in the store
|
||||||
@@ -102,8 +100,9 @@ export class MetadataService {
|
|||||||
private store: Store<CoreState>,
|
private store: Store<CoreState>,
|
||||||
private hardRedirectService: HardRedirectService,
|
private hardRedirectService: HardRedirectService,
|
||||||
@Inject(APP_CONFIG) private appConfig: AppConfig,
|
@Inject(APP_CONFIG) private appConfig: AppConfig,
|
||||||
|
@Inject(DOCUMENT) private _document: Document,
|
||||||
private authorizationService: AuthorizationDataService,
|
private authorizationService: AuthorizationDataService,
|
||||||
private signpostginDataService: SignpostingDataService
|
private signpostingDataService: SignpostingDataService
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,9 +197,9 @@ export class MetadataService {
|
|||||||
*/
|
*/
|
||||||
private setSignpostingLinks() {
|
private setSignpostingLinks() {
|
||||||
if (this.currentObject.value instanceof Item){
|
if (this.currentObject.value instanceof Item){
|
||||||
const value = this.signpostginDataService.getLinks(this.currentObject.getValue().id);
|
const value = this.signpostingDataService.getLinks(this.currentObject.getValue().id);
|
||||||
value.subscribe(links => {
|
value.subscribe(links => {
|
||||||
links.payload.forEach(link => {
|
links.forEach(link => {
|
||||||
this.setLinkTag(link.href, link.rel, link.type);
|
this.setLinkTag(link.href, link.rel, link.type);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -208,17 +207,19 @@ export class MetadataService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setLinkTag(href: string, rel: string, type: string){
|
setLinkTag(href: string, rel: string, type: string){
|
||||||
let link: HTMLLinkElement = document.createElement('link');
|
let link: HTMLLinkElement = this._document.createElement('link');
|
||||||
link.href = href;
|
if (link) {
|
||||||
link.rel = rel;
|
link.href = href;
|
||||||
link.type = type;
|
link.rel = rel;
|
||||||
document.head.appendChild(link);
|
link.type = type;
|
||||||
linkTags.push(link);
|
this._document.head?.appendChild(link);
|
||||||
|
linkTags.push(link);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public clearLinkTags(){
|
public clearLinkTags(){
|
||||||
linkTags.forEach(link => {
|
linkTags.forEach(link => {
|
||||||
link.parentNode.removeChild(link);
|
link.parentNode?.removeChild(link);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -11,7 +11,7 @@ import { ActivatedRouteStub } from '../../shared/testing/active-router.stub';
|
|||||||
import { VarDirective } from '../../shared/utils/var.directive';
|
import { VarDirective } from '../../shared/utils/var.directive';
|
||||||
import { RouterTestingModule } from '@angular/router/testing';
|
import { RouterTestingModule } from '@angular/router/testing';
|
||||||
import { Item } from '../../core/shared/item.model';
|
import { Item } from '../../core/shared/item.model';
|
||||||
import { BehaviorSubject, of as observableOf } from 'rxjs';
|
import { BehaviorSubject, of as observableOf, of } from 'rxjs';
|
||||||
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
||||||
import { By } from '@angular/platform-browser';
|
import { By } from '@angular/platform-browser';
|
||||||
import { createSuccessfulRemoteDataObject, createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
|
import { createSuccessfulRemoteDataObject, createSuccessfulRemoteDataObject$ } from '../../shared/remote-data.utils';
|
||||||
@@ -20,6 +20,8 @@ import { createPaginatedList } from '../../shared/testing/utils.test';
|
|||||||
import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service';
|
import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service';
|
||||||
import { createRelationshipsObservable } from '../simple/item-types/shared/item.component.spec';
|
import { createRelationshipsObservable } from '../simple/item-types/shared/item.component.spec';
|
||||||
import { RemoteData } from '../../core/data/remote-data';
|
import { RemoteData } from '../../core/data/remote-data';
|
||||||
|
import { ServerResponseService } from '../../core/services/server-response.service';
|
||||||
|
import { SignpostingDataService } from '../../core/data/signposting-data.service';
|
||||||
|
|
||||||
const mockItem: Item = Object.assign(new Item(), {
|
const mockItem: Item = Object.assign(new Item(), {
|
||||||
bundles: createSuccessfulRemoteDataObject$(createPaginatedList([])),
|
bundles: createSuccessfulRemoteDataObject$(createPaginatedList([])),
|
||||||
@@ -55,8 +57,8 @@ describe('FullItemPageComponent', () => {
|
|||||||
let routeStub: ActivatedRouteStub;
|
let routeStub: ActivatedRouteStub;
|
||||||
let routeData;
|
let routeData;
|
||||||
let authorizationDataService: AuthorizationDataService;
|
let authorizationDataService: AuthorizationDataService;
|
||||||
|
let serverResponseService: jasmine.SpyObj<ServerResponseService>;
|
||||||
|
let signpostingDataService: jasmine.SpyObj<SignpostingDataService>;
|
||||||
|
|
||||||
beforeEach(waitForAsync(() => {
|
beforeEach(waitForAsync(() => {
|
||||||
authService = jasmine.createSpyObj('authService', {
|
authService = jasmine.createSpyObj('authService', {
|
||||||
@@ -76,6 +78,14 @@ describe('FullItemPageComponent', () => {
|
|||||||
isAuthorized: observableOf(false),
|
isAuthorized: observableOf(false),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
serverResponseService = jasmine.createSpyObj('ServerResponseService', {
|
||||||
|
setLinksetsHeader: jasmine.createSpy('setLinksetsHeader'),
|
||||||
|
});
|
||||||
|
|
||||||
|
signpostingDataService = jasmine.createSpyObj('SignpostingDataService', {
|
||||||
|
getLinksets: of('test'),
|
||||||
|
});
|
||||||
|
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [TranslateModule.forRoot({
|
imports: [TranslateModule.forRoot({
|
||||||
loader: {
|
loader: {
|
||||||
@@ -90,8 +100,9 @@ describe('FullItemPageComponent', () => {
|
|||||||
{ provide: MetadataService, useValue: metadataServiceStub },
|
{ provide: MetadataService, useValue: metadataServiceStub },
|
||||||
{ provide: AuthService, useValue: authService },
|
{ provide: AuthService, useValue: authService },
|
||||||
{ provide: AuthorizationDataService, useValue: authorizationDataService },
|
{ provide: AuthorizationDataService, useValue: authorizationDataService },
|
||||||
|
{ provide: ServerResponseService, useValue: serverResponseService },
|
||||||
|
{ provide: SignpostingDataService, useValue: signpostingDataService },
|
||||||
],
|
],
|
||||||
|
|
||||||
schemas: [NO_ERRORS_SCHEMA]
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
}).overrideComponent(FullItemPageComponent, {
|
}).overrideComponent(FullItemPageComponent, {
|
||||||
set: { changeDetection: ChangeDetectionStrategy.Default }
|
set: { changeDetection: ChangeDetectionStrategy.Default }
|
||||||
|
@@ -19,7 +19,6 @@ import { AuthorizationDataService } from '../../core/data/feature-authorization/
|
|||||||
import { ServerResponseService } from 'src/app/core/services/server-response.service';
|
import { ServerResponseService } from 'src/app/core/services/server-response.service';
|
||||||
import { SignpostingDataService } from 'src/app/core/data/signposting-data.service';
|
import { SignpostingDataService } from 'src/app/core/data/signposting-data.service';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This component renders a full item page.
|
* This component renders a full item page.
|
||||||
* The route parameter 'id' is used to request the item it represents.
|
* The route parameter 'id' is used to request the item it represents.
|
||||||
@@ -52,8 +51,8 @@ export class FullItemPageComponent extends ItemPageComponent implements OnInit,
|
|||||||
authorizationService: AuthorizationDataService,
|
authorizationService: AuthorizationDataService,
|
||||||
private _location: Location,
|
private _location: Location,
|
||||||
responseService: ServerResponseService,
|
responseService: ServerResponseService,
|
||||||
signpostginDataService: SignpostingDataService) {
|
signpostingDataService: SignpostingDataService) {
|
||||||
super(route, router, items, authService, authorizationService, responseService, signpostginDataService);
|
super(route, router, items, authService, authorizationService, responseService, signpostingDataService);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*** AoT inheritance fix, will hopefully be resolved in the near future **/
|
/*** AoT inheritance fix, will hopefully be resolved in the near future **/
|
||||||
|
@@ -22,6 +22,9 @@ import {
|
|||||||
import { AuthService } from '../../core/auth/auth.service';
|
import { AuthService } from '../../core/auth/auth.service';
|
||||||
import { createPaginatedList } from '../../shared/testing/utils.test';
|
import { createPaginatedList } from '../../shared/testing/utils.test';
|
||||||
import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service';
|
import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service';
|
||||||
|
import { of } from 'rxjs/internal/observable/of';
|
||||||
|
import { ServerResponseService } from '../../core/services/server-response.service';
|
||||||
|
import { SignpostingDataService } from '../../core/data/signposting-data.service';
|
||||||
|
|
||||||
const mockItem: Item = Object.assign(new Item(), {
|
const mockItem: Item = Object.assign(new Item(), {
|
||||||
bundles: createSuccessfulRemoteDataObject$(createPaginatedList([])),
|
bundles: createSuccessfulRemoteDataObject$(createPaginatedList([])),
|
||||||
@@ -41,6 +44,8 @@ describe('ItemPageComponent', () => {
|
|||||||
let fixture: ComponentFixture<ItemPageComponent>;
|
let fixture: ComponentFixture<ItemPageComponent>;
|
||||||
let authService: AuthService;
|
let authService: AuthService;
|
||||||
let authorizationDataService: AuthorizationDataService;
|
let authorizationDataService: AuthorizationDataService;
|
||||||
|
let serverResponseService: jasmine.SpyObj<ServerResponseService>;
|
||||||
|
let signpostingDataService: jasmine.SpyObj<SignpostingDataService>;
|
||||||
|
|
||||||
const mockMetadataService = {
|
const mockMetadataService = {
|
||||||
/* eslint-disable no-empty,@typescript-eslint/no-empty-function */
|
/* eslint-disable no-empty,@typescript-eslint/no-empty-function */
|
||||||
@@ -60,6 +65,13 @@ describe('ItemPageComponent', () => {
|
|||||||
authorizationDataService = jasmine.createSpyObj('authorizationDataService', {
|
authorizationDataService = jasmine.createSpyObj('authorizationDataService', {
|
||||||
isAuthorized: observableOf(false),
|
isAuthorized: observableOf(false),
|
||||||
});
|
});
|
||||||
|
serverResponseService = jasmine.createSpyObj('ServerResponseService', {
|
||||||
|
setLinksetsHeader: jasmine.createSpy('setLinksetsHeader'),
|
||||||
|
});
|
||||||
|
|
||||||
|
signpostingDataService = jasmine.createSpyObj('SignpostingDataService', {
|
||||||
|
getLinksets: of('test'),
|
||||||
|
});
|
||||||
|
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [TranslateModule.forRoot({
|
imports: [TranslateModule.forRoot({
|
||||||
@@ -76,6 +88,8 @@ describe('ItemPageComponent', () => {
|
|||||||
{ provide: Router, useValue: {} },
|
{ provide: Router, useValue: {} },
|
||||||
{ provide: AuthService, useValue: authService },
|
{ provide: AuthService, useValue: authService },
|
||||||
{ provide: AuthorizationDataService, useValue: authorizationDataService },
|
{ provide: AuthorizationDataService, useValue: authorizationDataService },
|
||||||
|
{ provide: ServerResponseService, useValue: serverResponseService },
|
||||||
|
{ provide: SignpostingDataService, useValue: signpostingDataService },
|
||||||
],
|
],
|
||||||
|
|
||||||
schemas: [NO_ERRORS_SCHEMA]
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
|
@@ -66,10 +66,10 @@ export class ItemPageComponent implements OnInit {
|
|||||||
private authService: AuthService,
|
private authService: AuthService,
|
||||||
private authorizationService: AuthorizationDataService,
|
private authorizationService: AuthorizationDataService,
|
||||||
private responseService: ServerResponseService,
|
private responseService: ServerResponseService,
|
||||||
private signpostginDataService: SignpostingDataService
|
private signpostingDataService: SignpostingDataService
|
||||||
) {
|
) {
|
||||||
this.route.params.subscribe(params => {
|
this.route.params.subscribe(params => {
|
||||||
this.signpostginDataService.getLinksets(params.id).subscribe(linksets => {
|
this.signpostingDataService.getLinksets(params.id).subscribe(linksets => {
|
||||||
this.responseService.setLinksetsHeader(linksets);
|
this.responseService.setLinksetsHeader(linksets);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user