1
|
|
|
var assert = require('chai').assert, |
2
|
|
|
GedcomX = require('../../'); |
3
|
|
|
|
4
|
|
|
describe('Name', function(){ |
5
|
|
|
|
6
|
|
|
it('Create plain', function(){ |
7
|
|
|
var newName = new GedcomX.Name(), |
8
|
|
|
name = GedcomX.Name(); |
9
|
|
|
assert.instanceOf(newName, GedcomX.Name, 'An instance of Name is not returned when calling the constructor with new.'); |
10
|
|
|
assert.instanceOf(name, GedcomX.Name, 'An instance of Name is not returned when calling the constructor without new.'); |
11
|
|
|
}); |
12
|
|
|
|
13
|
|
|
it('Create with JSON', function(){ |
14
|
|
|
var name = GedcomX.Name({ |
15
|
|
|
type: 'http://gedcomx.org/BirthName', |
16
|
|
|
date: { |
17
|
|
|
original: '1 June 1567' |
18
|
|
|
}, |
19
|
|
|
nameForms: [ |
20
|
|
|
{ |
21
|
|
|
lang: 'en', |
22
|
|
|
fullText: 'Jonathan Burrows', |
23
|
|
|
parts: [ |
24
|
|
|
{ |
25
|
|
|
type: 'http://gedcomx.org/Given', |
26
|
|
|
value: 'Jonathan' |
27
|
|
|
}, |
28
|
|
|
{ |
29
|
|
|
type: 'http://gedcomx.org/Surname', |
30
|
|
|
value: 'Burrows' |
31
|
|
|
} |
32
|
|
|
] |
33
|
|
|
} |
34
|
|
|
] |
35
|
|
|
}); |
36
|
|
|
assert.equal(name.getType(), 'http://gedcomx.org/BirthName'); |
37
|
|
|
assert.equal(name.getDate().getOriginal(), '1 June 1567'); |
38
|
|
|
assert.equal(name.getNameForms().length, 1); |
39
|
|
|
assert.equal(name.getNameForms()[0].getFullText(), 'Jonathan Burrows'); |
40
|
|
|
assert.equal(name.getNameForms()[0].getParts().length, 2); |
41
|
|
|
assert.equal(name.getNameForms()[0].getParts()[0].getType(), 'http://gedcomx.org/Given'); |
42
|
|
|
assert.equal(name.getNameForms()[0].getParts()[0].getValue(), 'Jonathan'); |
43
|
|
|
assert.equal(name.getNameForms()[0].getParts()[1].getType(), 'http://gedcomx.org/Surname'); |
44
|
|
|
assert.equal(name.getNameForms()[0].getParts()[1].getValue(), 'Burrows'); |
45
|
|
|
}); |
46
|
|
|
|
47
|
|
|
it('Create with mixed data', function(){ |
48
|
|
|
var name = GedcomX.Name({ |
49
|
|
|
type: 'http://gedcomx.org/BirthName', |
50
|
|
|
date: GedcomX.Date({ |
51
|
|
|
original: '1 June 1567' |
52
|
|
|
}), |
53
|
|
|
nameForms: [ |
54
|
|
|
GedcomX.NameForm({ |
55
|
|
|
lang: 'en', |
56
|
|
|
fullText: 'Jonathan Burrows', |
57
|
|
|
parts: [ |
58
|
|
|
GedcomX.NamePart({ |
59
|
|
|
type: 'http://gedcomx.org/Given', |
60
|
|
|
value: 'Jonathan' |
61
|
|
|
}), |
62
|
|
|
GedcomX.NamePart({ |
63
|
|
|
type: 'http://gedcomx.org/Surname', |
64
|
|
|
value: 'Burrows' |
65
|
|
|
}) |
66
|
|
|
] |
67
|
|
|
}) |
68
|
|
|
] |
69
|
|
|
}); |
70
|
|
|
assert.equal(name.getType(), 'http://gedcomx.org/BirthName'); |
71
|
|
|
assert.equal(name.getDate().getOriginal(), '1 June 1567'); |
72
|
|
|
assert.equal(name.getNameForms().length, 1); |
73
|
|
|
assert.equal(name.getNameForms()[0].getFullText(), 'Jonathan Burrows'); |
74
|
|
|
assert.equal(name.getNameForms()[0].getParts().length, 2); |
75
|
|
|
assert.equal(name.getNameForms()[0].getParts()[0].getType(), 'http://gedcomx.org/Given'); |
76
|
|
|
assert.equal(name.getNameForms()[0].getParts()[0].getValue(), 'Jonathan'); |
77
|
|
|
assert.equal(name.getNameForms()[0].getParts()[1].getType(), 'http://gedcomx.org/Surname'); |
78
|
|
|
assert.equal(name.getNameForms()[0].getParts()[1].getValue(), 'Burrows'); |
79
|
|
|
}); |
80
|
|
|
|
81
|
|
|
it('Build', function(){ |
82
|
|
|
var name = GedcomX.Name() |
83
|
|
|
.setType('http://gedcomx.org/BirthName') |
84
|
|
|
.setDate(GedcomX.Date().setOriginal('1 June 1567')) |
85
|
|
|
.addNameForm( |
86
|
|
|
GedcomX.NameForm() |
87
|
|
|
.setFullText('Jonathan Burrows') |
88
|
|
|
.addPart(GedcomX.NamePart().setType('http://gedcomx.org/Given').setValue('Jonathan')) |
89
|
|
|
.addPart(GedcomX.NamePart().setType('http://gedcomx.org/Surname').setValue('Burrows')) |
90
|
|
|
); |
91
|
|
|
assert.equal(name.getType(), 'http://gedcomx.org/BirthName'); |
92
|
|
|
assert.equal(name.getDate().getOriginal(), '1 June 1567'); |
93
|
|
|
assert.equal(name.getNameForms().length, 1); |
94
|
|
|
assert.equal(name.getNameForms()[0].getFullText(), 'Jonathan Burrows'); |
95
|
|
|
assert.equal(name.getNameForms()[0].getParts().length, 2); |
96
|
|
|
assert.equal(name.getNameForms()[0].getParts()[0].getType(), 'http://gedcomx.org/Given'); |
97
|
|
|
assert.equal(name.getNameForms()[0].getParts()[0].getValue(), 'Jonathan'); |
98
|
|
|
assert.equal(name.getNameForms()[0].getParts()[1].getType(), 'http://gedcomx.org/Surname'); |
99
|
|
|
assert.equal(name.getNameForms()[0].getParts()[1].getValue(), 'Burrows'); |
100
|
|
|
}); |
101
|
|
|
|
102
|
|
|
it('toJSON', function(){ |
103
|
|
|
var data = { |
104
|
|
|
type: 'http://gedcomx.org/BirthName', |
105
|
|
|
date: { |
106
|
|
|
original: '1 June 1567' |
107
|
|
|
}, |
108
|
|
|
nameForms: [ |
109
|
|
|
{ |
110
|
|
|
lang: 'en', |
111
|
|
|
fullText: 'Jonathan Burrows', |
112
|
|
|
parts: [ |
113
|
|
|
{ |
114
|
|
|
type: 'http://gedcomx.org/Given', |
115
|
|
|
value: 'Jonathan' |
116
|
|
|
}, |
117
|
|
|
{ |
118
|
|
|
type: 'http://gedcomx.org/Surname', |
119
|
|
|
value: 'Burrows' |
120
|
|
|
} |
121
|
|
|
] |
122
|
|
|
} |
123
|
|
|
] |
124
|
|
|
}, name = GedcomX.Name(data); |
125
|
|
|
assert.deepEqual(name.toJSON(), data); |
126
|
|
|
}); |
127
|
|
|
|
128
|
|
|
it('constructor does not copy instances', function(){ |
129
|
|
|
var obj1 = GedcomX.Name(); |
130
|
|
|
var obj2 = GedcomX.Name(obj1); |
131
|
|
|
assert.strictEqual(obj1, obj2); |
132
|
|
|
}); |
133
|
|
|
|
134
|
|
|
}); |