From af3a388db8b699e7f808220c7467d5671d166a58 Mon Sep 17 00:00:00 2001 From: Arc676/Alessandro Vinciguerra Date: Wed, 11 Nov 2026 21:46:27 +0100 Subject: [PATCH 1/2] test(kinship): separate tests by language Signed-off-by: Arc676/Alessandro Vinciguerra --- frontend/src/utils/kinship/kinship.en.test.js | 40 +++++++++++++++++++ .../{kinship.test.js => kinship.fr.test.js} | 38 +----------------- 2 files changed, 41 insertions(+), 37 deletions(-) create mode 100644 frontend/src/utils/kinship/kinship.en.test.js rename frontend/src/utils/kinship/{kinship.test.js => kinship.fr.test.js} (63%) diff --git a/frontend/src/utils/kinship/kinship.en.test.js b/frontend/src/utils/kinship/kinship.en.test.js new file mode 100644 index 0000000..a0ecc03 --- /dev/null +++ b/frontend/src/utils/kinship/kinship.en.test.js @@ -0,0 +1,40 @@ +import { describe, it, expect } from 'vitest' +import { nameKinship } from './index.js' +import { path } from './kinship.fr.test.js' + +const both = (moves) => ['male', 'female', null].map((sex) => nameKinship(path(moves, sex), 'en')) + +describe('nommage anglais', () => { + it('genre le mot quand le sexe est connu', () => { + expect(both(['up'])).toEqual(['Father', 'Mother', 'Parent']) + expect(both(['up', 'up'])).toEqual(['Grandfather', 'Grandmother', 'Grandparent']) + expect(both(['up', 'up', 'up', 'up'])).toEqual(['Great-great-grandfather', 'Great-great-grandmother', 'Great-great-grandparent']) + expect(both(['down', 'down'])).toEqual(['Grandson', 'Granddaughter', 'Grandchild']) + expect(both(['sibling'])).toEqual(['Brother', 'Sister', 'Sibling']) + expect(both(['up', 'sibling'])).toEqual(['Uncle', 'Aunt', 'Uncle/Aunt']) + expect(both(['sibling', 'down'])).toEqual(['Nephew', 'Niece', 'Nibling']) + expect(both(['spouse', 'up'])).toEqual(['Father-in-law', 'Mother-in-law', 'Parent-in-law']) + expect(both(['up', 'spouse'])).toEqual(['Stepfather', 'Stepmother', 'Stepparent']) + expect(both(['spouse', 'down'])).toEqual(['Stepson', 'Stepdaughter', 'Stepchild']) + expect(both(['down', 'spouse'])).toEqual(['Son-in-law', 'Daughter-in-law', 'Child-in-law']) + expect(both(['spouse', 'sibling'])).toEqual(['Brother-in-law', 'Sister-in-law', 'Brother/sister-in-law']) + expect(both(['sibling', 'spouse'])).toEqual(['Brother-in-law', 'Sister-in-law', 'Brother/sister-in-law']) + expect(both(['up', 'spouse', 'down'])).toEqual(['Stepbrother', 'Stepsister', 'Stepsibling']) + expect(both(['up', 'down'])).toEqual(['Half-brother', 'Half-sister', 'Half-sibling']) + expect(both(['spouse'])).toEqual(['Partner', 'Partner', 'Partner']) + expect(both(['up', 'sibling', 'down'])).toEqual(['First cousin', 'First cousin', 'First cousin']) + expect(both(['up', 'up', 'sibling', 'down', 'down'])).toEqual(['Second cousin', 'Second cousin', 'Second cousin']) + expect(both(['up', 'up', 'sibling', 'down'])).toEqual(['First cousin once removed', 'First cousin once removed', 'First cousin once removed']) + expect(both(['up', 'up', 'up', 'up', 'up', 'up', 'sibling', 'down', 'down', 'down'])).toEqual(['Third cousin thrice removed', 'Third cousin thrice removed', 'Third cousin thrice removed']) + expect(both(['up', 'up', 'up', 'sibling', 'down'])).toEqual(['First cousin twice removed', 'First cousin twice removed', 'First cousin twice removed']) + expect(both(['up', 'up', 'up', 'up', 'up', 'sibling', 'down'])).toEqual(['First cousin 4 times removed', 'First cousin 4 times removed', 'First cousin 4 times removed']) + expect(both(['up', 'up', 'up', 'up', 'sibling', 'down', 'down', 'down', 'down'])).toEqual(['4th cousin', '4th cousin', '4th cousin']) + expect(both(['up', 'up', 'sibling'])).toEqual(['Great-uncle', 'Great-aunt', 'Great-uncle/aunt']) + expect(both(['up', 'up', 'up', 'sibling'])).toEqual(['Great-great-uncle', 'Great-great-aunt', 'Great-great-uncle/aunt']) + expect(both(['sibling', 'down', 'down'])).toEqual(['Grandnephew', 'Grandniece', 'Grandnibling']) + }) + + it('une langue inconnue retombe sur l’anglais', () => { + expect(nameKinship(path(['up'], 'female'), 'xx')).toBe('Mother') + }) +}) diff --git a/frontend/src/utils/kinship/kinship.test.js b/frontend/src/utils/kinship/kinship.fr.test.js similarity index 63% rename from frontend/src/utils/kinship/kinship.test.js rename to frontend/src/utils/kinship/kinship.fr.test.js index b86710c..de424e6 100644 --- a/frontend/src/utils/kinship/kinship.test.js +++ b/frontend/src/utils/kinship/kinship.fr.test.js @@ -3,13 +3,12 @@ import { kinshipFacts, nameKinship, normalizeSex } from './index.js' import { computeRelationshipLabel, kinshipPath } from '../../components/galaxy/pathfinding.js' // Chemin écrit à la main : moves = suite de pas, sex = sexe de la personne au bout -const path = (moves, sex = null, extra = {}) => ({ +export const path = (moves, sex = null, extra = {}) => ({ from: { id: 'moi', sex: null, birthYear: null }, steps: moves.map((move, i) => ({ move, person: { id: `p${i}`, sex: i === moves.length - 1 ? sex : null, birthYear: null, ...(extra[i] || {}) } })), }) const both = (moves) => ['male', 'female', null].map((sex) => nameKinship(path(moves, sex), 'fr')) -const bothEn = (moves) => ['male', 'female', null].map((sex) => nameKinship(path(moves, sex), 'en')) describe('nommage français', () => { it('genre le mot quand le sexe est connu, garde la forme double sinon', () => { @@ -59,41 +58,6 @@ describe('nommage français', () => { }) }) -describe('nommage anglais', () => { - it('genre le mot quand le sexe est connu', () => { - expect(bothEn(['up'])).toEqual(['Father', 'Mother', 'Parent']) - expect(bothEn(['up', 'up'])).toEqual(['Grandfather', 'Grandmother', 'Grandparent']) - expect(bothEn(['up', 'up', 'up', 'up'])).toEqual(['Great-great-grandfather', 'Great-great-grandmother', 'Great-great-grandparent']) - expect(bothEn(['down', 'down'])).toEqual(['Grandson', 'Granddaughter', 'Grandchild']) - expect(bothEn(['sibling'])).toEqual(['Brother', 'Sister', 'Sibling']) - expect(bothEn(['up', 'sibling'])).toEqual(['Uncle', 'Aunt', 'Uncle/Aunt']) - expect(bothEn(['sibling', 'down'])).toEqual(['Nephew', 'Niece', 'Nibling']) - expect(bothEn(['spouse', 'up'])).toEqual(['Father-in-law', 'Mother-in-law', 'Parent-in-law']) - expect(bothEn(['up', 'spouse'])).toEqual(['Stepfather', 'Stepmother', 'Stepparent']) - expect(bothEn(['spouse', 'down'])).toEqual(['Stepson', 'Stepdaughter', 'Stepchild']) - expect(bothEn(['down', 'spouse'])).toEqual(['Son-in-law', 'Daughter-in-law', 'Child-in-law']) - expect(bothEn(['spouse', 'sibling'])).toEqual(['Brother-in-law', 'Sister-in-law', 'Brother/sister-in-law']) - expect(bothEn(['sibling', 'spouse'])).toEqual(['Brother-in-law', 'Sister-in-law', 'Brother/sister-in-law']) - expect(bothEn(['up', 'spouse', 'down'])).toEqual(['Stepbrother', 'Stepsister', 'Stepsibling']) - expect(bothEn(['up', 'down'])).toEqual(['Half-brother', 'Half-sister', 'Half-sibling']) - expect(bothEn(['spouse'])).toEqual(['Partner', 'Partner', 'Partner']) - expect(bothEn(['up', 'sibling', 'down'])).toEqual(['First cousin', 'First cousin', 'First cousin']) - expect(bothEn(['up', 'up', 'sibling', 'down', 'down'])).toEqual(['Second cousin', 'Second cousin', 'Second cousin']) - expect(bothEn(['up', 'up', 'sibling', 'down'])).toEqual(['First cousin once removed', 'First cousin once removed', 'First cousin once removed']) - expect(bothEn(['up', 'up', 'up', 'up', 'up', 'up', 'sibling', 'down', 'down', 'down'])).toEqual(['Third cousin thrice removed', 'Third cousin thrice removed', 'Third cousin thrice removed']) - expect(bothEn(['up', 'up', 'up', 'sibling', 'down'])).toEqual(['First cousin twice removed', 'First cousin twice removed', 'First cousin twice removed']) - expect(bothEn(['up', 'up', 'up', 'up', 'up', 'sibling', 'down'])).toEqual(['First cousin 4 times removed', 'First cousin 4 times removed', 'First cousin 4 times removed']) - expect(bothEn(['up', 'up', 'up', 'up', 'sibling', 'down', 'down', 'down', 'down'])).toEqual(['4th cousin', '4th cousin', '4th cousin']) - expect(bothEn(['up', 'up', 'sibling'])).toEqual(['Great-uncle', 'Great-aunt', 'Great-uncle/aunt']) - expect(bothEn(['up', 'up', 'up', 'sibling'])).toEqual(['Great-great-uncle', 'Great-great-aunt', 'Great-great-uncle/aunt']) - expect(bothEn(['sibling', 'down', 'down'])).toEqual(['Grandnephew', 'Grandniece', 'Grandnibling']) - }) - - it('une langue inconnue retombe sur l’anglais', () => { - expect(nameKinship(path(['up'], 'female'), 'xx')).toBe('Mother') - }) -}) - describe('chemin de parenté depuis le chemin BFS', () => { // moi → union de mes parents → mon père → union des grands-parents → ma tante const edgePath = [ From b806661d9be7d541631f34f071cbe29cf6ad025e Mon Sep 17 00:00:00 2001 From: IliesAllali Date: Sat, 14 Nov 2026 17:37:37 +0100 Subject: [PATCH 2/2] test(kinship): shared helpers instead of importing a test file Importing `path` from kinship.fr.test.js made Vitest run the French tests a second time inside kinship.en.test.js (18 tests instead of 10). `path` and a `namesBySex(lang)` helper now live in test-helpers.js, which the test include pattern ignores. Co-Authored-By: Claude Opus 5.5 Signed-off-by: IliesAllali --- frontend/src/utils/kinship/kinship.en.test.js | 4 ++-- frontend/src/utils/kinship/kinship.fr.test.js | 9 ++------- frontend/src/utils/kinship/test-helpers.js | 12 ++++++++++++ 3 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 frontend/src/utils/kinship/test-helpers.js diff --git a/frontend/src/utils/kinship/kinship.en.test.js b/frontend/src/utils/kinship/kinship.en.test.js index a0ecc03..5521d7e 100644 --- a/frontend/src/utils/kinship/kinship.en.test.js +++ b/frontend/src/utils/kinship/kinship.en.test.js @@ -1,8 +1,8 @@ import { describe, it, expect } from 'vitest' import { nameKinship } from './index.js' -import { path } from './kinship.fr.test.js' +import { path, namesBySex } from './test-helpers.js' -const both = (moves) => ['male', 'female', null].map((sex) => nameKinship(path(moves, sex), 'en')) +const both = namesBySex('en') describe('nommage anglais', () => { it('genre le mot quand le sexe est connu', () => { diff --git a/frontend/src/utils/kinship/kinship.fr.test.js b/frontend/src/utils/kinship/kinship.fr.test.js index de424e6..d024cef 100644 --- a/frontend/src/utils/kinship/kinship.fr.test.js +++ b/frontend/src/utils/kinship/kinship.fr.test.js @@ -1,14 +1,9 @@ import { describe, it, expect } from 'vitest' import { kinshipFacts, nameKinship, normalizeSex } from './index.js' import { computeRelationshipLabel, kinshipPath } from '../../components/galaxy/pathfinding.js' +import { path, namesBySex } from './test-helpers.js' -// Chemin écrit à la main : moves = suite de pas, sex = sexe de la personne au bout -export const path = (moves, sex = null, extra = {}) => ({ - from: { id: 'moi', sex: null, birthYear: null }, - steps: moves.map((move, i) => ({ move, person: { id: `p${i}`, sex: i === moves.length - 1 ? sex : null, birthYear: null, ...(extra[i] || {}) } })), -}) - -const both = (moves) => ['male', 'female', null].map((sex) => nameKinship(path(moves, sex), 'fr')) +const both = namesBySex('fr') describe('nommage français', () => { it('genre le mot quand le sexe est connu, garde la forme double sinon', () => { diff --git a/frontend/src/utils/kinship/test-helpers.js b/frontend/src/utils/kinship/test-helpers.js new file mode 100644 index 0000000..ee140a0 --- /dev/null +++ b/frontend/src/utils/kinship/test-helpers.js @@ -0,0 +1,12 @@ +// Partagé par les fichiers kinship..test.js. Ce n'est pas un fichier de test : +// Vitest ne le ramasse pas (include: src/**/*.test.{js,jsx}). +import { nameKinship } from './index.js' + +// Chemin écrit à la main : moves = suite de pas, sex = sexe de la personne au bout +export const path = (moves, sex = null, extra = {}) => ({ + from: { id: 'moi', sex: null, birthYear: null }, + steps: moves.map((move, i) => ({ move, person: { id: `p${i}`, sex: i === moves.length - 1 ? sex : null, birthYear: null, ...(extra[i] || {}) } })), +}) + +// Nomme le même chemin pour un homme, une femme et un sexe non précisé au bout +export const namesBySex = (lang) => (moves) => ['male', 'female', null].map((sex) => nameKinship(path(moves, sex), lang))