mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-13 21:13:07 +00:00
DURACOM-235 Update comcol-metadata.component.ts and tests
This commit is contained in:
@@ -17,7 +17,7 @@ import {
|
||||
} from '../../../../remote-data.utils';
|
||||
import { ComcolMetadataComponent } from './comcol-metadata.component';
|
||||
|
||||
describe('ComColMetadataComponent', () => {
|
||||
fdescribe('ComColMetadataComponent', () => {
|
||||
let comp: ComcolMetadataComponent<any>;
|
||||
let fixture: ComponentFixture<ComcolMetadataComponent<any>>;
|
||||
let dsoDataService;
|
||||
@@ -29,8 +29,6 @@ describe('ComColMetadataComponent', () => {
|
||||
let routerStub;
|
||||
let routeStub;
|
||||
|
||||
const logoEndpoint = 'rest/api/logo/endpoint';
|
||||
|
||||
function initializeVars() {
|
||||
community = Object.assign(new Community(), {
|
||||
uuid: 'a20da287-e174-466a-9926-f66b9300d347',
|
||||
@@ -51,7 +49,6 @@ describe('ComColMetadataComponent', () => {
|
||||
communityDataServiceStub = {
|
||||
update: (com, uuid?) => createSuccessfulRemoteDataObject$(newCommunity),
|
||||
patch: () => null,
|
||||
getLogoEndpoint: () => observableOf(logoEndpoint)
|
||||
};
|
||||
|
||||
routerStub = {
|
||||
@@ -118,7 +115,6 @@ describe('ComColMetadataComponent', () => {
|
||||
}
|
||||
/* eslint-enable no-empty,@typescript-eslint/no-empty-function */
|
||||
},
|
||||
deleteLogo: false,
|
||||
};
|
||||
spyOn(router, 'navigate');
|
||||
});
|
||||
@@ -150,48 +146,84 @@ describe('ComColMetadataComponent', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('with at least one item in the uploader\'s queue', () => {
|
||||
describe('with an empty operations array', () => {
|
||||
beforeEach(() => {
|
||||
data = {
|
||||
dso: Object.assign(new Community(), {
|
||||
metadata: [{
|
||||
key: 'dc.title',
|
||||
value: 'test'
|
||||
}]
|
||||
}),
|
||||
operations: [],
|
||||
dso: new Community(),
|
||||
uploader: {
|
||||
options: {
|
||||
url: ''
|
||||
},
|
||||
queue: [
|
||||
{}
|
||||
],
|
||||
queue: [],
|
||||
/* eslint-disable no-empty,@typescript-eslint/no-empty-function */
|
||||
uploadAll: () => {
|
||||
}
|
||||
/* eslint-enable no-empty,@typescript-eslint/no-empty-function */
|
||||
}
|
||||
},
|
||||
};
|
||||
spyOn(router, 'navigate');
|
||||
});
|
||||
|
||||
it('should navigate', () => {
|
||||
comp.onSubmit(data);
|
||||
fixture.detectChanges();
|
||||
expect(router.navigate).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('with a not empty operations array', () => {
|
||||
beforeEach(() => {
|
||||
data = {
|
||||
operations: [
|
||||
{
|
||||
op: 'replace',
|
||||
path: '/metadata/dc.title',
|
||||
value: {
|
||||
value: 'test',
|
||||
language: null,
|
||||
},
|
||||
},
|
||||
],
|
||||
dso: new Community(),
|
||||
uploader: {
|
||||
options: {
|
||||
url: ''
|
||||
},
|
||||
queue: [],
|
||||
/* eslint-disable no-empty,@typescript-eslint/no-empty-function */
|
||||
uploadAll: () => {
|
||||
}
|
||||
/* eslint-enable no-empty,@typescript-eslint/no-empty-function */
|
||||
},
|
||||
};
|
||||
spyOn(router, 'navigate');
|
||||
});
|
||||
|
||||
describe('when successful', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
spyOn(dsoDataService, 'patch').and.returnValue(createSuccessfulRemoteDataObject$({}));
|
||||
});
|
||||
|
||||
it('should navigate', () => {
|
||||
comp.onSubmit(data);
|
||||
fixture.detectChanges();
|
||||
expect(router.navigate).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('on failure', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
spyOn(dsoDataService, 'patch').and.returnValue(createFailedRemoteDataObject$('Error', 500));
|
||||
});
|
||||
|
||||
it('should not navigate', () => {
|
||||
spyOn(router, 'navigate');
|
||||
comp.onSubmit(data);
|
||||
fixture.detectChanges();
|
||||
expect(router.navigate).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should set the uploader\'s url to the logo\'s endpoint', () => {
|
||||
comp.onSubmit(data);
|
||||
fixture.detectChanges();
|
||||
expect(data.uploader.options.url).toEqual(logoEndpoint);
|
||||
});
|
||||
|
||||
it('should call the uploader\'s uploadAll', () => {
|
||||
spyOn(data.uploader, 'uploadAll');
|
||||
comp.onSubmit(data);
|
||||
fixture.detectChanges();
|
||||
expect(data.uploader.uploadAll).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -18,15 +18,14 @@ import { Collection } from '../../../../../core/shared/collection.model';
|
||||
template: ''
|
||||
})
|
||||
export class ComcolMetadataComponent<TDomain extends Community | Collection> implements OnInit {
|
||||
/**
|
||||
* Frontend endpoint for this type of DSO
|
||||
*/
|
||||
protected frontendURL: string;
|
||||
/**
|
||||
* The initial DSO object
|
||||
*/
|
||||
public dsoRD$: Observable<RemoteData<TDomain>>;
|
||||
|
||||
/**
|
||||
* Frontend endpoint for this type of DSO
|
||||
*/
|
||||
protected frontendURL: string;
|
||||
/**
|
||||
* The type of the dso
|
||||
*/
|
||||
@@ -54,7 +53,7 @@ export class ComcolMetadataComponent<TDomain extends Community | Collection> imp
|
||||
this.dsoDataService.patch(event.dso, event.operations).pipe(getFirstCompletedRemoteData())
|
||||
.subscribe(async (response: RemoteData<DSpaceObject>) => {
|
||||
if (response.hasSucceeded) {
|
||||
await this.router.navigate([this.frontendURL + event.dso.uuid]);
|
||||
await this.router.navigate([this.frontendURL, event.dso.uuid]);
|
||||
this.notificationsService.success(null, this.translate.get(`${this.type.value}.edit.notifications.success`));
|
||||
} else if (response.statusCode === 403) {
|
||||
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
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.router.navigate([this.frontendURL + event.dso.uuid]);
|
||||
this.router.navigate([this.frontendURL, event.dso.uuid]);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user