|
| 1 | +import test from 'ava'; |
| 2 | +import { JsonForms } from '../src/core'; |
| 3 | + |
| 4 | +test('get available options for reference attribute', t => { |
| 5 | + |
| 6 | + const classA = { |
| 7 | + "eClass": "http://www.eclipse.org/emf/2002/Ecore#//EClass", |
| 8 | + "name": "classA", |
| 9 | + "_id" : "id-class-a", |
| 10 | + "eStructuralFeatures": [ |
| 11 | + { |
| 12 | + "eClass": "http://www.eclipse.org/emf/2002/Ecore#//EAttribute", |
| 13 | + "eType": {}, |
| 14 | + "name": "attributeOne" |
| 15 | + }, |
| 16 | + { |
| 17 | + "eClass": "http://www.eclipse.org/emf/2002/Ecore#//EAttribute", |
| 18 | + "eType": {}, |
| 19 | + "name": "attributeTwo" |
| 20 | + }, |
| 21 | + { |
| 22 | + "eClass": "http://www.eclipse.org/emf/2002/Ecore#//EReference", |
| 23 | + "name": "referenceOne", |
| 24 | + "eType": "id-class-b" |
| 25 | + } |
| 26 | + ] |
| 27 | + }; |
| 28 | + |
| 29 | + const classB = { |
| 30 | + "eClass": "http://www.eclipse.org/emf/2002/Ecore#//EClass", |
| 31 | + "name": "classB", |
| 32 | + "_id": "id-class-B", |
| 33 | + "eStructuralFeatures": [ |
| 34 | + { |
| 35 | + "eClass": "http://www.eclipse.org/emf/2002/Ecore#//EAttribute", |
| 36 | + "eType": {}, |
| 37 | + "name": "attributeOne" |
| 38 | + }, |
| 39 | + ] |
| 40 | + } |
| 41 | + |
| 42 | + const enumOne = { |
| 43 | + "eClass": "http://www.eclipse.org/emf/2002/Ecore#//EEnum", |
| 44 | + "name": "enumOne", |
| 45 | + "_id": "id-enum-one", |
| 46 | + "eLiterals": [ |
| 47 | + "enumLiteralOne", "enumLiteralTwo", "enumLiteralThree" |
| 48 | + ] |
| 49 | + } |
| 50 | + |
| 51 | + const dataTypeOne = { |
| 52 | + "eClass": "http://www.eclipse.org/emf/2002/Ecore#//EDataType", |
| 53 | + "name": "dataTypeOne", |
| 54 | + "_id": "id-datatype-one", |
| 55 | + "instanceClassName" : "dataTypeOne", |
| 56 | + "instanceTypeName" : "java.lang.String" |
| 57 | + } |
| 58 | + |
| 59 | + // data has to consist of a bunch of eClassifiers |
| 60 | + // so we can verify whether the filtering works |
| 61 | + const data = { |
| 62 | + "name": "packageOne", |
| 63 | + "eClassifiers": [ |
| 64 | + classA, |
| 65 | + classB, |
| 66 | + enumOne, |
| 67 | + dataTypeOne |
| 68 | + ] |
| 69 | + }; |
| 70 | + |
| 71 | + JsonForms.modelMapping = { |
| 72 | + 'attribute': 'eClass', |
| 73 | + 'mapping': { |
| 74 | + 'http://www.eclipse.org/emf/2002/Ecore#//EEnum': '#enum', |
| 75 | + 'http://www.eclipse.org/emf/2002/Ecore#//EClass': '#class', |
| 76 | + 'http://www.eclipse.org/emf/2002/Ecore#//EDataType': '#datatype', |
| 77 | + 'http://www.eclipse.org/emf/2002/Ecore#//EReference': '#reference', |
| 78 | + 'http://www.eclipse.org/emf/2002/Ecore#//EAttribute': '#attribute' |
| 79 | + } |
| 80 | + }; |
| 81 | + const candidates = [ |
| 82 | + classA, |
| 83 | + classB, |
| 84 | + enumOne, |
| 85 | + dataTypeOne |
| 86 | + ]; |
| 87 | + |
| 88 | + // test filtering |
| 89 | + const matchingOptions = JsonForms.filterObjectsByType(candidates, "#class"); |
| 90 | + t.is(Object.keys(matchingOptions).length, 2, "array of length two expected"); |
| 91 | + |
| 92 | + // TODO: test retun of all available options |
| 93 | + // const allOptions = JsonForms.filterObjectsByType(candidates, null); |
| 94 | + // t.is(Object.keys(allOptions).length, 4, "array of length four expected"); |
| 95 | + |
| 96 | +}); |
0 commit comments