From 5783d27b2e7641b8491f28d6f0245de4421bfc1f Mon Sep 17 00:00:00 2001 From: mdelez <60604010+mdelez@users.noreply.github.com> Date: Fri, 10 Sep 2021 14:25:50 +0200 Subject: [PATCH] fix(resource-instance-form): resource class name now updates correctly in the event that the name was changed and the page was not refreshed (#531) --- .../resource-instance-form.component.spec.ts | 20 +++++-------------- .../resource-instance-form.component.ts | 6 +++--- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/src/app/workspace/resource/resource-instance-form/resource-instance-form.component.spec.ts b/src/app/workspace/resource/resource-instance-form/resource-instance-form.component.spec.ts index 43d4db8042..9a426142d0 100644 --- a/src/app/workspace/resource/resource-instance-form/resource-instance-form.component.spec.ts +++ b/src/app/workspace/resource/resource-instance-form/resource-instance-form.component.spec.ts @@ -299,7 +299,7 @@ describe('ResourceInstanceFormComponent', () => { usersEndpoint: jasmine.createSpyObj('usersEndpoint', ['getUserByUsername']) }, v2: { - onto: jasmine.createSpyObj('onto', ['getOntologiesByProjectIri']), + onto: jasmine.createSpyObj('onto', ['getOntologiesByProjectIri', 'getOntology', 'getResourceClassDefinition']), ontologyCache: jasmine.createSpyObj('ontologyCache', ['getOntology', 'getResourceClassDefinition']), res: jasmine.createSpyObj('res', ['createResource']) } @@ -452,16 +452,11 @@ describe('ResourceInstanceFormComponent', () => { it('should show the select resource class component', () => { const dspConnSpy = TestBed.inject(DspApiConnectionToken); - (dspConnSpy.v2.ontologyCache as jasmine.SpyObj).getOntology.and.callFake( + (dspConnSpy.v2.onto as jasmine.SpyObj).getOntology.and.callFake( () => { const anythingOnto = MockOntology.mockReadOntology('http://0.0.0.0:3333/ontology/0001/anything/v2'); - - const ontoMap: Map = new Map(); - - ontoMap.set('http://0.0.0.0:3333/ontology/0001/anything/v2', anythingOnto); - - return of(ontoMap); + return of(anythingOnto); } ); @@ -484,16 +479,11 @@ describe('ResourceInstanceFormComponent', () => { const dspConnSpy = TestBed.inject(DspApiConnectionToken); - (dspConnSpy.v2.ontologyCache as jasmine.SpyObj).getOntology.and.callFake( + (dspConnSpy.v2.onto as jasmine.SpyObj).getOntology.and.callFake( () => { const anythingOnto = MockOntology.mockReadOntology('http://0.0.0.0:3333/ontology/0001/anything/v2'); - - const ontoMap: Map = new Map(); - - ontoMap.set('http://0.0.0.0:3333/ontology/0001/anything/v2', anythingOnto); - - return of(ontoMap); + return of(anythingOnto); } ); diff --git a/src/app/workspace/resource/resource-instance-form/resource-instance-form.component.ts b/src/app/workspace/resource/resource-instance-form/resource-instance-form.component.ts index 0d524acc76..102a73bac1 100644 --- a/src/app/workspace/resource/resource-instance-form/resource-instance-form.component.ts +++ b/src/app/workspace/resource/resource-instance-form/resource-instance-form.component.ts @@ -305,9 +305,9 @@ export class ResourceInstanceFormComponent implements OnInit, OnDestroy { this.selectedOntology = ontologyIri; - this._dspApiConnection.v2.ontologyCache.getOntology(ontologyIri).subscribe( - (onto: Map) => { - this.resourceClasses = onto.get(ontologyIri).getClassDefinitionsByType(ResourceClassDefinition); + this._dspApiConnection.v2.onto.getOntology(ontologyIri).subscribe( + (onto: ReadOntology) => { + this.resourceClasses = onto.getClassDefinitionsByType(ResourceClassDefinition); if (this.selectResourceClassComponent && this.resourceClasses.length === 1) { // since the component already exists, the ngAfterInit method of the component will not be called so we must assign the value here manually