@@ -22,7 +22,8 @@ import {
2222 useSignUpAuthFormSchema ,
2323 useForgotPasswordAuthFormSchema ,
2424 useEmailLinkAuthFormSchema ,
25- usePhoneAuthFormSchema ,
25+ usePhoneAuthNumberFormSchema ,
26+ usePhoneAuthVerifyFormSchema ,
2627} from "./hooks" ;
2728import { createFirebaseUIProvider , createMockUI } from "~/tests/utils" ;
2829import { registerLocale , enUs } from "@firebase-ui/translations" ;
@@ -508,7 +509,7 @@ describe("useEmailLinkAuthFormSchema", () => {
508509 } ) ;
509510} ) ;
510511
511- describe ( "usePhoneAuthFormSchema " , ( ) => {
512+ describe ( "usePhoneAuthNumberFormSchema " , ( ) => {
512513 beforeEach ( ( ) => {
513514 vi . clearAllMocks ( ) ;
514515 cleanup ( ) ;
@@ -517,7 +518,7 @@ describe("usePhoneAuthFormSchema", () => {
517518 it ( "returns schema with default English error messages" , ( ) => {
518519 const mockUI = createMockUI ( ) ;
519520
520- const { result } = renderHook ( ( ) => usePhoneAuthFormSchema ( ) , {
521+ const { result } = renderHook ( ( ) => usePhoneAuthNumberFormSchema ( ) , {
521522 wrapper : ( { children } ) => createFirebaseUIProvider ( { children, ui : mockUI } ) ,
522523 } ) ;
523524
@@ -540,7 +541,7 @@ describe("usePhoneAuthFormSchema", () => {
540541 const customLocale = registerLocale ( "es-ES" , customTranslations ) ;
541542 const mockUI = createMockUI ( { locale : customLocale } ) ;
542543
543- const { result } = renderHook ( ( ) => usePhoneAuthFormSchema ( ) , {
544+ const { result } = renderHook ( ( ) => usePhoneAuthNumberFormSchema ( ) , {
544545 wrapper : ( { children } ) => createFirebaseUIProvider ( { children, ui : mockUI } ) ,
545546 } ) ;
546547
@@ -556,7 +557,7 @@ describe("usePhoneAuthFormSchema", () => {
556557 it ( "returns stable reference when UI hasn't changed" , ( ) => {
557558 const mockUI = createMockUI ( ) ;
558559
559- const { result, rerender } = renderHook ( ( ) => usePhoneAuthFormSchema ( ) , {
560+ const { result, rerender } = renderHook ( ( ) => usePhoneAuthNumberFormSchema ( ) , {
560561 wrapper : ( { children } ) => createFirebaseUIProvider ( { children, ui : mockUI } ) ,
561562 } ) ;
562563
@@ -570,7 +571,7 @@ describe("usePhoneAuthFormSchema", () => {
570571 it ( "returns new schema when locale changes" , ( ) => {
571572 const mockUI = createMockUI ( ) ;
572573
573- const { result, rerender } = renderHook ( ( ) => usePhoneAuthFormSchema ( ) , {
574+ const { result, rerender } = renderHook ( ( ) => usePhoneAuthNumberFormSchema ( ) , {
574575 wrapper : ( { children } ) => createFirebaseUIProvider ( { children, ui : mockUI } ) ,
575576 } ) ;
576577
@@ -599,3 +600,95 @@ describe("usePhoneAuthFormSchema", () => {
599600 }
600601 } ) ;
601602} ) ;
603+
604+ describe ( "usePhoneAuthVerifyFormSchema" , ( ) => {
605+ beforeEach ( ( ) => {
606+ vi . clearAllMocks ( ) ;
607+ cleanup ( ) ;
608+ } ) ;
609+
610+ it ( "returns schema with default English error messages" , ( ) => {
611+ const mockUI = createMockUI ( ) ;
612+
613+ const { result } = renderHook ( ( ) => usePhoneAuthVerifyFormSchema ( ) , {
614+ wrapper : ( { children } ) => createFirebaseUIProvider ( { children, ui : mockUI } ) ,
615+ } ) ;
616+
617+ const schema = result . current ;
618+
619+ const verifyResult = schema . safeParse ( { verificationId : "test-id" , verificationCode : "123" } ) ;
620+ expect ( verifyResult . success ) . toBe ( false ) ;
621+ if ( ! verifyResult . success ) {
622+ expect ( verifyResult . error . issues [ 0 ] ! . message ) . toBe ( enUs . translations . errors ! . invalidVerificationCode ) ;
623+ }
624+ } ) ;
625+
626+ it ( "returns schema with custom error messages when locale changes" , ( ) => {
627+ const customTranslations = {
628+ errors : {
629+ invalidVerificationCode : "Por favor ingresa un código de verificación válido" ,
630+ } ,
631+ } ;
632+
633+ const customLocale = registerLocale ( "es-ES" , customTranslations ) ;
634+ const mockUI = createMockUI ( { locale : customLocale } ) ;
635+
636+ const { result } = renderHook ( ( ) => usePhoneAuthVerifyFormSchema ( ) , {
637+ wrapper : ( { children } ) => createFirebaseUIProvider ( { children, ui : mockUI } ) ,
638+ } ) ;
639+
640+ const schema = result . current ;
641+
642+ const verifyResult = schema . safeParse ( { verificationId : "test-id" , verificationCode : "123" } ) ;
643+ expect ( verifyResult . success ) . toBe ( false ) ;
644+ if ( ! verifyResult . success ) {
645+ expect ( verifyResult . error . issues [ 0 ] ! . message ) . toBe ( "Por favor ingresa un código de verificación válido" ) ;
646+ }
647+ } ) ;
648+
649+ it ( "returns stable reference when UI hasn't changed" , ( ) => {
650+ const mockUI = createMockUI ( ) ;
651+
652+ const { result, rerender } = renderHook ( ( ) => usePhoneAuthVerifyFormSchema ( ) , {
653+ wrapper : ( { children } ) => createFirebaseUIProvider ( { children, ui : mockUI } ) ,
654+ } ) ;
655+
656+ const initialSchema = result . current ;
657+
658+ rerender ( ) ;
659+
660+ expect ( result . current ) . toBe ( initialSchema ) ;
661+ } ) ;
662+
663+ it ( "returns new schema when locale changes" , ( ) => {
664+ const mockUI = createMockUI ( ) ;
665+
666+ const { result, rerender } = renderHook ( ( ) => usePhoneAuthVerifyFormSchema ( ) , {
667+ wrapper : ( { children } ) => createFirebaseUIProvider ( { children, ui : mockUI } ) ,
668+ } ) ;
669+
670+ const initialSchema = result . current ;
671+
672+ const customTranslations = {
673+ errors : {
674+ invalidVerificationCode : "Custom verification error" ,
675+ } ,
676+ } ;
677+ const customLocale = registerLocale ( "fr-FR" , customTranslations ) ;
678+
679+ act ( ( ) => {
680+ mockUI . setKey ( "locale" , customLocale ) ;
681+ } ) ;
682+
683+ rerender ( ) ;
684+
685+ expect ( result . current ) . not . toBe ( initialSchema ) ;
686+
687+ const verifyResult = result . current . safeParse ( { verificationId : "test-id" , verificationCode : "123" } ) ;
688+ expect ( verifyResult . success ) . toBe ( false ) ;
689+
690+ if ( ! verifyResult . success ) {
691+ expect ( verifyResult . error . issues [ 0 ] ! . message ) . toBe ( "Custom verification error" ) ;
692+ }
693+ } ) ;
694+ } ) ;
0 commit comments