/
property-info.component.spec.ts
359 lines (307 loc) · 13.7 KB
/
property-info.component.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
import { Component, DebugElement, ViewChild } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { MatDialogModule } from '@angular/material/dialog';
import { MatIconModule } from '@angular/material/icon';
import { MatListModule } from '@angular/material/list';
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, 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';
/**
* Test host component to simulate parent component
* Property is of type simple text
*/
@Component({
template: '<app-property-info #propertyInfo [propCard]="propertyCardinality" [propDef]="propertyDefinition"></app-property-info>'
})
class SimpleTextHostComponent {
@ViewChild('propertyInfo') propertyInfoComponent: PropertyInfoComponent;
propertyCardinality: IHasProperty = {
propertyIndex: "http://0.0.0.0:3333/ontology/1111/Notizblogg/v2#notgkygty",
cardinality: 0,
guiOrder: 1,
isInherited: false
};
propertyDefinition: ResourcePropertyDefinitionWithAllLanguages = {
"id": "http://0.0.0.0:3333/ontology/1111/Notizblogg/v2#notgkygty",
"subPropertyOf": ["http://api.knora.org/ontology/knora-api/v2#hasValue"],
"comment": "Beschreibt einen Namen",
"label": "Name",
"guiElement": "http://api.knora.org/ontology/salsah-gui/v2#SimpleText",
"objectType": "http://api.knora.org/ontology/knora-api/v2#TextValue",
"isLinkProperty": false,
"isLinkValueProperty": false,
"isEditable": true,
"guiAttributes": [],
"comments": [{
"language": "de",
"value": "Beschreibt einen Namen"
}],
"labels": [{
"language": "de",
"value": "Name"
}]
};
}
/**
* Test host component to simulate parent component
* Property is of type resource link
*/
@Component({
template: '<app-property-info #propertyInfo [propCard]="propertyCardinality" [propDef]="propertyDefinition"></app-property-info>'
})
class LinkHostComponent {
@ViewChild('propertyInfo') propertyInfoComponent: PropertyInfoComponent;
propertyCardinality: IHasProperty = {
"propertyIndex": "http://0.0.0.0:3333/ontology/0001/anything/v2#hasOtherThing",
"cardinality": 2,
"guiOrder": 1,
"isInherited": false
};
propertyDefinition: ResourcePropertyDefinitionWithAllLanguages = {
"id": "http://0.0.0.0:3333/ontology/0001/anything/v2#hasOtherThing",
"subPropertyOf": ["http://api.knora.org/ontology/knora-api/v2#hasLinkTo"],
"label": "Ein anderes Ding",
"guiElement": "http://api.knora.org/ontology/salsah-gui/v2#Searchbox",
"subjectType": "http://0.0.0.0:3333/ontology/0001/anything/v2#Thing",
"objectType": "http://0.0.0.0:3333/ontology/0001/anything/v2#Thing",
"isLinkProperty": true,
"isLinkValueProperty": false,
"isEditable": true,
"guiAttributes": [],
"comments": [],
"labels": [{
"language": "de",
"value": "Ein anderes Ding"
}, {
"language": "en",
"value": "Another thing"
}, {
"language": "fr",
"value": "Une autre chose"
}, {
"language": "it",
"value": "Un'altra cosa"
}]
};
}
/**
* Test host component to simulate parent component
* Property is of type list dropdown
*/
@Component({
template: '<app-property-info #propertyInfo [propCard]="propertyCardinality" [propDef]="propertyDefinition"></app-property-info>'
})
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=<http://rdfh.ch/lists/0001/treeList>"],
"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<SimpleTextHostComponent>;
let linkHostComponent: LinkHostComponent;
let linkHostFixture: ComponentFixture<LinkHostComponent>;
let listHostComponent: ListHostComponent;
let listHostFixture: ComponentFixture<ListHostComponent>;
beforeEach(async(() => {
const dspConnSpy = {
v2: {
ontologyCache: jasmine.createSpyObj('ontologyCache', ['getOntology']),
}
};
const cacheServiceSpy = jasmine.createSpyObj('CacheService', ['get']);
TestBed.configureTestingModule({
declarations: [
LinkHostComponent,
ListHostComponent,
SimpleTextHostComponent,
PropertyInfoComponent
],
imports: [
BrowserAnimationsModule,
MatDialogModule,
MatIconModule,
MatListModule,
MatSnackBarModule,
MatTooltipModule
],
providers: [
{
provide: CacheService,
useValue: cacheServiceSpy
}
]
})
.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);
(cacheSpy as jasmine.SpyObj<CacheService>).get.and.callFake(
() => {
let response: ReadOntology = MockOntology.mockReadOntology('http://0.0.0.0:3333/ontology/0001/anything/v2');
return of(response);
}
);
linkHostFixture = TestBed.createComponent(LinkHostComponent);
linkHostComponent = linkHostFixture.componentInstance;
linkHostFixture.detectChanges();
expect(linkHostComponent).toBeTruthy();
});
beforeEach(() => {
// mock cache service for currentOntology
const cacheSpy = TestBed.inject(CacheService);
(cacheSpy as jasmine.SpyObj<CacheService>).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();
});
it('expect cardinality 0 = only one but required value (1)', () => {
expect(simpleTextHostComponent.propertyInfoComponent).toBeTruthy();
expect(simpleTextHostComponent.propertyInfoComponent.propCard).toBeDefined();
expect(simpleTextHostComponent.propertyInfoComponent.propCard.cardinality).toBe(0);
const hostCompDe = simpleTextHostFixture.debugElement;
const multipleIcon: DebugElement = hostCompDe.query(By.css('.multiple'));
const requiredIcon: DebugElement = hostCompDe.query(By.css('.required'));
// cardinality 0 means "no multiple values"
expect(multipleIcon.nativeElement.innerText).toEqual('check_box_outline_blank');
// and cardinality 0 means also "required value"
expect(requiredIcon.nativeElement.innerText).toEqual('check_box');
});
it('expect property type "text" and gui element "simple input"', () => {
expect(simpleTextHostComponent.propertyInfoComponent).toBeTruthy();
expect(simpleTextHostComponent.propertyInfoComponent.propDef).toBeDefined();
expect(simpleTextHostComponent.propertyInfoComponent.propDef.guiElement).toBe(Constants.SalsahGui + Constants.HashDelimiter + 'SimpleText');
const hostCompDe = simpleTextHostFixture.debugElement;
const typeIcon: DebugElement = hostCompDe.query(By.css('.type'));
// property type and gui element should be Text: simple Text
expect(typeIcon.nativeElement.innerText).toEqual('short_text');
});
it('expect property type "link" and gui element "search box"', () => {
expect(linkHostComponent.propertyInfoComponent).toBeTruthy();
expect(linkHostComponent.propertyInfoComponent.propDef).toBeDefined();
expect(linkHostComponent.propertyInfoComponent.propDef.guiElement).toBe(Constants.SalsahGui + Constants.HashDelimiter + 'Searchbox');
const hostCompDe = linkHostFixture.debugElement;
const typeIcon: DebugElement = hostCompDe.query(By.css('.type'));
// expect "link" icon
expect(typeIcon.nativeElement.innerText).toEqual('link');
});
it('expect link to other resource called "Thing"', () => {
expect(linkHostComponent.propertyInfoComponent).toBeTruthy();
expect(linkHostComponent.propertyInfoComponent.propDef).toBeDefined();
const hostCompDe = linkHostFixture.debugElement;
const attribute: DebugElement = hostCompDe.query(By.css('.attribute'));
// expect linked resource called "Thing"
expect(attribute.nativeElement.innerText).toContain('Thing');
});
it('expect cardinality 2 = not required but multiple values (0-n)', () => {
expect(linkHostComponent.propertyInfoComponent).toBeTruthy();
expect(linkHostComponent.propertyInfoComponent.propDef).toBeDefined();
const hostCompDe = linkHostFixture.debugElement;
const multipleIcon: DebugElement = hostCompDe.query(By.css('.multiple'));
const requiredIcon: DebugElement = hostCompDe.query(By.css('.required'));
// cardinality 2 means "multiple values"
expect(multipleIcon.nativeElement.innerText).toEqual('check_box');
// 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');
});
});