From 03a8589b5146da90c2057d2a680eaf654e99bd5c Mon Sep 17 00:00:00 2001 From: maxgfr <25312957+maxgfr@users.noreply.github.com> Date: Tue, 3 Dec 2024 15:19:31 +0100 Subject: [PATCH] fix: glossary --- .../src/workers/glossary/__mocks__/glossaryData.ts | 7 +++++++ .../workers/glossary/__tests__/addGlossaryContent.test.ts | 8 ++++++++ .../src/workers/glossary/explodeGlossaryTerms.ts | 4 ++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/targets/export-elasticsearch/src/workers/glossary/__mocks__/glossaryData.ts b/targets/export-elasticsearch/src/workers/glossary/__mocks__/glossaryData.ts index 36236e50c..f4946c1ee 100644 --- a/targets/export-elasticsearch/src/workers/glossary/__mocks__/glossaryData.ts +++ b/targets/export-elasticsearch/src/workers/glossary/__mocks__/glossaryData.ts @@ -1,4 +1,11 @@ export const glossaryData = [ + { + abbreviations: ["ZC"], + definition: "Definition de la zone commerciale", + term: "Zone commerciale", + variants: [], + references: [], + }, { abbreviations: [], definition: diff --git a/targets/export-elasticsearch/src/workers/glossary/__tests__/addGlossaryContent.test.ts b/targets/export-elasticsearch/src/workers/glossary/__tests__/addGlossaryContent.test.ts index ffd454bcf..ca655b3b6 100644 --- a/targets/export-elasticsearch/src/workers/glossary/__tests__/addGlossaryContent.test.ts +++ b/targets/export-elasticsearch/src/workers/glossary/__tests__/addGlossaryContent.test.ts @@ -542,6 +542,14 @@ describe("Glossary", () => { `ward` ); }); + + test("should work with a composed name in tag with a non breaking space", async () => { + const htmlContent = "

Une zone commerciale 

"; + expect(await addGlossaryContent(glossaryData, htmlContent)).toEqual( + `

Une zone commerciale 

` + ); + }); + test("should match a variant with plural", async () => { const htmlContent = `wards`; expect( diff --git a/targets/export-elasticsearch/src/workers/glossary/explodeGlossaryTerms.ts b/targets/export-elasticsearch/src/workers/glossary/explodeGlossaryTerms.ts index 9bbac238b..b5e1623f5 100644 --- a/targets/export-elasticsearch/src/workers/glossary/explodeGlossaryTerms.ts +++ b/targets/export-elasticsearch/src/workers/glossary/explodeGlossaryTerms.ts @@ -3,8 +3,8 @@ import { GlossaryTerms, Glossary, Term } from "@socialgouv/cdtn-types"; const conventionMatchers = "[Cc]onventions? [Cc]ollectives?|[Aa]ccords? de [Bb]ranches?|[Dd]ispositions? [Cc]onventionnelles?"; -const startWordBreaks = `(?<=^| |\\.|,|'|>|\\()`; -const endWordBreaks = `(?= |\\.|,|'|$|<|\\))`; +const startWordBreaks = `(?<=^| |\\.|,|'|>|\\(| )`; +const endWordBreaks = `(?= |\\.|,|'|$|<|\\)| )`; const startAnchorOmit = `(?[^<]*)`; const endAnchorOmit = `(?![^<]*(?:||.*|))`;