From edaf8eab30216922dcd01faf7de4f5ca7be116d3 Mon Sep 17 00:00:00 2001 From: Josh Guyette Date: Fri, 5 Jan 2024 13:35:02 -0600 Subject: [PATCH] jest test (wip) --- src/FamilyFriendly.spec.ts | 67 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/FamilyFriendly.spec.ts diff --git a/src/FamilyFriendly.spec.ts b/src/FamilyFriendly.spec.ts new file mode 100644 index 0000000..e4b350c --- /dev/null +++ b/src/FamilyFriendly.spec.ts @@ -0,0 +1,67 @@ +import { FamilyFriendly, FamilyFriendlyOptions } from "./FamilyFriendly"; + +// Mock data for bad words in different languages +const mockEnglishWords = new Set(["badword1", "badword2"]); +const mockArabicWords = new Set(["سيئة1", "سيئة2"]); +const mockChineseWords = new Set(["坏词1", "坏词2"]); +const mockFrenchWords = new Set(["mauvais1", "mauvais2"]); +const mockGermanWords = new Set(["schlecht1", "schlecht2"]); +const mockIndonesianWords = new Set(["buruk1", "buruk2"]); +const mockItalianWords = new Set(["cattivo1", "cattivo2"]); +const mockSpanishWords = new Set(["malo1", "malo2"]); + +jest.mock("./words/english", () => ({ badEnglishWords: mockEnglishWords })); +jest.mock("./words/arabic", () => ({ badArabicWords: mockArabicWords })); +jest.mock("./words/chinese", () => ({ badChineseWords: mockChineseWords })); +jest.mock("./words/french", () => ({ badFrenchWords: mockFrenchWords })); +jest.mock("./words/german", () => ({ badGermanWords: mockGermanWords })); +jest.mock("./words/indonesian", () => ({ + badIndonesianWords: mockIndonesianWords, +})); +jest.mock("./words/italian", () => ({ badItalianWords: mockItalianWords })); +jest.mock("./words/spanish", () => ({ badSpanishWords: mockSpanishWords })); + +describe("FamilyFriendly", () => { + const testOptions: FamilyFriendlyOptions = { + allLanguages: false, + includeEnglish: true, + includeArabic: true, + includeChinese: true, + includeFrench: true, + includeGerman: true, + includeIndonesian: true, + includeItalian: true, + includeSpanish: true, + }; + + const ff = new FamilyFriendly(testOptions); + + it("should include all specified languages", () => { + expect(ff.containsBadWord("badword1")).toBeTruthy(); + expect(ff.containsBadWord("سيئة1")).toBeTruthy(); + expect(ff.containsBadWord("坏词1")).toBeTruthy(); + expect(ff.containsBadWord("mauvais1")).toBeTruthy(); + expect(ff.containsBadWord("schlecht1")).toBeTruthy(); + expect(ff.containsBadWord("buruk1")).toBeTruthy(); + expect(ff.containsBadWord("cattivo1")).toBeTruthy(); + expect(ff.containsBadWord("malo1")).toBeTruthy(); + }); + + it("should return true if a string contains a bad word", () => { + expect(ff.containsBadWord("This sentence has badword1")).toBeTruthy(); + }); + + it("should return false if a string does not contain a bad word", () => { + expect(ff.containsBadWord("This is a clean sentence")).toBeFalsy(); + }); + + it("should mask all bad words in a string", () => { + const testSentence = + "badword1, سيئة1, 坏词1, mauvais1, schlecht1, buruk1, cattivo1, malo1"; + const masked = ff.maskBadWords(testSentence, "*"); + const expectedMasked = "******* **** *** ****** ********* ********** *****"; + expect(masked).toBe(expectedMasked); + }); + + // Additional tests for individual language options and other scenarios can be added here +});