mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Url parsing
Lint fix
This commit is contained in:
@@ -17,7 +17,7 @@ import { RemoteData } from '../../../../core/data/remote-data';
|
|||||||
import { Bitstream } from '../../../../core/shared/bitstream.model';
|
import { Bitstream } from '../../../../core/shared/bitstream.model';
|
||||||
import { HALEndpointService } from '../../../../core/shared/hal-endpoint.service';
|
import { HALEndpointService } from '../../../../core/shared/hal-endpoint.service';
|
||||||
import { Item } from '../../../../core/shared/item.model';
|
import { Item } from '../../../../core/shared/item.model';
|
||||||
import { MetadataMap, MetadataValue } from '../../../../core/shared/metadata.models';
|
import { MetadataMap } from '../../../../core/shared/metadata.models';
|
||||||
import { UUIDService } from '../../../../core/shared/uuid.service';
|
import { UUIDService } from '../../../../core/shared/uuid.service';
|
||||||
import { TranslateLoaderMock } from '../../../../shared/mocks/translate-loader.mock';
|
import { TranslateLoaderMock } from '../../../../shared/mocks/translate-loader.mock';
|
||||||
import { NotificationsService } from '../../../../shared/notifications/notifications.service';
|
import { NotificationsService } from '../../../../shared/notifications/notifications.service';
|
||||||
@@ -31,7 +31,6 @@ import {
|
|||||||
import { PublicationComponent } from './publication.component';
|
import { PublicationComponent } from './publication.component';
|
||||||
import { createPaginatedList } from '../../../../shared/testing/utils.test';
|
import { createPaginatedList } from '../../../../shared/testing/utils.test';
|
||||||
import { RouteService } from '../../../../core/services/route.service';
|
import { RouteService } from '../../../../core/services/route.service';
|
||||||
import { UntypedItemComponent } from '../untyped-item/untyped-item.component';
|
|
||||||
|
|
||||||
const noMetadata = new MetadataMap();
|
const noMetadata = new MetadataMap();
|
||||||
|
|
||||||
@@ -155,7 +154,7 @@ describe('PublicationComponent', () => {
|
|||||||
beforeEach(waitForAsync(() => {
|
beforeEach(waitForAsync(() => {
|
||||||
const localMockRouteService = {
|
const localMockRouteService = {
|
||||||
getPreviousUrl(): Observable<string> {
|
getPreviousUrl(): Observable<string> {
|
||||||
return of('/search?query=test');
|
return of('/search?query=test%20query&fakeParam=true');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const iiifEnabledMap: MetadataMap = {
|
const iiifEnabledMap: MetadataMap = {
|
||||||
@@ -176,8 +175,7 @@ describe('PublicationComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should retrieve the query term for previous route', fakeAsync((): void => {
|
it('should retrieve the query term for previous route', fakeAsync((): void => {
|
||||||
//tick(10)
|
expect(comp.iiifQuery$.subscribe(result => expect(result).toEqual('test query')));
|
||||||
expect(comp.iiifQuery$.subscribe(result => expect(result).toEqual('test')));
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -2,6 +2,7 @@ import { Item } from '../../../../core/shared/item.model';
|
|||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { filter, map, take } from 'rxjs/operators';
|
import { filter, map, take } from 'rxjs/operators';
|
||||||
import { RouteService } from '../../../../core/services/route.service';
|
import { RouteService } from '../../../../core/services/route.service';
|
||||||
|
import { DefaultUrlSerializer, UrlTree } from '@angular/router';
|
||||||
|
|
||||||
export const isIiifEnabled = (item: Item) => {
|
export const isIiifEnabled = (item: Item) => {
|
||||||
return !!item.firstMetadataValue('dspace.iiif.enabled');
|
return !!item.firstMetadataValue('dspace.iiif.enabled');
|
||||||
@@ -21,13 +22,14 @@ export const isIiifSearchEnabled = (item: Item) => {
|
|||||||
* @param routeService
|
* @param routeService
|
||||||
*/
|
*/
|
||||||
export const getDSpaceQuery = (item: Item, routeService: RouteService): Observable<string> => {
|
export const getDSpaceQuery = (item: Item, routeService: RouteService): Observable<string> => {
|
||||||
|
|
||||||
return routeService.getPreviousUrl().pipe(
|
return routeService.getPreviousUrl().pipe(
|
||||||
filter(r => {
|
filter(r => {
|
||||||
return r.includes('/search');
|
return r.includes('/search');
|
||||||
}),
|
}),
|
||||||
map(r => {
|
map((r: string) => {
|
||||||
const v = r.split('query=');
|
const url: UrlTree = new DefaultUrlSerializer().parse(r);
|
||||||
return v[1];
|
return url.queryParamMap.get('query');
|
||||||
}),
|
}),
|
||||||
take(1)
|
take(1)
|
||||||
);
|
);
|
||||||
|
@@ -173,7 +173,7 @@ describe('UntypedItemComponent', () => {
|
|||||||
beforeEach(waitForAsync(() => {
|
beforeEach(waitForAsync(() => {
|
||||||
const localMockRouteService = {
|
const localMockRouteService = {
|
||||||
getPreviousUrl(): Observable<string> {
|
getPreviousUrl(): Observable<string> {
|
||||||
return of('/search?query=test');
|
return of('/search?query=test%20query&fakeParam=true');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const iiifEnabledMap: MetadataMap = {
|
const iiifEnabledMap: MetadataMap = {
|
||||||
@@ -194,7 +194,7 @@ describe('UntypedItemComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should retrieve the query term for previous route', (): void => {
|
it('should retrieve the query term for previous route', (): void => {
|
||||||
expect(comp.iiifQuery$.subscribe(result => expect(result).toEqual('test')));
|
expect(comp.iiifQuery$.subscribe(result => expect(result).toEqual('test query')));
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user