Skip to content

Commit a059c31

Browse files
author
Mattia Vianelli
committed
DURACOM-235 Update comcol-metadata.component.ts and tests
1 parent 9d49045 commit a059c31

2 files changed

Lines changed: 67 additions & 36 deletions

File tree

src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.spec.ts

Lines changed: 61 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
} from '../../../../remote-data.utils';
1818
import { ComcolMetadataComponent } from './comcol-metadata.component';
1919

20-
describe('ComColMetadataComponent', () => {
20+
fdescribe('ComColMetadataComponent', () => {
2121
let comp: ComcolMetadataComponent<any>;
2222
let fixture: ComponentFixture<ComcolMetadataComponent<any>>;
2323
let dsoDataService;
@@ -29,8 +29,6 @@ describe('ComColMetadataComponent', () => {
2929
let routerStub;
3030
let routeStub;
3131

32-
const logoEndpoint = 'rest/api/logo/endpoint';
33-
3432
function initializeVars() {
3533
community = Object.assign(new Community(), {
3634
uuid: 'a20da287-e174-466a-9926-f66b9300d347',
@@ -51,7 +49,6 @@ describe('ComColMetadataComponent', () => {
5149
communityDataServiceStub = {
5250
update: (com, uuid?) => createSuccessfulRemoteDataObject$(newCommunity),
5351
patch: () => null,
54-
getLogoEndpoint: () => observableOf(logoEndpoint)
5552
};
5653

5754
routerStub = {
@@ -118,7 +115,6 @@ describe('ComColMetadataComponent', () => {
118115
}
119116
/* eslint-enable no-empty,@typescript-eslint/no-empty-function */
120117
},
121-
deleteLogo: false,
122118
};
123119
spyOn(router, 'navigate');
124120
});
@@ -150,48 +146,84 @@ describe('ComColMetadataComponent', () => {
150146
});
151147
});
152148

153-
describe('with at least one item in the uploader\'s queue', () => {
149+
describe('with an empty operations array', () => {
154150
beforeEach(() => {
155151
data = {
156-
dso: Object.assign(new Community(), {
157-
metadata: [{
158-
key: 'dc.title',
159-
value: 'test'
160-
}]
161-
}),
152+
operations: [],
153+
dso: new Community(),
162154
uploader: {
163155
options: {
164156
url: ''
165157
},
166-
queue: [
167-
{}
168-
],
158+
queue: [],
169159
/* eslint-disable no-empty,@typescript-eslint/no-empty-function */
170160
uploadAll: () => {
171161
}
172-
/* eslint-enable no-empty, @typescript-eslint/no-empty-function */
173-
}
162+
/* eslint-enable no-empty,@typescript-eslint/no-empty-function */
163+
},
174164
};
165+
spyOn(router, 'navigate');
175166
});
176167

177-
it('should not navigate', () => {
178-
spyOn(router, 'navigate');
168+
it('should navigate', () => {
179169
comp.onSubmit(data);
180170
fixture.detectChanges();
181-
expect(router.navigate).not.toHaveBeenCalled();
171+
expect(router.navigate).toHaveBeenCalled();
182172
});
173+
});
183174

184-
it('should set the uploader\'s url to the logo\'s endpoint', () => {
185-
comp.onSubmit(data);
186-
fixture.detectChanges();
187-
expect(data.uploader.options.url).toEqual(logoEndpoint);
175+
describe('with a not empty operations array', () => {
176+
beforeEach(() => {
177+
data = {
178+
operations: [
179+
{
180+
op: 'replace',
181+
path: '/metadata/dc.title',
182+
value: {
183+
value: 'test',
184+
language: null,
185+
},
186+
},
187+
],
188+
dso: new Community(),
189+
uploader: {
190+
options: {
191+
url: ''
192+
},
193+
queue: [],
194+
/* eslint-disable no-empty,@typescript-eslint/no-empty-function */
195+
uploadAll: () => {
196+
}
197+
/* eslint-enable no-empty,@typescript-eslint/no-empty-function */
198+
},
199+
};
200+
spyOn(router, 'navigate');
188201
});
189202

190-
it('should call the uploader\'s uploadAll', () => {
191-
spyOn(data.uploader, 'uploadAll');
192-
comp.onSubmit(data);
193-
fixture.detectChanges();
194-
expect(data.uploader.uploadAll).toHaveBeenCalled();
203+
describe('when successful', () => {
204+
205+
beforeEach(() => {
206+
spyOn(dsoDataService, 'patch').and.returnValue(createSuccessfulRemoteDataObject$({}));
207+
});
208+
209+
it('should navigate', () => {
210+
comp.onSubmit(data);
211+
fixture.detectChanges();
212+
expect(router.navigate).toHaveBeenCalled();
213+
});
214+
});
215+
216+
describe('on failure', () => {
217+
218+
beforeEach(() => {
219+
spyOn(dsoDataService, 'patch').and.returnValue(createFailedRemoteDataObject$('Error', 500));
220+
});
221+
222+
it('should not navigate', () => {
223+
comp.onSubmit(data);
224+
fixture.detectChanges();
225+
expect(router.navigate).not.toHaveBeenCalled();
226+
});
195227
});
196228
});
197229
});

src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@ import { Collection } from '../../../../../core/shared/collection.model';
1818
template: ''
1919
})
2020
export class ComcolMetadataComponent<TDomain extends Community | Collection> implements OnInit {
21-
/**
22-
* Frontend endpoint for this type of DSO
23-
*/
24-
protected frontendURL: string;
2521
/**
2622
* The initial DSO object
2723
*/
2824
public dsoRD$: Observable<RemoteData<TDomain>>;
29-
25+
/**
26+
* Frontend endpoint for this type of DSO
27+
*/
28+
protected frontendURL: string;
3029
/**
3130
* The type of the dso
3231
*/
@@ -54,7 +53,7 @@ export class ComcolMetadataComponent<TDomain extends Community | Collection> imp
5453
this.dsoDataService.patch(event.dso, event.operations).pipe(getFirstCompletedRemoteData())
5554
.subscribe(async (response: RemoteData<DSpaceObject>) => {
5655
if (response.hasSucceeded) {
57-
await this.router.navigate([this.frontendURL + event.dso.uuid]);
56+
await this.router.navigate([this.frontendURL, event.dso.uuid]);
5857
this.notificationsService.success(null, this.translate.get(`${this.type.value}.edit.notifications.success`));
5958
} else if (response.statusCode === 403) {
6059
this.notificationsService.error(null, this.translate.get(`${this.type.value}.edit.notifications.unauthorized`));
@@ -63,7 +62,7 @@ export class ComcolMetadataComponent<TDomain extends Community | Collection> imp
6362
}
6463
});
6564
} else {
66-
this.router.navigate([this.frontendURL + event.dso.uuid]);
65+
this.router.navigate([this.frontendURL, event.dso.uuid]);
6766
}
6867
}
6968

0 commit comments

Comments
 (0)