-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathancestor-chart.spec.ts
More file actions
97 lines (89 loc) · 2.36 KB
/
Copy pathancestor-chart.spec.ts
File metadata and controls
97 lines (89 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/// <reference path="./jsdom-global.d.ts" />
import * as jsdomGlobal from 'jsdom-global';
import {AncestorChart} from '../src/ancestor-chart';
import {JsonDataProvider, JsonGedcomData} from '../src/data';
import {FakeRenderer} from './fake_renderer';
// Initialize DOM.
(jsdomGlobal as any)(); // tslint:disable-line
describe('Ancestor chart', () => {
beforeEach(() => {
document.body.innerHTML = '<svg></svg>';
});
it('should work for a single person', () => {
const json: JsonGedcomData = {fams: [], indis: [{id: 'I1'}]};
const data = new JsonDataProvider(json);
const chart = new AncestorChart({
data,
startIndi: 'I1',
renderer: new FakeRenderer(),
svgSelector: 'svg',
});
chart.render();
expect(document.querySelectorAll('g.node').length).toEqual(1);
});
it('should work with a common ancestor of two spouses', () => {
// I5+I6
// F3
// |
// I3+I4
// F2
// |
// +-++
// | |
// I1+I2
// F1
const json: JsonGedcomData = {
fams: [
{id: 'F1', husb: 'I1', wife: 'I2'},
{id: 'F2', husb: 'I3', wife: 'I4', children: ['I1', 'I2']},
{id: 'F3', husb: 'I5', wife: 'I6', children: ['I3']},
],
indis: [
{id: 'I1', fams: ['F1'], famc: 'F2'},
{id: 'I2', fams: ['F1'], famc: 'F2'},
{id: 'I3', fams: ['F2'], famc: 'F3'},
{id: 'I4', fams: ['F2']},
{id: 'I5', fams: ['F3']},
{id: 'I6', fams: ['F3']},
],
};
const data = new JsonDataProvider(json);
const chart = new AncestorChart({
data,
startFam: json.fams[0].id,
renderer: new FakeRenderer(),
svgSelector: 'svg',
});
chart.render();
});
it('should work with FAM values only', () => {
// I5+I6
// F3
// |
// I3+I4
// F2
// |
// +-++
// | |
// I1+I2
// F1
const json: JsonGedcomData = {
fams: [
{id: 'F1', children: []},
],
indis: [
{id: 'I1', fams: ['F1'], sex: "M"},
{id: 'I2', fams: ['F1'], sex: "F"},
{id: 'I3', famc: 'F1', sex: "F"},
],
};
const data = new JsonDataProvider(json);
const chart = new AncestorChart({
data,
startFam: json.fams[0].id,
renderer: new FakeRenderer(),
svgSelector: 'svg',
});
chart.render();
});
});