-
Notifications
You must be signed in to change notification settings - Fork 529
Expand file tree
/
Copy pathexport.menu.spec.ts
More file actions
110 lines (97 loc) · 3.3 KB
/
export.menu.spec.ts
File metadata and controls
110 lines (97 loc) · 3.3 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
import { TestBed } from '@angular/core/testing';
import { AuthorizationDataService } from '@dspace/core/data/feature-authorization/authorization-data.service';
import { ScriptDataService } from '@dspace/core/data/processes/script-data.service';
import { AuthorizationDataServiceStub } from '@dspace/core/testing/authorization-service.stub';
import { ScriptServiceStub } from '@dspace/core/testing/script-service.stub';
import { of } from 'rxjs';
import { MenuItemType } from '../menu-item-type.model';
import { PartialMenuSection } from '../menu-provider.model';
import { ExportMenuProvider } from './export.menu';
describe('ExportMenuProvider', () => {
const expectedTopSection: PartialMenuSection = {
accessibilityHandle: 'export',
visible: true,
model: {
type: MenuItemType.TEXT,
text: 'menu.section.export',
},
icon: 'file-export',
};
const expectedSubSections: PartialMenuSection[] = [
{
visible: true,
model: {
type: MenuItemType.ONCLICK,
text: 'menu.section.export_metadata',
function: jasmine.any(Function) as any,
},
},
{
visible: true,
model: {
type: MenuItemType.ONCLICK,
text: 'menu.section.export_batch',
function: jasmine.any(Function) as any,
},
},
];
let provider: ExportMenuProvider;
let authorizationServiceStub = new AuthorizationDataServiceStub();
beforeEach(() => {
spyOn(authorizationServiceStub, 'isAuthorized').and.returnValue(
of(true),
);
TestBed.configureTestingModule({
providers: [
ExportMenuProvider,
{ provide: AuthorizationDataService, useValue: authorizationServiceStub },
{ provide: ScriptDataService, useClass: ScriptServiceStub },
],
});
provider = TestBed.inject(ExportMenuProvider);
});
it('should be created', () => {
expect(provider).toBeTruthy();
});
it('getTopSection should return expected menu section', (done) => {
provider.getTopSection().subscribe((section) => {
expect(section).toEqual(expectedTopSection);
done();
});
});
it('getSubSections should return expected menu sections', (done) => {
provider.getSubSections().subscribe((sections) => {
expect(sections).toEqual(expectedSubSections);
done();
});
});
describe('when user has no permissions', () => {
let noPermsProvider: ExportMenuProvider;
let noPermsAuthStub = new AuthorizationDataServiceStub();
beforeEach(() => {
spyOn(noPermsAuthStub, 'isAuthorized').and.returnValue(of(false));
TestBed.resetTestingModule();
TestBed.configureTestingModule({
providers: [
ExportMenuProvider,
{ provide: AuthorizationDataService, useValue: noPermsAuthStub },
{ provide: ScriptDataService, useClass: ScriptServiceStub },
],
});
noPermsProvider = TestBed.inject(ExportMenuProvider);
});
it('getTopSection should return visible false', (done) => {
noPermsProvider.getTopSection().subscribe((section) => {
expect(section.visible).toBeFalse();
done();
});
});
});
});