mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 15:33:04 +00:00
intermediate commit
This commit is contained in:
@@ -5,15 +5,31 @@ import { MenuService } from './menu.service';
|
||||
import { cold, hot } from 'jasmine-marbles';
|
||||
import { MenuID } from './initial-menus-state';
|
||||
import { of as observableOf } from 'rxjs';
|
||||
import {
|
||||
ActivateMenuSectionAction,
|
||||
AddMenuSectionAction,
|
||||
CollapseMenuAction, CollapseMenuPreviewAction, DeactivateMenuSectionAction,
|
||||
ExpandMenuAction, ExpandMenuPreviewAction, HideMenuAction,
|
||||
RemoveMenuSectionAction, ShowMenuAction, ToggleActiveMenuSectionAction, ToggleMenuAction
|
||||
} from './menu.actions';
|
||||
|
||||
fdescribe('MenuService', () => {
|
||||
describe('MenuService', () => {
|
||||
let service: MenuService;
|
||||
let selectSpy;
|
||||
const store = observableOf({}) as any;
|
||||
const fakeMenu = { id: MenuID.ADMIN } as any;
|
||||
const store = Object.assign(observableOf({}), {
|
||||
dispatch: () => {/***/
|
||||
}
|
||||
}) as any;
|
||||
const fakeMenu = {
|
||||
id: MenuID.ADMIN,
|
||||
collapsed: true,
|
||||
visible: false,
|
||||
previewCollapsed: true
|
||||
} as any;
|
||||
const visibleSection1 = {
|
||||
id: 'section',
|
||||
visible: true
|
||||
visible: true,
|
||||
active: false
|
||||
};
|
||||
const visibleSection2 = {
|
||||
id: 'section_2',
|
||||
@@ -48,6 +64,7 @@ fdescribe('MenuService', () => {
|
||||
beforeEach(() => {
|
||||
service = new MenuService(store);
|
||||
selectSpy = spyOnProperty(ngrx, 'select');
|
||||
spyOn(store, 'dispatch');
|
||||
});
|
||||
|
||||
describe('getMenu', () => {
|
||||
@@ -83,37 +100,297 @@ fdescribe('MenuService', () => {
|
||||
};
|
||||
});
|
||||
});
|
||||
it('should return only the visible top MenuSections', () => {
|
||||
it('should return only the visible top MenuSections when mustBeVisible is true', () => {
|
||||
|
||||
const result = service.getMenuTopSections(MenuID.ADMIN);
|
||||
const expected = cold('b', {
|
||||
b: [visibleSection1, visibleSection2]
|
||||
});
|
||||
|
||||
expect(result).toBeObservable(expected);
|
||||
});
|
||||
|
||||
it('should return only the all top MenuSections when mustBeVisible is false', () => {
|
||||
|
||||
const result = service.getMenuTopSections(MenuID.ADMIN, false);
|
||||
const expected = cold('b', {
|
||||
b: [visibleSection1, visibleSection2, hiddenSection3]
|
||||
});
|
||||
|
||||
expect(result).toBeObservable(expected);
|
||||
})
|
||||
});
|
||||
|
||||
// TODO finish this test
|
||||
describe('getSubSectionsByParentID', () => {
|
||||
describe('when the subsection list is not empty', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
spyOn(service, 'getMenuSection').and.returnValue(observableOf(visibleSection1));
|
||||
selectSpy.and.callFake(() => {
|
||||
return () => {
|
||||
return () => hot('a', {
|
||||
a: ['id1', 'id2']
|
||||
}
|
||||
);
|
||||
};
|
||||
});
|
||||
});
|
||||
it('should return the MenuSections with the given parentID', () => {
|
||||
|
||||
const result = service.getSubSectionsByParentID(MenuID.ADMIN, 'fakeId');
|
||||
const expected = cold('b', {
|
||||
b: [visibleSection1, visibleSection1]
|
||||
});
|
||||
|
||||
expect(result).toBeObservable(expected);
|
||||
})
|
||||
});
|
||||
describe('when the subsection list is undefined', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
selectSpy.and.callFake(() => {
|
||||
return () => {
|
||||
return () => hot('a', {
|
||||
a: undefined
|
||||
}
|
||||
);
|
||||
};
|
||||
});
|
||||
});
|
||||
it('should return an observable that emits nothing', () => {
|
||||
|
||||
const result = service.getSubSectionsByParentID(MenuID.ADMIN, 'fakeId');
|
||||
const expected = cold('');
|
||||
|
||||
expect(result).toBeObservable(expected);
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
describe('hasSubSections', () => {
|
||||
describe('when the subsection list is not empty', () => {
|
||||
beforeEach(() => {
|
||||
selectSpy.and.callFake(() => {
|
||||
return () => {
|
||||
return () => hot('a', {
|
||||
a: ['id1', 'id2']
|
||||
}
|
||||
);
|
||||
};
|
||||
});
|
||||
});
|
||||
it('should return true', () => {
|
||||
|
||||
const result = service.hasSubSections(MenuID.ADMIN, 'fakeId');
|
||||
const expected = cold('b', {
|
||||
b: true
|
||||
});
|
||||
|
||||
expect(result).toBeObservable(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the subsection list is empty', () => {
|
||||
beforeEach(() => {
|
||||
selectSpy.and.callFake(() => {
|
||||
return () => {
|
||||
return () => hot('a', {
|
||||
a: []
|
||||
}
|
||||
);
|
||||
};
|
||||
});
|
||||
});
|
||||
it('should return false', () => {
|
||||
|
||||
const result = service.hasSubSections(MenuID.ADMIN, 'fakeId');
|
||||
const expected = cold('b', {
|
||||
b: false
|
||||
});
|
||||
|
||||
expect(result).toBeObservable(expected);
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
describe('getMenuSection', () => {
|
||||
beforeEach(() => {
|
||||
selectSpy.and.callFake(() => {
|
||||
return () => {
|
||||
return () => hot('a', {
|
||||
a: topSections
|
||||
a: hiddenSection3
|
||||
}
|
||||
);
|
||||
};
|
||||
});
|
||||
});
|
||||
it('should return only the visible top MenuSections', () => {
|
||||
it('should return false', () => {
|
||||
|
||||
const result = service.getMenuTopSections(MenuID.ADMIN);
|
||||
const result = service.getMenuSection(MenuID.ADMIN, 'fakeId');
|
||||
const expected = cold('b', {
|
||||
b: [visibleSection1, visibleSection2]
|
||||
b: hiddenSection3
|
||||
});
|
||||
|
||||
expect(result).toBeObservable(expected);
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
describe('isMenuCollapsed', () => {
|
||||
beforeEach(() => {
|
||||
spyOn(service, 'getMenu').and.returnValue(observableOf(fakeMenu));
|
||||
});
|
||||
it('should return true when the menu is collapsed', () => {
|
||||
|
||||
const result = service.isMenuCollapsed(MenuID.ADMIN);
|
||||
const expected = cold('(b|)', {
|
||||
b: fakeMenu.collapsed
|
||||
});
|
||||
|
||||
expect(result).toBeObservable(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isMenuPreviewCollapsed', () => {
|
||||
beforeEach(() => {
|
||||
spyOn(service, 'getMenu').and.returnValue(observableOf(fakeMenu));
|
||||
});
|
||||
it('should return true when the menu\'s preview is collapsed', () => {
|
||||
|
||||
const result = service.isMenuPreviewCollapsed(MenuID.ADMIN);
|
||||
const expected = cold('(b|)', {
|
||||
b: fakeMenu.previewCollapsed
|
||||
});
|
||||
|
||||
expect(result).toBeObservable(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isMenuVisible', () => {
|
||||
beforeEach(() => {
|
||||
spyOn(service, 'getMenu').and.returnValue(observableOf(fakeMenu));
|
||||
|
||||
});
|
||||
it('should return false when the menu is hidden', () => {
|
||||
|
||||
const result = service.isMenuVisible(MenuID.ADMIN);
|
||||
const expected = cold('(b|)', {
|
||||
b: fakeMenu.visible
|
||||
});
|
||||
|
||||
expect(result).toBeObservable(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isSectionActive', () => {
|
||||
beforeEach(() => {
|
||||
spyOn(service, 'getMenuSection').and.returnValue(observableOf(visibleSection1));
|
||||
});
|
||||
|
||||
it('should return false when the section is not active', () => {
|
||||
const result = service.isSectionActive(MenuID.ADMIN, 'fakeID');
|
||||
const expected = cold('(b|)', {
|
||||
b: visibleSection1.active
|
||||
});
|
||||
|
||||
expect(result).toBeObservable(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isSectionVisible', () => {
|
||||
beforeEach(() => {
|
||||
spyOn(service, 'getMenuSection').and.returnValue(observableOf(hiddenSection3));
|
||||
});
|
||||
|
||||
it('should return false when the section is hidden', () => {
|
||||
const result = service.isSectionVisible(MenuID.ADMIN, 'fakeID');
|
||||
const expected = cold('(b|)', {
|
||||
b: hiddenSection3.visible
|
||||
});
|
||||
expect(result).toBeObservable(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('addSection', () => {
|
||||
it('should dispatch an AddMenuSectionAction with the correct arguments', () => {
|
||||
service.addSection(MenuID.ADMIN, visibleSection1 as any);
|
||||
expect(store.dispatch).toHaveBeenCalledWith(new AddMenuSectionAction(MenuID.ADMIN, visibleSection1 as any));
|
||||
});
|
||||
});
|
||||
|
||||
describe('removeSection', () => {
|
||||
it('should dispatch an RemoveMenuSectionAction with the correct arguments', () => {
|
||||
service.removeSection(MenuID.ADMIN, 'fakeID');
|
||||
expect(store.dispatch).toHaveBeenCalledWith(new RemoveMenuSectionAction(MenuID.ADMIN, 'fakeID'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('expandMenu', () => {
|
||||
it('should dispatch an ExpandMenuAction with the correct arguments', () => {
|
||||
service.expandMenu(MenuID.ADMIN);
|
||||
expect(store.dispatch).toHaveBeenCalledWith(new ExpandMenuAction(MenuID.ADMIN));
|
||||
});
|
||||
});
|
||||
|
||||
describe('collapseMenu', () => {
|
||||
it('should dispatch an CollapseMenuAction with the correct arguments', () => {
|
||||
service.collapseMenu(MenuID.ADMIN);
|
||||
expect(store.dispatch).toHaveBeenCalledWith(new CollapseMenuAction(MenuID.ADMIN));
|
||||
});
|
||||
});
|
||||
|
||||
describe('expandMenuPreview', () => {
|
||||
it('should dispatch an ExpandMenuPreviewAction with the correct arguments', () => {
|
||||
service.expandMenuPreview(MenuID.ADMIN);
|
||||
expect(store.dispatch).toHaveBeenCalledWith(new ExpandMenuPreviewAction(MenuID.ADMIN));
|
||||
});
|
||||
});
|
||||
|
||||
describe('collapseMenuPreview', () => {
|
||||
it('should dispatch an CollapseMenuPreviewAction with the correct arguments', () => {
|
||||
service.collapseMenuPreview(MenuID.ADMIN);
|
||||
expect(store.dispatch).toHaveBeenCalledWith(new CollapseMenuPreviewAction(MenuID.ADMIN));
|
||||
});
|
||||
});
|
||||
|
||||
describe('toggleMenu', () => {
|
||||
it('should dispatch an ToggleMenuAction with the correct arguments', () => {
|
||||
service.toggleMenu(MenuID.ADMIN);
|
||||
expect(store.dispatch).toHaveBeenCalledWith(new ToggleMenuAction(MenuID.ADMIN));
|
||||
});
|
||||
});
|
||||
|
||||
describe('showMenu', () => {
|
||||
it('should dispatch an ShowMenuAction with the correct arguments', () => {
|
||||
service.showMenu(MenuID.ADMIN);
|
||||
expect(store.dispatch).toHaveBeenCalledWith(new ShowMenuAction(MenuID.ADMIN));
|
||||
});
|
||||
});
|
||||
|
||||
describe('hideMenu', () => {
|
||||
it('should dispatch an HideMenuAction with the correct arguments', () => {
|
||||
service.hideMenu(MenuID.ADMIN);
|
||||
expect(store.dispatch).toHaveBeenCalledWith(new HideMenuAction(MenuID.ADMIN));
|
||||
});
|
||||
});
|
||||
|
||||
describe('toggleActiveSection', () => {
|
||||
it('should dispatch an ToggleActiveMenuSectionAction with the correct arguments', () => {
|
||||
service.toggleActiveSection(MenuID.ADMIN, 'fakeID');
|
||||
expect(store.dispatch).toHaveBeenCalledWith(new ToggleActiveMenuSectionAction(MenuID.ADMIN, 'fakeID'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('activateSection', () => {
|
||||
it('should dispatch an ActivateMenuSectionAction with the correct arguments', () => {
|
||||
service.activateSection(MenuID.ADMIN, 'fakeID');
|
||||
expect(store.dispatch).toHaveBeenCalledWith(new ActivateMenuSectionAction(MenuID.ADMIN, 'fakeID'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('deactivateSection', () => {
|
||||
it('should dispatch an DeactivateMenuSectionAction with the correct arguments', () => {
|
||||
service.deactivateSection(MenuID.ADMIN, 'fakeID');
|
||||
expect(store.dispatch).toHaveBeenCalledWith(new DeactivateMenuSectionAction(MenuID.ADMIN, 'fakeID'));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user