diff --git a/frontend/tests/unittests/services/ForestClientService.spec.ts b/frontend/tests/unittests/services/ForestClientService.spec.ts index 9f32b7d42..0591d13d2 100644 --- a/frontend/tests/unittests/services/ForestClientService.spec.ts +++ b/frontend/tests/unittests/services/ForestClientService.spec.ts @@ -7,6 +7,7 @@ import { toTitleCase, getTagColorByClientStatus, goodStanding, + formatPhoneNumber, } from "@/services/ForestClientService"; import type { Contact, Address } from "@/dto/ApplyClientNumberDto"; @@ -169,4 +170,26 @@ describe("ForestClientService.ts", () => { }); }); }); + + describe("formatPhoneNumber", () => { + it("formats 10-digit phone numbers properly", () => { + const result = formatPhoneNumber("1234567890"); + expect(result).toEqual("(123) 456-7890"); + }); + + it("doesn't crash when phone numbers has more than 10 digits", () => { + const result = formatPhoneNumber("1234567890123"); + expect(result).toEqual("(123) 456-7890123"); + }); + + it("doesn't crash when phone numbers has less than 10 digits", () => { + const result = formatPhoneNumber("12345678"); + expect(result).toEqual("(123) 456-78"); + }); + + it("returns an empty string if phone number is undefined", () => { + const result = formatPhoneNumber(undefined); + expect(result).toEqual(""); + }); + }); });