@@ -22,7 +22,8 @@ import {
22
22
useSignUpAuthFormSchema ,
23
23
useForgotPasswordAuthFormSchema ,
24
24
useEmailLinkAuthFormSchema ,
25
- usePhoneAuthFormSchema ,
25
+ usePhoneAuthNumberFormSchema ,
26
+ usePhoneAuthVerifyFormSchema ,
26
27
} from "./hooks" ;
27
28
import { createFirebaseUIProvider , createMockUI } from "~/tests/utils" ;
28
29
import { registerLocale , enUs } from "@firebase-ui/translations" ;
@@ -508,7 +509,7 @@ describe("useEmailLinkAuthFormSchema", () => {
508
509
} ) ;
509
510
} ) ;
510
511
511
- describe ( "usePhoneAuthFormSchema " , ( ) => {
512
+ describe ( "usePhoneAuthNumberFormSchema " , ( ) => {
512
513
beforeEach ( ( ) => {
513
514
vi . clearAllMocks ( ) ;
514
515
cleanup ( ) ;
@@ -517,7 +518,7 @@ describe("usePhoneAuthFormSchema", () => {
517
518
it ( "returns schema with default English error messages" , ( ) => {
518
519
const mockUI = createMockUI ( ) ;
519
520
520
- const { result } = renderHook ( ( ) => usePhoneAuthFormSchema ( ) , {
521
+ const { result } = renderHook ( ( ) => usePhoneAuthNumberFormSchema ( ) , {
521
522
wrapper : ( { children } ) => createFirebaseUIProvider ( { children, ui : mockUI } ) ,
522
523
} ) ;
523
524
@@ -540,7 +541,7 @@ describe("usePhoneAuthFormSchema", () => {
540
541
const customLocale = registerLocale ( "es-ES" , customTranslations ) ;
541
542
const mockUI = createMockUI ( { locale : customLocale } ) ;
542
543
543
- const { result } = renderHook ( ( ) => usePhoneAuthFormSchema ( ) , {
544
+ const { result } = renderHook ( ( ) => usePhoneAuthNumberFormSchema ( ) , {
544
545
wrapper : ( { children } ) => createFirebaseUIProvider ( { children, ui : mockUI } ) ,
545
546
} ) ;
546
547
@@ -556,7 +557,7 @@ describe("usePhoneAuthFormSchema", () => {
556
557
it ( "returns stable reference when UI hasn't changed" , ( ) => {
557
558
const mockUI = createMockUI ( ) ;
558
559
559
- const { result, rerender } = renderHook ( ( ) => usePhoneAuthFormSchema ( ) , {
560
+ const { result, rerender } = renderHook ( ( ) => usePhoneAuthNumberFormSchema ( ) , {
560
561
wrapper : ( { children } ) => createFirebaseUIProvider ( { children, ui : mockUI } ) ,
561
562
} ) ;
562
563
@@ -570,7 +571,7 @@ describe("usePhoneAuthFormSchema", () => {
570
571
it ( "returns new schema when locale changes" , ( ) => {
571
572
const mockUI = createMockUI ( ) ;
572
573
573
- const { result, rerender } = renderHook ( ( ) => usePhoneAuthFormSchema ( ) , {
574
+ const { result, rerender } = renderHook ( ( ) => usePhoneAuthNumberFormSchema ( ) , {
574
575
wrapper : ( { children } ) => createFirebaseUIProvider ( { children, ui : mockUI } ) ,
575
576
} ) ;
576
577
@@ -599,3 +600,95 @@ describe("usePhoneAuthFormSchema", () => {
599
600
}
600
601
} ) ;
601
602
} ) ;
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