|
1
|
|
|
var assert = require('chai').assert, |
|
2
|
|
|
GedcomX = require('../../'); |
|
3
|
|
|
|
|
4
|
|
|
describe('SourceReference', function(){ |
|
5
|
|
|
|
|
6
|
|
|
it('Create plain', function(){ |
|
7
|
|
|
var newSourceRef = new GedcomX.SourceReference(), |
|
8
|
|
|
sourceRef = GedcomX.SourceReference(); |
|
9
|
|
|
assert.instanceOf(newSourceRef, GedcomX.SourceReference, 'An instance of SourceReference is not returned when calling the constructor with new.'); |
|
10
|
|
|
assert.instanceOf(sourceRef, GedcomX.SourceReference, 'An instance of SourceReference is not returned when calling the constructor without new.'); |
|
11
|
|
|
}); |
|
12
|
|
|
|
|
13
|
|
|
it('Create with JSON', function(){ |
|
14
|
|
|
var ref = GedcomX.SourceReference({ |
|
15
|
|
|
id: 'source-ref', |
|
16
|
|
|
description: 'http://some/uri', |
|
17
|
|
|
attribution: { |
|
18
|
|
|
created: 11121211112 |
|
19
|
|
|
} |
|
20
|
|
|
}); |
|
21
|
|
|
assert.equal(ref.getId(), 'source-ref'); |
|
22
|
|
|
assert.equal(ref.getDescription(), 'http://some/uri'); |
|
23
|
|
|
assert.equal(ref.getAttribution().getCreated().getTime(), 11121211112); |
|
24
|
|
|
}); |
|
25
|
|
|
|
|
26
|
|
|
it('Create with mixed data', function(){ |
|
27
|
|
|
var ref = GedcomX.SourceReference({ |
|
28
|
|
|
id: 'source-ref', |
|
29
|
|
|
description: 'http://some/uri', |
|
30
|
|
|
attribution: GedcomX.Attribution({ |
|
31
|
|
|
created: 11121211112 |
|
32
|
|
|
}) |
|
33
|
|
|
}); |
|
34
|
|
|
assert.equal(ref.getId(), 'source-ref'); |
|
35
|
|
|
assert.equal(ref.getDescription(), 'http://some/uri'); |
|
36
|
|
|
assert.equal(ref.getAttribution().getCreated().getTime(), 11121211112); |
|
37
|
|
|
}); |
|
38
|
|
|
|
|
39
|
|
|
it('Build', function(){ |
|
40
|
|
|
var ref = GedcomX.SourceReference() |
|
41
|
|
|
.setId('source-ref') |
|
42
|
|
|
.setDescription('http://some/uri') |
|
43
|
|
|
.setAttribution({ created: 11121211112 }); |
|
44
|
|
|
assert.equal(ref.getId(), 'source-ref'); |
|
45
|
|
|
assert.equal(ref.getDescription(), 'http://some/uri'); |
|
46
|
|
|
assert.equal(ref.getAttribution().getCreated().getTime(), 11121211112); |
|
47
|
|
|
}); |
|
48
|
|
|
|
|
49
|
|
|
it('toJSON', function(){ |
|
50
|
|
|
var refData = { |
|
51
|
|
|
id: 'source-ref', |
|
52
|
|
|
description: 'http://some/uri', |
|
53
|
|
|
attribution: { |
|
54
|
|
|
created: 11121211112 |
|
55
|
|
|
} |
|
56
|
|
|
}, |
|
57
|
|
|
ref = GedcomX.SourceReference(refData); |
|
58
|
|
|
assert.deepEqual(ref.toJSON(), refData); |
|
59
|
|
|
}); |
|
60
|
|
|
|
|
61
|
|
|
it('constructor does not copy instances', function(){ |
|
62
|
|
|
var obj1 = GedcomX.SourceReference(); |
|
63
|
|
|
var obj2 = GedcomX.SourceReference(obj1); |
|
64
|
|
|
assert.strictEqual(obj1, obj2); |
|
65
|
|
|
}); |
|
66
|
|
|
|
|
67
|
|
|
}); |