From a3ac2421dfcc58053ec3577d7c623d959d24631b Mon Sep 17 00:00:00 2001 From: Fernando Terra Date: Fri, 10 Jan 2025 15:08:10 -0300 Subject: [PATCH] test: format phone number --- .../services/ForestClientService.spec.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) 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(""); + }); + }); });