| @@ 1-147 (lines=147) @@ | ||
| 1 | var assert = require('chai').assert, |
|
| 2 | GedcomX = require('../../'); |
|
| 3 | ||
| 4 | describe('Person', function(){ |
|
| 5 | ||
| 6 | it('Create plain', function(){ |
|
| 7 | var newPerson = new GedcomX.Person(), |
|
| 8 | person = GedcomX.Person(); |
|
| 9 | assert.instanceOf(newPerson, GedcomX.Person, 'An instance of Person is not returned when calling the constructor with new.'); |
|
| 10 | assert.instanceOf(person, GedcomX.Person, 'An instance of Person is not returned when calling the constructor without new.'); |
|
| 11 | }); |
|
| 12 | ||
| 13 | it('Create with JSON', function(){ |
|
| 14 | var person = GedcomX.Person({ |
|
| 15 | id: 'testPerson', |
|
| 16 | private: true, |
|
| 17 | gender: { |
|
| 18 | type: 'http://gedcomx.org/Female' |
|
| 19 | }, |
|
| 20 | names: [ |
|
| 21 | { |
|
| 22 | type: 'http://gedcomx.org/BirthName', |
|
| 23 | nameForms: [ |
|
| 24 | { |
|
| 25 | fullText: 'Joanna Hopkins' |
|
| 26 | } |
|
| 27 | ] |
|
| 28 | } |
|
| 29 | ], |
|
| 30 | facts: [ |
|
| 31 | { |
|
| 32 | type: 'http://gedcomx.org/Birth', |
|
| 33 | date: { |
|
| 34 | formal: '+2001-04-09' |
|
| 35 | }, |
|
| 36 | place: { |
|
| 37 | original: 'Farm house' |
|
| 38 | } |
|
| 39 | } |
|
| 40 | ] |
|
| 41 | }); |
|
| 42 | assert.equal(person.getId(), 'testPerson'); |
|
| 43 | assert.equal(person.getPrivate(), true); |
|
| 44 | assert.equal(person.getGender().getType(), 'http://gedcomx.org/Female'); |
|
| 45 | assert.equal(person.getNames()[0].getNameForms()[0].getFullText(), 'Joanna Hopkins'); |
|
| 46 | assert.equal(person.getFacts()[0].getDate().getFormal(), '+2001-04-09'); |
|
| 47 | assert.equal(person.getFacts()[0].getPlace().getOriginal(), 'Farm house'); |
|
| 48 | }); |
|
| 49 | ||
| 50 | it('Create with mixed data', function(){ |
|
| 51 | var person = GedcomX.Person({ |
|
| 52 | id: 'testPerson', |
|
| 53 | private: true, |
|
| 54 | gender: GedcomX.Gender({ |
|
| 55 | type: 'http://gedcomx.org/Female' |
|
| 56 | }), |
|
| 57 | names: [ |
|
| 58 | GedcomX.Name({ |
|
| 59 | type: 'http://gedcomx.org/BirthName', |
|
| 60 | nameForms: [ |
|
| 61 | { |
|
| 62 | fullText: 'Joanna Hopkins' |
|
| 63 | } |
|
| 64 | ] |
|
| 65 | }) |
|
| 66 | ], |
|
| 67 | facts: [ |
|
| 68 | GedcomX.Fact({ |
|
| 69 | type: 'http://gedcomx.org/Birth', |
|
| 70 | date: GedcomX.Date({ |
|
| 71 | formal: '+2001-04-09' |
|
| 72 | }), |
|
| 73 | place: GedcomX.PlaceReference({ |
|
| 74 | original: 'Farm house' |
|
| 75 | }) |
|
| 76 | }) |
|
| 77 | ] |
|
| 78 | }); |
|
| 79 | assert.equal(person.getId(), 'testPerson'); |
|
| 80 | assert.equal(person.getPrivate(), true); |
|
| 81 | assert.equal(person.getGender().getType(), 'http://gedcomx.org/Female'); |
|
| 82 | assert.equal(person.getNames()[0].getNameForms()[0].getFullText(), 'Joanna Hopkins'); |
|
| 83 | assert.equal(person.getFacts()[0].getDate().getFormal(), '+2001-04-09'); |
|
| 84 | assert.equal(person.getFacts()[0].getPlace().getOriginal(), 'Farm house'); |
|
| 85 | }); |
|
| 86 | ||
| 87 | it('Build', function(){ |
|
| 88 | var person = GedcomX.Person() |
|
| 89 | .setId('testPerson') |
|
| 90 | .setPrivate(true) |
|
| 91 | .setGender(GedcomX.Gender().setType('http://gedcomx.org/Female')) |
|
| 92 | .addName(GedcomX.Name().addNameForm(GedcomX.NameForm().setFullText('Joanna Hopkins'))) |
|
| 93 | .addFact(GedcomX.Fact().setDate(GedcomX.Date().setFormal('+2001-04-09')).setPlace(GedcomX.PlaceReference().setOriginal('Farm house'))); |
|
| 94 | assert.equal(person.getId(), 'testPerson'); |
|
| 95 | assert.equal(person.getPrivate(), true); |
|
| 96 | assert.equal(person.getGender().getType(), 'http://gedcomx.org/Female'); |
|
| 97 | assert.equal(person.getNames()[0].getNameForms()[0].getFullText(), 'Joanna Hopkins'); |
|
| 98 | assert.equal(person.getFacts()[0].getDate().getFormal(), '+2001-04-09'); |
|
| 99 | assert.equal(person.getFacts()[0].getPlace().getOriginal(), 'Farm house'); |
|
| 100 | }); |
|
| 101 | ||
| 102 | it('toJSON', function(){ |
|
| 103 | var data = { |
|
| 104 | id: 'testPerson', |
|
| 105 | private: true, |
|
| 106 | gender: { |
|
| 107 | type: 'http://gedcomx.org/Female' |
|
| 108 | }, |
|
| 109 | names: [ |
|
| 110 | { |
|
| 111 | type: 'http://gedcomx.org/BirthName', |
|
| 112 | nameForms: [ |
|
| 113 | { |
|
| 114 | fullText: 'Joanna Hopkins' |
|
| 115 | } |
|
| 116 | ] |
|
| 117 | } |
|
| 118 | ], |
|
| 119 | facts: [ |
|
| 120 | { |
|
| 121 | type: 'http://gedcomx.org/Birth', |
|
| 122 | date: { |
|
| 123 | formal: '+2001-04-09' |
|
| 124 | }, |
|
| 125 | place: { |
|
| 126 | original: 'Farm house' |
|
| 127 | } |
|
| 128 | } |
|
| 129 | ] |
|
| 130 | }, person = GedcomX.Person(data); |
|
| 131 | assert.deepEqual(person.toJSON(), data); |
|
| 132 | person = GedcomX.Person() |
|
| 133 | .setId('testPerson') |
|
| 134 | .setPrivate(true) |
|
| 135 | .setGender(GedcomX.Gender().setType('http://gedcomx.org/Female')) |
|
| 136 | .addName(GedcomX.Name().setType('http://gedcomx.org/BirthName').addNameForm(GedcomX.NameForm().setFullText('Joanna Hopkins'))) |
|
| 137 | .addFact(GedcomX.Fact().setType('http://gedcomx.org/Birth').setDate(GedcomX.Date().setFormal('+2001-04-09')).setPlace(GedcomX.PlaceReference().setOriginal('Farm house'))); |
|
| 138 | assert.deepEqual(person.toJSON(), data); |
|
| 139 | }); |
|
| 140 | ||
| 141 | it('constructor does not copy instances', function(){ |
|
| 142 | var obj1 = GedcomX.Person(); |
|
| 143 | var obj2 = GedcomX.Person(obj1); |
|
| 144 | assert.strictEqual(obj1, obj2); |
|
| 145 | }); |
|
| 146 | ||
| 147 | }); |
|
| @@ 1-105 (lines=105) @@ | ||
| 1 | var assert = require('chai').assert, |
|
| 2 | GedcomX = require('../../'); |
|
| 3 | ||
| 4 | describe('Person', function(){ |
|
| 5 | ||
| 6 | it('Create with JSON', function(){ |
|
| 7 | var person = GedcomX.Person({ |
|
| 8 | id: 'testPerson', |
|
| 9 | private: true, |
|
| 10 | living: true, |
|
| 11 | gender: { |
|
| 12 | type: 'http://gedcomx.org/Female' |
|
| 13 | }, |
|
| 14 | names: [ |
|
| 15 | { |
|
| 16 | type: 'http://gedcomx.org/BirthName', |
|
| 17 | nameForms: [ |
|
| 18 | { |
|
| 19 | fullText: 'Joanna Hopkins' |
|
| 20 | } |
|
| 21 | ] |
|
| 22 | } |
|
| 23 | ], |
|
| 24 | facts: [ |
|
| 25 | { |
|
| 26 | type: 'http://gedcomx.org/Birth', |
|
| 27 | date: { |
|
| 28 | formal: '+2001-04-09' |
|
| 29 | }, |
|
| 30 | place: { |
|
| 31 | original: 'Farm house' |
|
| 32 | } |
|
| 33 | } |
|
| 34 | ], |
|
| 35 | display: { |
|
| 36 | "name" : "Joanna Hopkins", |
|
| 37 | "gender" : "Female" |
|
| 38 | } |
|
| 39 | }); |
|
| 40 | assert.equal(person.getLiving(), true); |
|
| 41 | assert.equal(person.getId(), 'testPerson'); |
|
| 42 | assert.equal(person.getPrivate(), true); |
|
| 43 | assert.equal(person.getGender().getType(), 'http://gedcomx.org/Female'); |
|
| 44 | assert.equal(person.getNames()[0].getNameForms()[0].getFullText(), 'Joanna Hopkins'); |
|
| 45 | assert.equal(person.getFacts()[0].getDate().getFormal(), '+2001-04-09'); |
|
| 46 | assert.equal(person.getFacts()[0].getPlace().getOriginal(), 'Farm house'); |
|
| 47 | assert.equal(person.getDisplay().getName(), 'Joanna Hopkins'); |
|
| 48 | }); |
|
| 49 | ||
| 50 | it('Build', function(){ |
|
| 51 | var person = GedcomX.Person() |
|
| 52 | .setId('testPerson') |
|
| 53 | .setLiving(true) |
|
| 54 | .setPrivate(true) |
|
| 55 | .setGender(GedcomX.Gender().setType('http://gedcomx.org/Female')) |
|
| 56 | .addName(GedcomX.Name().addNameForm(GedcomX.NameForm().setFullText('Joanna Hopkins'))) |
|
| 57 | .addFact(GedcomX.Fact().setDate(GedcomX.Date().setFormal('+2001-04-09')).setPlace(GedcomX.PlaceReference().setOriginal('Farm house'))) |
|
| 58 | .setDisplay(GedcomX.DisplayProperties().setName("Joanna Hopkins").setGender("Female")); |
|
| 59 | assert.equal(person.getLiving(), true); |
|
| 60 | assert.equal(person.getId(), 'testPerson'); |
|
| 61 | assert.equal(person.getPrivate(), true); |
|
| 62 | assert.equal(person.getGender().getType(), 'http://gedcomx.org/Female'); |
|
| 63 | assert.equal(person.getNames()[0].getNameForms()[0].getFullText(), 'Joanna Hopkins'); |
|
| 64 | assert.equal(person.getFacts()[0].getDate().getFormal(), '+2001-04-09'); |
|
| 65 | assert.equal(person.getFacts()[0].getPlace().getOriginal(), 'Farm house'); |
|
| 66 | assert.equal(person.getDisplay().getName(), 'Joanna Hopkins'); |
|
| 67 | }); |
|
| 68 | ||
| 69 | it('toJSON', function(){ |
|
| 70 | var data = { |
|
| 71 | id: 'testPerson', |
|
| 72 | private: true, |
|
| 73 | gender: { |
|
| 74 | type: 'http://gedcomx.org/Female' |
|
| 75 | }, |
|
| 76 | names: [ |
|
| 77 | { |
|
| 78 | type: 'http://gedcomx.org/BirthName', |
|
| 79 | nameForms: [ |
|
| 80 | { |
|
| 81 | fullText: 'Joanna Hopkins' |
|
| 82 | } |
|
| 83 | ] |
|
| 84 | } |
|
| 85 | ], |
|
| 86 | facts: [ |
|
| 87 | { |
|
| 88 | type: 'http://gedcomx.org/Birth', |
|
| 89 | date: { |
|
| 90 | formal: '+2001-04-09' |
|
| 91 | }, |
|
| 92 | place: { |
|
| 93 | original: 'Farm house' |
|
| 94 | } |
|
| 95 | } |
|
| 96 | ], |
|
| 97 | display: { |
|
| 98 | "name" : "Joanna Hopkins", |
|
| 99 | "gender" : "Female" |
|
| 100 | } |
|
| 101 | }, person = GedcomX.Person(data); |
|
| 102 | assert.deepEqual(person.toJSON(), data); |
|
| 103 | }); |
|
| 104 | ||
| 105 | }); |
|