Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions src/app/core/breadcrumbs/community-breadcrumb.resolver.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { Community } from '../shared/community.model';
import { createSuccessfulRemoteDataObject$ } from '../utilities/remote-data.utils';
import { communityBreadcrumbResolver } from './community-breadcrumb.resolver';

describe('communityBreadcrumbResolver', () => {
let breadcrumbService: any;
let communityDataService: any;
let community: Community;
let parentCommunity: Community;
let state: any;

beforeEach(() => {
community = Object.assign(new Community(), {
uuid: '1234-65487-12354-1235',
type: 'community',
});
parentCommunity = Object.assign(new Community(), {
uuid: '4321-76548-45321-5321',
type: 'community',
});
breadcrumbService = {};
state = {};
communityDataService = jasmine.createSpyObj('communityDataService', ['findById']);
communityDataService.findById.and.callFake((uuid: string) =>
createSuccessfulRemoteDataObject$(uuid === parentCommunity.uuid ? parentCommunity : community),
);
});

it('should resolve the community from the route id', () => {
const resolvedConfig = (communityBreadcrumbResolver as any)(
{ data: {}, params: { id: community.uuid }, queryParams: {} } as any,
state,
breadcrumbService,
communityDataService,
);

let emitted = false;
resolvedConfig.subscribe((config) => {
emitted = true;
expect(config).toEqual({
provider: breadcrumbService,
key: community,
url: `/communities/${community.uuid}`,
});
});
expect(emitted).toBeTrue();
expect(communityDataService.findById.calls.mostRecent().args[0]).toEqual(community.uuid);
});

it('should resolve the parent community from the configured query parameter', () => {
const resolvedConfig = (communityBreadcrumbResolver as any)(
{
data: { breadcrumbQueryParam: 'parent' },
params: {},
queryParams: { parent: parentCommunity.uuid },
} as any,
state,
breadcrumbService,
communityDataService,
);

let emitted = false;
resolvedConfig.subscribe((config) => {
emitted = true;
expect(config).toEqual({
provider: breadcrumbService,
key: parentCommunity,
url: `/communities/${parentCommunity.uuid}`,
});
});
expect(emitted).toBeTrue();
expect(communityDataService.findById.calls.mostRecent().args[0]).toEqual(parentCommunity.uuid);
});

it('should not request a community when the configured query parameter is absent', () => {
const resolvedConfig = (communityBreadcrumbResolver as any)(
{ data: { breadcrumbQueryParam: 'parent' }, params: {}, queryParams: {} } as any,
state,
breadcrumbService,
communityDataService,
);

let emitted = false;
resolvedConfig.subscribe((config) => {
emitted = true;
expect(config).toBeUndefined();
});
expect(emitted).toBeTrue();
expect(communityDataService.findById).not.toHaveBeenCalled();
});
});
13 changes: 10 additions & 3 deletions src/app/core/breadcrumbs/community-breadcrumb.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import {
RouterStateSnapshot,
} from '@angular/router';
import { hasValue } from '@dspace/shared/utils/empty.util';
import { Observable } from 'rxjs';
import {
Observable,
of,
} from 'rxjs';

import { CommunityDataService } from '../data/community-data.service';
import {
Expand All @@ -31,11 +34,15 @@ export const communityBreadcrumbResolver: ResolveFn<BreadcrumbConfig<Community>>
dataService: CommunityDataService = inject(CommunityDataService),
): Observable<BreadcrumbConfig<Community>> => {
const linksToFollow: FollowLinkConfig<DSpaceObject>[] = COMMUNITY_PAGE_LINKS_TO_FOLLOW as FollowLinkConfig<DSpaceObject>[];
if (hasValue(route.data.breadcrumbQueryParam) && hasValue(route.queryParams[route.data.breadcrumbQueryParam])) {
if (hasValue(route.data.breadcrumbQueryParam)) {
const queryParam = route.queryParams[route.data.breadcrumbQueryParam];
if (!hasValue(queryParam)) {
return of(undefined);
}
return DSOBreadcrumbResolverByUuid(
route,
state,
route.queryParams[route.data.breadcrumbQueryParam],
queryParam,
breadcrumbService,
dataService,
...linksToFollow,
Expand Down
Loading