Commits
Art Lowel authored b55e4327a88
8 8 | import { createFailedRemoteDataObject$, createSuccessfulRemoteDataObject$ } from '../shared/remote-data.utils'; |
9 9 | import { NotificationsServiceStub } from '../shared/testing/notifications-service.stub'; |
10 10 | import { RouterStub } from '../shared/testing/router.stub'; |
11 11 | import { NotificationsService } from '../shared/notifications/notifications.service'; |
12 12 | import { Router } from '@angular/router'; |
13 13 | import { FormsModule, ReactiveFormsModule } from '@angular/forms'; |
14 14 | import { By } from '@angular/platform-browser'; |
15 15 | import { ConfigurationDataService } from '../core/data/configuration-data.service'; |
16 16 | import { ConfigurationProperty } from '../core/shared/configuration-property.model'; |
17 17 | import { getProcessDetailRoute } from '../process-page/process-page-routing.paths'; |
18 + | import { HandleService } from '../shared/handle.service'; |
18 19 | |
19 20 | describe('CurationFormComponent', () => { |
20 21 | let comp: CurationFormComponent; |
21 22 | let fixture: ComponentFixture<CurationFormComponent>; |
22 23 | |
23 24 | let scriptDataService: ScriptDataService; |
24 25 | let processDataService: ProcessDataService; |
25 26 | let configurationDataService: ConfigurationDataService; |
27 + | let handleService: HandleService; |
26 28 | let notificationsService; |
27 29 | let router; |
28 30 | |
29 31 | const process = Object.assign(new Process(), {processId: 'process-id'}); |
30 32 | |
31 33 | beforeEach(waitForAsync(() => { |
32 34 | |
33 35 | scriptDataService = jasmine.createSpyObj('scriptDataService', { |
34 36 | invoke: createSuccessfulRemoteDataObject$(process) |
35 37 | }); |
44 46 | values: [ |
45 47 | 'org.dspace.ctask.general.ProfileFormats = profileformats', |
46 48 | '', |
47 49 | 'org.dspace.ctask.general.RequiredMetadata = requiredmetadata', |
48 50 | 'org.dspace.ctask.general.MetadataValueLinkChecker = checklinks', |
49 51 | 'value-to-be-skipped' |
50 52 | ] |
51 53 | })) |
52 54 | }); |
53 55 | |
56 + | handleService = { |
57 + | normalizeHandle: (a) => a |
58 + | } as any; |
59 + | |
54 60 | notificationsService = new NotificationsServiceStub(); |
55 61 | router = new RouterStub(); |
56 62 | |
57 63 | TestBed.configureTestingModule({ |
58 64 | imports: [TranslateModule.forRoot(), FormsModule, ReactiveFormsModule], |
59 65 | declarations: [CurationFormComponent], |
60 66 | providers: [ |
61 - | {provide: ScriptDataService, useValue: scriptDataService}, |
62 - | {provide: ProcessDataService, useValue: processDataService}, |
63 - | {provide: NotificationsService, useValue: notificationsService}, |
64 - | {provide: Router, useValue: router}, |
65 - | {provide: ConfigurationDataService, useValue: configurationDataService}, |
67 + | { provide: ScriptDataService, useValue: scriptDataService }, |
68 + | { provide: ProcessDataService, useValue: processDataService }, |
69 + | { provide: NotificationsService, useValue: notificationsService }, |
70 + | { provide: HandleService, useValue: handleService }, |
71 + | { provide: Router, useValue: router}, |
72 + | { provide: ConfigurationDataService, useValue: configurationDataService }, |
66 73 | ], |
67 74 | schemas: [CUSTOM_ELEMENTS_SCHEMA] |
68 75 | }).compileComponents(); |
69 76 | })); |
70 77 | |
71 78 | beforeEach(() => { |
72 79 | fixture = TestBed.createComponent(CurationFormComponent); |
73 80 | comp = fixture.componentInstance; |
74 81 | |
75 82 | fixture.detectChanges(); |
136 143 | }); |
137 144 | it('should use "all" when the handle provided by the form is empty and when no dsoHandle is provided', () => { |
138 145 | |
139 146 | comp.submit(); |
140 147 | |
141 148 | expect(scriptDataService.invoke).toHaveBeenCalledWith('curate', [ |
142 149 | {name: '-t', value: 'profileformats'}, |
143 150 | {name: '-i', value: 'all'}, |
144 151 | ], []); |
145 152 | }); |
153 + | |
154 + | it(`should show an error notification and return when an invalid dsoHandle is provided`, () => { |
155 + | comp.dsoHandle = 'test-handle'; |
156 + | spyOn(handleService, 'normalizeHandle').and.returnValue(null); |
157 + | comp.submit(); |
158 + | |
159 + | expect(notificationsService.error).toHaveBeenCalled(); |
160 + | expect(scriptDataService.invoke).not.toHaveBeenCalled(); |
161 + | }); |
146 162 | }); |