Skip to content

Commit 1c1bcc7

Browse files
committed
Merge branch 'refactor-menu-resolvers-7.6_basic-providers-tests' into refactor-menu-resolvers-7.6_sketch-branch
2 parents a105131 + 83dc069 commit 1c1bcc7

17 files changed

Lines changed: 1056 additions & 2 deletions
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/**
2+
* The contents of this file are subject to the license and copyright
3+
* detailed in the LICENSE and NOTICE files at the root of the source
4+
* tree and available online at
5+
*
6+
* http://www.dspace.org/license/
7+
*/
8+
9+
import { TestBed } from '@angular/core/testing';
10+
import { MenuItemType } from '../menu-item-type.model';
11+
import { MenuSubSection, MenuTopSection } from './expandable-menu-provider';
12+
import { AuthorizationDataServiceStub } from '../../testing/authorization-service.stub';
13+
import { of as observableOf } from 'rxjs';
14+
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
15+
import { FeatureID } from '../../../core/data/feature-authorization/feature-id';
16+
import { AccessControlMenuProvider } from './access-control.menu';
17+
import { ScriptDataService } from '../../../core/data/processes/script-data.service';
18+
import { ScriptServiceStub } from '../../testing/script-service.stub';
19+
20+
const expectedTopSection: MenuTopSection = {
21+
model: {
22+
type: MenuItemType.TEXT,
23+
text: 'menu.section.access_control',
24+
},
25+
icon: 'key'
26+
};
27+
28+
const expectedSubSections: MenuSubSection[] = [
29+
{
30+
visible: true,
31+
model: {
32+
type: MenuItemType.LINK,
33+
text: 'menu.section.access_control_people',
34+
link: '/access-control/epeople',
35+
},
36+
},
37+
{
38+
visible: false,
39+
model: {
40+
type: MenuItemType.LINK,
41+
text: 'menu.section.access_control_groups',
42+
link: '/access-control/groups',
43+
},
44+
},
45+
{
46+
visible: true,
47+
model: {
48+
type: MenuItemType.LINK,
49+
text: 'menu.section.access_control_bulk',
50+
link: '/access-control/bulk-access',
51+
},
52+
},
53+
];
54+
55+
describe('AccessControlMenuProvider', () => {
56+
let provider: AccessControlMenuProvider;
57+
let authorizationServiceStub = new AuthorizationDataServiceStub();
58+
59+
beforeEach(() => {
60+
spyOn(authorizationServiceStub, 'isAuthorized').and.callFake((id: FeatureID) => {
61+
if (id === FeatureID.CanManageGroups) {
62+
return observableOf(false);
63+
} else {
64+
return observableOf(true);
65+
}
66+
});
67+
68+
TestBed.configureTestingModule({
69+
providers: [
70+
AccessControlMenuProvider,
71+
{ provide: AuthorizationDataService, useValue: authorizationServiceStub },
72+
{ provide: ScriptDataService, useClass: ScriptServiceStub },
73+
],
74+
});
75+
provider = TestBed.inject(AccessControlMenuProvider);
76+
});
77+
78+
it('should be created', () => {
79+
expect(provider).toBeTruthy();
80+
});
81+
82+
it('getTopSection should return expected menu section', (done) => {
83+
provider.getTopSection().subscribe((section) => {
84+
expect(section).toEqual(expectedTopSection);
85+
done();
86+
});
87+
});
88+
89+
it('getSubSections should return expected menu sections', (done) => {
90+
provider.getSubSections().subscribe((sections) => {
91+
expect(sections).toEqual(expectedSubSections);
92+
done();
93+
});
94+
});
95+
});
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* The contents of this file are subject to the license and copyright
3+
* detailed in the LICENSE and NOTICE files at the root of the source
4+
* tree and available online at
5+
*
6+
* http://www.dspace.org/license/
7+
*/
8+
9+
import { TestBed } from '@angular/core/testing';
10+
import { PartialMenuSection } from '../menu-provider';
11+
import { MenuItemType } from '../menu-item-type.model';
12+
import { AdminSearchMenuProvider } from './admin-search.menu';
13+
import { AuthorizationDataServiceStub } from '../../testing/authorization-service.stub';
14+
import { of as observableOf } from 'rxjs';
15+
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
16+
17+
const expectedSections: PartialMenuSection[] = [
18+
{
19+
visible: true,
20+
model: {
21+
type: MenuItemType.LINK,
22+
text: 'menu.section.admin_search',
23+
link: '/admin/search',
24+
},
25+
icon: 'search',
26+
},
27+
];
28+
29+
describe('AdminSearchMenuProvider', () => {
30+
let provider: AdminSearchMenuProvider;
31+
let authorizationServiceStub = new AuthorizationDataServiceStub();
32+
33+
beforeEach(() => {
34+
spyOn(authorizationServiceStub, 'isAuthorized').and.returnValue(
35+
observableOf(true)
36+
);
37+
38+
TestBed.configureTestingModule({
39+
providers: [
40+
AdminSearchMenuProvider,
41+
{ provide: AuthorizationDataService, useValue: authorizationServiceStub },
42+
],
43+
});
44+
provider = TestBed.inject(AdminSearchMenuProvider);
45+
});
46+
47+
it('should be created', () => {
48+
expect(provider).toBeTruthy();
49+
});
50+
51+
it('getSections should return expected menu sections', (done) => {
52+
provider.getSections().subscribe((sections) => {
53+
expect(sections).toEqual(expectedSections);
54+
done();
55+
});
56+
});
57+
});
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/**
2+
* The contents of this file are subject to the license and copyright
3+
* detailed in the LICENSE and NOTICE files at the root of the source
4+
* tree and available online at
5+
*
6+
* http://www.dspace.org/license/
7+
*/
8+
9+
import { TestBed } from '@angular/core/testing';
10+
import { BrowseMenuProvider } from './browse.menu';
11+
import { MenuItemType } from '../menu-item-type.model';
12+
import { MenuSubSection, MenuTopSection } from './expandable-menu-provider';
13+
import { BrowseService } from '../../../core/browse/browse.service';
14+
import { BrowseServiceStub } from '../../testing/browse-service.stub';
15+
import { ObjectCacheService } from '../../../core/cache/object-cache.service';
16+
import { getMockObjectCacheService } from '../../mocks/object-cache.service.mock';
17+
import { BrowseDefinition } from '../../../core/shared/browse-definition.model';
18+
import { createSuccessfulRemoteDataObject$ } from '../../remote-data.utils';
19+
import { createPaginatedList } from '../../testing/utils.test';
20+
21+
const expectedTopSection: MenuTopSection = {
22+
model: {
23+
type: MenuItemType.TEXT,
24+
text: 'menu.section.browse_global',
25+
},
26+
icon: 'globe',
27+
};
28+
29+
const expectedSubSections: MenuSubSection[] = [
30+
{
31+
visible: true,
32+
model: {
33+
type: MenuItemType.LINK,
34+
text: 'menu.section.browse_global_by_author',
35+
link: '/browse/author',
36+
},
37+
},
38+
{
39+
visible: true,
40+
model: {
41+
type: MenuItemType.LINK,
42+
text: 'menu.section.browse_global_by_subject',
43+
link: '/browse/subject',
44+
},
45+
},
46+
];
47+
48+
describe('BrowseMenuProvider', () => {
49+
let provider: BrowseMenuProvider;
50+
let browseServiceStub = new BrowseServiceStub();
51+
52+
beforeEach(() => {
53+
spyOn(browseServiceStub, 'getBrowseDefinitions').and.returnValue(
54+
createSuccessfulRemoteDataObject$(createPaginatedList([
55+
{ id: 'author' } as BrowseDefinition,
56+
{ id: 'subject' } as BrowseDefinition,
57+
]))
58+
);
59+
60+
TestBed.configureTestingModule({
61+
providers: [
62+
BrowseMenuProvider,
63+
{ provide: BrowseService, useValue: browseServiceStub },
64+
{ provide: ObjectCacheService, useValue: getMockObjectCacheService() },
65+
],
66+
});
67+
provider = TestBed.inject(BrowseMenuProvider);
68+
});
69+
70+
it('should be created', () => {
71+
expect(provider).toBeTruthy();
72+
});
73+
74+
it('getTopSection should return expected menu section', (done) => {
75+
provider.getTopSection().subscribe((section) => {
76+
expect(section).toEqual(expectedTopSection);
77+
done();
78+
});
79+
});
80+
81+
it('getSubSections should return expected menu sections', (done) => {
82+
provider.getSubSections().subscribe((sections) => {
83+
expect(sections).toEqual(expectedSubSections);
84+
done();
85+
});
86+
});
87+
});
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* The contents of this file are subject to the license and copyright
3+
* detailed in the LICENSE and NOTICE files at the root of the source
4+
* tree and available online at
5+
*
6+
* http://www.dspace.org/license/
7+
*/
8+
9+
import { TestBed } from '@angular/core/testing';
10+
import { CommunityListMenuProvider } from './community-list.menu';
11+
import { PartialMenuSection } from '../menu-provider';
12+
import { MenuItemType } from '../menu-item-type.model';
13+
14+
const expectedSections: PartialMenuSection[] = [
15+
{
16+
visible: true,
17+
model: {
18+
type: MenuItemType.LINK,
19+
text: `menu.section.browse_global_communities_and_collections`,
20+
link: `/community-list`,
21+
},
22+
icon: 'diagram-project'
23+
},
24+
];
25+
26+
describe('CommunityListMenuProvider', () => {
27+
let provider: CommunityListMenuProvider;
28+
29+
beforeEach(() => {
30+
TestBed.configureTestingModule({
31+
providers: [
32+
CommunityListMenuProvider,
33+
],
34+
});
35+
provider = TestBed.inject(CommunityListMenuProvider);
36+
});
37+
38+
it('should be created', () => {
39+
expect(provider).toBeTruthy();
40+
});
41+
42+
it('getSections should return expected menu sections', (done) => {
43+
provider.getSections().subscribe((sections) => {
44+
expect(sections).toEqual(expectedSections);
45+
done();
46+
});
47+
});
48+
});
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* The contents of this file are subject to the license and copyright
3+
* detailed in the LICENSE and NOTICE files at the root of the source
4+
* tree and available online at
5+
*
6+
* http://www.dspace.org/license/
7+
*/
8+
9+
import { TestBed } from '@angular/core/testing';
10+
import { PartialMenuSection } from '../menu-provider';
11+
import { MenuItemType } from '../menu-item-type.model';
12+
import { AuthorizationDataServiceStub } from '../../testing/authorization-service.stub';
13+
import { of as observableOf } from 'rxjs';
14+
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
15+
import { CurationMenuProvider } from './curation.menu';
16+
17+
const expectedSections: PartialMenuSection[] = [
18+
{
19+
visible: true,
20+
model: {
21+
type: MenuItemType.LINK,
22+
text: 'menu.section.curation_task',
23+
link: 'admin/curation-tasks',
24+
},
25+
icon: 'filter',
26+
},
27+
];
28+
29+
describe('CurationMenuProvider', () => {
30+
let provider: CurationMenuProvider;
31+
let authorizationServiceStub = new AuthorizationDataServiceStub();
32+
33+
beforeEach(() => {
34+
spyOn(authorizationServiceStub, 'isAuthorized').and.returnValue(
35+
observableOf(true)
36+
);
37+
38+
TestBed.configureTestingModule({
39+
providers: [
40+
CurationMenuProvider,
41+
{ provide: AuthorizationDataService, useValue: authorizationServiceStub },
42+
],
43+
});
44+
provider = TestBed.inject(CurationMenuProvider);
45+
});
46+
47+
it('should be created', () => {
48+
expect(provider).toBeTruthy();
49+
});
50+
51+
it('getSections should return expected menu sections', (done) => {
52+
provider.getSections().subscribe((sections) => {
53+
expect(sections).toEqual(expectedSections);
54+
done();
55+
});
56+
});
57+
});

0 commit comments

Comments
 (0)