From a059c31badfd93e397bd4f17e16e9c521afb506a Mon Sep 17 00:00:00 2001 From: Mattia Vianelli Date: Mon, 26 Feb 2024 12:18:35 +0100 Subject: [PATCH] DURACOM-235 Update comcol-metadata.component.ts and tests --- .../comcol-metadata.component.spec.ts | 92 +++++++++++++------ .../comcol-metadata.component.ts | 13 ++- 2 files changed, 68 insertions(+), 37 deletions(-) diff --git a/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.spec.ts b/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.spec.ts index ef69e82c8c..0ed06140d7 100644 --- a/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.spec.ts +++ b/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.spec.ts @@ -17,7 +17,7 @@ import { } from '../../../../remote-data.utils'; import { ComcolMetadataComponent } from './comcol-metadata.component'; -describe('ComColMetadataComponent', () => { +fdescribe('ComColMetadataComponent', () => { let comp: ComcolMetadataComponent; let fixture: ComponentFixture>; 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 */ - } + /* eslint-enable no-empty,@typescript-eslint/no-empty-function */ + }, }; - }); - - 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', () => { + it('should navigate', () => { comp.onSubmit(data); fixture.detectChanges(); - expect(data.uploader.options.url).toEqual(logoEndpoint); + 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'); }); - it('should call the uploader\'s uploadAll', () => { - spyOn(data.uploader, 'uploadAll'); - comp.onSubmit(data); - fixture.detectChanges(); - expect(data.uploader.uploadAll).toHaveBeenCalled(); + 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', () => { + comp.onSubmit(data); + fixture.detectChanges(); + expect(router.navigate).not.toHaveBeenCalled(); + }); }); }); }); diff --git a/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.ts b/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.ts index 7fb1ad1c2c..8777568f0a 100644 --- a/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.ts +++ b/src/app/shared/comcol/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.ts @@ -18,15 +18,14 @@ import { Collection } from '../../../../../core/shared/collection.model'; template: '' }) export class ComcolMetadataComponent implements OnInit { - /** - * Frontend endpoint for this type of DSO - */ - protected frontendURL: string; /** * The initial DSO object */ public dsoRD$: Observable>; - + /** + * Frontend endpoint for this type of DSO + */ + protected frontendURL: string; /** * The type of the dso */ @@ -54,7 +53,7 @@ export class ComcolMetadataComponent imp this.dsoDataService.patch(event.dso, event.operations).pipe(getFirstCompletedRemoteData()) .subscribe(async (response: RemoteData) => { 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 imp } }); } else { - this.router.navigate([this.frontendURL + event.dso.uuid]); + this.router.navigate([this.frontendURL, event.dso.uuid]); } }