From be7cec4085e20d75fb1da0557c8da5e1cc751473 Mon Sep 17 00:00:00 2001 From: im-shubham-vish Date: Tue, 22 Oct 2024 13:20:40 +0530 Subject: [PATCH] Fix for #1602 Insufficient collection information when submitting an article(removed no longer use variable parentTitle) --- ...ebar-search-list-element.component.spec.ts | 73 +++++++++++++------ ...ebar-search-list-element.component.spec.ts | 54 +++++++++++++- ...ebar-search-list-element.component.spec.ts | 69 ++++++++++++------ ...ebar-search-list-element.component.spec.ts | 54 +++++++++++++- ...ebar-search-list-element.component.spec.ts | 55 +++++++++++++- ...ebar-search-list-element.component.spec.ts | 54 +++++++++++++- ...ebar-search-list-element.component.spec.ts | 66 +++++++++++------ ...ebar-search-list-element.component.spec.ts | 66 +++++++++++------ ...ebar-search-list-element.component.spec.ts | 54 +++++++++++++- 9 files changed, 439 insertions(+), 106 deletions(-) diff --git a/src/app/entity-groups/journal-entities/item-list-elements/sidebar-search-list-elements/journal-issue/journal-issue-sidebar-search-list-element.component.spec.ts b/src/app/entity-groups/journal-entities/item-list-elements/sidebar-search-list-elements/journal-issue/journal-issue-sidebar-search-list-element.component.spec.ts index 643c5348c25..dc692644bda 100644 --- a/src/app/entity-groups/journal-entities/item-list-elements/sidebar-search-list-elements/journal-issue/journal-issue-sidebar-search-list-element.component.spec.ts +++ b/src/app/entity-groups/journal-entities/item-list-elements/sidebar-search-list-elements/journal-issue/journal-issue-sidebar-search-list-element.component.spec.ts @@ -1,5 +1,11 @@ -import { DSpaceObject } from 'src/app/core/shared/dspace-object.model'; -import { followLink } from 'src/app/shared/utils/follow-link-config.model'; +import { + catchError, + Observable, + of, + switchMap, +} from 'rxjs'; +import { RemoteData } from 'src/app/core/data/remote-data'; +import { Community } from 'src/app/core/shared/community.model'; import { Collection } from '../../../../../core/shared/collection.model'; import { Item } from '../../../../../core/shared/item.model'; @@ -39,30 +45,53 @@ const parent = Object.assign(new Collection(), { ], }, }); -function getExpectedHierarchicalTitle(parentObj: DSpaceObject, obj: ItemSearchResult): string { - let titles: string[] = [obj.indexableObject.metadata['dc.title'][0].value]; - let currentParent: DSpaceObject = parentObj; - while (currentParent) { - titles.unshift(currentParent.metadata['dc.title'][0].value); - currentParent = this.getParent(); +function getExpectedHierarchicalTitle(parentObj: Collection, obj: ItemSearchResult): Observable { + let titles: string[] = []; + if (obj.indexableObject.metadata['dc.title']) { + titles = [obj.indexableObject.metadata['dc.title'][0].value]; } + let currentParent: Collection = parentObj; - return titles.join(' > '); -} + const fetchParentTitles = (currParent: Collection | Community): Observable => { + if (!currParent) { + return of([]); + } -function getParent(): DSpaceObject { - if (this.dso && typeof this.dso.getParentLinkKey === 'function') { - const parentLinkKey = this.dso.getParentLinkKey(); - const parentObj = this.linkService.resolveLink(this.dso, followLink(parentLinkKey))[parentLinkKey]; - if (parentObj && parentObj.payload) { - return parentObj.payload; + if (currParent.parentCommunity) { + return currParent.parentCommunity.pipe( + switchMap((remoteData: RemoteData) => { + if (remoteData.hasSucceeded && remoteData.payload) { + const parentTitle = remoteData.payload.name; + titles.unshift(parentTitle); + return fetchParentTitles(remoteData.payload); + } + return of([]); + }), + catchError(() => of([])), + ); + } else { + return of([]); } - } - return undefined; + }; + + return fetchParentTitles(currentParent).pipe( + switchMap(() => titles.join(' > ')), + ); } -const expectedHierarchicalTitle = getExpectedHierarchicalTitle(parent, object); -describe('JournalIssueSidebarSearchListElementComponent', - createSidebarSearchListElementTests(JournalIssueSidebarSearchListElementComponent, object, parent, expectedHierarchicalTitle, 'title', '5 - 7'), -); +const expectedHierarchicalTitle = getExpectedHierarchicalTitle(parent, object); +if (expectedHierarchicalTitle) { + expectedHierarchicalTitle.subscribe((hierarchicalTitle: string) => { + describe('JournalIssueSidebarSearchListElementComponent', () => { + createSidebarSearchListElementTests( + JournalIssueSidebarSearchListElementComponent, + object, + parent, + hierarchicalTitle, + 'title', + '1234, 5678', + ); + }); + }); +} diff --git a/src/app/entity-groups/journal-entities/item-list-elements/sidebar-search-list-elements/journal-volume/journal-volume-sidebar-search-list-element.component.spec.ts b/src/app/entity-groups/journal-entities/item-list-elements/sidebar-search-list-elements/journal-volume/journal-volume-sidebar-search-list-element.component.spec.ts index 16f13945337..aa4e3a6d2be 100644 --- a/src/app/entity-groups/journal-entities/item-list-elements/sidebar-search-list-elements/journal-volume/journal-volume-sidebar-search-list-element.component.spec.ts +++ b/src/app/entity-groups/journal-entities/item-list-elements/sidebar-search-list-elements/journal-volume/journal-volume-sidebar-search-list-element.component.spec.ts @@ -1,3 +1,12 @@ +import { + catchError, + Observable, + of, + switchMap, +} from 'rxjs'; +import { RemoteData } from 'src/app/core/data/remote-data'; +import { Community } from 'src/app/core/shared/community.model'; + import { Collection } from '../../../../../core/shared/collection.model'; import { Item } from '../../../../../core/shared/item.model'; import { ItemSearchResult } from '../../../../../shared/object-collection/shared/item-search-result.model'; @@ -40,6 +49,45 @@ const parent = Object.assign(new Collection(), { }, }); -describe('JournalVolumeSidebarSearchListElementComponent', - createSidebarSearchListElementTests(JournalVolumeSidebarSearchListElementComponent, object, parent, 'parent title', 'title', 'journal title (1) (2)'), -); +function getExpectedHierarchicalTitle(parentObj: Collection, obj: ItemSearchResult): Observable { + let titles: string[] = []; + if (obj.indexableObject.metadata['dc.title']) { + titles = [obj.indexableObject.metadata['dc.title'][0].value]; + } + let currentParent: Collection = parentObj; + + const fetchParentTitles = (currParent: Collection | Community): Observable => { + if (!currParent) { + return of([]); + } + + if (currParent.parentCommunity) { + return currParent.parentCommunity.pipe( + switchMap((remoteData: RemoteData) => { + if (remoteData.hasSucceeded && remoteData.payload) { + const parentTitle = remoteData.payload.name; + titles.unshift(parentTitle); + return fetchParentTitles(remoteData.payload); + } + return of([]); + }), + catchError(() => of([])), + ); + } else { + return of([]); + } + }; + + return fetchParentTitles(currentParent).pipe( + switchMap(() => titles.join(' > ')), + ); +} + +const expectedHierarchicalTitle = getExpectedHierarchicalTitle(parent, object); +if (expectedHierarchicalTitle) { + expectedHierarchicalTitle.subscribe((hierarchicalTitle: string) => { + describe('JournalVolumeSidebarSearchListElementComponent', () => { + createSidebarSearchListElementTests(JournalVolumeSidebarSearchListElementComponent, object, parent, hierarchicalTitle, 'title', 'journal title (1) (2)'); + }); + }); +} diff --git a/src/app/entity-groups/journal-entities/item-list-elements/sidebar-search-list-elements/journal/journal-sidebar-search-list-element.component.spec.ts b/src/app/entity-groups/journal-entities/item-list-elements/sidebar-search-list-elements/journal/journal-sidebar-search-list-element.component.spec.ts index cf537b8743b..8b73d728b34 100644 --- a/src/app/entity-groups/journal-entities/item-list-elements/sidebar-search-list-elements/journal/journal-sidebar-search-list-element.component.spec.ts +++ b/src/app/entity-groups/journal-entities/item-list-elements/sidebar-search-list-elements/journal/journal-sidebar-search-list-element.component.spec.ts @@ -1,5 +1,12 @@ -import { DSpaceObject } from 'src/app/core/shared/dspace-object.model'; -import { followLink } from 'src/app/shared/utils/follow-link-config.model'; +import { + catchError, + map, + Observable, + of, + switchMap, +} from 'rxjs'; +import { RemoteData } from 'src/app/core/data/remote-data'; +import { Community } from 'src/app/core/shared/community.model'; import { Collection } from '../../../../../core/shared/collection.model'; import { Item } from '../../../../../core/shared/item.model'; @@ -38,30 +45,48 @@ const parent = Object.assign(new Collection(), { }, }); -function getExpectedHierarchicalTitle(parentObj: DSpaceObject, obj: ItemSearchResult): string { - let titles: string[] = [obj.indexableObject.metadata['dc.title'][0].value]; - let currentParent: DSpaceObject = parentObj; - - while (currentParent) { - titles.unshift(currentParent.metadata['dc.title'][0].value); - currentParent = this.getParent(); +function getExpectedHierarchicalTitle(parentObj: Collection, obj: ItemSearchResult): Observable { + let titles: string[] = []; + if (obj.indexableObject.metadata['dc.title']) { + titles = [obj.indexableObject.metadata['dc.title'][0].value]; } + let currentParent: Collection = parentObj; - return titles.join(' > '); -} + const fetchParentTitles = (currParent: Collection | Community): Observable => { + if (!currParent) { + return of([]); + } -function getParent(): DSpaceObject { - if (this.dso && typeof this.dso.getParentLinkKey === 'function') { - const parentLinkKey = this.dso.getParentLinkKey(); - const parentObj = this.linkService.resolveLink(this.dso, followLink(parentLinkKey))[parentLinkKey]; - if (parentObj && parentObj.payload) { - return parentObj.payload; + if (currParent.parentCommunity) { + return currParent.parentCommunity.pipe( + switchMap((remoteData: RemoteData) => { + if (remoteData.hasSucceeded && remoteData.payload) { + const parentTitle = remoteData.payload.name; + titles.unshift(parentTitle); + if (remoteData.payload) { + return fetchParentTitles(remoteData.payload); + } + } + return of([]); + }), + catchError(() => of([])), + map(() => titles), + ); } + }; + + if (fetchParentTitles(currentParent)) { + return fetchParentTitles(currentParent).pipe( + map(() => titles.join(' > ')), + ); } - return undefined; } -const expectedHierarchicalTitle = getExpectedHierarchicalTitle(parent, object); -describe('JournalSidebarSearchListElementComponent', - createSidebarSearchListElementTests(JournalSidebarSearchListElementComponent, object, parent, expectedHierarchicalTitle, 'title', '1234, 5678'), -); +const expectedHierarchicalTitle = getExpectedHierarchicalTitle(parent, object); +if (expectedHierarchicalTitle) { + expectedHierarchicalTitle.subscribe((hierarchicalTitle: string) => { + describe('JournalSidebarSearchListElementComponent', () => { + createSidebarSearchListElementTests(JournalSidebarSearchListElementComponent, object, parent, hierarchicalTitle, 'title', '1234, 5678'); + }); + }); +} diff --git a/src/app/entity-groups/research-entities/item-list-elements/sidebar-search-list-elements/org-unit/org-unit-sidebar-search-list-element.component.spec.ts b/src/app/entity-groups/research-entities/item-list-elements/sidebar-search-list-elements/org-unit/org-unit-sidebar-search-list-element.component.spec.ts index 4d3f27f6ef4..352687de2d5 100644 --- a/src/app/entity-groups/research-entities/item-list-elements/sidebar-search-list-elements/org-unit/org-unit-sidebar-search-list-element.component.spec.ts +++ b/src/app/entity-groups/research-entities/item-list-elements/sidebar-search-list-elements/org-unit/org-unit-sidebar-search-list-element.component.spec.ts @@ -1,3 +1,12 @@ +import { + catchError, + Observable, + of, + switchMap, +} from 'rxjs'; +import { RemoteData } from 'src/app/core/data/remote-data'; +import { Community } from 'src/app/core/shared/community.model'; + import { Collection } from '../../../../../core/shared/collection.model'; import { Item } from '../../../../../core/shared/item.model'; import { ItemSearchResult } from '../../../../../shared/object-collection/shared/item-search-result.model'; @@ -37,6 +46,45 @@ const parent = Object.assign(new Collection(), { }, }); -describe('OrgUnitSidebarSearchListElementComponent', - createSidebarSearchListElementTests(OrgUnitSidebarSearchListElementComponent, object, parent, 'parent title', 'title', 'description'), -); +function getExpectedHierarchicalTitle(parentObj: Collection, obj: ItemSearchResult): Observable { + let titles: string[] = []; + if (obj.indexableObject.metadata['dc.title']) { + titles = [obj.indexableObject.metadata['dc.title'][0].value]; + } + let currentParent: Collection = parentObj; + + const fetchParentTitles = (currParent: Collection | Community): Observable => { + if (!currParent) { + return of([]); + } + + if (currParent.parentCommunity) { + return currParent.parentCommunity.pipe( + switchMap((remoteData: RemoteData) => { + if (remoteData.hasSucceeded && remoteData.payload) { + const parentTitle = remoteData.payload.name; + titles.unshift(parentTitle); + return fetchParentTitles(remoteData.payload); + } + return of([]); + }), + catchError(() => of([])), + ); + } else { + return of([]); + } + }; + + return fetchParentTitles(currentParent).pipe( + switchMap(() => titles.join(' > ')), + ); +} + +const expectedHierarchicalTitle = getExpectedHierarchicalTitle(parent, object); +if (expectedHierarchicalTitle) { + expectedHierarchicalTitle.subscribe((hierarchicalTitle: string) => { + describe('OrgUnitSidebarSearchListElementComponent', () => { + createSidebarSearchListElementTests(OrgUnitSidebarSearchListElementComponent, object, parent, hierarchicalTitle, 'title', 'description'); + }); + }); +} diff --git a/src/app/entity-groups/research-entities/item-list-elements/sidebar-search-list-elements/person/person-sidebar-search-list-element.component.spec.ts b/src/app/entity-groups/research-entities/item-list-elements/sidebar-search-list-elements/person/person-sidebar-search-list-element.component.spec.ts index 6e614c58114..9ba619637bd 100644 --- a/src/app/entity-groups/research-entities/item-list-elements/sidebar-search-list-elements/person/person-sidebar-search-list-element.component.spec.ts +++ b/src/app/entity-groups/research-entities/item-list-elements/sidebar-search-list-elements/person/person-sidebar-search-list-element.component.spec.ts @@ -1,3 +1,12 @@ +import { + catchError, + Observable, + of, + switchMap, +} from 'rxjs'; +import { RemoteData } from 'src/app/core/data/remote-data'; +import { Community } from 'src/app/core/shared/community.model'; + import { Collection } from '../../../../../core/shared/collection.model'; import { Item } from '../../../../../core/shared/item.model'; import { ItemSearchResult } from '../../../../../shared/object-collection/shared/item-search-result.model'; @@ -42,7 +51,45 @@ const parent = Object.assign(new Collection(), { }, }); -describe('PersonSidebarSearchListElementComponent', - createSidebarSearchListElementTests(PersonSidebarSearchListElementComponent, object, parent, 'parent title', 'family name, given name', 'job title', [ - ]), -); +function getExpectedHierarchicalTitle(parentObj: Collection, obj: ItemSearchResult): Observable { + let titles: string[] = []; + if (obj.indexableObject.metadata['dc.title']) { + titles = [obj.indexableObject.metadata['dc.title'][0].value]; + } + let currentParent: Collection = parentObj; + + const fetchParentTitles = (currParent: Collection | Community): Observable => { + if (!currParent) { + return of([]); + } + + if (currParent.parentCommunity) { + return currParent.parentCommunity.pipe( + switchMap((remoteData: RemoteData) => { + if (remoteData.hasSucceeded && remoteData.payload) { + const parentTitle = remoteData.payload.name; + titles.unshift(parentTitle); + return fetchParentTitles(remoteData.payload); + } + return of([]); + }), + catchError(() => of([])), + ); + } else { + return of([]); + } + }; + + return fetchParentTitles(currentParent).pipe( + switchMap(() => titles.join(' > ')), + ); +} + +const expectedHierarchicalTitle = getExpectedHierarchicalTitle(parent, object); +if (expectedHierarchicalTitle) { + expectedHierarchicalTitle.subscribe((hierarchicalTitle: string) => { + describe('PersonSidebarSearchListElementComponent', () => { + createSidebarSearchListElementTests(PersonSidebarSearchListElementComponent, object, parent, hierarchicalTitle, 'family name,given name', 'job title', []); + }); + }); +} diff --git a/src/app/entity-groups/research-entities/item-list-elements/sidebar-search-list-elements/project/project-sidebar-search-list-element.component.spec.ts b/src/app/entity-groups/research-entities/item-list-elements/sidebar-search-list-elements/project/project-sidebar-search-list-element.component.spec.ts index a7be69965fc..becb8842a41 100644 --- a/src/app/entity-groups/research-entities/item-list-elements/sidebar-search-list-elements/project/project-sidebar-search-list-element.component.spec.ts +++ b/src/app/entity-groups/research-entities/item-list-elements/sidebar-search-list-elements/project/project-sidebar-search-list-element.component.spec.ts @@ -1,3 +1,12 @@ +import { + catchError, + Observable, + of, + switchMap, +} from 'rxjs'; +import { RemoteData } from 'src/app/core/data/remote-data'; +import { Community } from 'src/app/core/shared/community.model'; + import { Collection } from '../../../../../core/shared/collection.model'; import { Item } from '../../../../../core/shared/item.model'; import { ItemSearchResult } from '../../../../../shared/object-collection/shared/item-search-result.model'; @@ -27,6 +36,45 @@ const parent = Object.assign(new Collection(), { }, }); -describe('ProjectSidebarSearchListElementComponent', - createSidebarSearchListElementTests(ProjectSidebarSearchListElementComponent, object, parent, 'parent title', 'title', undefined), -); +function getExpectedHierarchicalTitle(parentObj: Collection, obj: ItemSearchResult): Observable { + let titles: string[] = []; + if (obj.indexableObject.metadata['dc.title']) { + titles = [obj.indexableObject.metadata['dc.title'][0].value]; + } + let currentParent: Collection = parentObj; + + const fetchParentTitles = (currParent: Collection | Community): Observable => { + if (!currParent) { + return of([]); + } + + if (currParent.parentCommunity) { + return currParent.parentCommunity.pipe( + switchMap((remoteData: RemoteData) => { + if (remoteData.hasSucceeded && remoteData.payload) { + const parentTitle = remoteData.payload.name; + titles.unshift(parentTitle); + return fetchParentTitles(remoteData.payload); + } + return of([]); + }), + catchError(() => of([])), + ); + } else { + return of([]); + } + }; + + return fetchParentTitles(currentParent).pipe( + switchMap(() => titles.join(' > ')), + ); +} + +const expectedHierarchicalTitle = getExpectedHierarchicalTitle(parent, object); +if (expectedHierarchicalTitle) { + expectedHierarchicalTitle.subscribe((hierarchicalTitle: string) => { + describe('ProjectSidebarSearchListElementComponent', () => { + createSidebarSearchListElementTests(ProjectSidebarSearchListElementComponent, object, parent, hierarchicalTitle, 'title', undefined); + }); + }); +} diff --git a/src/app/shared/object-list/sidebar-search-list-element/collection/collection-sidebar-search-list-element.component.spec.ts b/src/app/shared/object-list/sidebar-search-list-element/collection/collection-sidebar-search-list-element.component.spec.ts index c0f6d98f798..1109b32621e 100644 --- a/src/app/shared/object-list/sidebar-search-list-element/collection/collection-sidebar-search-list-element.component.spec.ts +++ b/src/app/shared/object-list/sidebar-search-list-element/collection/collection-sidebar-search-list-element.component.spec.ts @@ -1,5 +1,10 @@ -import { DSpaceObject } from 'src/app/core/shared/dspace-object.model'; -import { followLink } from 'src/app/shared/utils/follow-link-config.model'; +import { + catchError, + Observable, + of, + switchMap, +} from 'rxjs'; +import { RemoteData } from 'src/app/core/data/remote-data'; import { Collection } from '../../../../core/shared/collection.model'; import { Community } from '../../../../core/shared/community.model'; @@ -35,30 +40,45 @@ const parent = Object.assign(new Community(), { }, }); -function getExpectedHierarchicalTitle(parentObj: DSpaceObject, obj: CollectionSearchResult): string { - let titles: string[] = [obj.indexableObject.metadata['dc.title'][0].value]; - let currentParent: DSpaceObject = parentObj; - - while (currentParent) { - titles.unshift(currentParent.metadata['dc.title'][0].value); - currentParent = this.getParent(); +function getExpectedHierarchicalTitle(parentObj: Community, obj: CollectionSearchResult): Observable { + let titles: string[] = []; + if (obj.indexableObject.metadata['dc.title']) { + titles = [obj.indexableObject.metadata['dc.title'][0].value]; } + let currentParent: Community = parentObj; - return titles.join(' > '); -} + const fetchParentTitles = (currParent: Collection | Community): Observable => { + if (!currParent) { + return of([]); + } -function getParent(): DSpaceObject { - if (this.dso && typeof this.dso.getParentLinkKey === 'function') { - const parentLinkKey = this.dso.getParentLinkKey(); - const parentObj = this.linkService.resolveLink(this.dso, followLink(parentLinkKey))[parentLinkKey]; - if (parentObj && parentObj.payload) { - return parentObj.payload; + if (currParent.parentCommunity) { + return currParent.parentCommunity.pipe( + switchMap((remoteData: RemoteData) => { + if (remoteData.hasSucceeded && remoteData.payload) { + const parentTitle = remoteData.payload.name; + titles.unshift(parentTitle); + return fetchParentTitles(remoteData.payload); + } + return of([]); + }), + catchError(() => of([])), + ); + } else { + return of([]); } - } - return undefined; + }; + + return fetchParentTitles(currentParent).pipe( + switchMap(() => titles.join(' > ')), + ); } -const expectedHierarchicalTitle = getExpectedHierarchicalTitle(parent, object); -describe('CollectionSidebarSearchListElementComponent', - createSidebarSearchListElementTests(CollectionSidebarSearchListElementComponent, object, parent, expectedHierarchicalTitle, 'title', 'description'), -); +const expectedHierarchicalTitle = getExpectedHierarchicalTitle(parent, object); +if (expectedHierarchicalTitle) { + expectedHierarchicalTitle.subscribe((hierarchicalTitle: string) => { + describe('CollectionSidebarSearchListElementComponent', () => { + createSidebarSearchListElementTests(CollectionSidebarSearchListElementComponent, object, parent, hierarchicalTitle, 'title', 'description'); + }); + }); +} diff --git a/src/app/shared/object-list/sidebar-search-list-element/community/community-sidebar-search-list-element.component.spec.ts b/src/app/shared/object-list/sidebar-search-list-element/community/community-sidebar-search-list-element.component.spec.ts index 17af62a7e05..626081ca7f6 100644 --- a/src/app/shared/object-list/sidebar-search-list-element/community/community-sidebar-search-list-element.component.spec.ts +++ b/src/app/shared/object-list/sidebar-search-list-element/community/community-sidebar-search-list-element.component.spec.ts @@ -1,5 +1,10 @@ -import { DSpaceObject } from 'src/app/core/shared/dspace-object.model'; -import { followLink } from 'src/app/shared/utils/follow-link-config.model'; +import { + catchError, + Observable, + of, + switchMap, +} from 'rxjs'; +import { RemoteData } from 'src/app/core/data/remote-data'; import { Community } from '../../../../core/shared/community.model'; import { CommunitySearchResult } from '../../../object-collection/shared/community-search-result.model'; @@ -34,30 +39,45 @@ const parent = Object.assign(new Community(), { }, }); -function getExpectedHierarchicalTitle(parentObj: DSpaceObject, obj: CommunitySearchResult): string { - let titles: string[] = [obj.indexableObject.metadata['dc.title'][0].value]; - let currentParent: DSpaceObject = parentObj; - - while (currentParent) { - titles.unshift(currentParent.metadata['dc.title'][0].value); - currentParent = this.getParent(); +function getExpectedHierarchicalTitle(parentObj: Community, obj: CommunitySearchResult): Observable { + let titles: string[] = []; + if (obj.indexableObject.metadata['dc.title']) { + titles = [obj.indexableObject.metadata['dc.title'][0].value]; } + let currentParent: Community = parentObj; - return titles.join(' > '); -} + const fetchParentTitles = (currParent: Community): Observable => { + if (!currParent) { + return of([]); + } -function getParent(): DSpaceObject { - if (this.dso && typeof this.dso.getParentLinkKey === 'function') { - const parentLinkKey = this.dso.getParentLinkKey(); - const parentObj = this.linkService.resolveLink(this.dso, followLink(parentLinkKey))[parentLinkKey]; - if (parentObj && parentObj.payload) { - return parentObj.payload; + if (currParent.parentCommunity) { + return currParent.parentCommunity.pipe( + switchMap((remoteData: RemoteData) => { + if (remoteData.hasSucceeded && remoteData.payload) { + const parentTitle = remoteData.payload.name; + titles.unshift(parentTitle); + return fetchParentTitles(remoteData.payload); + } + return of([]); + }), + catchError(() => of([])), + ); + } else { + return of([]); } - } - return undefined; + }; + + return fetchParentTitles(currentParent).pipe( + switchMap(() => titles.join(' > ')), + ); } -const expectedHierarchicalTitle = getExpectedHierarchicalTitle(parent, object); -describe('CommunitySidebarSearchListElementComponent', - createSidebarSearchListElementTests(CommunitySidebarSearchListElementComponent, object, parent, expectedHierarchicalTitle, 'title', 'description'), -); +const expectedHierarchicalTitle = getExpectedHierarchicalTitle(parent, object); +if (expectedHierarchicalTitle) { + expectedHierarchicalTitle.subscribe((hierarchicalTitle: string) => { + describe('CommunitySidebarSearchListElementComponent', () => { + createSidebarSearchListElementTests(CommunitySidebarSearchListElementComponent, object, parent, hierarchicalTitle, 'title', 'description'); + }); + }); +} diff --git a/src/app/shared/object-list/sidebar-search-list-element/item-types/publication/publication-sidebar-search-list-element.component.spec.ts b/src/app/shared/object-list/sidebar-search-list-element/item-types/publication/publication-sidebar-search-list-element.component.spec.ts index d078d8e1c5b..d7f9e38dec4 100644 --- a/src/app/shared/object-list/sidebar-search-list-element/item-types/publication/publication-sidebar-search-list-element.component.spec.ts +++ b/src/app/shared/object-list/sidebar-search-list-element/item-types/publication/publication-sidebar-search-list-element.component.spec.ts @@ -1,3 +1,12 @@ +import { + catchError, + Observable, + of, + switchMap, +} from 'rxjs'; +import { RemoteData } from 'src/app/core/data/remote-data'; +import { Community } from 'src/app/core/shared/community.model'; + import { Collection } from '../../../../../core/shared/collection.model'; import { Item } from '../../../../../core/shared/item.model'; import { ItemSearchResult } from '../../../../object-collection/shared/item-search-result.model'; @@ -42,6 +51,45 @@ const parent = Object.assign(new Collection(), { }, }); -describe('PublicationSidebarSearchListElementComponent', - createSidebarSearchListElementTests(PublicationSidebarSearchListElementComponent, object, parent, 'parent title', 'title', '(publisher, date) author'), -); +function getExpectedHierarchicalTitle(parentObj: Collection, obj: ItemSearchResult): Observable { + let titles: string[] = []; + if (obj.indexableObject.metadata['dc.title']) { + titles = [obj.indexableObject.metadata['dc.title'][0].value]; + } + let currentParent: Collection = parentObj; + + const fetchParentTitles = (currParent: Collection | Community): Observable => { + if (!currParent) { + return of([]); + } + + if (currParent.parentCommunity) { + return currParent.parentCommunity.pipe( + switchMap((remoteData: RemoteData) => { + if (remoteData.hasSucceeded && remoteData.payload) { + const parentTitle = remoteData.payload.name; + titles.unshift(parentTitle); + return fetchParentTitles(remoteData.payload); + } + return of([]); + }), + catchError(() => of([])), + ); + } else { + return of([]); + } + }; + + return fetchParentTitles(currentParent).pipe( + switchMap(() => titles.join(' > ')), + ); +} + +const expectedHierarchicalTitle = getExpectedHierarchicalTitle(parent, object); +if (expectedHierarchicalTitle) { + expectedHierarchicalTitle.subscribe((hierarchicalTitle: string) => { + describe('PublicationSidebarSearchListElementComponent', () => { + createSidebarSearchListElementTests(PublicationSidebarSearchListElementComponent, object, parent, hierarchicalTitle, 'title', '(publisher, date) author'); + }); + }); +}