|
| 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 { of as observableOf } from 'rxjs'; |
| 11 | + |
| 12 | +import { ConfigurationDataService } from '../../../core/data/configuration-data.service'; |
| 13 | +import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service'; |
| 14 | +import { FeatureID } from '../../../core/data/feature-authorization/feature-id'; |
| 15 | +import { ConfigurationProperty } from '../../../core/shared/configuration-property.model'; |
| 16 | +import { createSuccessfulRemoteDataObject$ } from '../../remote-data.utils'; |
| 17 | +import { AuthorizationDataServiceStub } from '../../testing/authorization-service.stub'; |
| 18 | +import { ConfigurationDataServiceStub } from '../../testing/configuration-data.service.stub'; |
| 19 | +import { LinkMenuItemModel } from '../menu-item/models/link.model'; |
| 20 | +import { TextMenuItemModel } from '../menu-item/models/text.model'; |
| 21 | +import { MenuItemType } from '../menu-item-type.model'; |
| 22 | +import { PartialMenuSection } from '../menu-provider.model'; |
| 23 | +import { CreateReportMenuProvider } from './create-report.menu'; |
| 24 | + |
| 25 | +describe('CreateReportMenuProvider', () => { |
| 26 | + const expectedTopSection: PartialMenuSection = { |
| 27 | + visible: true, |
| 28 | + model: { |
| 29 | + type: MenuItemType.TEXT, |
| 30 | + text: 'menu.section.reports', |
| 31 | + } as TextMenuItemModel, |
| 32 | + icon: 'file-alt', |
| 33 | + }; |
| 34 | + |
| 35 | + const expectedSubSections: PartialMenuSection[] = [ |
| 36 | + { |
| 37 | + visible: true, |
| 38 | + model: { |
| 39 | + type: MenuItemType.LINK, |
| 40 | + text: 'menu.section.reports.collections', |
| 41 | + link: '/admin/reports/collections', |
| 42 | + } as LinkMenuItemModel, |
| 43 | + icon: 'user-check', |
| 44 | + }, |
| 45 | + { |
| 46 | + visible: true, |
| 47 | + model: { |
| 48 | + type: MenuItemType.LINK, |
| 49 | + text: 'menu.section.reports.queries', |
| 50 | + link: '/admin/reports/queries', |
| 51 | + } as LinkMenuItemModel, |
| 52 | + icon: 'user-check', |
| 53 | + }, |
| 54 | + ]; |
| 55 | + |
| 56 | + let provider: CreateReportMenuProvider; |
| 57 | + let authorizationServiceStub = new AuthorizationDataServiceStub(); |
| 58 | + let configurationDataService = new ConfigurationDataServiceStub(); |
| 59 | + |
| 60 | + beforeEach(() => { |
| 61 | + spyOn(authorizationServiceStub, 'isAuthorized').and.callFake((id: FeatureID) => { |
| 62 | + if (id === FeatureID.CanManageGroups) { |
| 63 | + return observableOf(false); |
| 64 | + } else { |
| 65 | + return observableOf(true); |
| 66 | + } |
| 67 | + }); |
| 68 | + |
| 69 | + spyOn(configurationDataService, 'findByPropertyName').and.callFake((property: string) => { |
| 70 | + return createSuccessfulRemoteDataObject$(Object.assign({}, new ConfigurationProperty(), { values: ['true'] })); |
| 71 | + }); |
| 72 | + |
| 73 | + TestBed.configureTestingModule({ |
| 74 | + providers: [ |
| 75 | + CreateReportMenuProvider, |
| 76 | + { provide: AuthorizationDataService, useValue: authorizationServiceStub }, |
| 77 | + { provide: ConfigurationDataService, useValue: configurationDataService }, |
| 78 | + ], |
| 79 | + }); |
| 80 | + provider = TestBed.inject(CreateReportMenuProvider); |
| 81 | + }); |
| 82 | + |
| 83 | + it('should be created', () => { |
| 84 | + expect(provider).toBeTruthy(); |
| 85 | + }); |
| 86 | + |
| 87 | + it('getTopSection should return expected menu section', (done) => { |
| 88 | + provider.getTopSection().subscribe((section) => { |
| 89 | + expect(section).toEqual(expectedTopSection); |
| 90 | + done(); |
| 91 | + }); |
| 92 | + }); |
| 93 | + |
| 94 | + it('getSubSections should return expected menu sections', (done) => { |
| 95 | + provider.getSubSections().subscribe((sections) => { |
| 96 | + expect(sections).toEqual(expectedSubSections); |
| 97 | + done(); |
| 98 | + }); |
| 99 | + }); |
| 100 | +}); |
0 commit comments