From d96d31daf26225bb633886e1d7d4e3a6f178c849 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Kilchenmann?= Date: Mon, 22 Feb 2021 11:15:25 +0100 Subject: [PATCH 1/4] fix(ontology): bug fix in list property --- .../ontology/property-info/property-info.component.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/app/project/ontology/property-info/property-info.component.ts b/src/app/project/ontology/property-info/property-info.component.ts index 0fc815961e..3ca4ed1569 100644 --- a/src/app/project/ontology/property-info/property-info.component.ts +++ b/src/app/project/ontology/property-info/property-info.component.ts @@ -5,6 +5,7 @@ import { ApiResponseData, Constants, IHasProperty, + ListNodeInfo, ListsResponse, ReadOntology, ResourcePropertyDefinitionWithAllLanguages @@ -119,11 +120,14 @@ export class PropertyInfoComponent implements OnInit, AfterContentInit { // this property is a list property // get current ontology lists to get linked list information this._cache.get('currentOntologyLists').subscribe( - (response: ApiResponseData) => { + (response: ListNodeInfo[]) => { + console.log(JSON.stringify(response)) + console.log('-------------------------') const re: RegExp = /\<([^)]+)\>/; const listIri = this.propDef.guiAttributes[0].match(re)[1]; const listUrl = `/project/${this.projectcode}/lists/${encodeURIComponent(listIri)}`; - this.propAttribute = `${response[0].labels[0].value}`; + const list = response.find(i => i.id === listIri); + this.propAttribute = `${list.labels[0].value}`; } ); } From d73edb6f94d13eb3c0b775ce827c7371ec9979f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Kilchenmann?= Date: Mon, 22 Feb 2021 11:15:42 +0100 Subject: [PATCH 2/4] test(ontology): new test for list property --- .../property-info.component.spec.ts | 139 ++++++++++++++++-- 1 file changed, 129 insertions(+), 10 deletions(-) diff --git a/src/app/project/ontology/property-info/property-info.component.spec.ts b/src/app/project/ontology/property-info/property-info.component.spec.ts index 950cc37619..4b49d31e2f 100644 --- a/src/app/project/ontology/property-info/property-info.component.spec.ts +++ b/src/app/project/ontology/property-info/property-info.component.spec.ts @@ -7,7 +7,7 @@ import { MatSnackBarModule } from '@angular/material/snack-bar'; import { MatTooltipModule } from '@angular/material/tooltip'; import { By } from '@angular/platform-browser'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; -import { Constants, IHasProperty, MockOntology, ReadOntology, ResourcePropertyDefinitionWithAllLanguages } from '@dasch-swiss/dsp-js'; +import { Constants, IHasProperty, ListNodeInfo, MockOntology, ReadOntology, ResourcePropertyDefinitionWithAllLanguages } from '@dasch-swiss/dsp-js'; import { of } from 'rxjs'; import { CacheService } from 'src/app/main/cache/cache.service'; import { PropertyInfoComponent } from './property-info.component'; @@ -98,13 +98,62 @@ class LinkHostComponent { } -describe('PropertyInfoComponent', () => { +/** + * Test host component to simulate parent component + * Property is of type list dropdown + */ +@Component({ + template: '' +}) +class ListHostComponent { + + @ViewChild('propertyInfo') propertyInfoComponent: PropertyInfoComponent; + + propertyCardinality: IHasProperty = { + "propertyIndex": "http://0.0.0.0:3333/ontology/0001/anything/v2#hasListItem", + "cardinality": 2, + "guiOrder": 0, + "isInherited": true + }; + propertyDefinition: ResourcePropertyDefinitionWithAllLanguages = { + "id": "http://0.0.0.0:3333/ontology/0001/anything/v2#hasListItem", + "subPropertyOf": ["http://api.knora.org/ontology/knora-api/v2#hasValue"], + "label": "Listenelement", + "guiElement": "http://api.knora.org/ontology/salsah-gui/v2#List", + "subjectType": "http://0.0.0.0:3333/ontology/0001/anything/v2#Thing", + "objectType": "http://api.knora.org/ontology/knora-api/v2#ListValue", + "isLinkProperty": false, + "isLinkValueProperty": false, + "isEditable": true, + "guiAttributes": ["hlist="], + "comments": [], + "labels": [{ + "language": "de", + "value": "Listenelement" + }, { + "language": "en", + "value": "List element" + }, { + "language": "fr", + "value": "Elément de liste" + }, { + "language": "it", + "value": "Elemento di lista" + }] + }; + +} + +fdescribe('PropertyInfoComponent', () => { let simpleTextHostComponent: SimpleTextHostComponent; let simpleTextHostFixture: ComponentFixture; let linkHostComponent: LinkHostComponent; let linkHostFixture: ComponentFixture; + let listHostComponent: ListHostComponent; + let listHostFixture: ComponentFixture; + beforeEach(async(() => { const dspConnSpy = { v2: { @@ -117,6 +166,7 @@ describe('PropertyInfoComponent', () => { TestBed.configureTestingModule({ declarations: [ LinkHostComponent, + ListHostComponent, SimpleTextHostComponent, PropertyInfoComponent ], @@ -138,6 +188,14 @@ describe('PropertyInfoComponent', () => { .compileComponents(); })); + beforeEach(() => { + simpleTextHostFixture = TestBed.createComponent(SimpleTextHostComponent); + simpleTextHostComponent = simpleTextHostFixture.componentInstance; + simpleTextHostFixture.detectChanges(); + + expect(simpleTextHostComponent).toBeTruthy(); + }); + beforeEach(() => { // mock cache service for currentOntology const cacheSpy = TestBed.inject(CacheService); @@ -149,14 +207,6 @@ describe('PropertyInfoComponent', () => { } ); - simpleTextHostFixture = TestBed.createComponent(SimpleTextHostComponent); - simpleTextHostComponent = simpleTextHostFixture.componentInstance; - simpleTextHostFixture.detectChanges(); - - expect(simpleTextHostComponent).toBeTruthy(); - }); - - beforeEach(() => { linkHostFixture = TestBed.createComponent(LinkHostComponent); linkHostComponent = linkHostFixture.componentInstance; linkHostFixture.detectChanges(); @@ -164,6 +214,64 @@ describe('PropertyInfoComponent', () => { expect(linkHostComponent).toBeTruthy(); }); + beforeEach(() => { + // mock cache service for currentOntology + const cacheSpy = TestBed.inject(CacheService); + + (cacheSpy as jasmine.SpyObj).get.and.callFake( + (key = 'currentOntologyLists') => { + let response: ListNodeInfo[] = [{ + "comments": [], + "id": "http://rdfh.ch/lists/0001/otherTreeList", + "isRootNode": true, + "labels": [{ + "language": "en", + "value": "Tree list root" + }], + "projectIri": "http://rdfh.ch/projects/0001" + }, { + "comments": [{ + "language": "en", + "value": "a list that is not in used in ontology or data" + }], + "id": "http://rdfh.ch/lists/0001/notUsedList", + "isRootNode": true, + "labels": [{ + "language": "de", + "value": "unbenutzte Liste" + }, { + "language": "en", + "value": "a list that is not used" + }], + "name": "notUsedList", + "projectIri": "http://rdfh.ch/projects/0001" + }, { + "comments": [{ + "language": "en", + "value": "Anything Tree List" + }], + "id": "http://rdfh.ch/lists/0001/treeList", + "isRootNode": true, + "labels": [{ + "language": "de", + "value": "Listenwurzel" + }, { + "language": "en", + "value": "Tree list root" + }], + "name": "treelistroot", + "projectIri": "http://rdfh.ch/projects/0001" + }]; + return of(response); + } + ); + listHostFixture = TestBed.createComponent(ListHostComponent); + listHostComponent = listHostFixture.componentInstance; + listHostFixture.detectChanges(); + + expect(listHostComponent).toBeTruthy(); + }); + it('should create an instance', () => { expect(simpleTextHostComponent.propertyInfoComponent).toBeTruthy(); }); @@ -237,4 +345,15 @@ describe('PropertyInfoComponent', () => { // and cardinality 2 means also "not required value" expect(requiredIcon.nativeElement.innerText).toEqual('check_box_outline_blank'); }); + + it('expect list property with connection to list "Listenwurzel"', () => { + expect(listHostComponent.propertyInfoComponent).toBeTruthy(); + expect(listHostComponent.propertyInfoComponent.propDef).toBeDefined(); + + const hostCompDe = listHostFixture.debugElement; + + const attribute: DebugElement = hostCompDe.query(By.css('.attribute')); + // expect list called "Listenwurzel" + expect(attribute.nativeElement.innerText).toContain('Listenwurzel'); + }); }); From ada10e157a21edeaeb73d608999bf54a0310a2c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Kilchenmann?= Date: Mon, 22 Feb 2021 11:17:33 +0100 Subject: [PATCH 3/4] refactor(ontology): delete console.log --- .../project/ontology/property-info/property-info.component.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/app/project/ontology/property-info/property-info.component.ts b/src/app/project/ontology/property-info/property-info.component.ts index 3ca4ed1569..b5bd26191c 100644 --- a/src/app/project/ontology/property-info/property-info.component.ts +++ b/src/app/project/ontology/property-info/property-info.component.ts @@ -121,8 +121,6 @@ export class PropertyInfoComponent implements OnInit, AfterContentInit { // get current ontology lists to get linked list information this._cache.get('currentOntologyLists').subscribe( (response: ListNodeInfo[]) => { - console.log(JSON.stringify(response)) - console.log('-------------------------') const re: RegExp = /\<([^)]+)\>/; const listIri = this.propDef.guiAttributes[0].match(re)[1]; const listUrl = `/project/${this.projectcode}/lists/${encodeURIComponent(listIri)}`; From 21eea72ff0f564de7582d01b00a90a1a608ca2ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Kilchenmann?= Date: Mon, 22 Feb 2021 15:55:34 +0100 Subject: [PATCH 4/4] test(ontology): reactivate all tests --- .../ontology/property-info/property-info.component.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/project/ontology/property-info/property-info.component.spec.ts b/src/app/project/ontology/property-info/property-info.component.spec.ts index 4b49d31e2f..203aabc96b 100644 --- a/src/app/project/ontology/property-info/property-info.component.spec.ts +++ b/src/app/project/ontology/property-info/property-info.component.spec.ts @@ -144,7 +144,7 @@ class ListHostComponent { } -fdescribe('PropertyInfoComponent', () => { +describe('PropertyInfoComponent', () => { let simpleTextHostComponent: SimpleTextHostComponent; let simpleTextHostFixture: ComponentFixture;