1
|
|
|
var assert = require('chai').assert, |
2
|
|
|
GedcomX = require('../../'); |
3
|
|
|
|
4
|
|
|
describe('FieldDescriptor', function(){ |
5
|
|
|
|
6
|
|
|
it('Create plain', function(){ |
7
|
|
|
assert.instanceOf(new GedcomX.FieldDescriptor(), GedcomX.FieldDescriptor, 'An instance of FieldDescriptor is not returned when calling the constructor with new.'); |
8
|
|
|
assert.instanceOf(GedcomX.FieldDescriptor(), GedcomX.FieldDescriptor, 'An instance of FieldDescriptor is not returned when calling the constructor without new.'); |
9
|
|
|
}); |
10
|
|
|
|
11
|
|
|
it('Create with JSON', function(){ |
12
|
|
|
var fd = GedcomX.FieldDescriptor({ |
13
|
|
|
originalLabel: 'Name', |
14
|
|
|
descriptions: [ |
15
|
|
|
{ lang: 'en-US', value: 'Full Name' } |
16
|
|
|
], |
17
|
|
|
values: [{ |
18
|
|
|
optional: true, |
19
|
|
|
type: 'http://gedcomx.org/Original', |
20
|
|
|
labelId: 'name', |
21
|
|
|
displayLabels: [ |
22
|
|
|
{ lang: 'en-US', value: 'Name' } |
23
|
|
|
] |
24
|
|
|
}] |
25
|
|
|
}); |
26
|
|
|
assert.equal(fd.getOriginalLabel(), 'Name'); |
27
|
|
|
assert.equal(fd.getDescriptions().length, 1); |
28
|
|
|
assert.equal(fd.getDescriptions()[0].getLang(), 'en-US'); |
29
|
|
|
assert.equal(fd.getDescriptions()[0].getValue(), 'Full Name'); |
30
|
|
|
assert.equal(fd.getValues().length, 1); |
31
|
|
|
}); |
32
|
|
|
|
33
|
|
|
it('Build', function(){ |
34
|
|
|
var fd = GedcomX.FieldDescriptor() |
35
|
|
|
.setOriginalLabel('Name') |
36
|
|
|
.addDescription({ lang: 'en-US', value: 'Full Name' }) |
37
|
|
|
.addValue({ |
38
|
|
|
optional: true, |
39
|
|
|
type: 'http://gedcomx.org/Original', |
40
|
|
|
labelId: 'name', |
41
|
|
|
displayLabels: [ |
42
|
|
|
{ lang: 'en-US', value: 'Name' } |
43
|
|
|
] |
44
|
|
|
}); |
45
|
|
|
assert.equal(fd.getOriginalLabel(), 'Name'); |
46
|
|
|
assert.equal(fd.getDescriptions().length, 1); |
47
|
|
|
assert.equal(fd.getDescriptions()[0].getLang(), 'en-US'); |
48
|
|
|
assert.equal(fd.getDescriptions()[0].getValue(), 'Full Name'); |
49
|
|
|
assert.equal(fd.getValues().length, 1); |
50
|
|
|
}); |
51
|
|
|
|
52
|
|
|
it('toJSON', function(){ |
53
|
|
|
var data = { |
54
|
|
|
originalLabel: 'Name', |
55
|
|
|
descriptions: [ |
56
|
|
|
{ lang: 'en-US', value: 'Full Name' } |
57
|
|
|
], |
58
|
|
|
values: [{ |
59
|
|
|
optional: true, |
60
|
|
|
type: 'http://gedcomx.org/Original', |
61
|
|
|
labelId: 'name', |
62
|
|
|
displayLabels: [ |
63
|
|
|
{ lang: 'en-US', value: 'Name' } |
64
|
|
|
] |
65
|
|
|
}] |
66
|
|
|
}, fvd = GedcomX.FieldDescriptor(data); |
67
|
|
|
assert.deepEqual(fvd.toJSON(), data); |
68
|
|
|
}); |
69
|
|
|
|
70
|
|
|
it('constructor does not copy instances', function(){ |
71
|
|
|
var obj1 = GedcomX.FieldDescriptor(); |
72
|
|
|
var obj2 = GedcomX.FieldDescriptor(obj1); |
73
|
|
|
assert.strictEqual(obj1, obj2); |
74
|
|
|
}); |
75
|
|
|
|
76
|
|
|
}); |