mirror of
https://github.com/PeWu/topola-viewer.git
synced 2026-07-27 06:01:49 +00:00
Clickable link to spouse in details panel
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import {normalizeGedcom} from './gedcom_util';
|
||||
import {getName, normalizeGedcom} from './gedcom_util';
|
||||
|
||||
describe('normalizeGedcom()', () => {
|
||||
it('sorts children', () => {
|
||||
@@ -68,3 +68,73 @@ describe('normalizeGedcom()', () => {
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getName()', () => {
|
||||
it('returns undefined with no name available', () => {
|
||||
const person = {
|
||||
level: 1,
|
||||
pointer: '',
|
||||
tag: 'INDI',
|
||||
data: '',
|
||||
tree: [],
|
||||
};
|
||||
expect(getName(person)).toBe(undefined);
|
||||
});
|
||||
|
||||
it('returns first name available', () => {
|
||||
const person = {
|
||||
level: 1,
|
||||
pointer: '',
|
||||
tag: 'INDI',
|
||||
data: '',
|
||||
tree: [
|
||||
{level: 2, pointer: '', tag: 'NAME', data: 'First /Name/', tree: []},
|
||||
{level: 2, pointer: '', tag: 'NAME', data: 'Second /Name/', tree: []},
|
||||
],
|
||||
};
|
||||
expect(getName(person)).toBe('First Name');
|
||||
});
|
||||
|
||||
it('prefers a name without TYPE=married', () => {
|
||||
const person = {
|
||||
level: 1,
|
||||
pointer: '',
|
||||
tag: 'INDI',
|
||||
data: '',
|
||||
tree: [
|
||||
{
|
||||
level: 2,
|
||||
pointer: '',
|
||||
tag: 'NAME',
|
||||
data: 'First /Name/',
|
||||
tree: [
|
||||
{level: 3, pointer: '', tag: 'TYPE', data: 'married', tree: []},
|
||||
],
|
||||
},
|
||||
{level: 2, pointer: '', tag: 'NAME', data: 'Second /Name/', tree: []},
|
||||
],
|
||||
};
|
||||
expect(getName(person)).toBe('Second Name');
|
||||
});
|
||||
|
||||
it('picks a TYPE=married name if no other is available', () => {
|
||||
const person = {
|
||||
level: 1,
|
||||
pointer: '',
|
||||
tag: 'INDI',
|
||||
data: '',
|
||||
tree: [
|
||||
{
|
||||
level: 2,
|
||||
pointer: '',
|
||||
tag: 'NAME',
|
||||
data: 'Only /Name/',
|
||||
tree: [
|
||||
{level: 3, pointer: '', tag: 'TYPE', data: 'married', tree: []},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
expect(getName(person)).toBe('Only Name');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -270,3 +270,15 @@ export function getSoftware(head: GedcomEntry): string | null {
|
||||
sour && sour.tree && sour.tree.find((entry) => entry.tag === 'NAME');
|
||||
return (name && name.data) || null;
|
||||
}
|
||||
|
||||
export function getName(person: GedcomEntry): string | undefined {
|
||||
const names = person.tree.filter((subEntry) => subEntry.tag === 'NAME');
|
||||
const notMarriedName = names.find(
|
||||
(subEntry) =>
|
||||
subEntry.tree.filter(
|
||||
(nameEntry) => nameEntry.tag === 'TYPE' && nameEntry.data === 'married',
|
||||
).length === 0,
|
||||
);
|
||||
const name = notMarriedName || names[0];
|
||||
return name?.data.replace(/\//g, '');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user