mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Merge pull request #3033 from DSpace/backport-2951-to-dspace-7_x
[Port dspace-7_x] Fix display of dso names for EPersons
This commit is contained in:
@@ -9,6 +9,10 @@ describe(`DSONameService`, () => {
|
|||||||
let service: DSONameService;
|
let service: DSONameService;
|
||||||
let mockPersonName: string;
|
let mockPersonName: string;
|
||||||
let mockPerson: DSpaceObject;
|
let mockPerson: DSpaceObject;
|
||||||
|
let mockEPersonNameFirst: string;
|
||||||
|
let mockEPersonFirst: DSpaceObject;
|
||||||
|
let mockEPersonName: string;
|
||||||
|
let mockEPerson: DSpaceObject;
|
||||||
let mockOrgUnitName: string;
|
let mockOrgUnitName: string;
|
||||||
let mockOrgUnit: DSpaceObject;
|
let mockOrgUnit: DSpaceObject;
|
||||||
let mockDSOName: string;
|
let mockDSOName: string;
|
||||||
@@ -25,6 +29,26 @@ describe(`DSONameService`, () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
mockEPersonName = 'John Doe';
|
||||||
|
mockEPerson = Object.assign(new DSpaceObject(), {
|
||||||
|
firstMetadataValue(keyOrKeys: string | string[], valueFilter?: MetadataValueFilter): string {
|
||||||
|
return mockEPersonName;
|
||||||
|
},
|
||||||
|
getRenderTypes(): (string | GenericConstructor<ListableObject>)[] {
|
||||||
|
return ['EPerson', Item, DSpaceObject];
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
mockEPersonNameFirst = 'John';
|
||||||
|
mockEPersonFirst = Object.assign(new DSpaceObject(), {
|
||||||
|
firstMetadataValue(keyOrKeys: string | string[], valueFilter?: MetadataValueFilter): string {
|
||||||
|
return mockEPersonNameFirst;
|
||||||
|
},
|
||||||
|
getRenderTypes(): (string | GenericConstructor<ListableObject>)[] {
|
||||||
|
return ['EPerson', Item, DSpaceObject];
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
mockOrgUnitName = 'Molecular Spectroscopy';
|
mockOrgUnitName = 'Molecular Spectroscopy';
|
||||||
mockOrgUnit = Object.assign(new DSpaceObject(), {
|
mockOrgUnit = Object.assign(new DSpaceObject(), {
|
||||||
firstMetadataValue(keyOrKeys: string | string[], valueFilter?: MetadataValueFilter): string {
|
firstMetadataValue(keyOrKeys: string | string[], valueFilter?: MetadataValueFilter): string {
|
||||||
@@ -67,6 +91,15 @@ describe(`DSONameService`, () => {
|
|||||||
expect(result).toBe('Bingo!');
|
expect(result).toBe('Bingo!');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it(`should use the EPerson factory for EPerson objects`, () => {
|
||||||
|
spyOn((service as any).factories, 'EPerson').and.returnValue('Bingo!');
|
||||||
|
|
||||||
|
const result = service.getName(mockEPerson);
|
||||||
|
|
||||||
|
expect((service as any).factories.EPerson).toHaveBeenCalledWith(mockEPerson);
|
||||||
|
expect(result).toBe('Bingo!');
|
||||||
|
});
|
||||||
|
|
||||||
it(`should use the Default factory for regular DSpaceObjects`, () => {
|
it(`should use the Default factory for regular DSpaceObjects`, () => {
|
||||||
spyOn((service as any).factories, 'Default').and.returnValue('Bingo!');
|
spyOn((service as any).factories, 'Default').and.returnValue('Bingo!');
|
||||||
|
|
||||||
@@ -107,6 +140,35 @@ describe(`DSONameService`, () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe(`factories.EPerson`, () => {
|
||||||
|
describe(`with eperson.firstname and without eperson.lastname`, () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
spyOn(mockEPerson, 'firstMetadataValue').and.returnValues(...mockEPersonName.split(' '));
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`should return 'eperson.firstname' and 'eperson.lastname'`, () => {
|
||||||
|
const result = (service as any).factories.EPerson(mockEPerson);
|
||||||
|
expect(result).toBe(mockEPersonName);
|
||||||
|
expect(mockEPerson.firstMetadataValue).toHaveBeenCalledWith('eperson.firstname');
|
||||||
|
expect(mockEPerson.firstMetadataValue).toHaveBeenCalledWith('eperson.lastname');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe(` with eperson.firstname and without eperson.lastname`, () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
spyOn(mockEPersonFirst, 'firstMetadataValue').and.returnValues(mockEPersonNameFirst, undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`should return 'eperson.firstname'`, () => {
|
||||||
|
const result = (service as any).factories.EPerson(mockEPersonFirst);
|
||||||
|
expect(result).toBe(mockEPersonNameFirst);
|
||||||
|
expect(mockEPersonFirst.firstMetadataValue).toHaveBeenCalledWith('eperson.firstname');
|
||||||
|
expect(mockEPersonFirst.firstMetadataValue).toHaveBeenCalledWith('eperson.lastname');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
describe(`factories.OrgUnit`, () => {
|
describe(`factories.OrgUnit`, () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
spyOn(mockOrgUnit, 'firstMetadataValue').and.callThrough();
|
spyOn(mockOrgUnit, 'firstMetadataValue').and.callThrough();
|
||||||
|
@@ -85,7 +85,7 @@ export class EPerson extends DSpaceObject {
|
|||||||
public groups?: Observable<RemoteData<PaginatedList<Group>>>;
|
public groups?: Observable<RemoteData<PaginatedList<Group>>>;
|
||||||
|
|
||||||
getRenderTypes(): (string | GenericConstructor<ListableObject>)[] {
|
getRenderTypes(): (string | GenericConstructor<ListableObject>)[] {
|
||||||
return [this.constructor.name, ...super.getRenderTypes()];
|
return ['EPerson', this.constructor.name, ...super.getRenderTypes()];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user