forked from eclipsesource/jsonforms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodelmapping.test.ts
106 lines (89 loc) · 3.05 KB
/
modelmapping.test.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
import test from 'ava';
import { JsonForms } from '../src/core';
import { testDataSchema } from './data/modelreference.data';
import { SchemaService } from '../src/core/schema.service';
import { SchemaServiceImpl } from '../src/core/schema.service.impl';
test.beforeEach(t => {
const classA = {
'eClass': 'http://www.eclipse.org/emf/2002/Ecore#//EClass',
'name': 'classA',
'_id' : 'id-class-a',
'eStructuralFeatures': [
{
'eClass': 'http://www.eclipse.org/emf/2002/Ecore#//EAttribute',
'eType': {},
'name': 'attributeOne'
},
{
'eClass': 'http://www.eclipse.org/emf/2002/Ecore#//EAttribute',
'eType': {},
'name': 'attributeTwo'
},
{
'eClass': 'http://www.eclipse.org/emf/2002/Ecore#//EReference',
'name': 'referenceOne',
'eType': 'id-class-b'
}
]
};
const classB = {
'eClass': 'http://www.eclipse.org/emf/2002/Ecore#//EClass',
'name': 'classB',
'_id': 'id-class-b',
'eStructuralFeatures': [
{
'eClass': 'http://www.eclipse.org/emf/2002/Ecore#//EAttribute',
'eType': {},
'name': 'attributeOne'
},
]
};
const enumOne = {
'eClass': 'http://www.eclipse.org/emf/2002/Ecore#//EEnum',
'name': 'enumOne',
'_id': 'id-enum-one',
'eLiterals': [
'enumLiteralOne', 'enumLiteralTwo', 'enumLiteralThree'
]
};
const dataTypeOne = {
'eClass': 'http://www.eclipse.org/emf/2002/Ecore#//EDataType',
'name': 'dataTypeOne',
'_id': 'id-datatype-one',
'instanceClassName' : 'dataTypeOne',
'instanceTypeName' : 'java.lang.String'
};
t.context.candidates = [
classA,
classB,
enumOne,
dataTypeOne
];
// data has to consist of a bunch of eClassifiers
// so we can verify whether the filtering works
t.context.data = {
'name': 'packageOne',
'eClassifiers': t.context.candidates
};
t.context.modelMapping = {
'attribute': 'eClass',
'mapping': {
'http://www.eclipse.org/emf/2002/Ecore#//EEnum': '#enum',
'http://www.eclipse.org/emf/2002/Ecore#//EClass': '#class',
'http://www.eclipse.org/emf/2002/Ecore#//EDataType': '#datatype',
'http://www.eclipse.org/emf/2002/Ecore#//EReference': '#reference',
'http://www.eclipse.org/emf/2002/Ecore#//EAttribute': '#attribute'
}
};
JsonForms.modelMapping = t.context.modelMapping;
});
test('available options filtering for reference attribute candidates', t => {
const matchingOptions = JsonForms.filterObjectsByType(t.context.candidates, '#class');
t.is(Object.keys(matchingOptions).length, 2, 'array of length two expected');
});
test('available options filtering for reference attribute', t => {
const service: SchemaService = new SchemaServiceImpl(testDataSchema);
const reference = service.getReferenceProperties(testDataSchema.definitions.reference)[0];
const availableOptions = reference.findReferenceTargets(t.context.data);
t.is(Object.keys(availableOptions).length, 2, 'array of length two expected');
});