mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
97183 MenuResolver tests for regular user
This commit is contained in:
@@ -19,6 +19,7 @@ import { cold } from 'jasmine-marbles';
|
|||||||
import createSpy = jasmine.createSpy;
|
import createSpy = jasmine.createSpy;
|
||||||
import { createSuccessfulRemoteDataObject$ } from './shared/remote-data.utils';
|
import { createSuccessfulRemoteDataObject$ } from './shared/remote-data.utils';
|
||||||
import { createPaginatedList } from './shared/testing/utils.test';
|
import { createPaginatedList } from './shared/testing/utils.test';
|
||||||
|
import { Feature } from './core/shared/feature.model';
|
||||||
|
|
||||||
const BOOLEAN = { t: true, f: false };
|
const BOOLEAN = { t: true, f: false };
|
||||||
const MENU_STATE = {
|
const MENU_STATE = {
|
||||||
@@ -142,29 +143,7 @@ describe('MenuResolver', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('createAdminMenu$', () => {
|
describe('createAdminMenu$', () => {
|
||||||
it('should retrieve the menu by ID return an Observable that emits true as soon as it is created', () => {
|
const dontShowAdminSections = () => {
|
||||||
(menuService as any).getMenu.and.returnValue(cold('--u--m', {
|
|
||||||
u: undefined,
|
|
||||||
m: MENU_STATE,
|
|
||||||
}));
|
|
||||||
|
|
||||||
expect(resolver.createAdminMenu$()).toBeObservable(cold('-----(t|)', BOOLEAN));
|
|
||||||
expect(menuService.getMenu).toHaveBeenCalledOnceWith(MenuID.ADMIN);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('for regular user', () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
authorizationService.isAuthorized = createSpy('isAuthorized').and.callFake(() => {
|
|
||||||
return observableOf(false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach((done) => {
|
|
||||||
resolver.createAdminMenu$().subscribe((_) => {
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not show site admin section', () => {
|
it('should not show site admin section', () => {
|
||||||
expect(menuService.addSection).toHaveBeenCalledWith(MenuID.ADMIN, jasmine.objectContaining({
|
expect(menuService.addSection).toHaveBeenCalledWith(MenuID.ADMIN, jasmine.objectContaining({
|
||||||
id: 'admin_search', visible: false,
|
id: 'admin_search', visible: false,
|
||||||
@@ -183,19 +162,6 @@ describe('MenuResolver', () => {
|
|||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not show edit_community', () => {
|
|
||||||
expect(menuService.addSection).toHaveBeenCalledWith(MenuID.ADMIN, jasmine.objectContaining({
|
|
||||||
id: 'edit_community', visible: false,
|
|
||||||
}));
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not show edit_collection', () => {
|
|
||||||
expect(menuService.addSection).toHaveBeenCalledWith(MenuID.ADMIN, jasmine.objectContaining({
|
|
||||||
id: 'edit_collection', visible: false,
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should not show access control section', () => {
|
it('should not show access control section', () => {
|
||||||
expect(menuService.addSection).toHaveBeenCalledWith(MenuID.ADMIN, jasmine.objectContaining({
|
expect(menuService.addSection).toHaveBeenCalledWith(MenuID.ADMIN, jasmine.objectContaining({
|
||||||
id: 'access_control', visible: false,
|
id: 'access_control', visible: false,
|
||||||
@@ -222,6 +188,122 @@ describe('MenuResolver', () => {
|
|||||||
id: 'export', visible: true,
|
id: 'export', visible: true,
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const dontShowNewSection = () => {
|
||||||
|
it('should not show the "New" section', () => {
|
||||||
|
expect(menuService.addSection).toHaveBeenCalledWith(MenuID.ADMIN, jasmine.objectContaining({
|
||||||
|
id: 'new_community', visible: false,
|
||||||
|
}));
|
||||||
|
expect(menuService.addSection).toHaveBeenCalledWith(MenuID.ADMIN, jasmine.objectContaining({
|
||||||
|
id: 'new_collection', visible: false,
|
||||||
|
}));
|
||||||
|
expect(menuService.addSection).toHaveBeenCalledWith(MenuID.ADMIN, jasmine.objectContaining({
|
||||||
|
id: 'new_item', visible: false,
|
||||||
|
}));
|
||||||
|
expect(menuService.addSection).toHaveBeenCalledWith(MenuID.ADMIN, jasmine.objectContaining({
|
||||||
|
id: 'new', visible: false,
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const dontShowEditSection = () => {
|
||||||
|
it('should not show the "Edit" section', () => {
|
||||||
|
expect(menuService.addSection).toHaveBeenCalledWith(MenuID.ADMIN, jasmine.objectContaining({
|
||||||
|
id: 'edit_community', visible: false,
|
||||||
|
}));
|
||||||
|
expect(menuService.addSection).toHaveBeenCalledWith(MenuID.ADMIN, jasmine.objectContaining({
|
||||||
|
id: 'edit_collection', visible: false,
|
||||||
|
}));
|
||||||
|
expect(menuService.addSection).toHaveBeenCalledWith(MenuID.ADMIN, jasmine.objectContaining({
|
||||||
|
id: 'edit_item', visible: false,
|
||||||
|
}));
|
||||||
|
expect(menuService.addSection).toHaveBeenCalledWith(MenuID.ADMIN, jasmine.objectContaining({
|
||||||
|
id: 'edit', visible: false,
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
it('should retrieve the menu by ID return an Observable that emits true as soon as it is created', () => {
|
||||||
|
(menuService as any).getMenu.and.returnValue(cold('--u--m', {
|
||||||
|
u: undefined,
|
||||||
|
m: MENU_STATE,
|
||||||
|
}));
|
||||||
|
|
||||||
|
expect(resolver.createAdminMenu$()).toBeObservable(cold('-----(t|)', BOOLEAN));
|
||||||
|
expect(menuService.getMenu).toHaveBeenCalledOnceWith(MenuID.ADMIN);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('for regular user', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
authorizationService.isAuthorized = createSpy('isAuthorized').and.callFake((featureID) => {
|
||||||
|
return observableOf(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach((done) => {
|
||||||
|
resolver.createAdminMenu$().subscribe((_) => {
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
dontShowAdminSections();
|
||||||
|
dontShowNewSection();
|
||||||
|
dontShowEditSection();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('regular user who can submit', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
authorizationService.isAuthorized = createSpy('isAuthorized')
|
||||||
|
.and.callFake((featureID: FeatureID) => {
|
||||||
|
return observableOf(featureID === FeatureID.CanSubmit);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach((done) => {
|
||||||
|
resolver.createAdminMenu$().subscribe((_) => {
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should show "New Item" section', () => {
|
||||||
|
expect(menuService.addSection).toHaveBeenCalledWith(MenuID.ADMIN, jasmine.objectContaining({
|
||||||
|
id: 'new_item', visible: true,
|
||||||
|
}));
|
||||||
|
expect(menuService.addSection).toHaveBeenCalledWith(MenuID.ADMIN, jasmine.objectContaining({
|
||||||
|
id: 'new', visible: true,
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
dontShowAdminSections();
|
||||||
|
dontShowEditSection();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('regular user who can edit items', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
authorizationService.isAuthorized = createSpy('isAuthorized')
|
||||||
|
.and.callFake((featureID: FeatureID) => {
|
||||||
|
return observableOf(featureID === FeatureID.CanEditItem);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach((done) => {
|
||||||
|
resolver.createAdminMenu$().subscribe((_) => {
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should show "Edit Item" section', () => {
|
||||||
|
expect(menuService.addSection).toHaveBeenCalledWith(MenuID.ADMIN, jasmine.objectContaining({
|
||||||
|
id: 'edit_item', visible: true,
|
||||||
|
}));
|
||||||
|
expect(menuService.addSection).toHaveBeenCalledWith(MenuID.ADMIN, jasmine.objectContaining({
|
||||||
|
id: 'edit', visible: true,
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
dontShowAdminSections();
|
||||||
|
dontShowNewSection();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('for site admin', () => {
|
describe('for site admin', () => {
|
||||||
|
@@ -66,6 +66,10 @@ export class MenuServiceStub {
|
|||||||
return observableOf(true);
|
return observableOf(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isMenuVisibleWithVisibleSections(id: MenuID): Observable<boolean> {
|
||||||
|
return observableOf(true);
|
||||||
|
}
|
||||||
|
|
||||||
isMenuCollapsed(id: MenuID): Observable<boolean> {
|
isMenuCollapsed(id: MenuID): Observable<boolean> {
|
||||||
return observableOf(false);
|
return observableOf(false);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user