|
1
|
|
|
var assert = require('chai').assert, |
|
2
|
|
|
GedcomX = require('../../'); |
|
3
|
|
|
|
|
4
|
|
|
describe('FieldValueDescriptor', function(){ |
|
5
|
|
|
|
|
6
|
|
|
it('Create plain', function(){ |
|
7
|
|
|
assert.instanceOf(new GedcomX.FieldValueDescriptor(), GedcomX.FieldValueDescriptor, 'An instance of FieldValueDescriptor is not returned when calling the constructor with new.'); |
|
8
|
|
|
assert.instanceOf(GedcomX.FieldValueDescriptor(), GedcomX.FieldValueDescriptor, 'An instance of FieldValueDescriptor is not returned when calling the constructor without new.'); |
|
9
|
|
|
}); |
|
10
|
|
|
|
|
11
|
|
|
it('Create with JSON', function(){ |
|
12
|
|
|
var fvd = GedcomX.FieldValueDescriptor({ |
|
13
|
|
|
id: 'fvd', |
|
14
|
|
|
optional: true, |
|
15
|
|
|
type: 'http://gedcomx.org/Original', |
|
16
|
|
|
labelId: 'name', |
|
17
|
|
|
displayLabels: [ |
|
18
|
|
|
{ lang: 'en-US', value: 'Name' } |
|
19
|
|
|
] |
|
20
|
|
|
}); |
|
21
|
|
|
assert.equal(fvd.getId(), 'fvd'); |
|
22
|
|
|
assert(fvd.getOptional()); |
|
23
|
|
|
assert.equal(fvd.getType(), 'http://gedcomx.org/Original'); |
|
24
|
|
|
assert.equal(fvd.getLabelId(), 'name'); |
|
25
|
|
|
assert.equal(fvd.getDisplayLabels().length, 1); |
|
26
|
|
|
assert.equal(fvd.getDisplayLabels()[0].getLang(), 'en-US'); |
|
27
|
|
|
assert.equal(fvd.getDisplayLabels()[0].getValue(), 'Name'); |
|
28
|
|
|
}); |
|
29
|
|
|
|
|
30
|
|
|
it('Build', function(){ |
|
31
|
|
|
var fvd = GedcomX.FieldValueDescriptor() |
|
32
|
|
|
.setId('fvd') |
|
33
|
|
|
.setOptional(true) |
|
34
|
|
|
.setType('http://gedcomx.org/Original') |
|
35
|
|
|
.setLabelId('name') |
|
36
|
|
|
.addDisplayLabel({ lang: 'en-US', value: 'Name' }); |
|
37
|
|
|
assert.equal(fvd.getId(), 'fvd'); |
|
38
|
|
|
assert(fvd.getOptional()); |
|
39
|
|
|
assert.equal(fvd.getType(), 'http://gedcomx.org/Original'); |
|
40
|
|
|
assert.equal(fvd.getLabelId(), 'name'); |
|
41
|
|
|
assert.equal(fvd.getDisplayLabels().length, 1); |
|
42
|
|
|
assert.equal(fvd.getDisplayLabels()[0].getLang(), 'en-US'); |
|
43
|
|
|
assert.equal(fvd.getDisplayLabels()[0].getValue(), 'Name'); |
|
44
|
|
|
}); |
|
45
|
|
|
|
|
46
|
|
|
it('toJSON', function(){ |
|
47
|
|
|
var data = { |
|
48
|
|
|
id: 'fvd', |
|
49
|
|
|
optional: true, |
|
50
|
|
|
type: 'http://gedcomx.org/Original', |
|
51
|
|
|
labelId: 'name', |
|
52
|
|
|
displayLabels: [ |
|
53
|
|
|
{ lang: 'en-US', value: 'Name' } |
|
54
|
|
|
] |
|
55
|
|
|
}, fvd = GedcomX.FieldValueDescriptor(data); |
|
56
|
|
|
assert.deepEqual(fvd.toJSON(), data); |
|
57
|
|
|
}); |
|
58
|
|
|
|
|
59
|
|
|
it('constructor does not copy instances', function(){ |
|
60
|
|
|
var obj1 = GedcomX.FieldValueDescriptor(); |
|
61
|
|
|
var obj2 = GedcomX.FieldValueDescriptor(obj1); |
|
62
|
|
|
assert.strictEqual(obj1, obj2); |
|
63
|
|
|
}); |
|
64
|
|
|
|
|
65
|
|
|
}); |