Skip to content

Commit 1f599fb

Browse files
committed
test(angular): updated failing angular tests
1 parent 0e26e9a commit 1f599fb

File tree

10 files changed

+6518
-331
lines changed

10 files changed

+6518
-331
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3+
"version": 1,
4+
"newProjectRoot": "projects",
5+
"projects": {
6+
"firebase-ui-angular": {
7+
"projectType": "library",
8+
"root": "",
9+
"sourceRoot": "src",
10+
"prefix": "lib",
11+
"architect": {
12+
"build": {
13+
"builder": "@angular-devkit/build-angular:ng-packagr",
14+
"options": {
15+
"project": "ng-package.json"
16+
}
17+
},
18+
"test": {
19+
"builder": "@angular-devkit/build-angular:karma",
20+
"options": {
21+
"main": "src/test.ts",
22+
"tsConfig": "tsconfig.spec.json",
23+
"karmaConfig": "karma.conf.js",
24+
"polyfills": ["zone.js", "zone.js/testing"],
25+
"styles": [],
26+
"scripts": [],
27+
"assets": [],
28+
"include": [
29+
"src/**/*.spec.ts",
30+
"src/**/*.d.ts"
31+
]
32+
}
33+
}
34+
}
35+
}
36+
}
37+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
// Karma configuration file, see link for more information
18+
// https://karma-runner.github.io/1.0/config/configuration-file.html
19+
20+
module.exports = function (config) {
21+
config.set({
22+
basePath: "",
23+
frameworks: ["jasmine", "@angular-devkit/build-angular"],
24+
plugins: [
25+
require("karma-jasmine"),
26+
require("karma-chrome-launcher"),
27+
require("karma-jasmine-html-reporter"),
28+
require("karma-coverage"),
29+
require("@angular-devkit/build-angular/plugins/karma"),
30+
],
31+
client: {
32+
jasmine: {
33+
// you can add configuration options for Jasmine here
34+
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
35+
// for example, you can disable the random execution order
36+
// random: false
37+
},
38+
clearContext: false, // leave Jasmine Spec Runner output visible in browser
39+
},
40+
jasmineHtmlReporter: {
41+
suppressAll: true, // removes the duplicated traces
42+
},
43+
coverageReporter: {
44+
dir: require("path").join(__dirname, "./coverage/"),
45+
subdir: ".",
46+
reporters: [{ type: "html" }, { type: "text-summary" }],
47+
},
48+
reporters: ["progress", "kjhtml"],
49+
browsers: ["ChromeHeadless"],
50+
restartOnFileChange: true,
51+
});
52+
};

packages/firebaseui-angular/src/lib/auth/forms/email-password-form/email-password-form.component.spec.ts

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@
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";
1919
import {
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
3232
declare 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
})
4747
class 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
})
5757
class 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

Comments
 (0)