1414 * limitations under the License.
1515 */
1616
17- import { CommonModule } from ' @angular/common' ;
18- import { Component , Input } from ' @angular/core' ;
17+ import { CommonModule } from " @angular/common" ;
18+ import { Component , Input } from " @angular/core" ;
1919import {
2020 ComponentFixture ,
2121 TestBed ,
2222 fakeAsync ,
2323 tick ,
24- } from ' @angular/core/testing' ;
25- import { By } from ' @angular/platform-browser' ;
26- import { Router , provideRouter } from ' @angular/router' ;
27- import { TanStackField } from ' @tanstack/angular-form' ;
28- import { getFirebaseUITestProviders } from ' ../../../testing/test-helpers' ;
29- import { EmailPasswordFormComponent } from ' ./email-password-form.component' ;
24+ } from " @angular/core/testing" ;
25+ import { By } from " @angular/platform-browser" ;
26+ import { Router , provideRouter } from " @angular/router" ;
27+ import { TanStackField } from " @tanstack/angular-form" ;
28+ import { getFirebaseUITestProviders } from " ../../../testing/test-helpers" ;
29+ import { EmailPasswordFormComponent } from " ./email-password-form.component" ;
3030
3131// Define window properties for testing
3232declare global {
@@ -38,42 +38,42 @@ declare global {
3838
3939// Mock Button component
4040@Component ( {
41- selector : ' fui-button' ,
41+ selector : " fui-button" ,
4242 template : `<button (click)="click.emit()" data-testid="submit-button">
4343 <ng-content></ng-content>
4444 </button>` ,
4545 standalone : true ,
4646} )
4747class MockButtonComponent {
48- @Input ( ) type : string = ' button' ;
48+ @Input ( ) type : string = " button" ;
4949}
5050
5151// Mock TermsAndPrivacy component
5252@Component ( {
53- selector : ' fui-terms-and-privacy' ,
53+ selector : " fui-terms-and-privacy" ,
5454 template : `<div data-testid="terms-and-privacy"></div>` ,
5555 standalone : true ,
5656} )
5757class MockTermsAndPrivacyComponent { }
5858
59- describe ( ' EmailPasswordFormComponent' , ( ) => {
59+ describe ( " EmailPasswordFormComponent" , ( ) => {
6060 let component : EmailPasswordFormComponent ;
6161 let fixture : ComponentFixture < EmailPasswordFormComponent > ;
6262 let mockRouter : any ;
6363 let signInSpy : jasmine . Spy ;
6464
6565 // Expected error messages from the actual implementation
6666 const errorMessages = {
67- invalidEmail : ' Please enter a valid email address' ,
68- passwordTooShort : ' Password should be at least 8 characters' ,
69- unknownError : ' An unknown error occurred' ,
67+ invalidEmail : " Please enter a valid email address" ,
68+ passwordTooShort : " Password should be at least 8 characters" ,
69+ unknownError : " An unknown error occurred" ,
7070 } ;
7171
7272 // Mock schema returned by createEmailFormSchema
7373 const mockSchema = {
7474 safeParse : ( data : any ) => {
7575 // Test email validation
76- if ( ! data . email . includes ( '@' ) ) {
76+ if ( ! data . email . includes ( "@" ) ) {
7777 return {
7878 success : false ,
7979 error : {
@@ -101,22 +101,22 @@ describe('EmailPasswordFormComponent', () => {
101101 beforeEach ( async ( ) => {
102102 // Mock router
103103 mockRouter = {
104- navigateByUrl : jasmine . createSpy ( ' navigateByUrl' ) ,
104+ navigateByUrl : jasmine . createSpy ( " navigateByUrl" ) ,
105105 } ;
106106
107107 // Create spies for the global functions
108108 signInSpy = jasmine
109- . createSpy ( ' signInWithEmailAndPassword' )
109+ . createSpy ( " signInWithEmailAndPassword" )
110110 . and . returnValue ( Promise . resolve ( ) ) ;
111111
112112 // Define the function on the window object
113- Object . defineProperty ( window , ' signInWithEmailAndPassword' , {
113+ Object . defineProperty ( window , " signInWithEmailAndPassword" , {
114114 value : signInSpy ,
115115 writable : true ,
116116 configurable : true ,
117117 } ) ;
118118
119- Object . defineProperty ( window , ' createEmailFormSchema' , {
119+ Object . defineProperty ( window , " createEmailFormSchema" , {
120120 value : ( ) => mockSchema ,
121121 writable : true ,
122122 configurable : true ,
@@ -141,17 +141,17 @@ describe('EmailPasswordFormComponent', () => {
141141 component = fixture . componentInstance ;
142142
143143 // Set required inputs
144- component . forgotPasswordRoute = ' /forgot-password' ;
145- component . registerRoute = ' /register' ;
144+ component . forgotPasswordRoute = " /forgot-password" ;
145+ component . registerRoute = " /register" ;
146146
147147 // Mock the validateAndSignIn method without any TypeScript errors
148- component . validateAndSignIn = jasmine . createSpy ( ' validateAndSignIn' ) ;
148+ component . validateAndSignIn = jasmine . createSpy ( " validateAndSignIn" ) ;
149149
150150 fixture . detectChanges ( ) ;
151151 await fixture . whenStable ( ) ; // Wait for async ngOnInit
152152 } ) ;
153153
154- it ( ' renders the form correctly' , ( ) => {
154+ it ( " renders the form correctly" , ( ) => {
155155 expect ( component ) . toBeTruthy ( ) ;
156156
157157 // Check essential elements are present
@@ -162,26 +162,26 @@ describe('EmailPasswordFormComponent', () => {
162162 By . css ( 'input[type="password"]' )
163163 ) ;
164164 const termsAndPrivacy = fixture . debugElement . query (
165- By . css ( ' fui-terms-and-privacy' )
165+ By . css ( " fui-terms-and-privacy" )
166166 ) ;
167- const submitButton = fixture . debugElement . query ( By . css ( ' fui-button' ) ) ;
167+ const submitButton = fixture . debugElement . query ( By . css ( " fui-button" ) ) ;
168168
169169 expect ( emailInput ) . toBeTruthy ( ) ;
170170 expect ( passwordInput ) . toBeTruthy ( ) ;
171171 expect ( termsAndPrivacy ) . toBeTruthy ( ) ;
172172 expect ( submitButton ) . toBeTruthy ( ) ;
173173 } ) ;
174174
175- it ( ' submits the form when handleSubmit is called' , fakeAsync ( ( ) => {
175+ it ( " submits the form when handleSubmit is called" , fakeAsync ( ( ) => {
176176 // Set values directly on the form state
177- component . form . state . values . email = ' [email protected] ' ; 178- component . form . state . values . password = ' password123' ;
177+ component . form . state . values . email = " [email protected] " ; 178+ component . form . state . values . password = " password123" ;
179179
180180 // Create a submit event
181- const event = new Event ( ' submit' ) ;
181+ const event = new Event ( " submit" ) ;
182182 Object . defineProperties ( event , {
183- preventDefault : { value : jasmine . createSpy ( ' preventDefault' ) } ,
184- stopPropagation : { value : jasmine . createSpy ( ' stopPropagation' ) } ,
183+ preventDefault : { value : jasmine . createSpy ( " preventDefault" ) } ,
184+ stopPropagation : { value : jasmine . createSpy ( " stopPropagation" ) } ,
185185 } ) ;
186186
187187 // Call handleSubmit directly
@@ -190,62 +190,62 @@ describe('EmailPasswordFormComponent', () => {
190190
191191 // Check if validateAndSignIn was called with correct values
192192 expect ( component . validateAndSignIn ) . toHaveBeenCalledWith (
193- 194- ' password123'
193+ 194+ " password123"
195195 ) ;
196196 } ) ) ;
197197
198- it ( ' displays error message when sign in fails' , fakeAsync ( ( ) => {
198+ it ( " displays error message when sign in fails" , fakeAsync ( ( ) => {
199199 // Manually set the error
200- component . formError = ' Invalid credentials' ;
200+ component . formError = " Invalid credentials" ;
201201 fixture . detectChanges ( ) ;
202202
203203 // Check that the error message is displayed in the DOM
204- const formErrorEl = fixture . debugElement . query ( By . css ( ' .fui-form__error' ) ) ;
204+ const formErrorEl = fixture . debugElement . query ( By . css ( " .fui-form__error" ) ) ;
205205 expect ( formErrorEl ) . toBeTruthy ( ) ;
206206 expect ( formErrorEl . nativeElement . textContent . trim ( ) ) . toBe (
207- ' Invalid credentials'
207+ " Invalid credentials"
208208 ) ;
209209 } ) ) ;
210210
211- it ( ' shows an error message for invalid input' , ( ) => {
211+ it ( " shows an error message for invalid input" , ( ) => {
212212 // Manually set error message for testing
213213 component . formError = errorMessages . invalidEmail ;
214214 fixture . detectChanges ( ) ;
215215
216216 // Check for error display in the DOM
217- const formErrorEl = fixture . debugElement . query ( By . css ( ' .fui-form__error' ) ) ;
217+ const formErrorEl = fixture . debugElement . query ( By . css ( " .fui-form__error" ) ) ;
218218 expect ( formErrorEl ) . toBeTruthy ( ) ;
219219 expect ( formErrorEl . nativeElement . textContent . trim ( ) ) . toBe (
220220 errorMessages . invalidEmail
221221 ) ;
222222 } ) ;
223223
224- it ( ' navigates to register route when that button is clicked' , ( ) => {
224+ it ( " navigates to register route when that button is clicked" , ( ) => {
225225 // Find the register button (second action button)
226226 const registerButton = fixture . debugElement . queryAll (
227- By . css ( ' .fui-form__action' )
227+ By . css ( " .fui-form__action" )
228228 ) [ 1 ] ;
229229 expect ( registerButton ) . toBeTruthy ( ) ;
230230
231231 // Click the button
232232 registerButton . nativeElement . click ( ) ;
233233
234234 // Check navigation was triggered
235- expect ( mockRouter . navigateByUrl ) . toHaveBeenCalledWith ( ' /register' ) ;
235+ expect ( mockRouter . navigateByUrl ) . toHaveBeenCalledWith ( " /register" ) ;
236236 } ) ;
237237
238- it ( ' navigates to forgot password route when that button is clicked' , ( ) => {
238+ it ( " navigates to forgot password route when that button is clicked" , ( ) => {
239239 // Find the forgot password button (first action button)
240240 const forgotPasswordButton = fixture . debugElement . queryAll (
241- By . css ( ' .fui-form__action' )
241+ By . css ( " .fui-form__action" )
242242 ) [ 0 ] ;
243243 expect ( forgotPasswordButton ) . toBeTruthy ( ) ;
244244
245245 // Click the button
246246 forgotPasswordButton . nativeElement . click ( ) ;
247247
248248 // Check navigation was triggered
249- expect ( mockRouter . navigateByUrl ) . toHaveBeenCalledWith ( ' /forgot-password' ) ;
249+ expect ( mockRouter . navigateByUrl ) . toHaveBeenCalledWith ( " /forgot-password" ) ;
250250 } ) ;
251251} ) ;
0 commit comments