diff --git a/src/app/+admin/admin-sidebar/admin-sidebar.component.spec.ts b/src/app/+admin/admin-sidebar/admin-sidebar.component.spec.ts index ec571ff3d5..18e2988f48 100644 --- a/src/app/+admin/admin-sidebar/admin-sidebar.component.spec.ts +++ b/src/app/+admin/admin-sidebar/admin-sidebar.component.spec.ts @@ -16,6 +16,8 @@ import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { RouterTestingModule } from '@angular/router/testing'; import { ActivatedRoute } from '@angular/router'; import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service'; +import { FeatureID } from '../../core/data/feature-authorization/feature-id'; +import createSpy = jasmine.createSpy; describe('AdminSidebarComponent', () => { let comp: AdminSidebarComponent; @@ -170,4 +172,150 @@ describe('AdminSidebarComponent', () => { expect(menuService.collapseMenuPreview).toHaveBeenCalled(); })); }); + + describe('menu', () => { + beforeEach(() => { + spyOn(menuService, 'addSection'); + }); + + describe('for regular user', () => { + beforeEach(() => { + authorizationService.isAuthorized = createSpy('isAuthorized').and.callFake(() => { + return observableOf(false); + }); + }); + + beforeEach(() => { + comp.createMenu(); + }); + + it('should not show site admin section', () => { + expect(menuService.addSection).toHaveBeenCalledWith(comp.menuID, jasmine.objectContaining({ + id: 'admin_search', visible: false, + })); + expect(menuService.addSection).toHaveBeenCalledWith(comp.menuID, jasmine.objectContaining({ + id: 'registries', visible: false, + })); + expect(menuService.addSection).toHaveBeenCalledWith(comp.menuID, jasmine.objectContaining({ + parentID: 'registries', visible: false, + })); + expect(menuService.addSection).toHaveBeenCalledWith(comp.menuID, jasmine.objectContaining({ + id: 'curation_tasks', visible: false, + })); + expect(menuService.addSection).toHaveBeenCalledWith(comp.menuID, jasmine.objectContaining({ + id: 'workflow', visible: false, + })); + }); + + it('should not show edit_community', () => { + expect(menuService.addSection).toHaveBeenCalledWith(comp.menuID, jasmine.objectContaining({ + id: 'edit_community', visible: false, + })); + + }); + + it('should not show edit_collection', () => { + expect(menuService.addSection).toHaveBeenCalledWith(comp.menuID, jasmine.objectContaining({ + id: 'edit_collection', visible: false, + })); + }); + + it('should not show access control section', () => { + expect(menuService.addSection).toHaveBeenCalledWith(comp.menuID, jasmine.objectContaining({ + id: 'access_control', visible: false, + })); + expect(menuService.addSection).toHaveBeenCalledWith(comp.menuID, jasmine.objectContaining({ + parentID: 'access_control', visible: false, + })); + + }); + }) + + describe('for site admin', () => { + beforeEach(() => { + authorizationService.isAuthorized = createSpy('isAuthorized').and.callFake((featureID: FeatureID) => { + return observableOf(featureID === FeatureID.AdministratorOf); + }); + }); + + beforeEach(() => { + comp.createMenu(); + }); + + it('should contain site admin section', () => { + expect(menuService.addSection).toHaveBeenCalledWith(comp.menuID, jasmine.objectContaining({ + id: 'admin_search', visible: true, + })); + expect(menuService.addSection).toHaveBeenCalledWith(comp.menuID, jasmine.objectContaining({ + id: 'registries', visible: true, + })); + expect(menuService.addSection).toHaveBeenCalledWith(comp.menuID, jasmine.objectContaining({ + parentID: 'registries', visible: true, + })); + expect(menuService.addSection).toHaveBeenCalledWith(comp.menuID, jasmine.objectContaining({ + id: 'curation_tasks', visible: true, + })); + expect(menuService.addSection).toHaveBeenCalledWith(comp.menuID, jasmine.objectContaining({ + id: 'workflow', visible: true, + })); + }); + }); + + describe('for community admin', () => { + beforeEach(() => { + authorizationService.isAuthorized = createSpy('isAuthorized').and.callFake((featureID: FeatureID) => { + return observableOf(featureID === FeatureID.IsCommunityAdmin); + }); + }); + + beforeEach(() => { + comp.createMenu(); + }); + + it('should show edit_community', () => { + expect(menuService.addSection).toHaveBeenCalledWith(comp.menuID, jasmine.objectContaining({ + id: 'edit_community', visible: true, + })); + }); + }); + + describe('for collection admin', () => { + beforeEach(() => { + authorizationService.isAuthorized = createSpy('isAuthorized').and.callFake((featureID: FeatureID) => { + return observableOf(featureID === FeatureID.IsCollectionAdmin); + }); + }); + + beforeEach(() => { + comp.createMenu(); + }); + + it('should show edit_collection', () => { + expect(menuService.addSection).toHaveBeenCalledWith(comp.menuID, jasmine.objectContaining({ + id: 'edit_collection', visible: true, + })); + }); + }); + + describe('for group admin', () => { + beforeEach(() => { + authorizationService.isAuthorized = createSpy('isAuthorized').and.callFake((featureID: FeatureID) => { + return observableOf(featureID === FeatureID.CanManageGroups); + }); + }); + + beforeEach(() => { + comp.createMenu(); + }); + + it('should show access control section', () => { + expect(menuService.addSection).toHaveBeenCalledWith(comp.menuID, jasmine.objectContaining({ + id: 'access_control', visible: true, + })); + expect(menuService.addSection).toHaveBeenCalledWith(comp.menuID, jasmine.objectContaining({ + parentID: 'access_control', visible: true, + })); + }); + }); + }); }); diff --git a/src/app/shared/testing/menu-service.stub.ts b/src/app/shared/testing/menu-service.stub.ts index 1b6824c8ee..4f2828a7e1 100644 --- a/src/app/shared/testing/menu-service.stub.ts +++ b/src/app/shared/testing/menu-service.stub.ts @@ -52,7 +52,7 @@ export class MenuServiceStub { deactivateSection(): void { /***/ } - addSection(): void { /***/ + addSection(menuID: MenuID, section: MenuSection): void { /***/ } removeSection(): void { /***/