1414 */
1515
1616import { render , screen , fireEvent , waitFor } from "@testing-library/angular" ;
17- import { TestBed } from "@angular/core/testing" ;
18- import { PhoneMultiFactorGenerator } from "firebase/auth" ;
1917
2018import {
2119 SmsMultiFactorAssertionFormComponent ,
@@ -26,13 +24,18 @@ import {
2624import {
2725 verifyPhoneNumber ,
2826 signInWithMultiFactorAssertion ,
29- FirebaseUIError ,
27+ PhoneMultiFactorGenerator ,
3028} from "../../../tests/test-helpers" ;
3129
3230describe ( "<fui-sms-multi-factor-assertion-form>" , ( ) => {
3331 beforeEach ( ( ) => {
34- const { injectTranslation, injectUI, injectMultiFactorPhoneAuthNumberFormSchema, injectMultiFactorPhoneAuthVerifyFormSchema } = require ( "../../../provider" ) ;
35-
32+ const {
33+ injectTranslation,
34+ injectUI,
35+ injectMultiFactorPhoneAuthNumberFormSchema,
36+ injectMultiFactorPhoneAuthVerifyFormSchema,
37+ } = require ( "../../../tests/test-helpers" ) ;
38+
3639 injectTranslation . mockImplementation ( ( category : string , key : string ) => {
3740 const mockTranslations : Record < string , Record < string , string > > = {
3841 labels : {
@@ -144,17 +147,29 @@ describe("<fui-sms-multi-factor-assertion-form>", () => {
144147 fixture . componentInstance . onSuccess . subscribe ( onSuccessSpy ) ;
145148
146149 // Submit phone form to get to verification form
147- fireEvent . click ( screen . getByRole ( "button" , { name : "Send Code" } ) ) ;
150+ const phoneFormComponent = fixture . debugElement . query (
151+ ( el ) => el . componentInstance ?. constructor ?. name === "SmsMultiFactorAssertionPhoneFormComponent"
152+ ) ?. componentInstance ;
153+
154+ if ( phoneFormComponent ) {
155+ phoneFormComponent . form . setFieldValue ( "phoneNumber" , "+1234567890" ) ;
156+ await phoneFormComponent . form . handleSubmit ( ) ;
157+ }
148158
149159 await waitFor ( ( ) => {
150160 expect ( screen . getByLabelText ( "Verification Code" ) ) . toBeInTheDocument ( ) ;
151161 } ) ;
152162
153163 // Fill in verification code and submit
154- fireEvent . change ( screen . getByLabelText ( "Verification Code" ) , {
155- target : { value : "123456" } ,
156- } ) ;
157- fireEvent . click ( screen . getByRole ( "button" , { name : "Verify Code" } ) ) ;
164+ const verifyFormComponent = fixture . debugElement . query (
165+ ( el ) => el . componentInstance ?. constructor ?. name === "SmsMultiFactorAssertionVerifyFormComponent"
166+ ) ?. componentInstance ;
167+
168+ if ( verifyFormComponent ) {
169+ verifyFormComponent . form . setFieldValue ( "verificationCode" , "123456" ) ;
170+ verifyFormComponent . form . setFieldValue ( "verificationId" , "test-verification-id" ) ;
171+ await verifyFormComponent . form . handleSubmit ( ) ;
172+ }
158173
159174 await waitFor ( ( ) => {
160175 expect ( onSuccessSpy ) . toHaveBeenCalled ( ) ;
@@ -164,8 +179,12 @@ describe("<fui-sms-multi-factor-assertion-form>", () => {
164179
165180describe ( "<fui-sms-multi-factor-assertion-phone-form>" , ( ) => {
166181 beforeEach ( ( ) => {
167- const { injectTranslation, injectUI, injectMultiFactorPhoneAuthNumberFormSchema } = require ( "../../../provider" ) ;
168-
182+ const {
183+ injectTranslation,
184+ injectUI,
185+ injectMultiFactorPhoneAuthNumberFormSchema,
186+ } = require ( "../../../tests/test-helpers" ) ;
187+
169188 injectTranslation . mockImplementation ( ( category : string , key : string ) => {
170189 const mockTranslations : Record < string , Record < string , string > > = {
171190 labels : {
@@ -242,8 +261,12 @@ describe("<fui-sms-multi-factor-assertion-phone-form>", () => {
242261
243262describe ( "<fui-sms-multi-factor-assertion-verify-form>" , ( ) => {
244263 beforeEach ( ( ) => {
245- const { injectTranslation, injectUI, injectMultiFactorPhoneAuthVerifyFormSchema } = require ( "../../../provider" ) ;
246-
264+ const {
265+ injectTranslation,
266+ injectUI,
267+ injectMultiFactorPhoneAuthVerifyFormSchema,
268+ } = require ( "../../../tests/test-helpers" ) ;
269+
247270 injectTranslation . mockImplementation ( ( category : string , key : string ) => {
248271 const mockTranslations : Record < string , Record < string , string > > = {
249272 labels : {
@@ -303,10 +326,10 @@ describe("<fui-sms-multi-factor-assertion-verify-form>", () => {
303326 fixture . componentInstance . onSuccess . subscribe ( onSuccessSpy ) ;
304327
305328 // Fill in verification code and submit
306- fireEvent . change ( screen . getByLabelText ( "Verification Code" ) , {
307- target : { value : "123456" } ,
308- } ) ;
309- fireEvent . click ( screen . getByRole ( "button" , { name : "Verify Code" } ) ) ;
329+ const component = fixture . componentInstance ;
330+ component . form . setFieldValue ( "verificationCode" , "123456" ) ;
331+ component . form . setFieldValue ( "verificationId" , "test-verification-id" ) ;
332+ await component . form . handleSubmit ( ) ;
310333
311334 await waitFor ( ( ) => {
312335 expect ( onSuccessSpy ) . toHaveBeenCalled ( ) ;
0 commit comments