-
Notifications
You must be signed in to change notification settings - Fork 566
Expand file tree
/
Copy pathcommunity-breadcrumb.resolver.spec.ts
More file actions
91 lines (83 loc) · 2.91 KB
/
Copy pathcommunity-breadcrumb.resolver.spec.ts
File metadata and controls
91 lines (83 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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();
});
});