mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
[TLC-380] Template link fixes, spec test fixes
Correct use of routerLink and queryParams Removed unused method from browse service, specs New spec tests for MetadataRepresentationListElementComponent
This commit is contained in:
@@ -251,37 +251,4 @@ export class BrowseService {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the browse URL by providing a metadatum key and linkPath
|
||||
* @param metadatumKey
|
||||
* @param linkPath
|
||||
*/
|
||||
getBrowseDefinitionFor(metadataKeys: string[]): Observable<BrowseDefinition> {
|
||||
let searchKeyArray: string[] = [];
|
||||
metadataKeys.forEach((metadataKey) => {
|
||||
searchKeyArray = searchKeyArray.concat(BrowseService.toSearchKeyArray(metadataKey));
|
||||
});
|
||||
return this.getBrowseDefinitions().pipe(
|
||||
getRemoteDataPayload(),
|
||||
getPaginatedListPayload(),
|
||||
map((browseDefinitions: BrowseDefinition[]) => browseDefinitions
|
||||
.find((def: BrowseDefinition) => {
|
||||
//console.dir(def.metadataKeys);
|
||||
const matchingKeys = def.metadataKeys.find((key: string) => searchKeyArray.indexOf(key) >= 0);
|
||||
//console.dir(matchingKeys);
|
||||
return isNotEmpty(matchingKeys);
|
||||
})
|
||||
),
|
||||
map((def: BrowseDefinition) => {
|
||||
if (isEmpty(def) || isEmpty(def.id)) {
|
||||
//throw new Error(`A browse definition for field ${metadataKey} isn't configured`);
|
||||
} else {
|
||||
return def;
|
||||
}
|
||||
}),
|
||||
startWith(undefined),
|
||||
distinctUntilChanged()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -31,7 +31,8 @@
|
||||
<!-- Render value as a link to browse index -->
|
||||
<ng-template #browselink let-value="value">
|
||||
<a class="dont-break-out preserve-line-breaks ds-browse-link"
|
||||
href="/browse/{{browseDefinition.id}}?{{(browseDefinition.metadataBrowse?'value':'startsWith')}}={{value}}&bbm.page=1">
|
||||
[routerLink]="['/browse', browseDefinition.id]"
|
||||
[queryParams]="getQueryParams(value)">
|
||||
{{value}}
|
||||
</a>
|
||||
</ng-template>
|
||||
|
@@ -76,4 +76,17 @@ export class MetadataValuesComponent implements OnChanges {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a queryparams object for use in a link, with the key dependent on whether this browse
|
||||
* definition is metadata browse, or item browse
|
||||
* @param value the specific metadata value being linked
|
||||
*/
|
||||
getQueryParams(value) {
|
||||
let queryParams = {startsWith: value};
|
||||
if (this.browseDefinition.metadataBrowse) {
|
||||
return {value: value};
|
||||
}
|
||||
return queryParams;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,59 @@
|
||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { MetadatumRepresentation } from '../../../core/shared/metadata-representation/metadatum/metadatum-representation.model';
|
||||
import { mockData } from '../../testing/browse-definition-data-service.stub';
|
||||
import { MetadataRepresentationListElementComponent } from './metadata-representation-list-element.component';
|
||||
|
||||
// Mock metadata representation values
|
||||
const mockMetadataRepresentation = Object.assign(new MetadatumRepresentation('type', mockData[1]), {
|
||||
key: 'dc.contributor.author',
|
||||
value: 'Test Author'
|
||||
});
|
||||
const mockMetadataRepresentationUrl = Object.assign(new MetadatumRepresentation('type', mockData[1]), {
|
||||
key: 'dc.subject',
|
||||
value: 'https://www.google.com'
|
||||
});
|
||||
|
||||
describe('MetadataRepresentationListElementComponent', () => {
|
||||
let comp: MetadataRepresentationListElementComponent;
|
||||
let fixture: ComponentFixture<MetadataRepresentationListElementComponent>;
|
||||
|
||||
beforeEach(waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [],
|
||||
declarations: [MetadataRepresentationListElementComponent],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
}).overrideComponent(MetadataRepresentationListElementComponent, {
|
||||
set: { changeDetection: ChangeDetectionStrategy.Default }
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(waitForAsync(() => {
|
||||
fixture = TestBed.createComponent(MetadataRepresentationListElementComponent);
|
||||
comp = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
}));
|
||||
|
||||
describe('when the value is not a URL', () => {
|
||||
beforeEach(() => {
|
||||
comp.metadataRepresentation = mockMetadataRepresentation;
|
||||
});
|
||||
it('isLink correctly detects a non-URL string as false', () => {
|
||||
waitForAsync(() => {
|
||||
expect(comp.isLink()).toBe(false);
|
||||
});
|
||||
});
|
||||
})
|
||||
|
||||
describe('when the value is a URL', () => {
|
||||
beforeEach(() => {
|
||||
comp.metadataRepresentation = mockMetadataRepresentationUrl;
|
||||
});
|
||||
it('isLink correctly detects a URL string as true', () => {
|
||||
waitForAsync(() => {
|
||||
expect(comp.isLink()).toBe(true);
|
||||
});
|
||||
});
|
||||
})
|
||||
|
||||
});
|
@@ -18,8 +18,8 @@ export class MetadataRepresentationListElementComponent {
|
||||
* Returns true if this component's value matches a basic regex "Is this an HTTP URL" test
|
||||
*/
|
||||
isLink(): boolean {
|
||||
// Match any http:// or https://
|
||||
const linkPattern = /^https?\/\//;
|
||||
// Match any string that begins with http:// or https://
|
||||
const linkPattern = new RegExp(/^https?\/\/.*/);
|
||||
return linkPattern.test(this.metadataRepresentation.getValue());
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user