Commits
Yura Bondarenko authored 42a2c3c7e29
6 6 | import { CollectionDataService } from '../../../core/data/collection-data.service'; |
7 7 | import { ActivatedRoute, Router } from '@angular/router'; |
8 8 | import { of as observableOf } from 'rxjs'; |
9 9 | import { NO_ERRORS_SCHEMA } from '@angular/core'; |
10 10 | import { CollectionMetadataComponent } from './collection-metadata.component'; |
11 11 | import { NotificationsService } from '../../../shared/notifications/notifications.service'; |
12 12 | import { Item } from '../../../core/shared/item.model'; |
13 13 | import { ItemTemplateDataService } from '../../../core/data/item-template-data.service'; |
14 14 | import { Collection } from '../../../core/shared/collection.model'; |
15 15 | import { RequestService } from '../../../core/data/request.service'; |
16 - | import { createSuccessfulRemoteDataObject, createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils'; |
16 + | import { createFailedRemoteDataObject$, createSuccessfulRemoteDataObject, createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils'; |
17 17 | import { getCollectionItemTemplateRoute } from '../../collection-page-routing-paths'; |
18 18 | |
19 19 | describe('CollectionMetadataComponent', () => { |
20 20 | let comp: CollectionMetadataComponent; |
21 21 | let fixture: ComponentFixture<CollectionMetadataComponent>; |
22 22 | let router: Router; |
23 23 | let itemTemplateService: ItemTemplateDataService; |
24 24 | |
25 25 | const template = Object.assign(new Item(), { |
26 26 | _links: { |
32 32 | id: 'collection-id', |
33 33 | name: 'Fake Collection', |
34 34 | _links: { |
35 35 | self: { href: 'collection-selflink' } |
36 36 | } |
37 37 | }); |
38 38 | const collectionTemplateHref = 'rest/api/test/collections/template'; |
39 39 | |
40 40 | const itemTemplateServiceStub = jasmine.createSpyObj('itemTemplateService', { |
41 41 | findByCollectionID: createSuccessfulRemoteDataObject$(template), |
42 - | create: createSuccessfulRemoteDataObject$(template), |
43 - | deleteByCollectionID: observableOf(true), |
42 + | createByCollectionID: createSuccessfulRemoteDataObject$(template), |
43 + | delete: observableOf(true), |
44 44 | getCollectionEndpoint: observableOf(collectionTemplateHref), |
45 45 | }); |
46 46 | |
47 47 | const notificationsService = jasmine.createSpyObj('notificationsService', { |
48 48 | success: {}, |
49 49 | error: {} |
50 50 | }); |
51 51 | const requestService = jasmine.createSpyObj('requestService', { |
52 52 | setStaleByHrefSubstring: {} |
53 53 | }); |
84 84 | describe('addItemTemplate', () => { |
85 85 | it('should navigate to the collection\'s itemtemplate page', () => { |
86 86 | spyOn(router, 'navigate'); |
87 87 | comp.addItemTemplate(); |
88 88 | expect(router.navigate).toHaveBeenCalledWith([getCollectionItemTemplateRoute(collection.uuid)]); |
89 89 | }); |
90 90 | }); |
91 91 | |
92 92 | describe('deleteItemTemplate', () => { |
93 93 | beforeEach(() => { |
94 - | (itemTemplateService.deleteByCollectionID as jasmine.Spy).and.returnValue(observableOf(true)); |
94 + | (itemTemplateService.delete as jasmine.Spy).and.returnValue(createSuccessfulRemoteDataObject$({})); |
95 95 | comp.deleteItemTemplate(); |
96 96 | }); |
97 97 | |
98 - | it('should call ItemTemplateService.deleteByCollectionID', () => { |
99 - | expect(itemTemplateService.deleteByCollectionID).toHaveBeenCalledWith(template, 'collection-id'); |
98 + | it('should call ItemTemplateService.delete', () => { |
99 + | expect(itemTemplateService.delete).toHaveBeenCalledWith(template.uuid); |
100 100 | }); |
101 101 | |
102 102 | describe('when delete returns a success', () => { |
103 103 | it('should display a success notification', () => { |
104 104 | expect(notificationsService.success).toHaveBeenCalled(); |
105 105 | }); |
106 106 | }); |
107 107 | |
108 108 | describe('when delete returns a failure', () => { |
109 109 | beforeEach(() => { |
110 - | (itemTemplateService.deleteByCollectionID as jasmine.Spy).and.returnValue(observableOf(false)); |
110 + | (itemTemplateService.delete as jasmine.Spy).and.returnValue(createFailedRemoteDataObject$()); |
111 111 | comp.deleteItemTemplate(); |
112 112 | }); |
113 113 | |
114 114 | it('should display an error notification', () => { |
115 115 | expect(notificationsService.error).toHaveBeenCalled(); |
116 116 | }); |
117 117 | }); |
118 118 | }); |
119 119 | }); |