1
|
|
|
var assert = require('chai').assert, |
2
|
|
|
GedcomX = require('../../'); |
3
|
|
|
|
4
|
|
|
describe('Name', function(){ |
5
|
|
|
|
6
|
|
|
it('Create with JSON', function(){ |
7
|
|
|
var name = GedcomX.Name({ |
8
|
|
|
preferred: true, |
9
|
|
|
type: 'http://gedcomx.org/BirthName', |
10
|
|
|
date: { |
11
|
|
|
original: '1 June 1567' |
12
|
|
|
}, |
13
|
|
|
nameForms: [ |
14
|
|
|
{ |
15
|
|
|
lang: 'en', |
16
|
|
|
fullText: 'Jonathan Burrows', |
17
|
|
|
parts: [ |
18
|
|
|
{ |
19
|
|
|
type: 'http://gedcomx.org/Given', |
20
|
|
|
value: 'Jonathan' |
21
|
|
|
}, |
22
|
|
|
{ |
23
|
|
|
type: 'http://gedcomx.org/Surname', |
24
|
|
|
value: 'Burrows' |
25
|
|
|
} |
26
|
|
|
] |
27
|
|
|
} |
28
|
|
|
] |
29
|
|
|
}); |
30
|
|
|
assert(name.getPreferred()); |
31
|
|
|
assert.equal(name.getType(), 'http://gedcomx.org/BirthName'); |
32
|
|
|
assert.equal(name.getDate().getOriginal(), '1 June 1567'); |
33
|
|
|
assert.equal(name.getNameForms().length, 1); |
34
|
|
|
assert.equal(name.getNameForms()[0].getFullText(), 'Jonathan Burrows'); |
35
|
|
|
assert.equal(name.getNameForms()[0].getParts().length, 2); |
36
|
|
|
assert.equal(name.getNameForms()[0].getParts()[0].getType(), 'http://gedcomx.org/Given'); |
37
|
|
|
assert.equal(name.getNameForms()[0].getParts()[0].getValue(), 'Jonathan'); |
38
|
|
|
assert.equal(name.getNameForms()[0].getParts()[1].getType(), 'http://gedcomx.org/Surname'); |
39
|
|
|
assert.equal(name.getNameForms()[0].getParts()[1].getValue(), 'Burrows'); |
40
|
|
|
}); |
41
|
|
|
|
42
|
|
|
it('Build', function(){ |
43
|
|
|
var name = GedcomX.Name() |
44
|
|
|
.setPreferred(true) |
45
|
|
|
.setType('http://gedcomx.org/BirthName') |
46
|
|
|
.setDate(GedcomX.Date().setOriginal('1 June 1567')) |
47
|
|
|
.addNameForm( |
48
|
|
|
GedcomX.NameForm() |
49
|
|
|
.setFullText('Jonathan Burrows') |
50
|
|
|
.addPart(GedcomX.NamePart().setType('http://gedcomx.org/Given').setValue('Jonathan')) |
51
|
|
|
.addPart(GedcomX.NamePart().setType('http://gedcomx.org/Surname').setValue('Burrows')) |
52
|
|
|
); |
53
|
|
|
assert(name.getPreferred()); |
54
|
|
|
assert.equal(name.getType(), 'http://gedcomx.org/BirthName'); |
55
|
|
|
assert.equal(name.getDate().getOriginal(), '1 June 1567'); |
56
|
|
|
assert.equal(name.getNameForms().length, 1); |
57
|
|
|
assert.equal(name.getNameForms()[0].getFullText(), 'Jonathan Burrows'); |
58
|
|
|
assert.equal(name.getNameForms()[0].getParts().length, 2); |
59
|
|
|
assert.equal(name.getNameForms()[0].getParts()[0].getType(), 'http://gedcomx.org/Given'); |
60
|
|
|
assert.equal(name.getNameForms()[0].getParts()[0].getValue(), 'Jonathan'); |
61
|
|
|
assert.equal(name.getNameForms()[0].getParts()[1].getType(), 'http://gedcomx.org/Surname'); |
62
|
|
|
assert.equal(name.getNameForms()[0].getParts()[1].getValue(), 'Burrows'); |
63
|
|
|
}); |
64
|
|
|
|
65
|
|
|
it('toJSON', function(){ |
66
|
|
|
var data = { |
67
|
|
|
preferred: true, |
68
|
|
|
type: 'http://gedcomx.org/BirthName', |
69
|
|
|
date: { |
70
|
|
|
original: '1 June 1567' |
71
|
|
|
}, |
72
|
|
|
nameForms: [ |
73
|
|
|
{ |
74
|
|
|
lang: 'en', |
75
|
|
|
fullText: 'Jonathan Burrows', |
76
|
|
|
parts: [ |
77
|
|
|
{ |
78
|
|
|
type: 'http://gedcomx.org/Given', |
79
|
|
|
value: 'Jonathan' |
80
|
|
|
}, |
81
|
|
|
{ |
82
|
|
|
type: 'http://gedcomx.org/Surname', |
83
|
|
|
value: 'Burrows' |
84
|
|
|
} |
85
|
|
|
] |
86
|
|
|
} |
87
|
|
|
] |
88
|
|
|
}, name = GedcomX.Name(data); |
89
|
|
|
assert.deepEqual(name.toJSON(), data); |
90
|
|
|
}); |
91
|
|
|
|
92
|
|
|
}); |