From 2585c47de8056d3834c614f9653a2ebefbe25a64 Mon Sep 17 00:00:00 2001 From: sahil Date: Wed, 5 Nov 2025 16:33:56 +0530 Subject: [PATCH] =?UTF-8?q?Fixed=20bug=20[Bug]=20=20Fixes=20#2435?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/utils/src/namespaces/fonts.ts | 11 +++++++++ libs/utils/src/namespaces/tests/fonts.test.ts | 24 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 libs/utils/src/namespaces/tests/fonts.test.ts diff --git a/libs/utils/src/namespaces/fonts.ts b/libs/utils/src/namespaces/fonts.ts index 14fcc09d..4af07c5b 100644 --- a/libs/utils/src/namespaces/fonts.ts +++ b/libs/utils/src/namespaces/fonts.ts @@ -6,7 +6,18 @@ export type Font = { files: Record; }; +/** + * Known system fonts we consider available locally without fetching from Google Fonts. + * Extend this list when adding more system-safe families to the app. + */ export const localFonts = ["Arial", "Cambria", "Garamond", "Times New Roman"]; + +/** + * Checks whether a font family is a local/system font. + * + * Input: font family name (case-insensitive) + * Output: true if present in localFonts, otherwise false + */ export const isLocalFont = (family: string): boolean => localFonts.some((f) => f.toLowerCase() === family.toLowerCase()); diff --git a/libs/utils/src/namespaces/tests/fonts.test.ts b/libs/utils/src/namespaces/tests/fonts.test.ts new file mode 100644 index 00000000..ec1832e7 --- /dev/null +++ b/libs/utils/src/namespaces/tests/fonts.test.ts @@ -0,0 +1,24 @@ +import { describe, it, expect } from "vitest"; +import { isLocalFont, localFonts } from "../fonts"; + +describe("isLocalFont", () => { + it("returns true for known local fonts (case-insensitive)", () => { + expect(isLocalFont("Arial")).toBe(true); + expect(isLocalFont("arial")).toBe(true); + expect(isLocalFont("Times New Roman")).toBe(true); + expect(isLocalFont("times new roman")).toBe(true); + }); + + it("returns false for non-local fonts", () => { + expect(isLocalFont("Roboto")).toBe(false); + expect(isLocalFont("Open Sans")).toBe(false); + }); +}); + +describe("localFonts", () => { + it("includes the expected base set", () => { + for (const f of ["Arial", "Cambria", "Garamond", "Times New Roman"]) { + expect(localFonts).toContain(f); + } + }); +});