diff --git a/src/app/shared/mocks/dso-name.service.mock.ts b/src/app/shared/mocks/dso-name.service.mock.ts index 1e3280ce8d..cf3cf5466b 100644 --- a/src/app/shared/mocks/dso-name.service.mock.ts +++ b/src/app/shared/mocks/dso-name.service.mock.ts @@ -9,11 +9,19 @@ export class DSONameServiceMock { public getHitHighlights(object: any, dso: DSpaceObject) { if (object.hitHighlights && object.hitHighlights['dc.title']) { - return object.hitHighlights['dc.title'][0]; + return object.hitHighlights['dc.title'][0].value; } else if (object.hitHighlights && object.hitHighlights['organization.legalName']) { - return object.hitHighlights['organization.legalName'][0]; + return object.hitHighlights['organization.legalName'][0].value; } else if (object.hitHighlights && (object.hitHighlights['person.familyName'] || object.hitHighlights['person.givenName'])) { - return `${object.hitHighlights['person.familyName'][0] || ''}, ${object.hitHighlights['person.givenName'][0] || ''}`; + if (object.hitHighlights['person.familyName'] && object.hitHighlights['person.givenName']) { + return `${object.hitHighlights['person.familyName'][0].value}, ${object.hitHighlights['person.givenName'][0].value}`; + } + if (object.hitHighlights['person.familyName']) { + return `${object.hitHighlights['person.familyName'][0].value}`; + } + if (object.hitHighlights['person.givenName']) { + return `${object.hitHighlights['person.givenName'][0].value}`; + } } return UNDEFINED_NAME; } diff --git a/src/app/shared/object-grid/search-result-grid-element/item-search-result/item/item-search-result-grid-element.component.spec.ts b/src/app/shared/object-grid/search-result-grid-element/item-search-result/item/item-search-result-grid-element.component.spec.ts index f25937df34..dc42b033d8 100644 --- a/src/app/shared/object-grid/search-result-grid-element/item-search-result/item/item-search-result-grid-element.component.spec.ts +++ b/src/app/shared/object-grid/search-result-grid-element/item-search-result/item/item-search-result-grid-element.component.spec.ts @@ -31,7 +31,9 @@ mockItemWithMetadata.hitHighlights = {}; const dcTitle = 'This is just another title'; mockItemWithMetadata.indexableObject = Object.assign(new Item(), { hitHighlights: { - 'dc.title': [dcTitle], + 'dc.title': [{ + value: dcTitle + }], }, bundles: createSuccessfulRemoteDataObject$(buildPaginatedList(new PageInfo(), [])), metadata: { @@ -61,6 +63,114 @@ mockItemWithMetadata.indexableObject = Object.assign(new Item(), { ] } }); +const mockPerson: ItemSearchResult = Object.assign(new ItemSearchResult(), { + hitHighlights: { + 'person.familyName': [{ + value: 'Michel' + }], + }, + indexableObject: + Object.assign(new Item(), { + bundles: createSuccessfulRemoteDataObject$(buildPaginatedList(new PageInfo(), [])), + entityType: 'Person', + metadata: { + 'dc.title': [ + { + language: 'en_US', + value: 'This is just another title' + } + ], + 'dc.contributor.author': [ + { + language: 'en_US', + value: 'Smith, Donald' + } + ], + 'dc.publisher': [ + { + language: 'en_US', + value: 'a publisher' + } + ], + 'dc.date.issued': [ + { + language: 'en_US', + value: '2015-06-26' + } + ], + 'dc.description.abstract': [ + { + language: 'en_US', + value: 'This is the abstract' + } + ], + 'dspace.entity.type': [ + { + value: 'Person' + } + ], + 'person.familyName': [ + { + value: 'Michel' + } + ] + } + }) +}); +const mockOrgUnit: ItemSearchResult = Object.assign(new ItemSearchResult(), { + hitHighlights: { + 'organization.legalName': [{ + value: 'Science' + }], + }, + indexableObject: + Object.assign(new Item(), { + bundles: createSuccessfulRemoteDataObject$(buildPaginatedList(new PageInfo(), [])), + entityType: 'OrgUnit', + metadata: { + 'dc.title': [ + { + language: 'en_US', + value: 'This is just another title' + } + ], + 'dc.contributor.author': [ + { + language: 'en_US', + value: 'Smith, Donald' + } + ], + 'dc.publisher': [ + { + language: 'en_US', + value: 'a publisher' + } + ], + 'dc.date.issued': [ + { + language: 'en_US', + value: '2015-06-26' + } + ], + 'dc.description.abstract': [ + { + language: 'en_US', + value: 'This is the abstract' + } + ], + 'organization.legalName': [ + { + value: 'Science' + } + ], + 'dspace.entity.type': [ + { + value: 'OrgUnit' + } + ] + } + }) +}); const mockItemWithoutMetadata: ItemSearchResult = new ItemSearchResult(); mockItemWithoutMetadata.hitHighlights = {}; @@ -169,6 +279,30 @@ export function getEntityGridElementTestComponent(component, searchResultWithMet expect(titleField.nativeNode.innerHTML).toEqual(dcTitle); }); }); + + describe('When the item is Person and has title', () => { + beforeEach(() => { + comp.object = mockPerson; + fixture.detectChanges(); + }); + + it('should show highlighted title', () => { + const titleField = fixture.debugElement.query(By.css('.card-title')); + expect(titleField.nativeNode.innerHTML).toEqual('Michel'); + }); + }); + + describe('When the item is orgUnit and has title', () => { + beforeEach(() => { + comp.object = mockOrgUnit; + fixture.detectChanges(); + }); + + it('should show highlighted title', () => { + const titleField = fixture.debugElement.query(By.css('.card-title')); + expect(titleField.nativeNode.innerHTML).toEqual('Science'); + }); + }); }); }; } diff --git a/src/app/shared/object-list/search-result-list-element/item-search-result/item-types/item/item-search-result-list-element.component.spec.ts b/src/app/shared/object-list/search-result-list-element/item-search-result/item-types/item/item-search-result-list-element.component.spec.ts index 0d7c2cbc58..7665b7d64e 100644 --- a/src/app/shared/object-list/search-result-list-element/item-search-result/item-types/item/item-search-result-list-element.component.spec.ts +++ b/src/app/shared/object-list/search-result-list-element/item-search-result/item-types/item/item-search-result-list-element.component.spec.ts @@ -16,7 +16,9 @@ let fixture: ComponentFixture; const dcTitle = 'This is just another title'; const mockItemWithMetadata: ItemSearchResult = Object.assign(new ItemSearchResult(), { hitHighlights: { - 'dc.title': [dcTitle], + 'dc.title': [{ + value: dcTitle + }], }, indexableObject: Object.assign(new Item(), { @@ -25,7 +27,7 @@ const mockItemWithMetadata: ItemSearchResult = Object.assign(new ItemSearchResul 'dc.title': [ { language: 'en_US', - value: 'This is just another title' + value: dcTitle } ], 'dc.contributor.author': [ @@ -62,7 +64,114 @@ const mockItemWithoutMetadata: ItemSearchResult = Object.assign(new ItemSearchRe metadata: {} }) }); - +const mockPerson: ItemSearchResult = Object.assign(new ItemSearchResult(), { + hitHighlights: { + 'person.familyName': [{ + value: 'Michel' + }], + }, + indexableObject: + Object.assign(new Item(), { + bundles: observableOf({}), + entityType: 'Person', + metadata: { + 'dc.title': [ + { + language: 'en_US', + value: 'This is just another title' + } + ], + 'dc.contributor.author': [ + { + language: 'en_US', + value: 'Smith, Donald' + } + ], + 'dc.publisher': [ + { + language: 'en_US', + value: 'a publisher' + } + ], + 'dc.date.issued': [ + { + language: 'en_US', + value: '2015-06-26' + } + ], + 'dc.description.abstract': [ + { + language: 'en_US', + value: 'This is the abstract' + } + ], + 'person.familyName': [ + { + value: 'Michel' + } + ], + 'dspace.entity.type': [ + { + value: 'Person' + } + ] + } + }) +}); +const mockOrgUnit: ItemSearchResult = Object.assign(new ItemSearchResult(), { + hitHighlights: { + 'organization.legalName': [{ + value: 'Science' + }], + }, + indexableObject: + Object.assign(new Item(), { + bundles: observableOf({}), + entityType: 'OrgUnit', + metadata: { + 'dc.title': [ + { + language: 'en_US', + value: 'This is just another title' + } + ], + 'dc.contributor.author': [ + { + language: 'en_US', + value: 'Smith, Donald' + } + ], + 'dc.publisher': [ + { + language: 'en_US', + value: 'a publisher' + } + ], + 'dc.date.issued': [ + { + language: 'en_US', + value: '2015-06-26' + } + ], + 'dc.description.abstract': [ + { + language: 'en_US', + value: 'This is the abstract' + } + ], + 'organization.legalName': [ + { + value: 'Science' + } + ], + 'dspace.entity.type': [ + { + value: 'OrgUnit' + } + ] + } + }) +}); const environmentUseThumbs = { browseBy: { showThumbnails: true @@ -220,6 +329,30 @@ describe('ItemSearchResultListElementComponent', () => { }); }); + describe('When the item is Person and has title', () => { + beforeEach(() => { + publicationListElementComponent.object = mockPerson; + fixture.detectChanges(); + }); + + it('should show highlighted title', () => { + const titleField = fixture.debugElement.query(By.css('.item-list-title')); + expect(titleField.nativeNode.innerHTML).toEqual('Michel'); + }); + }); + + describe('When the item is orgUnit and has title', () => { + beforeEach(() => { + publicationListElementComponent.object = mockOrgUnit; + fixture.detectChanges(); + }); + + it('should show highlighted title', () => { + const titleField = fixture.debugElement.query(By.css('.item-list-title')); + expect(titleField.nativeNode.innerHTML).toEqual('Science'); + }); + }); + describe('When the item has no title', () => { beforeEach(() => { publicationListElementComponent.object = mockItemWithoutMetadata;