|
| 1 | +import { |
| 2 | + EnvironmentInjector, |
| 3 | + runInInjectionContext, |
| 4 | +} from '@angular/core'; |
| 5 | +import { TestBed } from '@angular/core/testing'; |
| 6 | +import { editItemBreadcrumbResolver } from '@dspace/core/breadcrumbs/edit-item-breadcrumb.resolver'; |
| 7 | +import { Item } from '@dspace/core/shared/item.model'; |
| 8 | +import { getTestScheduler } from 'jasmine-marbles'; |
| 9 | +import { of } from 'rxjs'; |
| 10 | + |
| 11 | +import { ItemDataService } from '../data/item-data.service'; |
| 12 | +import { createSuccessfulRemoteDataObject$ } from '../utilities/remote-data.utils'; |
| 13 | +import { DSOBreadcrumbsService } from './dso-breadcrumbs.service'; |
| 14 | + |
| 15 | +describe('editItemBreadcrumbResolver', () => { |
| 16 | + describe('resolve', () => { |
| 17 | + let resolver: any; |
| 18 | + let dsoBreadcrumbService: any; |
| 19 | + let itemDataService: any; |
| 20 | + let testItem: Item; |
| 21 | + let uuid: string; |
| 22 | + let breadcrumbUrl: string; |
| 23 | + let currentUrl: string; |
| 24 | + |
| 25 | + beforeEach(() => { |
| 26 | + uuid = '1234-65487-12354-1235'; |
| 27 | + breadcrumbUrl = `/items/${uuid}`; |
| 28 | + currentUrl = `${breadcrumbUrl}/edit`; |
| 29 | + testItem = Object.assign(new Item(), { |
| 30 | + uuid: uuid, |
| 31 | + type: 'item', |
| 32 | + }); |
| 33 | + |
| 34 | + itemDataService = { |
| 35 | + findById: () => createSuccessfulRemoteDataObject$(testItem), |
| 36 | + }; |
| 37 | + |
| 38 | + dsoBreadcrumbService = { |
| 39 | + getRepresentativeName: () => testItem.uuid, |
| 40 | + getBreadcrumbs: () => of({ provider: dsoBreadcrumbService, key: testItem, url: breadcrumbUrl }), |
| 41 | + }; |
| 42 | + |
| 43 | + TestBed.configureTestingModule({ |
| 44 | + providers: [ |
| 45 | + { provide: DSOBreadcrumbsService, useValue: dsoBreadcrumbService }, |
| 46 | + { provide: ItemDataService, useValue: itemDataService }, |
| 47 | + ], |
| 48 | + }); |
| 49 | + |
| 50 | + resolver = editItemBreadcrumbResolver; |
| 51 | + }); |
| 52 | + |
| 53 | + it('should resolve a breadcrumb config for the correct uuid', () => { |
| 54 | + const injector = TestBed.inject(EnvironmentInjector); |
| 55 | + const resolvedConfig = runInInjectionContext(injector, () => |
| 56 | + resolver({ params: { id: testItem.uuid + ':FULL' } } as any, { url: currentUrl } as any), |
| 57 | + ); |
| 58 | + const expectedConfig = { provider: dsoBreadcrumbService, key: testItem, url: breadcrumbUrl }; |
| 59 | + getTestScheduler().expectObservable(resolvedConfig).toBe('(a|)', { a: expectedConfig }); |
| 60 | + }); |
| 61 | + }); |
| 62 | +}); |
0 commit comments