|
| 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 | +}); |
0 commit comments