mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-15 14:03:06 +00:00
start of tests
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<li class="sidebar-section">
|
<li class="sidebar-section">
|
||||||
<a class="nav-item nav-link shortcut-icon" [routerLink]="section.model.link">
|
<a class="nav-item nav-link shortcut-icon" [routerLink]="itemModel.link">
|
||||||
<i class="fas fa-{{section.icon}} fa-fw"></i>
|
<i class="fas fa-{{section.icon}} fa-fw"></i>
|
||||||
</a>
|
</a>
|
||||||
<div class="sidebar-collapsible">
|
<div class="sidebar-collapsible">
|
||||||
|
@@ -3,6 +3,8 @@ import { MenuSectionComponent } from '../../../shared/menu/menu-section/menu-sec
|
|||||||
import { MenuID } from '../../../shared/menu/initial-menus-state';
|
import { MenuID } from '../../../shared/menu/initial-menus-state';
|
||||||
import { MenuService } from '../../../shared/menu/menu.service';
|
import { MenuService } from '../../../shared/menu/menu.service';
|
||||||
import { rendersSectionForMenu } from '../../../shared/menu/menu-section.decorator';
|
import { rendersSectionForMenu } from '../../../shared/menu/menu-section.decorator';
|
||||||
|
import { LinkMenuItemModel } from '../../../shared/menu/menu-item/models/link.model';
|
||||||
|
import { MenuSection } from '../../../shared/menu/menu.reducer';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a non-expandable section in the admin sidebar
|
* Represents a non-expandable section in the admin sidebar
|
||||||
@@ -15,13 +17,15 @@ import { rendersSectionForMenu } from '../../../shared/menu/menu-section.decorat
|
|||||||
})
|
})
|
||||||
@rendersSectionForMenu(MenuID.ADMIN, false)
|
@rendersSectionForMenu(MenuID.ADMIN, false)
|
||||||
export class AdminSidebarSectionComponent extends MenuSectionComponent implements OnInit {
|
export class AdminSidebarSectionComponent extends MenuSectionComponent implements OnInit {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This section resides in the Admin Sidebar
|
* This section resides in the Admin Sidebar
|
||||||
*/
|
*/
|
||||||
menuID: MenuID = MenuID.ADMIN;
|
menuID: MenuID = MenuID.ADMIN;
|
||||||
|
itemModel;
|
||||||
constructor(@Inject('sectionDataProvider') menuSection, protected menuService: MenuService, protected injector: Injector,) {
|
constructor(@Inject('sectionDataProvider') menuSection: MenuSection, protected menuService: MenuService, protected injector: Injector,) {
|
||||||
super(menuSection, menuService, injector);
|
super(menuSection, menuService, injector);
|
||||||
|
this.itemModel = menuSection.model as LinkMenuItemModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
@@ -1,11 +1,9 @@
|
|||||||
import { StoreEffects } from './store.effects';
|
import { StoreEffects } from './store.effects';
|
||||||
import { NotificationsEffects } from './shared/notifications/notifications.effects';
|
import { NotificationsEffects } from './shared/notifications/notifications.effects';
|
||||||
import { NavbarEffects } from './navbar/navbar.effects';
|
import { NavbarEffects } from './navbar/navbar.effects';
|
||||||
import { MenuEffects } from './shared/menu/menu.effects';
|
|
||||||
|
|
||||||
export const appEffects = [
|
export const appEffects = [
|
||||||
StoreEffects,
|
StoreEffects,
|
||||||
NavbarEffects,
|
NavbarEffects,
|
||||||
NotificationsEffects,
|
NotificationsEffects,
|
||||||
MenuEffects
|
|
||||||
];
|
];
|
||||||
|
@@ -14,7 +14,7 @@ import { AppState } from '../../app.reducer';
|
|||||||
import { formReducer } from './form.reducer';
|
import { formReducer } from './form.reducer';
|
||||||
import { getMockFormBuilderService } from '../mocks/mock-form-builder-service';
|
import { getMockFormBuilderService } from '../mocks/mock-form-builder-service';
|
||||||
|
|
||||||
fdescribe('FormService test suite', () => {
|
describe('FormService test suite', () => {
|
||||||
const config = {
|
const config = {
|
||||||
form: {
|
form: {
|
||||||
validatorMap: {
|
validatorMap: {
|
||||||
|
@@ -1,63 +0,0 @@
|
|||||||
import { Actions, Effect, ofType } from '@ngrx/effects';
|
|
||||||
import { Action } from '@ngrx/store';
|
|
||||||
import { Observable } from 'rxjs/index';
|
|
||||||
import { filter, first, map, switchMap } from 'rxjs/operators';
|
|
||||||
import { Injectable } from '@angular/core';
|
|
||||||
import {
|
|
||||||
ActivateMenuSectionAction,
|
|
||||||
CollapseMenuAction,
|
|
||||||
DeactivateMenuSectionAction,
|
|
||||||
ExpandMenuAction,
|
|
||||||
MenuActionTypes,
|
|
||||||
ToggleActiveMenuSectionAction,
|
|
||||||
ToggleMenuAction,
|
|
||||||
} from './menu.actions';
|
|
||||||
import { MenuState } from './menu.reducer';
|
|
||||||
import { MenuService } from './menu.service';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class MenuEffects {
|
|
||||||
//
|
|
||||||
// @Effect()
|
|
||||||
// public collapseSectionsOnCollapseMenu$: Observable<Action> = this.actions$.pipe(
|
|
||||||
// ofType(MenuActionTypes.COLLAPSE_MENU, MenuActionTypes.TOGGLE_MENU),
|
|
||||||
// switchMap((action: CollapseMenuAction | ToggleMenuAction) => {
|
|
||||||
// return this.menuService.getMenu(action.menuID).pipe(
|
|
||||||
// first(),
|
|
||||||
// switchMap((menu: MenuState) => {
|
|
||||||
// if (menu.collapsed) {
|
|
||||||
// const sections = menu.sections;
|
|
||||||
// return Object.keys(sections)
|
|
||||||
// .map((id) => {
|
|
||||||
// return new DeactivateMenuSectionAction(action.menuID, id);
|
|
||||||
// }
|
|
||||||
// )
|
|
||||||
// } else {
|
|
||||||
// return [{ type: 'NO_ACTION' }];
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// )
|
|
||||||
// )
|
|
||||||
// })
|
|
||||||
// );
|
|
||||||
|
|
||||||
// @Effect()
|
|
||||||
// public onExpandSectionMenuExpandMenu: Observable<Action> = this.actions$.pipe(
|
|
||||||
// ofType(MenuActionTypes.ACTIVATE_SECTION, MenuActionTypes.TOGGLE_ACTIVE_SECTION),
|
|
||||||
// switchMap((action: ActivateMenuSectionAction | ToggleActiveMenuSectionAction) => {
|
|
||||||
// return this.menuService.getMenu(action.menuID).pipe(
|
|
||||||
// first(),
|
|
||||||
// map((menu: MenuState) => {
|
|
||||||
// if (menu.collapsed) {
|
|
||||||
// return new ExpandMenuAction(menu.id)
|
|
||||||
// } else {
|
|
||||||
// return { type: 'NO_ACTION' };
|
|
||||||
// }
|
|
||||||
// }));
|
|
||||||
// })
|
|
||||||
// );
|
|
||||||
|
|
||||||
constructor(private actions$: Actions,
|
|
||||||
private menuService: MenuService) {
|
|
||||||
}
|
|
||||||
}
|
|
119
src/app/shared/menu/menu.service.spec.ts
Normal file
119
src/app/shared/menu/menu.service.spec.ts
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
import * as ngrx from '@ngrx/store';
|
||||||
|
import { Store } from '@ngrx/store';
|
||||||
|
import { async, TestBed } from '@angular/core/testing';
|
||||||
|
import { MenuService } from './menu.service';
|
||||||
|
import { cold, hot } from 'jasmine-marbles';
|
||||||
|
import { MenuID } from './initial-menus-state';
|
||||||
|
import { of as observableOf } from 'rxjs';
|
||||||
|
|
||||||
|
fdescribe('MenuService', () => {
|
||||||
|
let service: MenuService;
|
||||||
|
let selectSpy;
|
||||||
|
const store = observableOf({}) as any;
|
||||||
|
const fakeMenu = { id: MenuID.ADMIN } as any;
|
||||||
|
const visibleSection1 = {
|
||||||
|
id: 'section',
|
||||||
|
visible: true
|
||||||
|
};
|
||||||
|
const visibleSection2 = {
|
||||||
|
id: 'section_2',
|
||||||
|
visible: true
|
||||||
|
};
|
||||||
|
const hiddenSection3 = {
|
||||||
|
id: 'section_3',
|
||||||
|
visible: false
|
||||||
|
};
|
||||||
|
const subSection4 = {
|
||||||
|
id: 'section_4',
|
||||||
|
visible: true,
|
||||||
|
parentID: 'section1'
|
||||||
|
};
|
||||||
|
|
||||||
|
const topSections = {
|
||||||
|
section: visibleSection1,
|
||||||
|
section_2: visibleSection2,
|
||||||
|
section_3: hiddenSection3,
|
||||||
|
section_4: subSection4
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
providers: [
|
||||||
|
{ provide: Store, useValue: store },
|
||||||
|
{ provide: MenuService, useValue: service }
|
||||||
|
]
|
||||||
|
}).compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
service = new MenuService(store);
|
||||||
|
selectSpy = spyOnProperty(ngrx, 'select');
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getMenu', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
selectSpy.and.callFake(() => {
|
||||||
|
return () => {
|
||||||
|
return () => hot('a', {
|
||||||
|
a: fakeMenu
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('should return the menu', () => {
|
||||||
|
|
||||||
|
const result = service.getMenu(MenuID.ADMIN);
|
||||||
|
const expected = cold('b', {
|
||||||
|
b: fakeMenu
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result).toBeObservable(expected);
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getMenuTopSections', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
selectSpy.and.callFake(() => {
|
||||||
|
return () => {
|
||||||
|
return () => hot('a', {
|
||||||
|
a: topSections
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('should return only the visible top MenuSections', () => {
|
||||||
|
|
||||||
|
const result = service.getMenuTopSections(MenuID.ADMIN);
|
||||||
|
const expected = cold('b', {
|
||||||
|
b: [visibleSection1, visibleSection2]
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result).toBeObservable(expected);
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO finish this test
|
||||||
|
describe('getSubSectionsByParentID', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
selectSpy.and.callFake(() => {
|
||||||
|
return () => {
|
||||||
|
return () => hot('a', {
|
||||||
|
a: topSections
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('should return only the visible top MenuSections', () => {
|
||||||
|
|
||||||
|
const result = service.getMenuTopSections(MenuID.ADMIN);
|
||||||
|
const expected = cold('b', {
|
||||||
|
b: [visibleSection1, visibleSection2]
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result).toBeObservable(expected);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
});
|
Reference in New Issue
Block a user