From 738436061c0a66089b6a1e47554d8da63a41c699 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Wed, 29 Jan 2025 20:37:00 +0100 Subject: [PATCH] test(server/utils): add tests for removeDiacritic and normalize --- src/services/utils.spec.ts | 40 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/services/utils.spec.ts b/src/services/utils.spec.ts index 3ede44aa5..49adcc0f4 100644 --- a/src/services/utils.spec.ts +++ b/src/services/utils.spec.ts @@ -137,9 +137,45 @@ describe.todo("#timeLimit", () => {}); describe.todo("#deferred", () => {}); -describe.todo("#removeDiacritic", () => {}); +describe("#removeDiacritic", () => { -describe.todo("#normalize", () => {}); + const testCases: TestCase[] = [ + ["w/ 'Äpfel' it should replace the 'Ä'", ["Äpfel"], "Apfel"], + ["w/ 'Été' it should replace the 'É' and 'é'", ["Été"], "Ete"], + ["w/ 'Fête' it should replace the 'ê'", ["Fête"], "Fete"], + ["w/ 'Αλφαβήτα' it should replace the 'ή'", ["Αλφαβήτα"], "Αλφαβητα"], + ["w/ '' (empty string) it should return empty string", [""], ""], + ]; + + testCases.forEach(testCase => { + const [desc, fnParams, expected] = testCase; + it(desc, () => { + const result = utils.removeDiacritic(...fnParams); + expect(result).toStrictEqual(expected); + }); + }); +}); + + +describe("#normalize", () => { + + const testCases: TestCase[] = [ + ["w/ 'Äpfel' it should replace the 'Ä' and return lowercased", ["Äpfel"], "apfel"], + ["w/ 'Été' it should replace the 'É' and 'é' and return lowercased", ["Été"], "ete"], + ["w/ 'FêTe' it should replace the 'ê' and return lowercased", ["FêTe"], "fete"], + ["w/ 'ΑλΦαβήΤα' it should replace the 'ή' and return lowercased", ["ΑλΦαβήΤα"], "αλφαβητα"], + ["w/ '' (empty string) it should return empty string", [""], ""], + ]; + + testCases.forEach(testCase => { + const [desc, fnParams, expected] = testCase; + it(desc, () => { + const result = utils.normalize(...fnParams); + expect(result).toStrictEqual(expected); + }); + }); + +}); describe.todo("#toMap", () => {});